예제 #1
0
        public static void OnStationIdChangePre(UIStationWindow __instance, ref string __state)
        {
            if (__instance.stationId == 0 || __instance.factory == null || __instance.transport?.stationPool == null)
            {
                return;
            }

            StationComponent stationComponent = __instance.transport.stationPool[__instance.stationId];

            ItemProto itemProto = LDB.items.Select(__instance.factory.entityPool[stationComponent.entityId].protoId);

            if (itemProto.ID != GigaStationsPlugin.pls.ID && itemProto.ID != GigaStationsPlugin.ils.ID && itemProto.ID != GigaStationsPlugin.collector.ID)
            {
                return;
            }

            if (!__instance.active)
            {
                return;
            }

            string text = (!string.IsNullOrEmpty(stationComponent.name))
                ? stationComponent.name
                : ((!stationComponent.isStellar)
                    ? ("Planetary Giga Station #" + stationComponent.id)
                    : ((stationComponent.isCollector)
                        ? ("Orbital Giga Collector #" + stationComponent.gid)
                        : ("Interstellar Giga Station #" + stationComponent.gid)));

            __state = text;
        }
예제 #2
0
        public static void _OnOpen_Postfix(UIStationWindow __instance)
        {
            if (!Multiplayer.IsActive || __instance.transport == null)
            {
                return;
            }

            StationComponent stationComponent = __instance.transport.stationPool[__instance.stationId];

            Multiplayer.Session.StationsUI.SliderBarPacket    = new StationUI(__instance.factory.planet.id, stationComponent.id, stationComponent.gid, StationUI.EUISettings.None, 0);
            Multiplayer.Session.StationsUI.StorageMaxChangeId = -1;
            if (Multiplayer.Session.LocalPlayer.IsHost)
            {
                return;
            }
            lastUpdateGametick = GameMain.gameTick;

            // Stage 0 : Hide UI elements until sync data arrive
            __instance.titleText.text = "Loading...";
            for (int i = 0; i < __instance.storageUIs.Length; i++)
            {
                __instance.storageUIs[i]._Close();
                __instance.storageUIs[i].ClosePopMenu();
            }
            __instance.panelDown.SetActive(false);

            // for some reason advance miner has planetId set to 0, so we use UI's factory planetId
            Multiplayer.Session.Network.SendPacket(new StationUIInitialSyncRequest(__instance.factory.planetId, stationComponent.id, stationComponent.gid));
        }
예제 #3
0
 public static void _OnClose_Postfix(UIStationWindow __instance)
 {
     if (!SimulatedWorld.Initialized || LocalPlayer.IsMasterClient)
     {
         return;
     }
     if (__instance.factory == null)
     {
         __instance.factory = GameMain.localPlanet.factory;
     }
     if (__instance.transport == null)
     {
         __instance.transport = __instance.factory.transport;
     }
     if (__instance.stationId != 0 || StationUIManager.UIStationId != 0)
     {
         Debug.Log("sending unsubscriber");
         // it is actually 0 before we manually set it to the right value in StationUIInitialSyncProcessor.cs and thus its a good check to skip sending the packet on the Free() call
         LocalPlayer.SendPacket(new StationSubscribeUIUpdates(false, __instance.transport.stationPool[StationUIManager.UIStationId].gid));
         StationUIManager.lastSelectedGameObj = null;
         StationUIManager.UIIsSyncedStage     = 0;
         StationUIManager.UIStationId         = 0;
     }
     else
     {
         Debug.Log("skiping unsubscribe");
     }
 }
예제 #4
0
        public static bool _OnCreatePrefix(UIStationWindow __instance)
        {
            // do always

            //part of 1% sliderstep fix
            __instance.minDeliverDroneSlider.maxValue  = 100;
            __instance.minDeliverVesselSlider.maxValue = 100;

            GameObject prefab = GigaStationsPlugin.resource.bundle.LoadAsset <GameObject>("assets/gigastations/ui/station-scroll.prefab");

            GameObject scrollPane = Object.Instantiate(prefab, __instance.transform, false);

            scrollTrs = (RectTransform)scrollPane.transform;

            scrollTrs.anchorMin = Vector2.up;
            scrollTrs.anchorMax = Vector2.one;
            scrollTrs.pivot     = new Vector2(0.5f, 1);
            scrollTrs.offsetMin = new Vector2(40, 400);
            scrollTrs.offsetMax = new Vector2(-40, -90);

            GameObject contentPane = scrollPane.transform.Find("Viewport/pane").gameObject;

            contentTrs = (RectTransform)contentPane.transform;

            __instance.storageUIs = new UIStationStorage[12];
            for (int i = 0; i < __instance.storageUIs.Length; i++)
            {
                __instance.storageUIs[i] = Object.Instantiate(__instance.storageUIPrefab, contentTrs);
                __instance.storageUIs[i].stationWindow = __instance;
                __instance.storageUIs[i]._Create();
            }
            __instance.veinCollectorPanel._Create();

            return(false);
        }
