コード例 #1
0
ファイル: UIManager.cs プロジェクト: Juzzver/MobileUO
        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);
        }
コード例 #2
0
ファイル: UIManager.cs プロジェクト: xoozyx/ClassicUO
        public static Control Create(Serial sender, Serial gumpID, int x, int y, string layout, string[] lines)
        {
            if (GetGumpCachePosition(gumpID, out Point pos))
            {
                x = pos.X;
                y = pos.Y;
            }
            else
            {
                SavePosition(gumpID, new Point(x, y));
            }

            Gump 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;

            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 Button(gparams)
                    {
                        ContainsByBounds = true
                    }, page);

                    gump.Add(new StaticPic(Graphic.Parse(gparams[8]), Hue.Parse(gparams[9]))
                    {
                        X = int.Parse(gparams[1]) + int.Parse(gparams[10]),
                        Y = int.Parse(gparams[2]) + int.Parse(gparams[11]),

                        AcceptMouseInput = true
                    }, page);

                    break;

                case "checkertrans":
                    CheckerTrans t = new CheckerTrans(gparams);

                    applyCheckerTrans = true;
                    //bool applyTrans(int ii, int current_page)
                    //{
                    //    bool transparent = false;
                    //    for (; ii < gump.Children.Count; ii++)
                    //    {
                    //        var child = gump.Children[ii];

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

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

                    //    return transparent;
                    //}

                    //void checkerContains(int ii, float tr)
                    //{
                    //    var master = gump.Children[ii];

                    //    for (int i = 0; i < ii; i++)
                    //    {
                    //        var cc = gump.Children[i];

                    //        if (master.Bounds.Contains(cc.Bounds))
                    //        {
                    //            cc.Alpha = 1f;
                    //        }
                    //    }
                    //}

                    //Rectangle bounds = t.Bounds;
                    //bool trans = false;
                    //for (int i = gump.Children.Count - 1; i >= 0; i--)
                    //{
                    //    var cc = gump.Children[i];

                    //    if (cc is CheckerTrans)
                    //    {
                    //        trans = applyTrans(i, cc.Page);
                    //        bounds = cc.Bounds;
                    //        continue;
                    //    }

                    //    if (bounds.Contains(cc.Bounds))
                    //    {
                    //        cc.Alpha = 1f;
                    //    }
                    //    else
                    //        cc.Alpha = trans ? 1 : 0.5f;
                    //}

                    gump.Add(t, page);

                    //  int j = 0;
                    //  bool trans = applyTrans(j, page, null);
                    //  float alpha = trans ? 1 : 0.5f;
                    ////  checkerContains(j, alpha);
                    //  for (; j < gump.Children.Count; j++)
                    //  {
                    //      var child = gump.Children[j];

                    //      if (child is CheckerTrans tt)
                    //      {
                    //          trans = applyTrans(j, child.Page, tt);
                    //          alpha = trans ? 1 : .5f;
                    //          checkerContains(j, alpha);
                    //      }
                    //      else
                    //      {
                    //          child.Alpha = alpha != 1 ? 0.5f : alpha;
                    //      }
                    //  }


                    //float[] alpha = { 1f, 0.5f };

                    //bool checkTransparent(Control c, int start)
                    //{
                    //    bool transparent = false;
                    //    for (int i = start; i < c.Children.Count; i++)
                    //    //for (int i = start; i >= 0; i--)
                    //    {
                    //        var control = c.Children[i];

                    //        bool canDraw = /*c.Page == 0 || control.Page == 0 || c.Page == control.Page ||*/ control.Page == page;

                    //        if (canDraw && control is CheckerTrans)
                    //        {
                    //            transparent = true;
                    //        }
                    //    }

                    //    return transparent;
                    //}


                    //bool trans = checkTransparent(gump, 0);

                    //for (int i = gump.Children.Count - 1; i >= 0; i--)
                    //{
                    //    Control g = gump.Children[i];
                    //    g.Initialize();
                    //    g.IsTransparent = true;

                    //    if (g is CheckerTrans)
                    //    {
                    //        trans = checkTransparent(gump, i + 1);

                    //        continue;
                    //    }

                    //    g.Alpha = alpha[trans ? 0 : 1];
                    //}



                    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 = UOFileManager.Cliloc.GetString(1051000 + 2);
                            break;

                        case 0x6A:
                            s = UOFileManager.Cliloc.GetString(1051000 + 7);
                            break;

                        case 0x6B:
                            s = UOFileManager.Cliloc.GetString(1051000 + 5);
                            break;

                        case 0x6D:
                            s = UOFileManager.Cliloc.GetString(1051000 + 6);
                            break;

                        case 0x6E:
                            s = UOFileManager.Cliloc.GetString(1051000 + 1);
                            break;

                        case 0x6F:
                            s = UOFileManager.Cliloc.GetString(1051000 + 3);
                            break;

                        case 0x70:
                            s = UOFileManager.Cliloc.GetString(1051000 + 4);
                            break;

                        case 0x6C:
                        default:
                            s = UOFileManager.Cliloc.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", UOFileManager.Cliloc.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", UOFileManager.Cliloc.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 ? UOFileManager.Cliloc.GetString(int.Parse(gparams[8])) : UOFileManager.Cliloc.Translate(UOFileManager.Cliloc.GetString(int.Parse(gparams[8])), sb.ToString().Trim('@')), color, true), page);

                    break;

                case "page":

                    if (gparams.Count >= 1)
                    {
                        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":
                    gump.Add(new TextBox(gparams, lines), 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 cliloc = UOFileManager.Cliloc.GetString(int.Parse(gparams[1]));

                        if (gparams.Count > 2 && gparams[2][0] == '@')
                        {
                            string args = gparams[2];
                            //Convert tooltip args format to standard cliloc format
                            args = args.Trim('@').Replace('@', '\t');

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

                        gump.Children.Last()?.SetTooltip(cliloc);
                    }

                    break;

                case "itemproperty":

                    if (World.ClientFeatures.TooltipsEnabled)
                    {
                        var entity      = World.Get(Serial.Parse(gparams[1]));
                        var lastControl = gump.Children.LastOrDefault();

                        if (lastControl != default(Control) && entity != default(Entity))
                        {
                            lastControl.SetTooltip(entity);
                        }
                    }

                    break;

                case "noresize":

                    break;

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

                    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;
                    }
                }
            }

            Add(gump);

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

            return(gump);
        }