コード例 #1
0
    public override bool ButtonClicked(string name, SegmentEntity targetEntity)
    {
        FreightCartStation station = targetEntity as FreightCartStation;

        if (name.Contains("registry")) // drag drop to a slot
        {
            int slotNum = -1;
            int.TryParse(name.Replace("registry", ""), out slotNum); //Get slot name as number
            List <FreightRegistry> registries = FreightCartManager.instance.GetFreightEntries(station.NetworkID, station.massStorageCrate);

            if (slotNum > -1) // valid slot
            {
                FreightCartWindow.RemoveRegistry(station, registries[slotNum].FreightItem);
            }
            return(true);
        }
        else if (name == "hopitemoffer")
        {
            if (station.HopperInterface.OfferItem == null)
            {
                return(true);
            }
            FreightCartWindow.SetHopperOfferItem(station, null);
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "hopitemrequest")
        {
            if (station.HopperInterface.RequestItem == null)
            {
                return(true);
            }
            FreightCartWindow.SetHopperRequestItem(station, null);
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name.Contains("switchlowstock"))
        {
            this.ChooseLowStock = true;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name.Contains("switchhighstock"))
        {
            this.ChooseLowStock = false;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name.Contains("decreasestock"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("decreasestock", ""), out slotNum); //Get slot name as number
            List <FreightRegistry> registries = FreightCartManager.instance.GetFreightEntries(station.NetworkID, station.massStorageCrate);

            if (slotNum > -1) // valid slot
            {
                int amount = 100;
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    amount = 10;
                }
                if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                {
                    amount = 1;
                }
                if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
                {
                    amount = 1000;
                }

                int stock;
                if (this.ChooseLowStock)
                {
                    stock = registries[slotNum].LowStock - amount;
                    if (stock < 0)
                    {
                        stock = 0;
                    }
                    FreightCartWindow.SetLowStock(station, registries[slotNum].FreightItem, stock);
                    return(true);
                }
                else
                {
                    stock = registries[slotNum].HighStock - amount;
                    if (stock < 0)
                    {
                        stock = 0;
                    }
                    FreightCartWindow.SetHighStock(station, registries[slotNum].FreightItem, stock);
                    return(true);
                }
            }
        }
        else if (name.Contains("increasestock"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("increasestock", ""), out slotNum); //Get slot name as number
            List <FreightRegistry> registries = FreightCartManager.instance.GetFreightEntries(station.NetworkID, station.massStorageCrate);

            if (slotNum > -1) // valid slot
            {
                int amount = this.ModifierItemCount();
                int stock;
                if (this.ChooseLowStock)
                {
                    stock = registries[slotNum].LowStock + amount;
                    FreightCartWindow.SetLowStock(station, registries[slotNum].FreightItem, stock);
                    return(true);
                }
                else
                {
                    stock = registries[slotNum].HighStock + amount;
                    FreightCartWindow.SetHighStock(station, registries[slotNum].FreightItem, stock);
                    return(true);
                }
            }
        }
        else if (name == "hopofferdown")
        {
            int amount = station.HopperInterface.OfferLimit - this.ModifierItemCount();
            if (amount < 0)
            {
                amount = 0;
            }
            FreightCartWindow.SetHopperOffer(station, amount);
            return(true);
        }
        else if (name == "hopofferup")
        {
            int amount = station.HopperInterface.OfferLimit + this.ModifierItemCount();
            if (amount > station.HopperInterface.Machine.TotalCapacity)
            {
                amount = station.HopperInterface.Machine.TotalCapacity;
            }
            FreightCartWindow.SetHopperOffer(station, amount);
            return(true);
        }
        else if (name == "hoprequestdown")
        {
            int amount = station.HopperInterface.RequestLimit - this.ModifierItemCount();
            if (amount < 0)
            {
                amount = 0;
            }
            FreightCartWindow.SetHopperRequest(station, amount);
            return(true);
        }
        else if (name == "hoprequestup")
        {
            int amount = station.HopperInterface.RequestLimit + this.ModifierItemCount();
            FreightCartWindow.SetHopperRequest(station, amount);
            return(true);
        }
        else if (name.Contains("searchcancel"))
        {
            this.ItemSearchWindow        = false;
            this.SearchResults           = null;
            UIManager.mbEditingTextField = false;
            UIManager.RemoveUIRules("TextEntry");
            this.EntryString = "";
            GenericMachinePanelScript.instance.Scroll_Bar.GetComponent <UIScrollBar>().scrollValue = 0.0f;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name.Contains("itemicon"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("itemicon", ""), out slotNum); //Get slot name as number
            if (slotNum > -1)
            {
                switch (eSearchType)
                {
                case SearchType.Registry:
                    FreightCartWindow.AddRegistry(station, this.SearchResults[slotNum]);
                    break;

                case SearchType.HopperOffer:
                    FreightCartWindow.SetHopperOfferItem(station, this.SearchResults[slotNum]);
                    break;

                case SearchType.HopperRequest:
                    FreightCartWindow.SetHopperRequestItem(station, this.SearchResults[slotNum]);
                    break;
                }
                this.SearchResults    = null;
                this.ItemSearchWindow = false;
                this.EntryString      = "";
                GenericMachinePanelScript.instance.Scroll_Bar.GetComponent <UIScrollBar>().scrollValue = 0.0f;
                return(true);
            }
        }
        else if (name == "namenetwork")
        {
            this.SetNetworkID = true;
            this.Redraw(targetEntity);
            return(true);
        }
        else if (name == "stationname")
        {
            this.SetName = true;
            this.Redraw(targetEntity);
            return(true);
        }
        else if (name == "namestorage")
        {
            this.SetInventoryName = true;
            this.Redraw(targetEntity);
            return(true);
        }
        else if (name == "networkidcancel")
        {
            this.SetNetworkID            = false;
            this.SetName                 = false;
            this.SetInventoryName        = false;
            UIManager.mbEditingTextField = false;
            UIManager.RemoveUIRules("TextEntry");
            this.EntryString = "";
            if (string.IsNullOrEmpty(station.NetworkID))
            {
                GenericMachinePanelScript.instance.Hide();
                return(true);
            }
            this.manager.RedrawWindow();
        }
        else if (name == "setfreight")
        {
            this.SetFreightItems = true;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "freightdone")
        {
            this.SetFreightItems = false;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "increasecarts")
        {
            int amount = 1;
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                amount = 10;
            }
            FreightCartWindow.SetCartAssignment(station, station.AssignedCarts + amount);
            return(true);
        }
        else if (name == "decreasecarts")
        {
            int amount = 1;
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                amount = 10;
            }
            FreightCartWindow.SetCartAssignment(station, station.AssignedCarts - amount < 0 ? 0 : station.AssignedCarts - amount);
            return(true);
        }
        else if (name == "toggleload")
        {
            FreightCartWindow.ToggleLoadStatus(station, !station.mbWaitForFullLoad ? "Full" : "Any");
            return(true);
        }
        else if (name == "toggleoffer")
        {
            FreightCartWindow.ToggleOfferAll(station, !station.OfferAll ? "All" : "registry");
            return(true);
        }
        else if (name == "togglecarttier")
        {
            FreightCartWindow.ToggleCartTier(station, station.CartTier);
            return(true);
        }

        return(false);
    }
