示例#1
0
        public ItemBase TakeAnyItem(SegmentEntity entity)
        {
            if (GetFreeSpace(entity) == 1)
            {
                return(null);
            }
            var      conveyor = entity as ConveyorEntity;
            ItemBase ret      = null;

            if (conveyor.mCarriedCube != 0)
            {
                ret = ItemManager.SpawnCubeStack(conveyor.mCarriedCube, conveyor.mCarriedValue, 1);
            }
            else
            {
                ret = conveyor.mCarriedItem;
            }

            if (ret == null)
            {
                return(null);
            }
            conveyor.RemoveCube();
            conveyor.RemoveItem();
            conveyor.FinaliseOffloadingCargo();
            return(ret);
        }
    //You can also get a call when the player's cursor hovers over an icon/button so that you can display info about it
    //Example code below for displaying item info in the hotbar
    public override void ButtonEnter(string name, SegmentEntity targetEntity)
    {
        MyModMachine machine = targetEntity as MyModMachine;

        if (name == "itemicon")
        {
            ItemBase itemForSlot = ItemManager.SpawnItem(100);
            int      count       = itemForSlot.GetAmount();
            if (itemForSlot == null)
            {
                return;
            }
            if (HotBarManager.mbInited)
            {
                HotBarManager.SetCurrentBlockLabel(ItemManager.GetItemName(itemForSlot));
            }
            else
            {
                if (!SurvivalHotBarManager.mbInited)
                {
                    return;
                }
                string name1 = !WorldScript.mLocalPlayer.mResearch.IsKnown(itemForSlot) ? "Unknown Material" : ItemManager.GetItemName(itemForSlot);
                if (count > 1)
                {
                    SurvivalHotBarManager.SetCurrentBlockLabel(string.Format("{0} {1}", count, name1));
                }
                else
                {
                    SurvivalHotBarManager.SetCurrentBlockLabel(name1);
                }
            }
        }
    }
    public override bool ButtonRightClicked(string name, SegmentEntity targetEntity)
    {
        if (name.Contains("registry" + -1) || name == "hopitemoffer" || name == "hopitemrequest")
        {
            if (name == "hopitemoffer")
            {
                this.eSearchType = SearchType.HopperOffer;
            }
            else if (name == "hopitemrequest")
            {
                this.eSearchType = SearchType.HopperRequest;
            }
            else
            {
                this.eSearchType = SearchType.Registry;
            }

            this.ItemSearchWindow        = true;
            UIManager.mbEditingTextField = true;
            UIManager.AddUIRules("TextEntry", UIRules.RestrictMovement | UIRules.RestrictLooking | UIRules.RestrictBuilding | UIRules.RestrictInteracting | UIRules.SetUIUpdateRate);
            this.Redraw(targetEntity);
            GenericMachinePanelScript.instance.Scroll_Bar.GetComponent <UIScrollBar>().scrollValue = 0.0f;
            return(true);
        }
        else
        {
            return(base.ButtonRightClicked(name, targetEntity));
        }
    }
 public override void OnClose(SegmentEntity targetEntity)
 {
     this.SetName                 = false;
     this.EntryString             = "";
     UIManager.mbEditingTextField = false;
     UIManager.RemoveUIRules("TextEntry");
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static Boolean GiveItem(SegmentEntity entity, ItemBase item)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var type = SupportedType(entity);

            if (type == null)
            {
                return(false);
            }

            if (type == typeof(CommunityItemInterface))
            {
                var iEntity = entity as CommunityItemInterface;
                return(iEntity.GiveItem(item));
            }
            var interop = _supportedTypes[type];

            return(interop.GiveItem(entity, item));
        }
        public override void SpawnWindow(SegmentEntity targetEntity)
        {
            if (!(targetEntity is QuantumOutputPortMachine))
            {
                UIManager.RemoveUIRules("Machine");
            }
            else
            {
                manager.SetTitle("Quantum Output Port");
                if (!_itemSearch)
                {
                    manager.AddIcon(OutputItemIcon, "empty", Color.white, 10, 0);
                    manager.AddBigLabel(OutputTitleLabel, PersistentSettings.GetString("Choose_output"), Color.white, 70, 0);
                    manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, OutputStatusLabel,
                                     string.Empty, Color.white, false, 10, TextHeight * 2);
                    manager.AddButton(ChooseItemButton, PersistentSettings.GetString("Choose_Item"), 100,
                                      ButtonsRowStart + QuantumStorageModSettings.ButtonHeight * 2);
                    manager.AddButton(ToggleStatusButton, "Toggle item output", 100,
                                      ButtonsRowStart + QuantumStorageModSettings.ButtonHeight * 3);
                }
                else
                {
                    ItemSearchWindow.SpawnWindow((BaseMachineWindow)this);
                }

                Dirty = true;
            }
        }
