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);
    }
Beispiel #2
0
    public override bool ButtonClicked(string name, SegmentEntity targetEntity)
    {
        if (name == "nextnetwork") // Increment network count
        {
            this.SelectedNetwork++;
            if (this.SelectedNetwork >= fcm.Networks.Count)
            {
                this.SelectedNetwork = 0;
            }
            NetworkSync.NetworkStatus = null;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "prevnetwork") // Decrement network count
        {
            this.SelectedNetwork--;
            if (this.SelectedNetwork < 0)
            {
                this.SelectedNetwork = fcm.Networks.Count - 1;
            }
            NetworkSync.NetworkStatus = null;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "nextstorage") // Increment storage count
        {
            this.SelectedStorage++;
            if (this.SelectedStorage >= fcm.StationInventories.Count)
            {
                this.SelectedStorage = 0;
            }
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "prevstorage") // Decrement storage count
        {
            this.SelectedStorage--;
            if (this.SelectedStorage < 0)
            {
                this.SelectedStorage = fcm.StationInventories.Count - 1;
            }
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "allnetworks")
        {
            if (this.CurrentWindow == WindowTypes.GlobalInventory)
            {
                this.CurrentWindow = WindowTypes.NetworkStatus;
            }
            else
            {
                this.CurrentWindow = WindowTypes.GlobalInventory;
            }
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "tracknetworks")
        {
            if (this.CurrentWindow == WindowTypes.TrackNetworks)
            {
                this.CurrentWindow = WindowTypes.NetworkStatus;
            }
            else
            {
                this.CurrentWindow = WindowTypes.TrackNetworks;
            }
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "selnetwork")
        {
            if (this.CurrentWindow == WindowTypes.NetworkSelection)
            {
                this.CurrentWindow = WindowTypes.NetworkStatus;
            }
            else
            {
                this.CurrentWindow = WindowTypes.NetworkSelection;
            }
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "viewinventory")
        {
            if (this.CurrentWindow == WindowTypes.StorageInventory)
            {
                this.CurrentWindow = WindowTypes.NetworkStatus;
            }
            else
            {
                this.CurrentWindow = WindowTypes.StorageInventory;
            }
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name.Contains("networknum"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("networknum", ""), out slotNum); //Get slot name as number

            if (slotNum > -1)                                          // valid slot
            {
                this.SelectedNetwork      = slotNum;
                NetworkSync.NetworkStatus = null;
                this.CurrentWindow        = WindowTypes.NetworkStatus;
                this.manager.RedrawWindow();
                return(true);
            }
        }
        else if (name.Contains("trackicon"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("trackicon", ""), out slotNum); //Get slot name as number

            if (slotNum > -1)                                         // valid slot
            {
                if (this.TrackNetworkDisplay == slotNum)
                {
                    this.TrackNetworkDisplay = -1;
                }
                else
                {
                    this.TrackNetworkDisplay = slotNum;
                }
                this.StationDisplay = -1;
                this.CartDisplay    = -1;
                this.manager.RedrawWindow();
                return(true);
            }
        }
        else if (name.Contains("stationicon"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("stationicon", ""), out slotNum); //Get slot name as number

            if (slotNum > -1)                                           // valid slot
            {
                if (this.StationDisplay == slotNum)
                {
                    this.StationDisplay = -1;
                }
                else
                {
                    this.StationDisplay = slotNum;
                }
                this.CartDisplay = -1;
                this.manager.ClearWindow();
                this.manager.RedrawWindow();
                return(true);
            }
        }
        else if (name.Contains("carticon"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("carticon", ""), out slotNum); //Get slot name as number

            if (slotNum > -1)                                        // valid slot
            {
                if (this.CartDisplay == slotNum)
                {
                    this.CartDisplay = -1;
                }
                else
                {
                    this.CartDisplay = slotNum;
                }
                this.manager.RedrawWindow();
                return(true);
            }
        }
        else if (name == "addcart")
        {
            int amount = 1;
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                amount = 10;
            }
            FreightCartWindow.SetCartAssignment(this.CurrentStation, this.CurrentStation.AssignedCarts + amount);
            this.manager.UpdateLabel("stationcarts" + this.StationDisplay.ToString(), "Carts: " + this.CurrentStation.AvailableCarts.ToString() + " / " + this.CurrentStation.AssignedCarts.ToString(), this.CurrentStation.AvailableCarts > this.CurrentStation.AssignedCarts ? Color.green : this.CurrentStation.AvailableCarts == this.CurrentStation.AssignedCarts ? Color.white : Color.red);
            return(true);
        }
        else if (name == "removecart")
        {
            int amount = 1;
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                amount = 10;
            }
            FreightCartWindow.SetCartAssignment(this.CurrentStation, this.CurrentStation.AssignedCarts - amount < 0 ? 0 : this.CurrentStation.AssignedCarts - amount);
            this.manager.UpdateLabel("stationcarts" + this.StationDisplay.ToString(), "Carts: " + this.CurrentStation.AvailableCarts.ToString() + " / " + this.CurrentStation.AssignedCarts.ToString(), this.CurrentStation.AvailableCarts > this.CurrentStation.AssignedCarts ? Color.green : this.CurrentStation.AvailableCarts == this.CurrentStation.AssignedCarts ? Color.white : Color.red);
            return(true);
        }
        else if (name == "ordername")
        {
            this.OrderByName = true;
            this.manager.RedrawWindow();
        }
        else if (name == "ordercount")
        {
            this.OrderByName = false;
            this.manager.RedrawWindow();
        }
        else if (name == "togglelayout")
        {
            this.CompactLayout = !this.CompactLayout;
            this.manager.RedrawWindow();
        }

        return(false);
    }
    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
        });
    }