예제 #5
0
        public void ProcessPacket(StationUIInitialSync packet, NebulaConnection conn)
        {
            StationComponent[] gStationPool = null;
            if (packet.planetId == 0)
            {
                gStationPool = GameMain.data.galacticTransport.stationPool;
            }
            else
            {
                PlanetData pData = GameMain.galaxy.PlanetById(packet.planetId);
                if (pData?.factory?.transport != null)
                {
                    gStationPool = pData.factory.transport.stationPool;
                }
            }
            if (gStationPool != null && gStationPool.Length > packet.stationGId && StationUIManager.UIIsSyncedStage == 1)
            {
                StationComponent stationComponent = gStationPool[packet.stationGId];
                if (stationComponent != null)
                {
                    UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

                    stationComponent.tripRangeDrones       = packet.tripRangeDrones;
                    stationComponent.tripRangeShips        = packet.tripRangeShips;
                    stationComponent.deliveryDrones        = packet.deliveryDrones;
                    stationComponent.deliveryShips         = packet.deliveryShips;
                    stationComponent.warpEnableDist        = packet.warpEnableDist;
                    stationComponent.warperNecessary       = packet.warperNecessary;
                    stationComponent.includeOrbitCollector = packet.includeOrbitCollector;
                    stationComponent.energy        = packet.energy;
                    stationComponent.energyPerTick = packet.energyPerTick;
                    for (int i = 0; i < packet.itemId.Length; i++)
                    {
                        if (stationComponent.storage == null)
                        {
                            // 3 is games default storage places for PLS
                            stationComponent.storage = new StationStore[packet.itemId.Length];
                        }
                        stationComponent.storage[i].itemId      = packet.itemId[i];
                        stationComponent.storage[i].max         = packet.itemCountMax[i];
                        stationComponent.storage[i].count       = packet.itemCount[i];
                        stationComponent.storage[i].remoteOrder = packet.remoteOrder[i];
                        stationComponent.storage[i].localLogic  = (ELogisticStorage)packet.localLogic[i];
                        stationComponent.storage[i].remoteLogic = (ELogisticStorage)packet.remoteLogic[i];
                    }
                    if (stationWindow != null && stationWindow.active)
                    {
                        conn.SendPacket(new StationSubscribeUIUpdates(true, stationComponent.gid));
                        StationUIManager.UIIsSyncedStage++;
                        stationWindow._Free();
                        stationWindow._Init(stationComponent);
                        AccessTools.Field(typeof(UIStationWindow), "_stationId").SetValue(stationWindow, stationComponent.id);
                        stationWindow._Open();
                        stationWindow._Update();
                    }
                    StationUIManager.UIStationId = stationComponent.id;
                }
            }
        }
예제 #6
0
 public static bool _OnUpdate_Prefix(UIStationWindow __instance)
 {
     if (!SimulatedWorld.Initialized || LocalPlayer.IsMasterClient || StationUIManager.UIIsSyncedStage == 2)
     {
         return(true);
     }
     return(false);
 }
        public override void ProcessPacket(StationUIInitialSync packet, NebulaConnection conn)
        {
            StationComponent stationComponent = null;

            StationComponent[] gStationPool = GameMain.data.galacticTransport.stationPool;
            StationComponent[] stationPool  = GameMain.data.galaxy.PlanetById(packet.PlanetId).factory.transport.stationPool;

            stationComponent = packet.StationGId > 0 ? gStationPool[packet.StationGId] : stationPool?[packet.StationId];

            if (stationComponent == null)
            {
                Log.Error($"StationUIInitialSyncProcessor: Unable to find requested station on planet {packet.PlanetId} with id {packet.StationId} and gid of {packet.StationGId}");
                return;
            }

            if (StationUIManager.UIIsSyncedStage == 1)
            {
                UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

                stationComponent.tripRangeDrones       = packet.TripRangeDrones;
                stationComponent.tripRangeShips        = packet.TripRangeShips;
                stationComponent.deliveryDrones        = packet.DeliveryDrones;
                stationComponent.deliveryShips         = packet.DeliveryShips;
                stationComponent.warpEnableDist        = packet.WarperEnableDistance;
                stationComponent.warperNecessary       = packet.WarperNecessary;
                stationComponent.includeOrbitCollector = packet.IncludeOrbitCollector;
                stationComponent.energy        = packet.Energy;
                stationComponent.energyPerTick = packet.EnergyPerTick;

                for (int i = 0; i < packet.ItemId.Length; i++)
                {
                    if (stationComponent.storage == null)
                    {
                        stationComponent.storage = new StationStore[packet.ItemId.Length];
                    }

                    stationComponent.storage[i].itemId      = packet.ItemId[i];
                    stationComponent.storage[i].max         = packet.ItemCountMax[i];
                    stationComponent.storage[i].count       = packet.ItemCount[i];
                    stationComponent.storage[i].remoteOrder = packet.RemoteOrder[i];
                    stationComponent.storage[i].localLogic  = (ELogisticStorage)packet.LocalLogic[i];
                    stationComponent.storage[i].remoteLogic = (ELogisticStorage)packet.RemoteLogic[i];
                }

                if (stationWindow != null && stationWindow.active)
                {
                    conn.SendPacket(new StationSubscribeUIUpdates(true, stationComponent.planetId, stationComponent.id, stationComponent.gid));
                    StationUIManager.UIIsSyncedStage++;
                    stationWindow._Free();
                    stationWindow._Init(stationComponent);
                    AccessTools.Field(typeof(UIStationWindow), "_stationId").SetValue(stationWindow, stationComponent.id);
                    stationWindow._Open();
                    stationWindow._Update();
                }

                StationUIManager.UIStationId = stationComponent.id;
            }
        }
예제 #8
0
 public static bool OnWarperDistanceValueChange_Prefix(UIStationWindow __instance, float value)
 {
     if (__instance.event_lock || !Multiplayer.IsActive || Multiplayer.Session.Ships.PatchLockILS)
     {
         return(true);
     }
     Multiplayer.Session.StationsUI.SliderBarPacket.SettingIndex = StationUI.EUISettings.WarpDistance;
     Multiplayer.Session.StationsUI.SliderBarPacket.SettingValue = value;
     return(Multiplayer.Session.LocalPlayer.IsHost);
 }
