예제 #1
0
        public override void OnInitialize()
        {
            uIElement = new UIElement {
                Width    = { Percent = 0.8f },
                MaxWidth = UICommon.MaxPanelWidth,
                Top      = { Pixels = 220 },
                Height   = { Pixels = -220, Percent = 1f },
                HAlign   = 0.5f
            };

            uIPanel = new UIPanel {
                Width           = { Percent = 1f },
                Height          = { Pixels = -110, Percent = 1f },
                BackgroundColor = UICommon.mainPanelBackground,
                PaddingTop      = 0f
            };
            uIElement.Append(uIPanel);

            uiLoader = new UILoaderAnimatedImage(0.5f, 0.5f, 1f);

            modList = new UIList {
                Width       = { Pixels = -25, Percent = 1f },
                Height      = { Pixels = -50, Percent = 1f },
                Top         = { Pixels = 50 },
                ListPadding = 5f
            };
            uIPanel.Append(modList);

            var uIScrollbar = new UIScrollbar {
                Height = { Pixels = -50, Percent = 1f },
                Top    = { Pixels = 50 },
                HAlign = 1f
            }.WithView(100f, 1000f);

            uIPanel.Append(uIScrollbar);

            modList.SetScrollbar(uIScrollbar);

            var uIHeaderTexTPanel = new UITextPanel <string>(Language.GetTextValue("tModLoader.ModsModsList"), 0.8f, true)
            {
                HAlign          = 0.5f,
                Top             = { Pixels = -35 },
                BackgroundColor = UICommon.defaultUIBlue
            }.WithPadding(15f);

            uIElement.Append(uIHeaderTexTPanel);

            buttonEA = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsEnableAll"))
            {
                TextColor = Color.Green,
                Width     = new StyleDimension(-10f, 1f / 3f),
                Height    = { Pixels = 40 },
                VAlign    = 1f,
                Top       = { Pixels = -65 }
            }.WithFadedMouseOver();
            buttonEA.OnClick += EnableAll;
            uIElement.Append(buttonEA);

            // TODO CopyStyle doesn't capture all the duplication here, consider an inner method
            buttonDA = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsDisableAll"));
            buttonDA.CopyStyle(buttonEA);
            buttonDA.TextColor = Color.Red;
            buttonDA.HAlign    = 0.5f;
            buttonDA.WithFadedMouseOver();
            buttonDA.OnClick += DisableAll;
            uIElement.Append(buttonDA);

            buttonRM = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsReloadMods"));
            buttonRM.CopyStyle(buttonEA);
            buttonRM.HAlign = 1f;
            buttonDA.WithFadedMouseOver();
            buttonRM.OnClick += ReloadMods;
            uIElement.Append(buttonRM);

            buttonB = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("UI.Back"));
            buttonB.CopyStyle(buttonEA);
            buttonB.Top.Pixels = -20;
            buttonB.WithFadedMouseOver();
            buttonB.OnClick += BackClick;

            uIElement.Append(buttonB);
            buttonOMF = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsOpenModsFolder"));
            buttonOMF.CopyStyle(buttonB);
            buttonOMF.HAlign = 0.5f;
            buttonOMF.WithFadedMouseOver();
            buttonOMF.OnClick += OpenModsFolder;
            uIElement.Append(buttonOMF);

            var texture            = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.UIModBrowserIcons.png"));
            var upperMenuContainer = new UIElement {
                Width  = { Percent = 1f },
                Height = { Pixels = 32 },
                Top    = { Pixels = 10 }
            };

            UICycleImage toggleImage;

            for (int j = 0; j < 3; j++)
            {
                if (j == 0)                   //TODO: ouch, at least there's a loop but these click events look quite similar
                {
                    toggleImage = new UICycleImage(texture, 3, 32, 32, 34 * 3, 0);
                    toggleImage.setCurrentState((int)sortMode);
                    toggleImage.OnClick += (a, b) => {
                        sortMode     = sortMode.NextEnum();
                        updateNeeded = true;
                    };
                    toggleImage.OnRightClick += (a, b) => {
                        sortMode     = sortMode.PreviousEnum();
                        updateNeeded = true;
                    };
                }
                else if (j == 1)
                {
                    toggleImage = new UICycleImage(texture, 3, 32, 32, 34 * 4, 0);
                    toggleImage.setCurrentState((int)enabledFilterMode);
                    toggleImage.OnClick += (a, b) => {
                        enabledFilterMode = enabledFilterMode.NextEnum();
                        updateNeeded      = true;
                    };
                    toggleImage.OnRightClick += (a, b) => {
                        enabledFilterMode = enabledFilterMode.PreviousEnum();
                        updateNeeded      = true;
                    };
                }
                else
                {
                    toggleImage = new UICycleImage(texture, 5, 32, 32, 34 * 5, 0);
                    toggleImage.setCurrentState((int)modSideFilterMode);
                    toggleImage.OnClick += (a, b) => {
                        modSideFilterMode = modSideFilterMode.NextEnum();
                        updateNeeded      = true;
                    };
                    toggleImage.OnRightClick += (a, b) => {
                        modSideFilterMode = modSideFilterMode.PreviousEnum();
                        updateNeeded      = true;
                    };
                }
                toggleImage.Left.Pixels = j * 36 + 8;
                _categoryButtons.Add(toggleImage);
                upperMenuContainer.Append(toggleImage);
            }

            var filterTextBoxBackground = new UIPanel {
                Top    = { Percent = 0f },
                Left   = { Pixels = -170, Percent = 1f },
                Width  = { Pixels = 135 },
                Height = { Pixels = 40 }
            };

            filterTextBoxBackground.OnRightClick += (a, b) => filterTextBox.Text = "";
            upperMenuContainer.Append(filterTextBoxBackground);

            filterTextBox = new UIInputTextField(Language.GetTextValue("tModLoader.ModsTypeToSearch"))
            {
                Top    = { Pixels = 5 },
                Left   = { Pixels = -160, Percent = 1f },
                Width  = { Pixels = 120 },
                Height = { Pixels = 20 }
            };
            filterTextBox.OnTextChange += (a, b) => updateNeeded = true;
            upperMenuContainer.Append(filterTextBox);

            SearchFilterToggle = new UICycleImage(texture, 2, 32, 32, 34 * 2, 0)
            {
                Left = { Pixels = 545 }
            };
            SearchFilterToggle.setCurrentState((int)searchFilterMode);
            SearchFilterToggle.OnClick += (a, b) => {
                searchFilterMode = searchFilterMode.NextEnum();
                updateNeeded     = true;
            };
            SearchFilterToggle.OnRightClick += (a, b) => {
                searchFilterMode = searchFilterMode.PreviousEnum();
                updateNeeded     = true;
            };
            _categoryButtons.Add(SearchFilterToggle);
            upperMenuContainer.Append(SearchFilterToggle);

            buttonMP = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsModPacks"));
            buttonMP.CopyStyle(buttonOMF);
            buttonMP.HAlign = 1f;
            buttonMP.WithFadedMouseOver();
            buttonMP.OnClick += GotoModPacksMenu;
            uIElement.Append(buttonMP);

            uIPanel.Append(upperMenuContainer);
            Append(uIElement);
        }
