예제 #1
0
        public StbTextBox(List <string> parts, string[] lines) : this
            (
                1,
                parts[0] == "textentrylimited" ? int.Parse(parts[8]) : byte.MaxValue,
                int.Parse(parts[3]),
                style : FontStyle.BlackBorder | FontStyle.CropTexture,
                hue : (ushort)(UInt16Converter.Parse(parts[5]) + 1)
            )
        {
            X            = int.Parse(parts[1]);
            Y            = int.Parse(parts[2]);
            Width        = _rendererText.MaxWidth; //int.Parse(parts[3]);
            Height       = _rendererText.MaxHeight = int.Parse(parts[4]);
            Multiline    = false;
            _fromServer  = true;
            LocalSerial  = SerialHelper.Parse(parts[6]);
            IsFromServer = true;

            int index = int.Parse(parts[7]);

            if (index >= 0 && index < lines.Length)
            {
                SetText(lines[index]);
            }
        }
예제 #2
0
 public Checkbox(List <string> parts, string[] lines) : this(ushort.Parse(parts[3]), ushort.Parse(parts[4]))
 {
     X           = int.Parse(parts[1]);
     Y           = int.Parse(parts[2]);
     IsChecked   = parts[5] == "1";
     LocalSerial = SerialHelper.Parse(parts[6]);
 }
예제 #3
0
        public TextBox(List <string> parts, string[] lines) : this(1, parts[0] == "textentrylimited" ? int.Parse(parts[8]) : byte.MaxValue, 0, int.Parse(parts[3]), style : FontStyle.BlackBorder | FontStyle.CropTexture, hue : (ushort)(UInt16Converter.Parse(parts[5]) + 1))
        {
            X           = int.Parse(parts[1]);
            Y           = int.Parse(parts[2]);
            Width       = int.Parse(parts[3]);
            Height      = int.Parse(parts[4]);
            LocalSerial = SerialHelper.Parse(parts[6]);
            TxEntry.SetHeight(Height);

            int index = int.Parse(parts[7]);

            if (index >= 0 && index < lines.Length)
            {
                SetText(lines[index]);
            }
        }