예제 #9
0
 public static void _OnStationWindowClose(UIStationWindow __instance)
 {
     if (__instance != null &&
         __instance.stationId == Instance._lastStationId &&
         __instance.factory != null &&
         __instance.factory.index == Instance._lastStationFactoryIndex)
     {
         Instance._inspectingStation = false;
     }
 }
예제 #10
0
        public static void OnStationIdChange_Postfix(UIStationWindow __instance)
        {
            if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost)
            {
                return;
            }

            __instance.warperIconButton.button.interactable = true;
            __instance.shipIconButton.button.interactable   = true;
            __instance.droneIconButton.button.interactable  = true;
        }
예제 #11
0
        public static bool OnIncludeOrbitCollectorClick_Prefix(UIStationWindow __instance)
        {
            if (__instance.event_lock || !Multiplayer.IsActive || Multiplayer.Session.Ships.PatchLockILS)
            {
                return(true);
            }
            StationUI packet = new StationUI(__instance.factory.planet.id, __instance.factory.transport.stationPool[__instance.stationId].id, __instance.factory.transport.stationPool[__instance.stationId].gid, StationUI.EUISettings.IncludeCollectors, 0f);

            Multiplayer.Session.Network.SendPacket(packet);
            return(Multiplayer.Session.LocalPlayer.IsHost);
        }
        public override void ProcessPacket(StationUIInitialSync packet, NebulaConnection conn)
        {
            StationComponent stationComponent = null;

            StationComponent[] stationPool = GameMain.data.galaxy.PlanetById(packet.PlanetId).factory.transport.stationPool;
            // Assume the requesting station is on a loaded planet
            stationComponent = stationPool?[packet.StationId];

            if (stationComponent == null)
            {
                Log.Error($"StationUIInitialSyncProcessor: Unable to find requested station on planet {packet.PlanetId} with id {packet.StationId} and gid of {packet.StationGId}");
                return;
            }
            if (stationComponent.gid > 0 && stationComponent.gid != packet.StationGId)
            {
                Log.Error($"StationGid desync! Host:{packet.StationGId} Local:{stationComponent.gid}");
            }

            stationComponent.tripRangeDrones       = packet.TripRangeDrones;
            stationComponent.tripRangeShips        = packet.TripRangeShips;
            stationComponent.deliveryDrones        = packet.DeliveryDrones;
            stationComponent.deliveryShips         = packet.DeliveryShips;
            stationComponent.warpEnableDist        = packet.WarperEnableDistance;
            stationComponent.warperNecessary       = packet.WarperNecessary;
            stationComponent.includeOrbitCollector = packet.IncludeOrbitCollector;
            stationComponent.energy        = packet.Energy;
            stationComponent.energyPerTick = packet.EnergyPerTick;
            stationComponent.pilerCount    = packet.PilerCount;

            for (int i = 0; i < packet.ItemId.Length; i++)
            {
                if (stationComponent.storage == null)
                {
                    stationComponent.storage = new StationStore[packet.ItemId.Length];
                }

                stationComponent.storage[i].itemId      = packet.ItemId[i];
                stationComponent.storage[i].max         = packet.ItemCountMax[i];
                stationComponent.storage[i].count       = packet.ItemCount[i];
                stationComponent.storage[i].inc         = packet.ItemInc[i];
                stationComponent.storage[i].remoteOrder = packet.RemoteOrder[i];
                stationComponent.storage[i].localLogic  = (ELogisticStorage)packet.LocalLogic[i];
                stationComponent.storage[i].remoteLogic = (ELogisticStorage)packet.RemoteLogic[i];
            }

            UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

            if (stationWindow.active && stationWindow.factory?.planetId == packet.PlanetId && stationWindow.stationId == packet.StationId)
            {
                //Trigger OnStationIdChange() to refresh window
                stationWindow.OnStationIdChange();
            }
        }
예제 #13
0
        public static void OnPilerCountChange(UIStationWindow __instance)
        {
            if (__instance.event_lock || !Multiplayer.IsActive || Multiplayer.Session.Ships.PatchLockILS)
            {
                return;
            }

            StationComponent stationComponent = __instance.transport.stationPool[__instance.stationId];
            StationUI        packet           = new StationUI(__instance.factory.planet.id, stationComponent.id, stationComponent.gid, StationUI.EUISettings.PilerCount, stationComponent.pilerCount);

            Multiplayer.Session.Network.SendPacket(packet);
        }
예제 #14
0
        /*
         * call UIStationStorage.RefreshValues() on the current opened stations UI
         */
        private static void RefreshValuesUI(StationComponent stationComponent, int storageIndex)
        {
            UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

            if (stationWindow != null && FR_stationId(stationWindow) == stationComponent.id)
            {
                UIStationStorage[] stationStorageUI = FR_storageUIs(stationWindow);
                if (stationStorageUI != null && stationStorageUI.Length > storageIndex)
                {
                    MI_RefreshValues.Invoke(stationStorageUI[storageIndex], null);
                }
            }
        }
예제 #15
0
 public static bool OnMaxChargePowerSliderValueChange_Prefix(UIStationWindow __instance, float value)
 {
     if (SimulatedWorld.Initialized && !ILSShipManager.PatchLockILS)
     {
         StationUI packet = new StationUI(__instance.factory.transport.stationPool[__instance.stationId].gid, __instance.factory.planet.id, StationUI.UIsettings.MaxChargePower, value);
         LocalPlayer.SendPacket(packet);
         if (LocalPlayer.IsMasterClient)
         {
             return(true);
         }
         return(false);
     }
     return(true);
 }
