protected override void OnToolUpdate() { base.OnToolUpdate(); var building = m_hoverInstance.Building; if (m_toolController.IsInsideUI || !Cursor.visible || building == 0) { ShowToolInfo(false, null, Vector3.zero); return; } // Don't show info for dummy or sub buildings. if (BuildingManager.instance.m_buildings.m_buffer[building].Info.GetAI() is DummyBuildingAI) { ShowToolInfo(false, null, Vector3.zero); return; } if (TransferManagerInfo.IsDistrictServicesBuilding(building) || TransferManagerInfo.IsCustomVehiclesBuilding(building)) { var position = BuildingManager.instance.m_buildings.m_buffer[building].m_position; var txt = GetBuildingInfoText(building); ShowToolInfo(true, txt, position); } }
/// <summary> /// Returns the input type of the building, used to determine which GUI elements are shown in the main panel. /// </summary> /// <param name="building"></param> /// <returns></returns> public static InputType GetBuildingInputType(int building) { if (building == 0) { return(InputType.NONE); } var result = InputType.NONE; // The only building type for which we will not show an outgoing tab is coal and heating power plants. var info = BuildingManager.instance.m_buildings.m_buffer[building].Info; if (TransferManagerInfo.IsDistrictServicesBuilding(building)) { if ((info?.GetService() == ItemClass.Service.Electricity && info?.GetAI() is PowerPlantAI) || (info?.GetService() == ItemClass.Service.Water && info?.GetAI() is HeatingPlantAI) || (info?.GetService() == ItemClass.Service.Monument && info?.gameObject?.name == "ChirpX Launch Control Center")) { } else if (!Settings.enableIndustriesControl && info?.GetService() == ItemClass.Service.PlayerIndustry) { } else { result |= InputType.OUTGOING; } } if (Settings.enableIndustriesControl && TransferManagerInfo.IsSupplyChainBuilding(building)) { result |= InputType.SUPPLY_CHAIN; if (!(info?.GetAI() is ExtractingFacilityAI || info?.GetAI() is FishFarmAI || info?.GetAI() is FishingHarborAI)) { result |= InputType.INCOMING; } } if (TransferManagerInfo.IsCustomVehiclesBuilding(building)) { result |= InputType.VEHICLES; } return(result); }
/// <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())); }
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); } }
/// <summary> /// Stock code that transfers people/materials between the buildings/vehicles referenced in the given offers. /// </summary> private static bool StartTransfer(TransferManager.TransferReason material, TransferManager.TransferOffer offerOut, TransferManager.TransferOffer offerIn, int delta) { try { if (offerIn.Building != 0 && TransferManagerInfo.IsCustomVehiclesBuilding(offerIn.Building)) { VehicleManagerMod.CurrentSourceBuilding = offerIn.Building; } bool active1 = offerIn.Active; bool active2 = offerOut.Active; if (active1 && offerIn.Vehicle != 0) { Array16 <Vehicle> vehicles = Singleton <VehicleManager> .instance.m_vehicles; ushort vehicle = offerIn.Vehicle; VehicleInfo info = vehicles.m_buffer[vehicle].Info; offerOut.Amount = delta; info.m_vehicleAI.StartTransfer(vehicle, ref vehicles.m_buffer[vehicle], material, offerOut); } else if (active2 && offerOut.Vehicle != 0) { Array16 <Vehicle> vehicles = Singleton <VehicleManager> .instance.m_vehicles; ushort vehicle = offerOut.Vehicle; VehicleInfo info = vehicles.m_buffer[vehicle].Info; offerIn.Amount = delta; info.m_vehicleAI.StartTransfer(vehicle, ref vehicles.m_buffer[vehicle], material, offerIn); } else if (active1 && (int)offerIn.Citizen != 0) { Array32 <Citizen> citizens = Singleton <CitizenManager> .instance.m_citizens; uint citizen = offerIn.Citizen; CitizenInfo citizenInfo = citizens.m_buffer[citizen].GetCitizenInfo(citizen); if (citizenInfo == null) { return(false); } offerOut.Amount = delta; // Workaround a bug in ResidentAI.StartTransfer if (material == TransferManager.TransferReason.ChildCare || material == TransferManager.TransferReason.ElderCare) { citizens.m_buffer[citizen].Sick = false; } citizenInfo.m_citizenAI.StartTransfer(citizen, ref citizens.m_buffer[citizen], material, offerOut); } else if (active2 && (int)offerOut.Citizen != 0) { Array32 <Citizen> citizens = Singleton <CitizenManager> .instance.m_citizens; uint citizen = offerOut.Citizen; CitizenInfo citizenInfo = citizens.m_buffer[citizen].GetCitizenInfo(citizen); if (citizenInfo == null) { return(false); } offerIn.Amount = delta; // Workaround a bug in ResidentAI.StartTransfer if (material == TransferManager.TransferReason.ChildCare || material == TransferManager.TransferReason.ElderCare) { citizens.m_buffer[citizen].Sick = false; } citizenInfo.m_citizenAI.StartTransfer(citizen, ref citizens.m_buffer[citizen], material, offerIn); } else if (active2 && offerOut.Building != 0) { Array16 <Building> buildings = Singleton <BuildingManager> .instance.m_buildings; ushort building = offerOut.Building; BuildingInfo info = buildings.m_buffer[building].Info; offerIn.Amount = delta; info.m_buildingAI.StartTransfer(building, ref buildings.m_buffer[building], material, offerIn); } else { if (!active1 || offerIn.Building == 0) { return(false); } Array16 <Building> buildings = Singleton <BuildingManager> .instance.m_buildings; ushort building = offerIn.Building; BuildingInfo info = buildings.m_buffer[building].Info; offerOut.Amount = delta; info.m_buildingAI.StartTransfer(building, ref buildings.m_buffer[building], material, offerOut); } return(true); } finally { VehicleManagerMod.CurrentSourceBuilding = 0; } }