예제 #1
0
        /// <summary>
        /// Helper method for displaying information, including district and supply chain constraints, about the
        /// building with given building id.
        /// </summary>
        /// <param name="building"></param>
        /// <returns></returns>
        private static string GetBuildingInfoText(ushort building)
        {
            var inputType = TransferManagerInfo.GetBuildingInputType(building);

            var txtItems = new List <string>();

            txtItems.Add($"{TransferManagerInfo.GetBuildingName(building)} ({building})");
            txtItems.Add(TransferManagerInfo.GetDistrictParkText(building));

            // Early return.  Rest of info pertains to building types that we deal with in the mod.
            if (!(TransferManagerInfo.IsDistrictServicesBuilding(building) || TransferManagerInfo.IsCustomVehiclesBuilding(building)))
            {
                return(string.Join("\n", txtItems.ToArray()));
            }

            txtItems.Add(TransferManagerInfo.GetBuildingInputTypeText(building));
            txtItems.Add(TransferManagerInfo.GetServicesText(building));

            if (!TransferManagerInfo.IsSupplyChainBuilding(building))
            {
                if (TransferManagerInfo.IsDistrictServicesBuilding(building))
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetOutputDistrictsServedText(building));
                }

                if (Settings.enableCustomVehicles &&
                    !VehicleManagerMod.BuildingUseDefaultVehicles[building] &&
                    VehicleManagerMod.BuildingToVehicles[building] != null &&
                    (inputType & InputType.VEHICLES) != InputType.NONE)
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetCustomVehiclesText(building));
                }

                return(string.Join("\n", txtItems.ToArray()));
            }

            if (Settings.enableIndustriesControl)
            {
                // From this point forth, we know this is a supply chain building ...
                txtItems.Add($"Supply Reserve: {Constraints.InternalSupplyBuffer(building)}");

                if ((inputType & InputType.INCOMING) != InputType.NONE)
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetSupplyBuildingSourcesText(building));
                }

                if ((inputType & InputType.OUTGOING) != InputType.NONE)
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetSupplyBuildingDestinationsText(building));
                }

                if (Settings.enableCustomVehicles &&
                    !VehicleManagerMod.BuildingUseDefaultVehicles[building] &&
                    VehicleManagerMod.BuildingToVehicles[building] != null &&
                    (inputType & InputType.VEHICLES) != InputType.NONE)
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetCustomVehiclesText(building));
                }

                var problemText = TransferManagerInfo.GetSupplyBuildingProblemsText(building);
                if (problemText != string.Empty)
                {
                    txtItems.Add("");
                    txtItems.Add($"<<WARNING: Cannot find the following materials to procure!>>");
                    txtItems.Add(problemText);
                }
            }

            return(string.Join("\n", txtItems.ToArray()));
        }
예제 #2
0
        protected override void OnToolGUI(Event e)
        {
            try
            {
                var hoverInstance = this.m_hoverInstance;
                var building      = hoverInstance.Building;

                WorldInfoPanel.HideAllWorldInfoPanels();

                if (Settings.keyCopy.IsPressed(e))
                {
                    if (building == 0 ||
                        BuildingManager.instance.m_buildings.m_buffer[building].Info.GetAI() is DummyBuildingAI ||
                        !(TransferManagerInfo.IsDistrictServicesBuilding(building) || TransferManagerInfo.IsCustomVehiclesBuilding(building)))
                    {
                        Utils.DisplayMessage(
                            str1: "Enhanced District Services",
                            str2: $"Cannot copy policy from this building!",
                            str3: "IconMessage");
                        return;
                    }

                    CopyPaste.BuildingTemplate = building;
                }

                if (Settings.keyPaste.IsPressed(e))
                {
                    if (CopyPaste.BuildingTemplate == 0)
                    {
                        Utils.DisplayMessage(
                            str1: "Enhanced District Services",
                            str2: $"Please hover over a valid building and press Ctrl-C to copy its policy first!",
                            str3: "IconMessage");
                        return;
                    }

                    if (building == 0 ||
                        BuildingManager.instance.m_buildings.m_buffer[building].Info.GetAI() is DummyBuildingAI ||
                        !(TransferManagerInfo.IsDistrictServicesBuilding(building) || TransferManagerInfo.IsCustomVehiclesBuilding(building)))
                    {
                        Utils.DisplayMessage(
                            str1: "Enhanced District Services",
                            str2: $"Cannot copy policy to this unsupported building!",
                            str3: "IconMessage");
                        return;
                    }

                    var inputType1 = TransferManagerInfo.GetBuildingInputType(CopyPaste.BuildingTemplate);
                    var inputType2 = TransferManagerInfo.GetBuildingInputType(building);

                    if (inputType1 != inputType2)
                    {
                        Utils.DisplayMessage(
                            str1: "Enhanced District Services",
                            str2: $"Can only copy-paste policy between buildings of the same policy type!",
                            str3: "IconMessage");
                        return;
                    }

                    var success = CopyPaste.CopyPolicyTo(building);
                    if (!success)
                    {
                        Utils.DisplayMessage(
                            str1: "Enhanced District Services",
                            str2: $"Could not copy certain supply chain restrictions.  Please check results of copy operation!",
                            str3: "IconMessage");
                        return;
                    }

                    var position = BuildingManager.instance.m_buildings.m_buffer[building].m_position;
                    var txt      = GetBuildingInfoText(building);
                    ShowToolInfo(true, txt, position);
                }

                if (!m_toolController.IsInsideUI && e.type == UnityEngine.EventType.MouseDown && e.button == 0)
                {
                    if (!(TransferManagerInfo.IsDistrictServicesBuilding(building) || TransferManagerInfo.IsCustomVehiclesBuilding(building)))
                    {
                        return;
                    }

                    if (this.m_selectErrors == ToolBase.ToolErrors.None || this.m_selectErrors == ToolBase.ToolErrors.RaycastFailed)
                    {
                        Vector3 mousePosition = this.m_mousePosition;
                        UIInput.MouseUsed();

                        if (!Singleton <InstanceManager> .instance.SelectInstance(hoverInstance))
                        {
                            return;
                        }

                        SimulationManager.instance.AddAction(() =>
                        {
                            var panel = EnhancedDistrictServicesUIPanel.Instance;

                            if (panel != null)
                            {
                                panel.SetBuilding(hoverInstance.Building);
                                panel.UpdatePositionToBuilding(hoverInstance.Building);
                                panel.UpdatePanelToBuilding(hoverInstance.Building);
                                panel.opacity = 1f;
                            }

                            Singleton <GuideManager> .instance.m_worldInfoNotUsed.Disable();
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogWarning($"EnhancedDistrictServicesTool::OnToolGUI: ...");
                Logger.LogException(ex);
            }
        }