예제 #16
0
 public static bool OnIncludeOrbitCollectorClick_Prefix(UIStationWindow __instance, int obj)
 {
     if (SimulatedWorld.Initialized && !ILSShipManager.PatchLockILS && (StationUIManager.UIIsSyncedStage == 2 || LocalPlayer.IsMasterClient))
     {
         StationUI packet = new StationUI(__instance.factory.transport.stationPool[__instance.stationId].gid, __instance.factory.planet.id, StationUI.UIsettings.includeCollectors, 0f);
         LocalPlayer.SendPacket(packet);
         if (LocalPlayer.IsMasterClient)
         {
             return(true);
         }
         return(false);
     }
     return(true);
 }
예제 #17
0
 public static bool OnMinDeliverVesselValueChange_Prefix(UIStationWindow __instance, float value)
 {
     if (SimulatedWorld.Initialized && !LocalPlayer.PatchLocks["UIStationWindow"] && (StationUIManager.UIIsSyncedStage == 2 || LocalPlayer.IsMasterClient))
     {
         StationUI packet = new StationUI(__instance.factory.transport.stationPool[__instance.stationId].gid, __instance.factory.planet.id, 4, value);
         LocalPlayer.SendPacket(packet);
         if (LocalPlayer.IsMasterClient)
         {
             return(true);
         }
         return(false);
     }
     return(true);
 }
예제 #18
0
 public static bool OnWarperNecessaryClick_Prefix(UIStationWindow __instance, int obj)
 {
     if (SimulatedWorld.Initialized && !LocalPlayer.PatchLocks["UIStationWindow"] && (StationUIManager.UIIsSyncedStage == 2 || LocalPlayer.IsMasterClient))
     {
         StationUI packet = new StationUI(__instance.factory.transport.stationPool[__instance.stationId].gid, __instance.factory.planet.id, 6, 0f);
         LocalPlayer.SendPacket(packet);
         if (LocalPlayer.IsMasterClient)
         {
             return(true);
         }
         return(false);
     }
     return(true);
 }
예제 #19
0
 public static bool OnWarperDistanceValueChange_Prefix(UIStationWindow __instance, float value)
 {
     if (SimulatedWorld.Initialized && !ILSShipManager.PatchLockILS && (StationUIManager.UIIsSyncedStage == 2 || LocalPlayer.IsMasterClient))
     {
         StationUI packet = new StationUI(__instance.factory.transport.stationPool[__instance.stationId].gid, __instance.factory.planet.id, StationUI.UIsettings.WarpDistance, value);
         LocalPlayer.SendPacket(packet);
         if (LocalPlayer.IsMasterClient)
         {
             return(true);
         }
         return(false);
     }
     return(true);
 }
예제 #20
0
        public static void OnStationUpdate(UIStationWindow __instance)
        {
            if (__instance.stationId == 0 || __instance.factory == null)
            {
                return;
            }

            StationComponent stationComponent = __instance.transport.stationPool[__instance.stationId];

            float size    = __instance.powerGroupRect.sizeDelta.x - 140;
            float percent = stationComponent.energy / (float)stationComponent.energyMax;

            float diff = percent > 0.7 ? -30 : 30;

            __instance.energyText.rectTransform.anchoredPosition = new Vector2(Mathf.Round(size * percent + diff), 0.0f);
        }
예제 #21
0
        public static bool UIStationWindow_OnCreate_Prefix(UIStationWindow __instance, ref UIStationStorage[] ___storageUIs, UIStationStorage ___storageUIPrefab)
        {
            bool showWarperSlot = Config.General.ShowWarperSlot.Value;

            if (showWarperSlot == true || ModDisabled == true)
            {
                return(true);
            }
            ___storageUIs = new UIStationStorage[5];
            for (int i = 0; i < ___storageUIs.Length; i++)
            {
                ___storageUIs[i] = Object.Instantiate(___storageUIPrefab, ___storageUIPrefab.transform.parent);
                ((RectTransform)___storageUIs[i].transform).anchoredPosition = new Vector2(40f, -90 - 76 * i);
                ___storageUIs[i].stationWindow = __instance;
                ___storageUIs[i]._Create();
            }
            return(false);
        }
예제 #22
0
        public static bool OnShipIconClick_Prefix(UIStationWindow __instance, int obj)
        {
            if (SimulatedWorld.Initialized && !ILSShipManager.PatchLockILS)
            {
                Player player = GameMain.mainPlayer;
                if (player.inhandItemCount > 0 && player.inhandItemId != 5002)
                {
                    ItemProto itemProto = LDB.items.Select(5002);
                    UIRealtimeTip.Popup("只能放入".Translate() + itemProto.name, true, 0);
                    return(false);
                }
                StationComponent stationComponent = __instance.transport.stationPool[__instance.stationId];
                int toAdd;
                if (player.inhandItemCount > 0)
                {
                    int shipAmount = stationComponent.idleShipCount + stationComponent.workShipCount;
                    int spaceLeft  = 10 - shipAmount;
                    if (spaceLeft < 0)
                    {
                        spaceLeft = 0;
                    }
                    toAdd = (__instance.player.inhandItemCount >= spaceLeft) ? spaceLeft : __instance.player.inhandItemCount;
                }
                else
                {
                    toAdd = stationComponent.idleShipCount * -1;
                }
                if (!LocalPlayer.IsMasterClient)
                {
                    StationUIManager.UIRequestedShipDronWarpChange = true;
                }
                StationUI packet = new StationUI(stationComponent.gid, __instance.factory.planet.id, StationUI.UIsettings.setShipCount, stationComponent.idleShipCount + toAdd);
                LocalPlayer.SendPacket(packet);

                if (LocalPlayer.IsMasterClient)
                {
                    return(true);
                }
                return(false);
            }
            return(true);
        }
