Exemplo n.º 1
0
        private void CreateColorButton_OnClick(UIMouseEvent evt, UIElement listeningElement)
        {
            if (Main.mouseItem == null)
            {
                Main.mouseItem = new Item();
            }
            Item selectedItem = Main.mouseItem.type == 0 ? Main.LocalPlayer.inventory[Main.LocalPlayer.selectedItem] : Main.mouseItem;

            if (selectedItem == null || selectedItem.type == 0 || selectedItem.stack <= 0 || (selectedItem.createTile == -1 && selectedItem.createWall == -1))
            {
                Main.NewText("Please select a valid tile/wall.");
                return;
            }
            colorGrid.Remove(createColorButton);
            byte paintColor = 0;

            if (Main.LocalPlayer.autoPaint && Main.LocalPlayer.builderAccStatus[3] == 0)
            {
                for (int i = 0; i < 50; i++)
                {
                    if (Main.LocalPlayer.inventory[i].paint > 0 && Main.LocalPlayer.inventory[i].stack > 0)
                    {
                        paintColor = Main.LocalPlayer.inventory[i].paint;
                        break;
                    }
                }
            }
            var colorUI = new ColorPanel(selectedItem, paintColor);

            colorUI.Activate();
            colorGrid.Add(colorUI);
            colorGrid.Add(createColorButton);
        }
Exemplo n.º 2
0
 private void DeleteColorButton_OnClick(UIMouseEvent evt, UIElement listeningElement)
 {
     if (selectedPanel != null)
     {
         colorGrid.Remove(selectedPanel);
         tileInfoText.SetText("No tile selected.");
         selectedPanel = null;
     }
 }
Exemplo n.º 3
0
        public override void OnEnterWorld(Player player)
        {
            if (player.whoAmI == Main.myPlayer)
            {
                List <ColorData> remove = new List <ColorData>();

                var ui = ((ColorPalette)mod).colorPaletteUI;
                ui.colorGrid.Clear();
                foreach (var data in PaletteIO.instance.datas)
                {
                    Item item = new Item();
                    if (data.id < ItemID.Count)
                    {
                        item.SetDefaults(data.id);
                    }
                    else
                    {
                        try
                        {
                            var split   = data.fullName.Split(new char[] { '.' });
                            var modItem = ModLoader.GetMod(split[0])?.GetItem(split[1]);
                            if (modItem != null)
                            {
                                item = modItem.item;
                            }
                        }
                        catch (Exception e)
                        {
                            mod.Logger.Warn(string.Format("Something went wrong while loading item: {0}. This will be removed.", data.fullName), e);
                            remove.Add(data);
                        }
                    }
                    if (item.type != 0)
                    {
                        var colorUI = new ColorPanel(item, data.paint)
                        {
                            colorData = data
                        };
                        colorUI.Initialize();
                        ui.colorGrid.Add(colorUI);
                    }
                }

                ui.colorGrid.Add(ui.createColorButton);
            }
        }