Exemple #1
0
        private void OpenItem(ModularItem item)
        {
            selectedItem = item;

            gridModules.Clear();

            foreach (int type in ModuleLoader.validModulesForItem[item.Type])
            {
                BaseModule module = ModuleLoader.GetModule(type);

                UIModule uiModule = new UIModule(module)
                {
                    Color  = item.IsInstalled(module.Type) ? Color.LimeGreen : Color.Red,
                    Width  = { Percent = 100 },
                    Height = { Pixels = 64 }
                };
                uiModule.OnClick += args =>
                {
                    args.Handled = true;

                    OpenModule(module);
                };
                gridModules.Add(uiModule);
            }
        }
Exemple #2
0
        public void Open()
        {
            selectedItem   = null;
            selectedModule = null;

            gridItems.Clear();

            foreach (Item item in InventoryUtility.InvArmorEquips(Main.LocalPlayer))
            {
                if (item.IsAir)
                {
                    continue;
                }

                if (item.ModItem is ModularItem modularItem)
                {
                    UIModularItem uiModularItem = new UIModularItem(modularItem)
                    {
                        Width  = { Pixels = 48 },
                        Height = { Pixels = 48 }
                    };
                    uiModularItem.OnClick += args =>
                    {
                        args.Handled = true;

                        OpenItem(modularItem);
                    };

                    gridItems.Add(uiModularItem);
                }
            }
        }
 public UIModularItem(ModularItem item)
 {
     if (bg == null)
     {
         bg = DrawingUtility.GetTexturePremultiplied(ModularTools.AssetPath + "Textures/UI/Upgrade/ModularItemBackground");
     }
     Item = item;
 }
Exemple #4
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        GUILayout.Space(25);
        ModularItem item = target as ModularItem;

        if (GUILayout.Button("Update Data"))
        {
            item.UpdateData();
        }
    }
Exemple #5
0
        public override void OnRemoved(ModularItem item)
        {
            item.EnergyStorage.ModifyCapacity(-EnergyCapacity);

            ulong max = 0;

            foreach (BaseModule module in item.InstalledModules)
            {
                if (ModuleData.EnergyTransfer.TryGet(module.Type, out ulong val) && val > max)
                {
                    max = val;
                }
            }

            item.EnergyStorage.SetMaxTransfer(max);
        }
 public override void OnUpdate(ModularItem item, Player player)
 {
     player.statDefense += ModuleData.Defense.Get(Type);
 }
 public override void OnRemoved(ModularItem item)
 {
 }
 public override void OnInstalled(ModularItem item)
 {
     item.HeatStorage.TransferCoefficient = Math.Max(14f, item.HeatStorage.TransferCoefficient);
 }
Exemple #9
0
        public override void StartServerSide(ICoreServerAPI api)
        {
            base.StartServerSide(api);

            api.RegisterCommand("tboxcreate", "Generates an empty modular tool", "", (player, groupId, args) =>
            {
                if (this.modularTool == null)
                {
                    this.modularTool = ModCore.api.World.GetItem(new AssetLocation("tbox:modulartool"));
                }

                ItemStack modularStack = new ItemStack(modularTool);

                player.InventoryManager.TryGiveItemstack(modularStack, true);
            }, Privilege.chat);

            api.RegisterCommand("tboxadd", "Adds a tool part to the held modular item", "", (player, groupId, args) =>
            {
                ItemSlot slot    = player.InventoryManager.ActiveHotbarSlot;
                ModularItem tool = slot.Itemstack?.Item as ModularItem;
                if (tool != null)
                {
                    string toolslot = args.PopWord();
                    ToolPart part   = GetItem(new AssetLocation(args.PopWord())) as ToolPart;

                    if (part != null)
                    {
                        if (tool.AddPart(slot.Itemstack, toolslot, new ItemStack(part, 1)))
                        {
                            slot.MarkDirty();
                        }
                        else
                        {
                            player.SendMessage(groupId, "Can't add part to modular item", EnumChatType.CommandError);
                        }
                    }
                    else
                    {
                        player.SendMessage(groupId, "Part does not exist or doesn't have the ToolPart class applied", EnumChatType.CommandError);
                    }
                }
                else
                {
                    player.SendMessage(groupId, "You are not holding a modular item", EnumChatType.CommandError);
                }
            }, Privilege.chat);

            api.RegisterCommand("tboxremove", "Removes a tool part from the held modular item", "", (player, groupId, args) =>
            {
                ItemSlot slot    = player.InventoryManager.ActiveHotbarSlot;
                ModularItem tool = slot.Itemstack?.Item as ModularItem;
                if (tool != null)
                {
                    string toolslot = args.PopWord();

                    ItemStack part = tool.RemovePart(slot.Itemstack, toolslot);
                    part.ResolveBlockOrItem(ModCore.api.World);

                    if (part != null)
                    {
                        player.InventoryManager.TryGiveItemstack(part, true);
                    }
                    slot.MarkDirty();
                }
                else
                {
                    player.SendMessage(groupId, "You are not holding a modular item", EnumChatType.CommandError);
                }
            }, Privilege.chat);
        }