예제 #23
0
        public static bool _OnUpdate_Prefix(UIStationWindow __instance)
        {
            if (!Multiplayer.IsActive)
            {
                return(true);
            }

            // When releasing left mouse button
            if (Input.GetMouseButtonUp(0))
            {
                if (Multiplayer.Session.StationsUI.SliderBarPacket.SettingIndex != StationUI.EUISettings.None)
                {
                    // Send SliderBarPacket when left mouse button is released
                    Multiplayer.Session.Network.SendPacket(Multiplayer.Session.StationsUI.SliderBarPacket);
                    Multiplayer.Session.StationsUI.SliderBarPacket.SettingIndex = StationUI.EUISettings.None;
                }
                if (Multiplayer.Session.StationsUI.StorageMaxChangeId >= 0)
                {
                    // Do the job in UIStationStorage.OnMaxSliderValueChange()
                    int          index        = Multiplayer.Session.StationsUI.StorageMaxChangeId;
                    float        val          = __instance.storageUIs[index].maxSlider.value;
                    StationStore stationStore = __instance.transport.stationPool[__instance.stationId].storage[index];
                    __instance.transport.SetStationStorage(__instance.stationId, index, stationStore.itemId, (int)(val * 100f + 0.5f), stationStore.localLogic, stationStore.remoteLogic, GameMain.mainPlayer);

                    // In client side, preserve displaying slider value until host response
                    Multiplayer.Session.StationsUI.StorageMaxChangeId = Multiplayer.Session.LocalPlayer.IsHost ? -1 : -2;
                }
            }

            // Request for remoteOrder update every 180tick
            if (Multiplayer.Session.LocalPlayer.IsClient && GameMain.gameTick - lastUpdateGametick > 180)
            {
                int gid = __instance.transport?.stationPool?[__instance.stationId].gid ?? 0;
                if (gid > 0)
                {
                    Multiplayer.Session.Network.SendPacket(new RemoteOrderUpdate(gid, System.Array.Empty <int>()));
                }
                lastUpdateGametick = GameMain.gameTick;
            }

            return(true);
        }
예제 #24
0
        public static void OnWarperIconClick_Posfix(UIStationWindow __instance, int __state)
        {
            if (__instance.event_lock || !Multiplayer.IsActive || Multiplayer.Session.Ships.PatchLockILS)
            {
                return;
            }

            StationComponent stationComponent = __instance.transport.stationPool[__instance.stationId];

            if (__state != stationComponent.warperCount)
            {
                StationUI packet = new StationUI(__instance.factory.planet.id, stationComponent.id, stationComponent.gid, StationUI.EUISettings.SetWarperCount, stationComponent.warperCount);
                Multiplayer.Session.Network.SendPacket(packet);
                if (Multiplayer.Session.LocalPlayer.IsClient)
                {
                    // Revert warper count until host verify
                    stationComponent.warperCount = __state;
                    __instance.warperIconButton.button.interactable = false;
                }
            }
        }
예제 #25
0
        public static bool OnStationIdChange_Prefix(UIStationWindow __instance)
        {
            if (!SimulatedWorld.Initialized || LocalPlayer.IsMasterClient || StationUIManager.UIIsSyncedStage > 0 || GameMain.localPlanet == null || !__instance.active)
            {
                return(true);
            }
            ((Text)AccessTools.Field(typeof(UIStationWindow), "titleText").GetValue(__instance)).text = "Loading...";
            StationUIManager.lastSelectedGameObj = EventSystem.current.currentSelectedGameObject;
            if (__instance.factory == null)
            {
                __instance.factory = GameMain.localPlanet.factory;
            }
            if (__instance.transport == null)
            {
                __instance.transport = __instance.factory.transport;
            }
            StationComponent stationComponent = null;

            if (__instance.stationId == 0)
            {
                UIStationStorage[] stationStorage = (UIStationStorage[])AccessTools.Field(typeof(UIStationWindow), "storageUIs").GetValue(__instance);
                if (stationStorage != null && stationStorage[0] != null && stationStorage[0].station.id != 0)
                {
                    stationComponent = __instance.transport.stationPool[stationStorage[0].station.id];
                }
            }
            else
            {
                stationComponent = __instance.transport.stationPool[__instance.stationId];
            }
            if (stationComponent != null && GameMain.localPlanet != null)
            {
                int id = (stationComponent.isStellar == true) ? stationComponent.gid : stationComponent.id;
                // for some reason PLS has planetId set to 0, so we use players localPlanet here (he should be on a planet anyways when opening the UI)
                LocalPlayer.SendPacket(new StationUIInitialSyncRequest(id, (stationComponent.isStellar == true) ? 0 : GameMain.localPlanet.id));
                StationUIManager.UIIsSyncedStage++;
            }
            return(false);
        }