예제 #2
0
        public override void OnInitialize()
        {
            uIElement = new UIElement();
            uIElement.Width.Set(0f, 0.8f);
            uIElement.MaxWidth.Set(600f, 0f);
            uIElement.Top.Set(220f, 0f);
            uIElement.Height.Set(-220f, 1f);
            uIElement.HAlign = 0.5f;

            uIPanel = new UIPanel();
            uIPanel.Width.Set(0f, 1f);
            uIPanel.Height.Set(-110f, 1f);
            uIPanel.BackgroundColor = new Color(33, 43, 79) * 0.8f;
            uIPanel.PaddingTop      = 0f;
            uIElement.Append(uIPanel);

            uiLoader = new UILoaderAnimatedImage(0.5f, 0.5f, 1f);

            modListAll = new List <UIModItem>();
            modList    = new UIList();
            modList.Width.Set(-25f, 1f);
            modList.Height.Set(-50f, 1f);
            modList.Top.Set(50f, 0f);
            modList.ListPadding = 5f;
            uIPanel.Append(modList);

            UIScrollbar uIScrollbar = new UIScrollbar();

            uIScrollbar.SetView(100f, 1000f);
            uIScrollbar.Height.Set(-50f, 1f);
            uIScrollbar.Top.Set(50f, 0f);
            uIScrollbar.HAlign = 1f;
            uIPanel.Append(uIScrollbar);

            modList.SetScrollbar(uIScrollbar);

            UITextPanel <string> uIHeaderTexTPanel = new UITextPanel <string>("Mods List", 0.8f, true);

            uIHeaderTexTPanel.HAlign = 0.5f;
            uIHeaderTexTPanel.Top.Set(-35f, 0f);
            uIHeaderTexTPanel.SetPadding(15f);
            uIHeaderTexTPanel.BackgroundColor = new Color(73, 94, 171);
            uIElement.Append(uIHeaderTexTPanel);
            buttonEA = new UIColorTextPanel("Enable All", Color.Green, 1f, false);
            buttonEA.Width.Set(-10f, 1f / 3f);
            buttonEA.Height.Set(25f, 0f);
            buttonEA.VAlign = 1f;
            buttonEA.Top.Set(-65f, 0f);
            buttonEA.OnMouseOver += UICommon.FadedMouseOver;
            buttonEA.OnMouseOut  += UICommon.FadedMouseOut;
            buttonEA.OnClick     += this.EnableAll;
            uIElement.Append(buttonEA);
            buttonDA = new UIColorTextPanel("Disable All", Color.Red, 1f, false);
            buttonDA.CopyStyle(buttonEA);
            buttonDA.HAlign       = 0.5f;
            buttonDA.OnMouseOver += UICommon.FadedMouseOver;
            buttonDA.OnMouseOut  += UICommon.FadedMouseOut;
            buttonDA.OnClick     += this.DisableAll;
            uIElement.Append(buttonDA);
            buttonRM = new UITextPanel <string>("Reload Mods", 1f, false);
            buttonRM.CopyStyle(buttonEA);
            buttonRM.HAlign       = 1f;
            buttonRM.OnMouseOver += UICommon.FadedMouseOver;
            buttonRM.OnMouseOut  += UICommon.FadedMouseOut;
            buttonRM.OnClick     += ReloadMods;
            uIElement.Append(buttonRM);
            buttonB = new UITextPanel <string>("Back", 1f, false);
            buttonB.CopyStyle(buttonEA);
            buttonB.Top.Set(-20f, 0f);
            buttonB.OnMouseOver += UICommon.FadedMouseOver;
            buttonB.OnMouseOut  += UICommon.FadedMouseOut;
            buttonB.OnClick     += BackClick;
            uIElement.Append(buttonB);
            buttonOMF = new UITextPanel <string>("Open Mods Folder", 1f, false);
            buttonOMF.CopyStyle(buttonB);
            buttonOMF.HAlign       = 0.5f;
            buttonOMF.OnMouseOver += UICommon.FadedMouseOver;
            buttonOMF.OnMouseOut  += UICommon.FadedMouseOut;
            buttonOMF.OnClick     += OpenModsFolder;
            uIElement.Append(buttonOMF);

            Texture2D texture            = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.UIModBrowserIcons.png"));
            UIElement upperMenuContainer = new UIElement();

            upperMenuContainer.Width.Set(0f, 1f);
            upperMenuContainer.Height.Set(32f, 0f);
            upperMenuContainer.Top.Set(10f, 0f);

            UICycleImage toggleImage;

            for (int j = 0; j < 2; j++)
            {
                if (j == 0)
                {
                    toggleImage = new UICycleImage(texture, 3, 32, 32, 34 * 3, 0);
                    toggleImage.setCurrentState((int)sortMode);
                    toggleImage.OnClick += (a, b) =>
                    {
                        sortMode     = sortMode.NextEnum();
                        updateNeeded = true;
                    };
                    toggleImage.OnRightClick += (a, b) =>
                    {
                        sortMode     = sortMode.PreviousEnum();
                        updateNeeded = true;
                    };
                }
                else
                {
                    toggleImage = new UICycleImage(texture, 3, 32, 32, 34 * 4, 0);
                    toggleImage.setCurrentState((int)enabledFilterMode);
                    toggleImage.OnClick += (a, b) =>
                    {
                        enabledFilterMode = enabledFilterMode.NextEnum();
                        updateNeeded      = true;
                    };
                    toggleImage.OnRightClick += (a, b) =>
                    {
                        enabledFilterMode = enabledFilterMode.PreviousEnum();
                        updateNeeded      = true;
                    };
                }
                toggleImage.Left.Set((float)(j * 36 + 8), 0f);
                _categoryButtons.Add(toggleImage);
                upperMenuContainer.Append(toggleImage);
            }

            UIPanel filterTextBoxBackground = new UIPanel();

            filterTextBoxBackground.Top.Set(0f, 0f);
            filterTextBoxBackground.Left.Set(-170f, 1f);
            filterTextBoxBackground.Width.Set(135f, 0f);
            filterTextBoxBackground.Height.Set(40f, 0f);
            upperMenuContainer.Append(filterTextBoxBackground);

            filterTextBox = new UIInputTextField("Type to search");
            filterTextBox.Top.Set(5f, 0f);
            filterTextBox.Left.Set(-160f, 1f);
            filterTextBox.OnTextChange += (a, b) => { updateNeeded = true; };
            upperMenuContainer.Append(filterTextBox);

            SearchFilterToggle = new UICycleImage(texture, 2, 32, 32, 34 * 2, 0);
            SearchFilterToggle.setCurrentState((int)searchFilterMode);
            SearchFilterToggle.OnClick += (a, b) =>
            {
                searchFilterMode = searchFilterMode.NextEnum();
                updateNeeded     = true;
            };
            SearchFilterToggle.OnRightClick += (a, b) =>
            {
                searchFilterMode = searchFilterMode.PreviousEnum();
                updateNeeded     = true;
            };
            SearchFilterToggle.Left.Set(545f, 0f);
            _categoryButtons.Add(SearchFilterToggle);
            upperMenuContainer.Append(SearchFilterToggle);

            buttonMP = new UITextPanel <string>("Mod Packs", 1f, false);
            buttonMP.CopyStyle(buttonOMF);
            buttonMP.HAlign       = 1f;
            buttonMP.OnMouseOver += UICommon.FadedMouseOver;
            buttonMP.OnMouseOut  += UICommon.FadedMouseOut;
            buttonMP.OnClick     += GotoModPacksMenu;
            uIElement.Append(buttonMP);

            uIPanel.Append(upperMenuContainer);
            Append(uIElement);
        }