示例#7
0
        public override void UpdateMachine(SegmentEntity targetEntity)
        {
            QuantumIoPortMachine ioPort = targetEntity as QuantumIoPortMachine;

            if (ioPort == null)
            {
                GenericMachinePanelScript.instance.Hide();
                UIManager.RemoveUIRules("Machine");
                return;
            }

            if (ItemSearch)
            {
                if (QuantumIoPortItemSearch.UpdateMachine((BaseMachineWindow)this))
                {
                    Dirty = true;
                    return;
                }
            }
            else
            {
                if (ioPort.GetController().GetItems().Count != SlotCount)
                {
                    Redraw(targetEntity);
                    Dirty = true;
                    return;
                }
                else
                {
                    WindowUpdate(ioPort.GetController());
                }
            }

            Dirty = false;
        }
        /// <summary>
        ///     Call this in GetPopupText to handle your UI Window
        /// </summary>
        /// <param name="theMachine">Pass the current machine</param>
        /// <param name="theWindow">The mod window inherited from BaseMachineWindow</param>
        /// <returns></returns>
        public static bool HandleThisMachineWindow(SegmentEntity theMachine, BaseMachineWindow theWindow)
        {
            try
            {
                UIUtil.TargetWindow = theWindow;

                bool flag1 = SetupMachineWindow(theMachine);
                if (!flag1)
                {
                    return(false);
                }

                bool flag2 = HandleWindowView(theMachine);
                if (!flag2)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("HandleThisMachineWindow: failed : " + ex.Message + " : " + ex.StackTrace);
            }

            return(true);
        }