예제 #26
0
 public static bool OnStationIdChange_Prefix(UIStationWindow __instance)
 {
     if (!SimulatedWorld.Initialized || LocalPlayer.IsMasterClient || StationUIManager.UIIsSyncedStage > 0 || GameMain.localPlanet == null || !__instance.active)
     {
         return(true);
     }
     Debug.Log("loading...");
     ((Text)AccessTools.Field(typeof(UIStationWindow), "titleText").GetValue(__instance)).text = "Loading...";
     StationUIManager.lastSelectedGameObj = EventSystem.current.currentSelectedGameObject;
     if (__instance.factory == null)
     {
         __instance.factory = GameMain.localPlanet.factory;
     }
     if (__instance.transport == null)
     {
         __instance.transport = __instance.factory.transport;
     }
     if (__instance.stationId == 0)
     {
         UIStationStorage[] stationStorage = (UIStationStorage[])AccessTools.Field(typeof(UIStationWindow), "storageUIs").GetValue(__instance);
         if (stationStorage != null && stationStorage[0] != null && stationStorage[0].station.id != 0)
         {
             Log.Info($"sending initial sync request id {__instance.transport.stationPool[stationStorage[0].station.id]} size: {__instance.transport.stationPool.Length}");
             Log.Info($"gid: {__instance.transport.stationPool[stationStorage[0].station.id].gid}");
             Debug.Log((int)AccessTools.Field(typeof(UIStationWindow), "_stationId").GetValue(__instance));
             LocalPlayer.SendPacket(new StationUIInitialSyncRequest(__instance.transport.stationPool[stationStorage[0].station.id].gid));
             StationUIManager.UIIsSyncedStage++;
         }
     }
     else
     {
         Debug.Log("sending initial sync request " + __instance.transport.stationPool[__instance.stationId].gid);
         Debug.Log((int)AccessTools.Field(typeof(UIStationWindow), "_stationId").GetValue(__instance));
         Debug.Log("gStationCursorl: " + GameMain.data.galacticTransport.stationCursor + " Len: " + GameMain.data.galacticTransport.stationPool.Length);
         LocalPlayer.SendPacket(new StationUIInitialSyncRequest(__instance.transport.stationPool[__instance.stationId].gid));
         StationUIManager.UIIsSyncedStage++;
     }
     return(false);
 }
예제 #27
0
        /*
         * Update station settings and drone, ship and warper counts.
         *
         * First determine if the local player has the station window opened and handle that accordingly.
         */
        private static void UpdateSettingsUI(StationUI packet)
        {
            UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

            StationComponent stationComponent = null;
            PlanetData       planet           = GameMain.galaxy?.PlanetById(packet.PlanetId);

            // If we can't find planet or the factory for said planet, we can just skip this
            if (planet?.factory?.transport == null)
            {
                return;
            }

            StationComponent[] gStationPool = GameMain.data.galacticTransport.stationPool;
            StationComponent[] stationPool  = planet?.factory?.transport?.stationPool;

            // Figure out if we're dealing with a PLS or a ILS station
            stationComponent = packet.StationGId > 0 ? gStationPool[packet.StationGId] : stationPool?[packet.StationId];

            if (stationComponent == null)
            {
                Log.Error($"UpdateStorageUI: Unable to find requested station on planet {packet.PlanetId} with id {packet.StationId} and gid of {packet.StationGId}");
                return;
            }

            if (stationWindow == null)
            {
                return;
            }

            int _stationId = (int)AccessTools.Field(typeof(UIStationWindow), "_stationId")?.GetValue(stationWindow);

            // Client has no knowledge of the planet, closed the window or
            // opened a different station, do all updates in the background.
            if (planet?.factory?.transport == null || stationComponent.id != _stationId)
            {
                UpdateSettingsUIBackground(packet, planet, stationComponent);
                return;
            }

            // this locks the patches so we can call vanilla functions without triggering our patches to avoid endless loops
            using (ILSShipManager.PatchLockILS.On())
            {
                if (packet.SettingIndex == StationUI.EUISettings.MaxChargePower)
                {
                    stationWindow.OnMaxChargePowerSliderValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.MaxTripDrones)
                {
                    stationWindow.OnMaxTripDroneSliderValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.MaxTripVessel)
                {
                    stationWindow.OnMaxTripVesselSliderValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.MinDeliverDrone)
                {
                    stationWindow.OnMinDeliverDroneValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.MinDeliverVessel)
                {
                    stationWindow.OnMinDeliverVesselValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.WarpDistance)
                {
                    stationWindow.OnWarperDistanceValueChange(packet.SettingValue);
                }
                if (packet.SettingIndex == StationUI.EUISettings.WarperNeeded)
                {
                    stationWindow.OnWarperNecessaryClick(0);
                }
                if (packet.SettingIndex == StationUI.EUISettings.IncludeCollectors)
                {
                    Type[]   args   = new Type[1];
                    object[] values = new object[1];
                    args[0]   = typeof(int);
                    values[0] = 0;
                    AccessTools.Method(typeof(UIStationWindow), "OnIncludeOrbitCollectorClick", args).Invoke(stationWindow, values);
                }
                if (packet.SettingIndex >= StationUI.EUISettings.SetDroneCount && packet.SettingIndex <= StationUI.EUISettings.SetWarperCount)
                {
                    if (packet.SettingIndex == StationUI.EUISettings.SetDroneCount)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        if (UIRequestedShipDronWarpChange)
                        {
                            AccessTools.Method(typeof(UIStationWindow), "OnDroneIconClick", args).Invoke(stationWindow, values);
                            UIRequestedShipDronWarpChange = false;
                        }
                        stationComponent.idleDroneCount = (int)packet.SettingValue;
                    }
                    if (packet.SettingIndex == StationUI.EUISettings.SetShipCount)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        if (UIRequestedShipDronWarpChange)
                        {
                            AccessTools.Method(typeof(UIStationWindow), "OnShipIconClick", args).Invoke(stationWindow, values);
                            UIRequestedShipDronWarpChange = false;
                        }
                        stationComponent.idleShipCount = (int)packet.SettingValue;
                    }
                    if (packet.SettingIndex == StationUI.EUISettings.SetWarperCount)
                    {
                        Type[]   args   = new Type[1];
                        object[] values = new object[1];
                        args[0]   = typeof(int);
                        values[0] = 0;
                        if (UIRequestedShipDronWarpChange)
                        {
                            AccessTools.Method(typeof(UIStationWindow), "OnWarperIconClick", args).Invoke(stationWindow, values);
                            UIRequestedShipDronWarpChange = false;
                        }
                        stationComponent.warperCount = (int)packet.SettingValue;
                    }
                }

                /*
                 * the idea is that clients request that they want to apply a change and do so once the server responded with an okay.
                 * the calls to OnItemIconMouseDown() and OnItemIconMouseUp() are blocked for clients and called only from here.
                 */
                if (packet.SettingIndex == StationUI.EUISettings.AddOrRemoveItemFromStorageRequest)
                {
                    if (stationComponent.storage != null)
                    {
                        if (packet.ShouldMimic)
                        {
                            BaseEventData      mouseEvent = LastMouseEvent;
                            UIStationStorage[] storageUIs = (UIStationStorage[])AccessTools.Field(typeof(UIStationWindow), "storageUIs").GetValue(stationWindow);

                            if (LastMouseEvent != null)
                            {
                                // TODO: change this such that only server sends the response, else clients with a desynced state could change servers storage to a faulty value
                                // issue #249
                                if (LastMouseEventWasDown)
                                {
                                    storageUIs[packet.StorageIdx].OnItemIconMouseDown(mouseEvent);
                                    StationUI packet2 = new StationUI(packet.PlanetId, packet.StationId, packet.StationGId, packet.StorageIdx, StationUI.EUISettings.AddOrRemoveItemFromStorageResponse, packet.ItemId, stationComponent.storage[packet.StorageIdx].count);
                                    LocalPlayer.SendPacket(packet2);
                                }
                                else
                                {
                                    storageUIs[packet.StorageIdx].OnItemIconMouseUp(mouseEvent);
                                    StationUI packet2 = new StationUI(packet.PlanetId, packet.StationId, packet.StationGId, packet.StorageIdx, StationUI.EUISettings.AddOrRemoveItemFromStorageResponse, packet.ItemId, stationComponent.storage[packet.StorageIdx].count);
                                    LocalPlayer.SendPacket(packet2);
                                }
                                LastMouseEvent = null;
                            }
                        }
                    }
                }
                if (packet.SettingIndex == StationUI.EUISettings.AddOrRemoveItemFromStorageResponse)
                {
                    if (stationComponent.storage != null)
                    {
                        stationComponent.storage[packet.StorageIdx].count = (int)packet.SettingValue;
                    }
                }
            }
        }
