public override void SpawnWindow(SegmentEntity targetEntity)
    {
        ExtraStorageHoppers hopper = targetEntity as ExtraStorageHoppers;

        if (hopper == null)
        {
            GenericMachinePanelScript.instance.Hide();
            UIManager.RemoveUIRules("Machine");
            return;
        }
        float x = GenericMachinePanelScript.instance.Label_Holder.transform.position.x;
        float y = GenericMachinePanelScript.instance.Label_Holder.transform.position.y;

        GenericMachinePanelScript.instance.Label_Holder.transform.position = new Vector3(x, y, 69.3f);
        string title = "UNKNOWN TYPE";

        if (hopper.GetHopperName() != "")
        {
            title = hopper.GetHopperName();
        }
        this.manager.SetTitle(title);
        int num  = 0;
        int num2 = 40;
        int num3 = 50;
        int num4 = 60;
        int num5 = 60;
        int num6 = 40;
        int num7 = num2 + num3 + 50 + num6 + 50;

        this.manager.AddTabButton("AddRemoveButton", "Add and Remove", true, 40, 0);
        this.manager.AddTabButton("LockedButton", "Locked", true, 160, 0);
        this.manager.AddTabButton("AddOnlyButton", "Add Only", true, 40, 40);
        this.manager.AddTabButton("RemoveOnlyButton", "Remove Only", true, 160, 40);
        this.manager.AddButton("ToggleHoover", "Toggle Vacuum", 30, 90);
        this.manager.AddBigLabel("HooverStatus", "Vacuum: Off", Color.white, 180, 90);
        this.manager.AddButton("ToggleShare", "Toggle Share", 30, 140);
        this.manager.AddBigLabel("ShareStatus", "Share Mode: Off", Color.white, 180, 140);
        this.manager.AddBigLabel("UsedStorage", "8888/8888", Color.white, 10, 190);
        this.SlotCount = this.CountUnique(hopper);
        for (int i = 0; i <= this.SlotCount; i++)
        {
            if (hopper.IsFull() && i == this.SlotCount)
            {
                break;
            }
            int num8 = i / 5;
            int num9 = i % 5;
            this.manager.AddIcon("ItemSlot" + i, "empty", Color.white, num9 * num5 + 10, num8 * num4 + num7 + num);
            this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "StackSize" + i, string.Empty, Color.white, false, num9 * num5 + 33, num8 * num4 + num7 + 22);
        }
        ExtraStorageHopperWindowNew.dirty = true;
    }
    public override bool ButtonClicked(string name, SegmentEntity targetEntity)
    {
        ExtraStorageHoppers hopper = targetEntity as ExtraStorageHoppers;

        if (name == "AddRemoveButton")
        {
            UIManager.ForceNGUIUpdate = 0.1f;
            ExtraStorageHopperWindowNew.SetPermissions(WorldScript.mLocalPlayer, hopper, eHopperPermissions.AddAndRemove);
            return(true);
        }
        if (name == "AddOnlyButton")
        {
            UIManager.ForceNGUIUpdate = 0.1f;
            ExtraStorageHopperWindowNew.SetPermissions(WorldScript.mLocalPlayer, hopper, eHopperPermissions.AddOnly);
            return(true);
        }
        if (name == "RemoveOnlyButton")
        {
            UIManager.ForceNGUIUpdate = 0.1f;
            ExtraStorageHopperWindowNew.SetPermissions(WorldScript.mLocalPlayer, hopper, eHopperPermissions.RemoveOnly);
            return(true);
        }
        if (name == "LockedButton")
        {
            UIManager.ForceNGUIUpdate = 0.1f;
            ExtraStorageHopperWindowNew.SetPermissions(WorldScript.mLocalPlayer, hopper, eHopperPermissions.Locked);
            return(true);
        }
        if (name == "ToggleHoover")
        {
            UIManager.ForceNGUIUpdate = 0.1f;
            AudioHUDManager.instance.HUDIn();
            ExtraStorageHopperWindowNew.ToggleHoover(WorldScript.mLocalPlayer, hopper);
            return(true);
        }
        if (name == "ToggleShare")
        {
            UIManager.ForceNGUIUpdate = 0.1f;
            AudioHUDManager.instance.HUDIn();
            ExtraStorageHopperWindowNew.ToggleShare(WorldScript.mLocalPlayer, hopper);
            return(true);
        }
        if (name.Contains("ItemSlot"))
        {
            int num = -1;
            int.TryParse(name.Replace("ItemSlot", string.Empty), out num);
            if (num > -1)
            {
                int num2 = 100;
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    num2 = 10;
                }
                if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                {
                    num2 = 1;
                }
                ItemBase item = ItemManager.CloneItem(this.GetNthItemSlot(hopper, num));
                if (num2 < ItemManager.GetCurrentStackSize(item))
                {
                    ItemManager.SetItemCount(item, num2);
                    if (hopper.IsFull())
                    {
                        ExtraStorageHopperWindowNew.networkRedraw = true;
                    }
                    else
                    {
                        ExtraStorageHopperWindowNew.dirty = true;
                    }
                }
                else
                {
                    ExtraStorageHopperWindowNew.networkRedraw = true;
                }
                ExtraStorageHopperWindowNew.TakeItems(WorldScript.mLocalPlayer, hopper, item);
                UIManager.ForceNGUIUpdate = 0.1f;
                AudioHUDManager.instance.OrePickup();
                if (WorldScript.meGameMode == eGameMode.eSurvival && SurvivalPlayerScript.meTutorialState == SurvivalPlayerScript.eTutorialState.RemoveCoalFromHopper)
                {
                    SurvivalPlayerScript.TutorialSectionComplete();
                }
                typeof(ExtraStorageHoppers).GetField("mRetakeDebounce", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(hopper, 0.5f);
                return(true);
            }
        }
        return(false);
    }