示例#9
0
        public override void SpawnWindow(SegmentEntity targetEntity)
        {
            if (!(targetEntity is QuantumIoPortMachine quantumIoPort))
            {
                GenericMachinePanelScript.instance.Hide();
                UIManager.RemoveUIRules("Machine");
                return;
            }

            QuantumIoPort = (QuantumIoPortMachine)targetEntity;

            if (!ItemSearch)
            {
                var itemWidth    = 60;
                var itemHeight   = 60;
                var textHeight   = 30;
                var itemRowStart = textHeight * 5;

                var items = quantumIoPort.GetController().GetItems();
                manager.SetTitle(QuantumIoPortMachine.MachineName);

                manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, StorageSizeLabel,
                                 string.Empty, Color.white,
                                 false, 10, textHeight);

                manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, StatusLabel,
                                 string.Empty, Color.white,
                                 false, 10, textHeight * 2);

                manager.AddButton(FindItemButton, "Search", 100, QuantumStorageModSettings.ButtonHeight * 3);

                SlotCount = 0;
                for (var index = 0; index < items.Count(); index++)
                {
                    var line   = index / 5;
                    var column = index % 5;
                    manager.AddIcon("iconItem" + index, "empty", Color.white, column * itemWidth + 10,
                                    line * itemHeight + itemRowStart + 10);
                    manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "labelItem" + index,
                                     string.Empty, Color.white, false, column * itemWidth + 28, line * itemHeight + itemRowStart + 17);
                    SlotCount++;
                }

                {
                    var line   = items.Count() / 5;
                    var column = items.Count() % 5;
                    manager.AddIcon("iconItem" + items.Count, "empty", Color.white, column * itemWidth + 10,
                                    line * itemHeight + itemRowStart + 10);
                    manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth,
                                     "labelItem" + items.Count,
                                     string.Empty, Color.white, false, column * itemWidth + 28, line * itemHeight + itemRowStart + 17);
                }
            }
            else
            {
                QuantumIoPortItemSearch.SpawnWindow(this);
            }

            Dirty = true;
        }
    public override void UpdateMachine(SegmentEntity targetEntity)
    {
        ExtraStorageHoppers hopper = targetEntity as ExtraStorageHoppers;

        if (hopper == null)
        {
            GenericMachinePanelScript.instance.Hide();
            UIManager.RemoveUIRules("Machine");
            return;
        }
        if (ExtraStorageHopperWindowNew.networkRedraw)
        {
            this.Redraw(targetEntity);
            ExtraStorageHopperWindowNew.networkRedraw = false;
        }
        if (targetEntity.mbNetworkUpdated)
        {
            ExtraStorageHopperWindowNew.dirty = true;
            targetEntity.mbNetworkUpdated     = false;
        }
        if (ExtraStorageHopperWindowNew.dirty)
        {
            this.WindowUpdate(hopper);
        }
    }
    public override void ButtonEnter(string name, SegmentEntity targetEntity)
    {
        ExtraStorageHoppers hopper = targetEntity as ExtraStorageHoppers;
        string   empty             = string.Empty;
        ItemBase itemForSlot       = this.GetItemForSlot(hopper, name);

        if (itemForSlot == null)
        {
            return;
        }
        if (HotBarManager.mbInited)
        {
            HotBarManager.SetCurrentBlockLabel(ItemManager.GetItemName(itemForSlot));
        }
        else
        {
            if (!SurvivalHotBarManager.mbInited)
            {
                return;
            }
            string text             = WorldScript.mLocalPlayer.mResearch.IsKnown(itemForSlot) ? ItemManager.GetItemName(itemForSlot) : "Unknown Material";
            int    currentStackSize = ItemManager.GetCurrentStackSize(itemForSlot);
            if (currentStackSize > 1)
            {
                SurvivalHotBarManager.SetCurrentBlockLabel(string.Format("{0} {1}", currentStackSize, text));
            }
            else
            {
                SurvivalHotBarManager.SetCurrentBlockLabel(text);
            }
        }
    }
示例#12
0
        public ItemBase TakeAnyItem(SegmentEntity entity)
        {
            var hopper = entity.As <StorageHopper>();

            if (hopper.mPermissions == eHopperPermissions.Locked || !hopper.mbAllowLogistics)
            {
                return(null);
            }
            ItemBase ret = null;

            if (hopper.mnStorageUsed >= 1)
            {
                ushort cubeType;
                ushort cubeValue;
                hopper.GetSpecificCubeRoundRobin(eHopperRequestType.eAny, out cubeType, out cubeValue);
                if (cubeType != 0)
                {
                    ret = ItemManager.SpawnCubeStack(cubeType, cubeValue, 1);
                }
                else
                {
                    ret = hopper.RemoveSingleSpecificItemOrCubeRoundRobin(eHopperRequestType.eAny);
                }
            }

            if (ret != null)
            {
                hopper.LogisticsOperation();
                hopper.RequestImmediateNetworkUpdate();
            }
            return(ret);
        }
        /// <summary>
        ///		Will return any <see cref="ItemBase">item</see> from the <see cref="SegmentEntity">entity</see>
        /// </summary>
        /// <param name="entity">The <see cref="SegmentEntity">entity</see> to get a <see cref="ItemBase">item</see> from</param>
        /// <returns>A <see cref="ItemBase">item</see>, or <c>NULL</c></returns>
        public static ItemBase TakeAnyItem(SegmentEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            try
            {
                var type = SupportedType(entity);
                if (type == null)
                {
                    return(null);
                }

                if (type == typeof(CommunityItemInterface))
                {
                    var iEntity = entity as CommunityItemInterface;
                    return(iEntity.TakeAnyItem());
                }

                var interop = _supportedTypes[type];
                return(interop.TakeAnyItem(entity));
            }
            catch (NotImplementedException)
            {
                return(null);
            }
        }