예제 #28
0
        private void OpenStation(int factoryIndex, int stationId)
        {
            if (factoryIndex < 0 || stationId < 0)
            {
                return;
            }
            if (!GameMain.isRunning || GameMain.instance.isMenuDemo)
            {
                return;
            }
            _lastFactoryIndex        = factoryIndex;
            _lastStationFactoryIndex = stationId;
            if (_uiGame == null || (_uiStation) == null)
            {
                _uiGame    = UIRoot.instance.uiGame;
                _uiStation = _uiGame.stationWindow;
            }

            if (!_uiStation.inited)
            {
                return;
            }

            if (_uiStation.active)
            {
                UIRealtimeTip.Popup("请先关闭目前物流站".Translate());
                return;
            }

            if (GameMain.data.factories != null &&
                GameMain.data.factories.Length > factoryIndex &&
                GameMain.data.factories[factoryIndex] != null)
            {
                try
                {
                    var factory   = GameMain.data.factories[factoryIndex];
                    var transport = factory.transport;
                    if (transport.stationPool != null &&
                        transport.stationPool.Length >= stationId &&
                        transport.stationPool[stationId] != null
                        )
                    {
                        _uiStation.stationId = stationId;
                        Traverse.Create(_uiStation).Property("active").SetValue(true);
                        if (!_uiStation.gameObject.activeSelf)
                        {
                            _uiStation.gameObject.SetActive(true);
                        }

                        _uiStation.factory     = factory;
                        _uiStation.transport   = factory.transport;
                        _uiStation.powerSystem = factory.powerSystem;
                        _uiStation.player      = GameMain.mainPlayer;
                        Traverse.Create(_uiStation).Method("OnStationIdChange").GetValue();
                        Traverse.Create(_uiStation).Field("eventLock").SetValue(true);

                        var eventInfo  = _uiStation.player.GetType().GetEvent("onIntendToTransferItems");
                        var methodInfo = _uiStation.GetType()
                                         .GetMethod("OnPlayerIntendToTransferItems", BindingFlags.NonPublic | BindingFlags.Instance);

                        if (eventInfo != null && methodInfo != null)
                        {
                            eventInfo.AddEventHandler(_uiStation.player,
                                                      Delegate.CreateDelegate(eventInfo.EventHandlerType, _uiStation, methodInfo));
                        }

                        _uiStation.transform.SetAsLastSibling();
                        _uiGame.OpenPlayerInventory();
                        _inspectingStation = true;
                    }
                    else
                    {
                        UIRealtimeTip.Popup("物流站ID不存在".Translate());
                    }
                }
                catch (Exception message)
                {
                    _inspectingStation = false;
                    Debug.Log(message.StackTrace);
                }
            }
            else
            {
                UIRealtimeTip.Popup("工厂不存在".Translate());
            }
        }
