// In OnInitialize, we place various UIElements onto our UIState (this class). // UIState classes have width and height equal to the full screen, because of this, usually we first define a UIElement that will act as the container for our UI. // We then place various other UIElement onto that container UIElement positioned relative to the container UIElement. public override void OnInitialize() { // Here we define our container UIElement. In DragableUIPanel.cs, you can see that DragableUIPanel is a UIPanel with a couple added features. // Here we define our container UIElement. In DragableUIPanel.cs, you can see that DragableUIPanel is a UIPanel with a couple added features. //pokemon icons // Next, we create another UIElement that we will place. Since we will be calling `mainPanel.Append(playButton);`, Left and Top are relative to the top left of the mainPanel UIElement. // By properly nesting UIElements, we can position things relatively to each other easily. mainPanel = new DragableUIPanel(); mainPanel.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. mainPanel.HAlign = 0.4f; mainPanel.VAlign = 0.65f; mainPanel.Width.Set(185, 0f); mainPanel.Height.Set(150f, 0f); partyslot1 = new VanillaItemSlotWrapper(ItemSlot.Context.BankItem, 1f); partyslot1.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. partyslot1.HAlign = 0.15f; partyslot1.VAlign = 0.15f; partyslot1.ValidItemFunc = item => item.IsAir || TerramonMod.PokeballFactory.GetEnum(item.modItem) != TerramonMod.PokeballFactory.Pokebals.Nothing; mainPanel.Append(partyslot1); partyslot2 = new VanillaItemSlotWrapper(ItemSlot.Context.BankItem, 1f); partyslot2.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. partyslot2.HAlign = 0.5f; partyslot2.VAlign = 0.15f; partyslot2.ValidItemFunc = item => item.IsAir || TerramonMod.PokeballFactory.GetEnum(item.modItem) != TerramonMod.PokeballFactory.Pokebals.Nothing; mainPanel.Append(partyslot2); partyslot3 = new VanillaItemSlotWrapper(ItemSlot.Context.BankItem, 1f); partyslot3.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. partyslot3.HAlign = 0.85f; partyslot3.VAlign = 0.15f; partyslot3.ValidItemFunc = item => item.IsAir || TerramonMod.PokeballFactory.GetEnum(item.modItem) != TerramonMod.PokeballFactory.Pokebals.Nothing; mainPanel.Append(partyslot3); partyslot4 = new VanillaItemSlotWrapper(ItemSlot.Context.BankItem, 1f); partyslot4.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. partyslot4.HAlign = 0.15f; partyslot4.VAlign = 0.85f; partyslot4.ValidItemFunc = item => item.IsAir || TerramonMod.PokeballFactory.GetEnum(item.modItem) != TerramonMod.PokeballFactory.Pokebals.Nothing; mainPanel.Append(partyslot4); partyslot5 = new VanillaItemSlotWrapper(ItemSlot.Context.BankItem, 1f); partyslot5.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. partyslot5.HAlign = 0.5f; partyslot5.VAlign = 0.85f; partyslot5.ValidItemFunc = item => item.IsAir || TerramonMod.PokeballFactory.GetEnum(item.modItem) != TerramonMod.PokeballFactory.Pokebals.Nothing; mainPanel.Append(partyslot5); partyslot6 = new VanillaItemSlotWrapper(ItemSlot.Context.BankItem, 1f); partyslot6.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. partyslot6.HAlign = 0.85f; partyslot6.VAlign = 0.85f; partyslot6.ValidItemFunc = item => item.IsAir || TerramonMod.PokeballFactory.GetEnum(item.modItem) != TerramonMod.PokeballFactory.Pokebals.Nothing; mainPanel.Append(partyslot6); Append(mainPanel); partyslot1.OnItemPlaced += UpdateUI; partyslot2.OnItemPlaced += UpdateUI; partyslot3.OnItemPlaced += UpdateUI; partyslot4.OnItemPlaced += UpdateUI; partyslot5.OnItemPlaced += UpdateUI; partyslot6.OnItemPlaced += UpdateUI; }
// In OnInitialize, we place various UIElements onto our UIState (this class). // UIState classes have width and height equal to the full screen, because of this, usually we first define a UIElement that will act as the container for our UI. // We then place various other UIElement onto that container UIElement positioned relative to the container UIElement. public override void OnInitialize() { // Here we define our container UIElement. In DragableUIPanel.cs, you can see that DragableUIPanel is a UIPanel with a couple added features. // Here we define our container UIElement. In DragableUIPanel.cs, you can see that DragableUIPanel is a UIPanel with a couple added features. //pokemon icons // Next, we create another UIElement that we will place. Since we will be calling `mainPanel.Append(playButton);`, Left and Top are relative to the top left of the mainPanel UIElement. // By properly nesting UIElements, we can position things relatively to each other easily. mainPanel = new DragableUIPanel(); mainPanel.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. mainPanel.HAlign = 0.4f; mainPanel.VAlign = 0.65f; mainPanel.Width.Set(180, 0f); mainPanel.Height.Set(70f, 0f); partyslot1 = new VanillaItemSlotWrapper(ItemSlot.Context.BankItem, 1f); partyslot1.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. partyslot1.HAlign = 0.15f; partyslot1.VAlign = 0.5f; partyslot1.ValidItemFunc = item => item.IsAir || TerramonMod.PokeballFactory.GetEnum(item.modItem) != TerramonMod.PokeballFactory.Pokebals.Nothing; mainPanel.Append(partyslot1); partyslot2 = new VanillaItemSlotWrapper(ItemSlot.Context.BankItem, 1f); partyslot2.SetPadding(0); // We need to place this UIElement in relation to its Parent. Later we will be calling `base.Append(mainPanel);`. // This means that this class, ExampleUI, will be our Parent. Since ExampleUI is a UIState, the Left and Top are relative to the top left of the screen. partyslot2.HAlign = 0.65f; partyslot2.VAlign = 0.5f; partyslot2.ValidItemFunc = item => item.IsAir || item.modItem is RareCandy; mainPanel.Append(partyslot2); PokemonGoesHere = new UIText("0/0"); PokemonGoesHere.HAlign = 0.5f; PokemonGoesHere.VAlign = 1.5f; PokemonGoesHere.SetText("Place a Pokémon in the first slot."); mainPanel.Append(PokemonGoesHere); RareCandiesGoHere = new UIText("0/0"); RareCandiesGoHere.HAlign = 0.5f; RareCandiesGoHere.VAlign = 1.7f; RareCandiesGoHere.SetText(""); mainPanel.Append(RareCandiesGoHere); Texture2D buttonSaveTexture = ModContent.GetTexture("Terraria/UI/ButtonPlay"); SaveButton = new UIHoverImageButton(buttonSaveTexture, "Evolve!"); // Localized text for "Close" SaveButton.HAlign = 0.95f; SaveButton.VAlign = 0.53f; SaveButton.Width.Set(30, 0f); SaveButton.Height.Set(30, 0f); SaveButton.OnClick += new MouseEvent(EvolveButtonClicked); //Texture2D buttonSaveTexture = ModContent.GetTexture("Terraria/UI/ButtonPlay"); //UIHoverImageButton SaveButton = new UIHoverImageButton(buttonSaveTexture, "Evolve"); // Localized text for "Close" //SaveButton.Left.Set(33, 0f); //SaveButton.Top.Set(7, 0f); //SaveButton.Width.Set(30, 0f); //SaveButton.Height.Set(30, 0f); //SaveButton.OnClick += new MouseEvent(); //mainPanel.Append(SaveButton); Append(mainPanel); // As a recap, ExampleUI is a UIState, meaning it covers the whole screen. We attach mainPanel to ExampleUI some distance from the top left corner. // We then place playButton, closeButton, and moneyDiplay onto mainPanel so we can easily place these UIElements relative to mainPanel. // Since mainPanel will move, this proper organization will move playButton, closeButton, and moneyDiplay properly when mainPanel moves. }