示例#14
0
 public bool HasFreeSpace(SegmentEntity entity, uint amount)
 {
     if (amount > 1)
     {
         return(false);
     }
     return(GetFreeSpace(entity) >= amount);
 }
    public override void SpawnWindow(SegmentEntity targetEntity)
    {
        TourCartStation station = targetEntity as TourCartStation;

        //Catch for when the window is called on an inappropriate machine
        if (station == null)
        {
            GenericMachinePanelScript.instance.Hide();
            UIManager.RemoveUIRules("Machine");
            return;
        }
        UIUtil.UIdelay = 0;
        UIUtil.UILock  = true;

        if (this.SetName || string.IsNullOrEmpty(station.StationName))
        {
            this.manager.SetTitle("Tour Cart Station - Set Name");
            UIManager.mbEditingTextField = true;
            UIManager.AddUIRules("TextEntry", UIRules.RestrictMovement | UIRules.RestrictLooking | UIRules.RestrictBuilding | UIRules.RestrictInteracting | UIRules.SetUIUpdateRate);
            GenericMachinePanelScript.instance.Scroll_Bar.GetComponent <UIScrollBar>().scrollValue = 0.0f;

            this.manager.AddButton("namecancel", "Cancel", 100, 0);
            this.manager.AddBigLabel("nametitle", "Enter Network ID", Color.white, 50, 40);
            this.manager.AddBigLabel("nameentry", "_", Color.cyan, 50, 65);
        }
        else
        {
            // Select destination
            this.manager.SetTitle("Select Tour Cart Destination");
            this.manager.AddButton("namestation", "Change Name", 15, 0);
            this.manager.AddBigLabel("stationname", station.StationName, Color.white, 165, 0);

            int spacing = 50; //Spacing between each registry line
            int yoffset = 65; //Offset below button row
            if (station.TrackNetwork != null && station.TrackNetwork.TourCartStations.Count != 0)
            {
                List <string> keys = station.TrackNetwork.TourCartStations.Keys.ToList();
                keys.Remove(station.StationName);
                for (int n = 0; n < keys.Count; n++)
                {
                    this.manager.AddButton("tourstation" + n, keys[n], 100, yoffset + (n * spacing));
                }
                if (keys.Count == 0)
                {
                    this.manager.AddBigLabel("nostations", "Add Additional Tour Cart Stations", Color.red, 0, yoffset);
                    this.manager.AddBigLabel("nostations1", "to Track Network...", Color.red, 0, yoffset + 22);
                }
            }
            else
            {
                this.manager.AddBigLabel("nostations", "Connect Tour Cart Station to", Color.red, 0, yoffset);
                this.manager.AddBigLabel("nostations1", "a Freight Track Network...", Color.red, 0, yoffset + 22);
            }
        }
        //dirty = true;
        networkredraw = false;
    }
示例#16
0
 public static bool IsSegmentPositionEqual(SegmentEntity segment, long tempPosX, long tempPosY, long tempPosZ)
 {
     if (segment == null)
     {
         return(false);
     }
     return(tempPosX == segment.mnX &&
            tempPosY == segment.mnY &&
            tempPosZ == segment.mnZ);
 }
示例#17
0
        protected override Byte CalculateOutput(SegmentEntity entity, UInt16 data)
        {
            StorageHopper hopper = entity as StorageHopper;

            if (hopper == null)
            {
                return(0);
            }
            return((Byte)Math.Min(hopper.mnStorageUsed, Byte.MaxValue));
        }
示例#18
0
        public int GetFreeSpace(SegmentEntity entity)
        {
            var conveyor = entity.As <ConveyorEntity>();

            if (conveyor.mbReadyToConvey)
            {
                return(1);
            }
            return(0);
        }