예제 #4
0
        public static Control Create(uint sender, uint gumpID, int x, int y, string layout, string[] lines)
        {
            Gump gump        = null;
            bool mustBeAdded = true;

            if (GetGumpCachePosition(gumpID, out Point pos))
            {
                x = pos.X;
                y = pos.Y;

                for (var last = Gumps.Last; last != null; last = last.Previous)
                {
                    var g = last.Value;

                    if (!g.IsDisposed && g.LocalSerial == sender && g.ServerSerial == gumpID)
                    {
                        g.Clear();
                        gump        = g as Gump;
                        mustBeAdded = false;
                        break;
                    }
                }
            }
            else
            {
                SavePosition(gumpID, new Point(x, y));
            }

            if (gump == null)
            {
                gump = new Gump(sender, gumpID)
                {
                    X       = x,
                    Y       = y,
                    CanMove = true,
                    CanCloseWithRightClick = true,
                    CanCloseWithEsc        = true
                }
            }
            ;
            int group = 0;
            int page  = 0;

            List <string> cmdlist           = _parser.GetTokens(layout);
            int           cmdlen            = cmdlist.Count;
            bool          applyCheckerTrans = false;
            bool          textBoxFocused    = false;

            for (int cnt = 0; cnt < cmdlen; cnt++)
            {
                List <string> gparams = _cmdparser.GetTokens(cmdlist[cnt], false);

                if (gparams.Count == 0)
                {
                    continue;
                }

                switch (gparams[0].ToLower())
                {
                case "button":
                    gump.Add(new Button(gparams), page);

                    break;

                case "buttontileart":

                    gump.Add(new ButtonTileArt(gparams), page);

                    break;

                case "checkertrans":
                    applyCheckerTrans = true;
                    gump.Add(new CheckerTrans(gparams), page);

                    break;

                case "croppedtext":
                    gump.Add(new CroppedText(gparams, lines), page);

                    break;

                case "gumppic":

                    GumpPic pic = new GumpPic(gparams);

                    if (gparams.Count >= 6 && gparams[5].ToLower().Contains("virtuegumpitem"))
                    {
                        pic.ContainsByBounds = true;
                        pic.IsVirtue         = true;

                        string s, lvl;

                        switch (pic.Hue)
                        {
                        case 2403:
                            lvl = "";
                            break;

                        case 1154:
                        case 1547:
                        case 2213:
                        case 235:
                        case 18:
                        case 2210:
                        case 1348:
                            lvl = "Seeker of ";
                            break;

                        case 2404:
                        case 1552:
                        case 2216:
                        case 2302:
                        case 2118:
                        case 618:
                        case 2212:
                        case 1352:
                            lvl = "Follower of ";
                            break;

                        case 43:
                        case 53:
                        case 1153:
                        case 33:
                        case 318:
                        case 67:
                        case 98:
                            lvl = "Knight of ";
                            break;

                        case 2406:
                            if (pic.Graphic == 0x6F)
                            {
                                lvl = "Seeker of ";
                            }
                            else
                            {
                                lvl = "Knight of ";
                            }
                            break;

                        default:
                            lvl = "";
                            break;
                        }

                        switch (pic.Graphic)
                        {
                        case 0x69:
                            s = ClilocLoader.Instance.GetString(1051000 + 2);
                            break;

                        case 0x6A:
                            s = ClilocLoader.Instance.GetString(1051000 + 7);
                            break;

                        case 0x6B:
                            s = ClilocLoader.Instance.GetString(1051000 + 5);
                            break;

                        case 0x6D:
                            s = ClilocLoader.Instance.GetString(1051000 + 6);
                            break;

                        case 0x6E:
                            s = ClilocLoader.Instance.GetString(1051000 + 1);
                            break;

                        case 0x6F:
                            s = ClilocLoader.Instance.GetString(1051000 + 3);
                            break;

                        case 0x70:
                            s = ClilocLoader.Instance.GetString(1051000 + 4);
                            break;

                        case 0x6C:
                        default:
                            s = ClilocLoader.Instance.GetString(1051000);
                            break;
                        }

                        if (string.IsNullOrEmpty(s))
                        {
                            s = "Unknown virtue";
                        }

                        pic.SetTooltip(lvl + s, 100);
                    }

                    gump.Add(pic, page);

                    break;

                case "gumppictiled":
                    gump.Add(new GumpPicTiled(gparams), page);

                    break;

                case "htmlgump":
                    gump.Add(new HtmlControl(gparams, lines), page);

                    break;

                case "xmfhtmlgump":
                    gump.Add(new HtmlControl(int.Parse(gparams[1]), int.Parse(gparams[2]), int.Parse(gparams[3]), int.Parse(gparams[4]), int.Parse(gparams[6]) == 1, int.Parse(gparams[7]) != 0, gparams[6] != "0" && gparams[7] == "2", ClilocLoader.Instance.GetString(int.Parse(gparams[5])), 0, true), page);

                    break;

                case "xmfhtmlgumpcolor":
                    int color = int.Parse(gparams[8]);

                    if (color == 0x7FFF)
                    {
                        color = 0x00FFFFFF;
                    }
                    gump.Add(new HtmlControl(int.Parse(gparams[1]), int.Parse(gparams[2]), int.Parse(gparams[3]), int.Parse(gparams[4]), int.Parse(gparams[6]) == 1, int.Parse(gparams[7]) != 0, gparams[6] != "0" && gparams[7] == "2", ClilocLoader.Instance.GetString(int.Parse(gparams[5])), color, true), page);

                    break;

                case "xmfhtmltok":
                    color = int.Parse(gparams[7]);

                    if (color == 0x7FFF)
                    {
                        color = 0x00FFFFFF;
                    }
                    StringBuilder sb = null;

                    if (gparams.Count > 9)
                    {
                        sb = new StringBuilder();
                        sb.Append(gparams[9]);

                        for (int i = 10; i < gparams.Count; i++)
                        {
                            sb.Append(' ');
                            sb.Append(gparams[i]);
                        }
                    }

                    gump.Add(new HtmlControl(int.Parse(gparams[1]), int.Parse(gparams[2]), int.Parse(gparams[3]), int.Parse(gparams[4]), int.Parse(gparams[5]) == 1, int.Parse(gparams[6]) != 0, gparams[5] != "0" && gparams[6] == "2", sb == null ? ClilocLoader.Instance.GetString(int.Parse(gparams[8])) : ClilocLoader.Instance.Translate(ClilocLoader.Instance.GetString(int.Parse(gparams[8])), sb.ToString().Trim('@').Replace('@', '\t')), color, true), page);

                    break;

                case "page":

                    if (gparams.Count >= 2)
                    {
                        page = int.Parse(gparams[1]);
                    }

                    break;

                case "resizepic":
                    gump.Add(new ResizePic(gparams), page);

                    break;

                case "text":
                    if (gparams.Count >= 5)
                    {
                        gump.Add(new Label(gparams, lines), page);
                    }

                    break;

                case "textentrylimited":
                case "textentry":
                    TextBox textBox = new TextBox(gparams, lines);

                    if (!textBoxFocused)
                    {
                        textBox.SetKeyboardFocus();
                        textBoxFocused = true;
                    }

                    gump.Add(textBox, page);

                    break;

                case "tilepichue":
                case "tilepic":
                    gump.Add(new StaticPic(gparams), page);

                    break;

                case "noclose":
                    gump.CanCloseWithRightClick = false;

                    break;

                case "nodispose":
                    gump.CanCloseWithEsc = false;

                    break;

                case "nomove":
                    gump.BlockMovement = true;

                    break;

                case "group":
                case "endgroup":
                    group++;

                    break;

                case "radio":
                    gump.Add(new RadioButton(group, gparams, lines), page);

                    break;

                case "checkbox":
                    gump.Add(new Checkbox(gparams, lines), page);

                    break;

                case "tooltip":

                    if (World.ClientFeatures.TooltipsEnabled)
                    {
                        string text = ClilocLoader.Instance.GetString(int.Parse(gparams[1]));

                        if (gparams.Count > 2 && gparams[2].Length != 0)
                        {
                            string args = gparams[2];

                            if (args.Length > 1)
                            {
                                text = ClilocLoader.Instance.Translate(text, args);
                            }
                            else
                            {
                                Log.Error($"String '{args}' too short, something wrong with gump tooltip: {text}");
                            }
                        }

                        gump.Children.LastOrDefault()?.SetTooltip(text);
                    }

                    break;

                case "itemproperty":

                    if (World.ClientFeatures.TooltipsEnabled)
                    {
                        gump.Children.LastOrDefault()?.SetTooltip(SerialHelper.Parse(gparams[1]));
                    }

                    break;

                case "noresize":

                    break;

                case "mastergump":
                    Log.Warn("Gump part 'mastergump' not handled.");

                    break;

                default:
                    Log.Warn(gparams[0]);
                    break;
                }
            }

            if (applyCheckerTrans)
            {
                bool applyTrans(int ii, int current_page)
                {
                    bool transparent = false;

                    for (; ii < gump.Children.Count; ii++)
                    {
                        var child = gump.Children[ii];

                        if (current_page == 0)
                        {
                            current_page = child.Page;
                        }

                        bool canDraw = /*current_page == 0 || child.Page == 0 ||*/
                                       current_page == child.Page;

                        if (canDraw && child.IsVisible && child is CheckerTrans)
                        {
                            transparent = true;
                            continue;
                        }

                        child.Alpha = transparent ? 0.5f : 0;
                    }

                    return(transparent);
                }

                bool  trans = applyTrans(0, 0);
                float alpha = trans ? 0.5f : 0;
                for (int i = 0; i < gump.Children.Count; i++)
                {
                    var cc = gump.Children[i];

                    if (cc is CheckerTrans)
                    {
                        trans = applyTrans(i + 1, cc.Page);
                        alpha = trans ? 0.5f : 0;
                    }
                    else
                    {
                        cc.Alpha = alpha;
                    }
                }
            }

            if (mustBeAdded)
            {
                Add(gump);
            }

            gump.Update(Time.Ticks, 0);
            gump.SetInScreen();

            return(gump);
        }