コード例 #2
0
    public static NetworkInterfaceResponse HandleNetworkCommand(Player player, NetworkInterfaceCommand nic)
    {
        FreightCartStation station = nic.target as FreightCartStation;

        string command = nic.command;

        if (command != null)
        {
            if (command == InterfaceRemoveReg)
            {
                FreightCartWindow.RemoveRegistry(station, nic.itemContext);
            }
            else if (command == InterfaceSetLowStock)
            {
                int stock = -1;
                int.TryParse(nic.payload ?? "-1", out stock);
                FreightCartWindow.SetLowStock(station, nic.itemContext, stock);
            }
            else if (command == InterfaceSetHighStock)
            {
                int stock = -1;
                int.TryParse(nic.payload ?? "-1", out stock);
                FreightCartWindow.SetHighStock(station, nic.itemContext, stock);
            }
            else if (command == InterfaceAssignedCarts)
            {
                int carts = 0;
                int.TryParse(nic.payload ?? "-1", out carts);
                FreightCartWindow.SetCartAssignment(station, carts);
            }
            else if (command == InterfaceCartTier)
            {
                int carttier = 0;
                int.TryParse(nic.payload ?? "2", out carttier);
                FreightCartWindow.ToggleCartTier(station, carttier);
            }
            else if (command == InterfaceHopperHigh)
            {
                int offer = -1;
                int.TryParse(nic.payload ?? "-1", out offer);
                FreightCartWindow.SetHopperOffer(station, offer);
            }
            else if (command == InterfaceHopperLow)
            {
                int request = -1;
                int.TryParse(nic.payload ?? "-1", out request);
                FreightCartWindow.SetHopperRequest(station, request);
            }
            else if (command == InterfaceToggleLoad)
            {
                FreightCartWindow.ToggleLoadStatus(station, nic.payload);
            }
            else if (command == InterfaceToggleOffer)
            {
                FreightCartWindow.ToggleOfferAll(station, nic.payload);
            }
            else if (command == InterfaceAddReg)
            {
                FreightCartWindow.AddRegistry(station, nic.itemContext);
            }
            else if (command == InterfaceSetNetwork)
            {
                FreightCartWindow.SetNetwork(station, nic.payload);
            }
            else if (command == InterfaceSetName)
            {
                FreightCartWindow.SetStationName(station, nic.payload);
            }
            else if (command == InterfaceSetInventoryName)
            {
                FreightCartWindow.NameInventory(station, nic.payload);
            }
            else if (command == InterfaceCopyFreight)
            {
                FreightCartWindow.CopyFreight(station);
            }
            else if (command == InterfacePasteFreight)
            {
                FreightCartWindow.PasteFreight(station);
            }
            else if (command == InterfaceHopperOffer)
            {
                FreightCartWindow.SetHopperOfferItem(station, nic.itemContext);
            }
            else if (command == InterfaceHopperRequest)
            {
                FreightCartWindow.SetHopperRequestItem(station, nic.itemContext);
            }
        }

        return(new NetworkInterfaceResponse
        {
            entity = station,
            inventory = player.mInventory
        });
    }