예제 #29
0
        private void OpenStation(int factoryIndex, int stationId)
        {
            if (factoryIndex < 0 || stationId < 0)
            {
                return;
            }
            if (!GameMain.isRunning || GameMain.instance.isMenuDemo)
            {
                return;
            }
            _lastFactoryIndex        = factoryIndex;
            _lastStationFactoryIndex = stationId;
            if (_uiGame == null || (_uiStation) == null)
            {
                _uiGame    = UIRoot.instance.uiGame;
                _uiStation = _uiGame.stationWindow;
            }

            if (!_uiStation.inited)
            {
                return;
            }

            if (_uiStation.active)
            {
                UIRealtimeTip.Popup("请先关闭目前物流站".Translate());
                return;
            }

            if (GameMain.data.factories != null &&
                GameMain.data.factories.Length > factoryIndex &&
                GameMain.data.factories[factoryIndex] != null)
            {
                try
                {
                    var factory   = GameMain.data.factories[factoryIndex];
                    var transport = factory.transport;
                    if (transport.stationPool != null &&
                        transport.stationPool.Length >= stationId &&
                        transport.stationPool[stationId] != null
                        )
                    {
                        _uiStation.stationId = stationId;
                        _uiStation.active    = true;
                        if (!_uiStation.gameObject.activeSelf)
                        {
                            _uiStation.gameObject.SetActive(true);
                        }

                        _uiStation.factory     = factory;
                        _uiStation.transport   = factory.transport;
                        _uiStation.powerSystem = factory.powerSystem;
                        _uiStation.player      = GameMain.mainPlayer;
                        _uiStation.OnStationIdChange();

                        _uiStation.nameInput.onValueChanged.AddListener(_uiStation.OnNameInputSubmit);
                        _uiStation.nameInput.onEndEdit.AddListener(_uiStation.OnNameInputSubmit);
                        _uiStation.player.onIntendToTransferItems += _uiStation.OnPlayerIntendToTransferItems;

                        _uiStation.transform.SetAsLastSibling();
                        _uiGame.OpenPlayerInventory();
                        _inspectingStation = true;
                    }
                    else
                    {
                        UIRealtimeTip.Popup("物流站ID不存在".Translate());
                    }
                }
                catch (Exception message)
                {
                    _inspectingStation = false;
                    Debug.Log(message.StackTrace);
                }
            }
            else
            {
                UIRealtimeTip.Popup("工厂不存在".Translate());
            }
        }
예제 #30
0
        public static void OnStationIdChangePost(UIStationWindow __instance, string __state)
        {
            if (__instance.stationId == 0 || __instance.factory == null || __instance.transport?.stationPool == null)
            {
                return;
            }

            StationComponent stationComponent = __instance.transport.stationPool[__instance.stationId];
            ItemProto        itemProto        = LDB.items.Select(__instance.factory.entityPool[stationComponent.entityId].protoId);

            int storageCount = ((stationComponent.isCollector || stationComponent.isVeinCollector) ? stationComponent.collectionIds.Length : stationComponent.storage.Length);

            int baseYSize = stationComponent.isStellar ? 376 : 316;

            if (stationComponent.isCollector)
            {
                baseYSize = 136;
            }
            else if (stationComponent.isVeinCollector)
            {
                baseYSize = 289;
            }

            ((RectTransform)__instance.storageUIs[0].transform).anchoredPosition = new Vector2(0, 0);

            int yPos = stationComponent.isVeinCollector ? -190 : -90;

            scrollTrs.anchoredPosition = new Vector2(scrollTrs.anchoredPosition.x, yPos);


            if (itemProto.ID != GigaStationsPlugin.pls.ID && itemProto.ID != GigaStationsPlugin.ils.ID && itemProto.ID != GigaStationsPlugin.collector.ID)
            {
                foreach (UIStationStorage slot in __instance.storageUIs)
                {
                    slot.popupBoxRect.anchoredPosition = new Vector2(5, 0);
                }

                scrollTrs.sizeDelta  = new Vector2(scrollTrs.sizeDelta.x, 76 * storageCount);
                contentTrs.sizeDelta = new Vector2(contentTrs.sizeDelta.x, 76 * storageCount);
                int newYSize = baseYSize + 76 * storageCount;

                __instance.windowTrans.sizeDelta = new Vector2(600, newYSize);
                return;
            }

            __instance.nameInput.text = __state;

            if (__instance.active)
            {
                int verticalCount = storageCount;
                int newXSize      = 600;

                if (GigaStationsPlugin.gridXCount > 1)
                {
                    int diff = 526 * (GigaStationsPlugin.gridXCount - 1);
                    newXSize     += diff;
                    verticalCount = storageCount / GigaStationsPlugin.gridXCount;

                    foreach (UIStationStorage slot in __instance.storageUIs)
                    {
                        slot.popupBoxRect.anchoredPosition = new Vector2(-200, 0);
                    }
                    bool logisticShipWarpDrive = GameMain.history.logisticShipWarpDrive;
                    __instance.powerGroupRect.sizeDelta = new Vector2((stationComponent.isStellar ? (logisticShipWarpDrive ? 320f : 380f) : 440f) + diff, 40f);
                }
                else
                {
                    foreach (UIStationStorage slot in __instance.storageUIs)
                    {
                        slot.popupBoxRect.anchoredPosition = new Vector2(5, 0);
                    }
                }
                int visibleCount = verticalCount > GigaStationsPlugin.gridYCount ? GigaStationsPlugin.gridYCount : verticalCount;
                int newYSize     = baseYSize + 76 * visibleCount;

                __instance.windowTrans.sizeDelta = new Vector2(newXSize, newYSize);

                int viewCount = verticalCount < GigaStationsPlugin.gridYCount ? verticalCount : GigaStationsPlugin.gridYCount;

                scrollTrs.sizeDelta  = new Vector2(scrollTrs.sizeDelta.x, 76 * viewCount);
                contentTrs.sizeDelta = new Vector2(contentTrs.sizeDelta.x, 76 * verticalCount);

                for (int i = 0; i < __instance.storageUIs.Length; i++)
                {
                    if (i < storageCount)
                    {
                        __instance.storageUIs[i].station = stationComponent;
                        __instance.storageUIs[i].index   = i;
                        __instance.storageUIs[i]._Open();
                    }
                    else
                    {
                        __instance.storageUIs[i].station = null;
                        __instance.storageUIs[i].index   = 0;
                        __instance.storageUIs[i]._Close();
                    }
                    __instance.storageUIs[i].ClosePopMenu();
                }
            }
        }