private void RefreshDisplayData() { uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex; uint num2 = currentFrameIndex & 255u; if (PlayerBuildingUI.refeshOnce || (MainDataStore.lastBuilding != WorldInfoPanel.GetCurrentInstanceID().Building)) { if (base.isVisible) { MainDataStore.lastBuilding = WorldInfoPanel.GetCurrentInstanceID().Building; Building buildingData = Singleton <BuildingManager> .instance.m_buildings.m_buffer[MainDataStore.lastBuilding]; if (GasStationAI.IsGasBuilding(MainDataStore.lastBuilding) == true) { this.Petrol.text = string.Format(Localization.Get("PETROL_STORED") + " [{0}]", MainDataStore.petrolBuffer[MainDataStore.lastBuilding]); this.inComingVehicleCount.text = string.Format(Localization.Get("INCOMING_VEHICLE_COUNT") + " [{0}]", MainDataStore.finalVehicleForFuelCount[MainDataStore.lastBuilding]); both.isVisible = true; heavy.isVisible = true; small.isVisible = true; both.isChecked = (MainDataStore.resourceCategory[MainDataStore.lastBuilding] == 0) ? true : false; heavy.isChecked = (MainDataStore.resourceCategory[MainDataStore.lastBuilding] == 1) ? true : false; small.isChecked = (MainDataStore.resourceCategory[MainDataStore.lastBuilding] == 2) ? true : false; both.text = Localization.Get("ACCEPT_ALL_VEHICLE"); heavy.text = Localization.Get("ACCEPT_HEAVY_VEHICLE"); small.text = Localization.Get("ACCEPT_SMALL_VEHICLE"); } else { this.Petrol.text = ""; this.inComingVehicleCount.text = ""; both.isVisible = false; heavy.isVisible = false; small.isVisible = false; Hide(); } PlayerBuildingUI.refeshOnce = false; } else { this.Hide(); } } }
private void OnEditTypeClick(UIComponent component, UIMouseEventParameter eventParam) { if ((UnityEngine.Object)VehicleEditor.Instance == (UnityEngine.Object)null) { return; } InstanceID currentInstanceId = WorldInfoPanel.GetCurrentInstanceID(); ushort firstVehicle = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[(int)currentInstanceId.Vehicle].GetFirstVehicle(currentInstanceId.Vehicle); if ((int)firstVehicle == 0) { return; } VehicleInfo info = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[(int)firstVehicle].Info; Singleton <InfoManager> .instance.SetCurrentMode(InfoManager.InfoMode.Transport, InfoManager.SubInfoMode.Default); VehicleEditor.Instance.SetPrefab(info); }
public override void Update() { var buildingID = WorldInfoPanel.GetCurrentInstanceID().Building; if ((Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingID].Info.m_class.m_service != ItemClass.Service.Residential) && Loader.isGuiRunning) { if (WorldInfoPanel.GetCurrentInstanceID() != InstanceID.Empty) { BuildingID = WorldInfoPanel.GetCurrentInstanceID(); } relativePosition = new Vector3(120, buildingInfo.size.y - height); Show(); } else { Hide(); } base.Update(); }
public override void HandleClick(UIMouseEventParameter p) { InstanceID instance = WorldInfoPanel.GetCurrentInstanceID(); Log._Debug($"Current citizen: {instance.Citizen}"); if (instance.Citizen != 0) { ushort citizenInstanceId = 0; Constants.ServiceFactory.CitizenService.ProcessCitizen(instance.Citizen, delegate(uint citId, ref Citizen cit) { citizenInstanceId = cit.m_instance; return(true); }); Log._Debug($"Current citizen: {instance.Citizen} Instance: {citizenInstanceId}"); if (citizenInstanceId != 0) { Constants.ServiceFactory.SimulationService.AddAction(() => Constants.ServiceFactory.CitizenService.ReleaseCitizenInstance(citizenInstanceId)); } } }
public override void Update() { var Building = WorldInfoPanel.GetCurrentInstanceID().Building; if (WorldInfoPanel.GetCurrentInstanceID() != InstanceID.Empty) { BuildingID = WorldInfoPanel.GetCurrentInstanceID(); } if (GasStationAI.IsGasBuilding(Building) && Loader.isGuiRunning) { relativePosition = new Vector3(playerBuildingInfo.size.x - width - 90, playerBuildingInfo.size.y - height); base.Show(); } else { base.Hide(); } base.Update(); }
private void OnChangeVehicleClick(UIComponent component, UIMouseEventParameter eventParam) { ushort firstVehicle = 0; ushort lineId = this.GetLineID(out firstVehicle); if ((int)lineId == 0) { return; } ushort num = !(component.name == "PreviousVehicle") ? TransportLineUtil.GetNextVehicle(lineId, firstVehicle) : TransportLineUtil.GetPreviousVehicle(lineId, firstVehicle); if ((int)firstVehicle == (int)num) { return; } InstanceID instanceId = new InstanceID(); instanceId.Vehicle = num; WorldInfoPanel.ChangeInstanceID(WorldInfoPanel.GetCurrentInstanceID(), instanceId); ToolsModifierControl.cameraController.SetTarget(instanceId, ToolsModifierControl.cameraController.transform.position, Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift)); }
// called every frame public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) { if (!FindComponents()) { return; } if (_panel.component.isVisible) { ushort buildingId = WorldInfoPanel.GetCurrentInstanceID().Building; if (_lastBuildingId != buildingId) { _HistoricalStatusCheckBox.isChecked = HistoricalStatusDataManager.Instance.IsHistorical(buildingId); _lastBuildingId = buildingId; } } else { _lastBuildingId = 0; } }
public override void Update() { if (!WorldInfoPanel.AnyWorldInfoPanelOpen()) { return; } var instanceId = WorldInfoPanel.GetCurrentInstanceID(); if (instanceId.Type == InstanceType.Building && instanceId.Building != 0) { ushort building = instanceId.Building; if (baseBuildingWindow != null && enabled && isVisible && Singleton <BuildingManager> .exists && ((Singleton <SimulationManager> .instance.m_currentFrameIndex & 15u) == 15u || selectedBuilding != building)) { BuildingManager instance = Singleton <BuildingManager> .instance; UpdateBuildingInfo(building, instance.m_buildings.m_buffer[building]); selectedBuilding = building; } } base.Update(); }
public override void Update() { if (!WorldInfoPanel.AnyWorldInfoPanelOpen() || !isVisible) { return; } var buildingId = WorldInfoPanel.GetCurrentInstanceID().Building; if (BuildingManager.instance != null && ((SimulationManager.instance.m_currentFrameIndex & 15u) == 15u || lastSelected != buildingId)) { strs = new string[] { Environment.NewLine, "", "", "", "", "" }; lastSelected = buildingId; Building data = BuildingManager.instance.m_buildings.m_buffer[buildingId]; FindBuildingType(data); text = String.IsNullOrEmpty(strs[1]) ? "" : String.Format(strs[5] == "" ? "{1} : {2}{0}{3} : {4}" : "{1} : {2}{0}{3} : {4}{0}{5}", strs); } base.Update(); }
public override void HandleClick(UIMouseEventParameter p) { InstanceID instance = WorldInfoPanel.GetCurrentInstanceID(); Log._Debug($"Current citizen: {instance.Citizen}"); if (instance.Citizen != 0) { ushort citizenInstanceId = 0; Constants.ServiceFactory.CitizenService.ProcessCitizen( instance.Citizen, (uint citId, ref Citizen cit) => { citizenInstanceId = cit.m_instance; return(true); }); Log._Debug( $"Current citizen: {instance.Citizen} Instance: {citizenInstanceId}"); if (citizenInstanceId != 0) { bool isTourist = CitizenManager.instance.m_instances.m_buffer[citizenInstanceId].Info.m_citizenAI is TouristAI; Constants.ServiceFactory.SimulationService.AddAction( () => Constants .ServiceFactory.CitizenService .ReleaseCitizenInstance(citizenInstanceId)); // InfoPanel needs to be closed manually because method responsible for hiding it testing against type Citizen instead of CitizenInstance // We are not removing Citizen but only instance if (isTourist) { WorldInfoPanel.Hide <TouristWorldInfoPanel>(); } else { WorldInfoPanel.Hide <CitizenWorldInfoPanel>(); } } } }
private void RefreshDisplayData() { if (refeshOnce || (MainDataStore.lastBuildingID != WorldInfoPanel.GetCurrentInstanceID().Building)) { if (base.isVisible) { MainDataStore.lastBuildingID = WorldInfoPanel.GetCurrentInstanceID().Building; if (GasStationAI.IsGasBuilding(MainDataStore.lastBuildingID, true) == true) { this.Petrol.text = string.Format(Localization.Get("PETROL_STORED") + " [{0}]", MainDataStore.petrolBuffer[MainDataStore.lastBuildingID]); this.inComingVehicleCount.text = string.Format(Localization.Get("INCOMING_VEHICLE_COUNT") + " [{0}]", MainDataStore.finalVehicleForFuelCount[MainDataStore.lastBuildingID]); } else { this.Petrol.text = ""; this.inComingVehicleCount.text = ""; } if (buildingType.text != Localization.Get("BUILDING_TYPE")) { buildingTypeDD.items = new string[] { Localization.Get("NORMAL_BUILDING"), Localization.Get("ACCEPT_ALL_VEHICLE"), Localization.Get("ACCEPT_HEAVY_VEHICLE"), Localization.Get("ACCEPT_SMALL_VEHICLE") } } ; if (buildingTypeDD.selectedIndex != MainDataStore.resourceCategory[MainDataStore.lastBuildingID]) { buildingTypeDD.selectedIndex = MainDataStore.resourceCategory[MainDataStore.lastBuildingID]; } buildingType.text = Localization.Get("BUILDING_TYPE"); refeshOnce = false; } else { this.Hide(); } } } }
/// <summary> /// Adds button to access building details from building info panels. /// </summary> internal static void AddInfoPanelButton() { // Get parent panel and apply button. ZonedBuildingWorldInfoPanel infoPanel = UIView.library.Get <ZonedBuildingWorldInfoPanel>(typeof(ZonedBuildingWorldInfoPanel).Name); UIButton panelButton = UIUtils.CreateButton(infoPanel.component, 133); // Basic setup. panelButton.height = 19.5f; panelButton.textScale = 0.65f; panelButton.textVerticalAlignment = UIVerticalAlignment.Bottom; panelButton.relativePosition = new UnityEngine.Vector3(infoPanel.component.width - panelButton.width - 10, 120); panelButton.text = Translations.Translate("RPR_REALPOP"); // Just in case other mods are interfering. panelButton.Enable(); // Event handler. panelButton.eventClick += (control, clickEvent) => { // Select current building in the building details panel and show. BuildingDetailsPanel.Open(InstanceManager.GetPrefabInfo(WorldInfoPanel.GetCurrentInstanceID()) as BuildingInfo); }; }
/// <summary> /// Updates the state of the service panel Realistic Population button - should only be visible and enabled when looking at elementary and high schools. /// </summary> internal static void UpdateServicePanelButton() { // Get current building instance. ushort building = WorldInfoPanel.GetCurrentInstanceID().Building; // Ensure valid building before proceeding. if (building > 0) { // Check for eduction service and level 1 or 2. BuildingInfo info = Singleton <BuildingManager> .instance.m_buildings.m_buffer[building].Info; if (info.GetService() == ItemClass.Service.Education && info.GetClassLevel() < ItemClass.Level.Level3) { // It's a school! Enable and show the button, and return. serviceButton.Enable(); serviceButton.Show(); return; } } // If we got here, it's not a valid school building; disable and hide the button. serviceButton.Disable(); serviceButton.Hide(); }
/// <summary> /// Called when the selected district has changed. /// </summary> public void DistrictChanged() { // Disable events while we make changes to avoid triggering event handler. disableEvents = true; // Update selected district ID> targetID = WorldInfoPanel.GetCurrentInstanceID().District; // Set name. nameLabel.text = Singleton <DistrictManager> .instance.GetDistrictName(targetID); // Set min and max levels. minLevelDropDown.selectedIndex = DistrictsABLC.minResLevel[targetID]; maxLevelDropDown.selectedIndex = DistrictsABLC.maxResLevel[targetID]; minWorkLevelDropDown.selectedIndex = DistrictsABLC.minWorkLevel[targetID]; maxWorkLevelDropDown.selectedIndex = DistrictsABLC.maxWorkLevel[targetID]; // Set flags. randomSpawnCheck.isChecked = (DistrictsABLC.flags[targetID] & (byte)DistrictFlags.randomSpawnLevels) != 0; // All done: re-enable events. disableEvents = false; }
private void RefreshDisplayData() { if (refeshOnce || (MainDataStore.lastBuildingID != WorldInfoPanel.GetCurrentInstanceID().Building)) { if (base.isVisible) { MainDataStore.lastBuildingID = WorldInfoPanel.GetCurrentInstanceID().Building; this.failedBuildingCount.text = Localization.Get("FAILED_BUILDING_COUNT") + ":" + MainDataStore.canNotConnectedBuildingIDCount[MainDataStore.lastBuildingID].ToString(); if (generateDetail.isChecked == true) { generateDetail.isChecked = false; } this.BringToFront(); } refeshOnce = false; this.Show(); } if (!MoreEffectiveTransfer.debugMode) { this.Hide(); } }
private ushort GetLineID() { if (WorldInfoPanel.GetCurrentInstanceID().Type == InstanceType.TransportLine) { return(WorldInfoPanel.GetCurrentInstanceID().TransportLine); } if (WorldInfoPanel.GetCurrentInstanceID().Type == InstanceType.Vehicle) { ushort firstVehicle = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[WorldInfoPanel.GetCurrentInstanceID().Vehicle].GetFirstVehicle(WorldInfoPanel.GetCurrentInstanceID().Vehicle); if (firstVehicle != 0) { return(Singleton <VehicleManager> .instance.m_vehicles.m_buffer[firstVehicle].m_transportLine); } } return(0); }
/// <summary> /// Called when the selected building has changed. /// </summary> internal void BuildingChanged() { // Update selected building ID. targetID = WorldInfoPanel.GetCurrentInstanceID().Building; // Check maximum level for this building type. int maxLevel = LevelUtils.GetMaxLevel(targetID); // If building doesn't have more than one level, then we don't have any business to do here. if (maxLevel == 1) { BuildingPanelManager.panelButton.Disable(); Hide(); return; } else { // Enable info panel button. BuildingPanelManager.panelButton.Enable(); // Make sure we're visible if we're not already. if (!isVisible) { Show(); } } // Disable events while we make changes to avoid triggering event handler. disableEvents = true; // Set name. nameLabel.text = Singleton <BuildingManager> .instance.GetBuildingName(targetID, InstanceID.Empty); // Build level dropdown ranges. minLevelDropDown.items = new string[maxLevel]; maxLevelDropDown.items = new string[maxLevel]; for (int i = 0; i < maxLevel; i++) { minLevelDropDown.items[i] = (i + 1).ToString(); maxLevelDropDown.items[i] = (i + 1).ToString(); } // Check to see if we have custom settings for this building. if (BuildingsABLC.levelRanges.ContainsKey(targetID)) { // Update dropdown selection to match building's settings. minLevelDropDown.selectedIndex = BuildingsABLC.levelRanges[targetID].minLevel; maxLevelDropDown.selectedIndex = BuildingsABLC.levelRanges[targetID].maxLevel; } else { // Set min and max to default. minLevelDropDown.selectedIndex = 0; maxLevelDropDown.selectedIndex = maxLevelDropDown.items.Length - 1; } // Initialise panel with correct level settings. UpdatePanel(); // All done: re-enable events. disableEvents = false; }
/// <summary> /// UPON HOUSE DESTROYED /// </summary> public static void RemoveHouse () { // Get link of buildings in game to modArray - List of List of strings with key : 1 to 1 to Roads array ushort alpha = (ushort)(Hook_Addresses_SaveGame.CitySave.Roads.Count()); List <string> roadinstance = new List <string>(); List <List <string> > buildingNames = new List <List <string> >(); for (ushort i = 0; i < alpha; i++) { buildingNames.Add(roadinstance); } for (ushort i = 0; i < BuildingManager.MAX_BUILDING_COUNT; i++) { string beta = BuildingManager.instance.GetBuildingName(i, WorldInfoPanel.GetCurrentInstanceID()); if (beta != null) { for (ushort j = 0; j < alpha; j++) { if ((beta.Contains(Hook_Addresses_SaveGame.CitySave.Roads[j]))) { buildingNames[j].Add(beta); } } } else { continue; } } // For each List in the new List... for (ushort i = 0; i < alpha; i++) { // ...check if number of simulation instance buildings using numbers is equal to number of "used" numbers in mod Array // in order to find the ONE List where that's not true if (buildingNames[i].Count() == (Hook_Addresses_SaveGame.CitySave.ModArray[1 + (2 * i)].Count() + Hook_Addresses_SaveGame.CitySave.ModArray[2 * i].Count())) { continue; } else { // Check which number is used by a building instance List <ushort> numbers_Used = new List <ushort>(); ushort delta = (ushort)(buildingNames[i].Count()); for (ushort j = 0; j < delta; j++) { ushort usedNumber = Logic_Tools.ConvertToNumber(buildingNames[i][j]); numbers_Used.Add(usedNumber); } // For each number in the modArray... ushort epsilon = (ushort)(Hook_Addresses_SaveGame.CitySave.ModArray[1 + (2 * i)].Count()); for (ushort j = 0; j < epsilon; j++) { // ...skip numbers that are found in building instances... if (numbers_Used.Contains(Hook_Addresses_SaveGame.CitySave.ModArray[1 + (2 * i)][j])) { continue; } // ...until the one number is found else { // delete number from mod array Hook_Addresses_SaveGame.CitySave.ModArray[1 + (2 * i)].Remove(Hook_Addresses_SaveGame.CitySave.ModArray[1 + (2 * i)][j]); // and if this was the last building on a road, delete that road from all mod arrays. // When the road WASN'T deleted, it get's added back in when the first new house is built on it // => Logic_Roads.AddRoad() called in Logic_Buildings.NameHouse called after the EvenOnHouseBuilt if (Hook_Addresses_SaveGame.CitySave.ModArray[1 + (2 * i)].Count() == 0) { Logic_Roads.RemoveRoad(Hook_Addresses_SaveGame.CitySave.Roads[i]); } return; } } } } }
public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) { if (_terminated) { return; } if (!_helper.GameLoaded) { return; } try { if (!_initialized) { if (!IsOverwatched()) { _helper.NotifyPlayer("Skylines Overwatch not found. Terminating..."); _terminated = true; return; } SkylinesOverwatch.Settings.Instance.Enable.VehicleMonitor = true; _initialized = true; _helper.NotifyPlayer("Initialized"); } else { if (WorldInfoPanel.AnyWorldInfoPanelOpen()) { _selected = WorldInfoPanel.GetCurrentInstanceID(); if (_selected.IsEmpty || _selected.Vehicle == 0) { _selected = default(InstanceID); } } else { _selected = default(InstanceID); } VehicleManager instance = Singleton <VehicleManager> .instance; InstanceID instanceID = new InstanceID(); SkylinesOverwatch.Data data = SkylinesOverwatch.Data.Instance; foreach (ushort i in data.VehiclesUpdated) { Vehicle v = instance.m_vehicles.m_buffer[(int)i]; bool isBlocked = !data.IsCar(i) && v.m_blockCounter >= 64; // we will let the game decide when to remove a blocked car bool isConfused = v.Info.m_vehicleAI.GetLocalizedStatus(i, ref v, out instanceID) == _confused; if (!isBlocked && !isConfused) { continue; } RemoveVehicle(i); } foreach (ushort i in _helper.ManualRemovalRequests) { RemoveVehicle(i); } _helper.ManualRemovalRequests.Clear(); } } catch (Exception e) { string error = String.Format("Failed to {0}\r\n", !_initialized ? "initialize" : "update"); error += String.Format("Error: {0}\r\n", e.Message); error += "\r\n"; error += "==== STACK TRACE ====\r\n"; error += e.StackTrace; _helper.Log(error); if (!_initialized) { _terminated = true; } } base.OnUpdate(realTimeDelta, simulationTimeDelta); }
private void RefreshDisplayData() { if (refeshOnce || (lastSegment != WorldInfoPanel.GetCurrentInstanceID().NetSegment&& WorldInfoPanel.GetCurrentInstanceID().Type == InstanceType.NetSegment)) { if (base.isVisible) { if (WorldInfoPanel.GetCurrentInstanceID().Type == InstanceType.NetSegment) { lastSegment = WorldInfoPanel.GetCurrentInstanceID().NetSegment; } var instance = Singleton <NetManager> .instance; var startNode = instance.m_segments.m_buffer[lastSegment].m_startNode; var endNode = instance.m_segments.m_buffer[lastSegment].m_endNode; if (Options.timedLightsEnabled && (TrafficLightSimulationManager.Instance.TrafficLightSimulations[(int)startNode].IsSimulationRunning() || TrafficLightSimulationManager.Instance.TrafficLightSimulations[(int)endNode].IsSimulationRunning())) { Tips2.text = Localization.Get("LEFT_TIPS"); } else { Tips2.text = Localization.Get("LEFT_TIPS") + ": " + Localization.Get("NEED_TMPE"); MainDataStore.canLeftWaiting[lastSegment] = false; } if (instance.m_nodes.m_buffer[startNode].m_flags.IsFlagSet(NetNode.Flags.TrafficLights) || instance.m_nodes.m_buffer[endNode].m_flags.IsFlagSet(NetNode.Flags.TrafficLights)) { Tips3.text = Localization.Get("UTURN_TIPS"); } else { Tips3.text = Localization.Get("UTURN_TIPS") + ": " + Localization.Get("NO_TRAFFIC_LIGHTS"); MainDataStore.canUTurn[lastSegment] = false; } CanLeftWaiting.isChecked = (MainDataStore.canLeftWaiting[lastSegment]) ? true : false; CanUTurn.isChecked = (MainDataStore.canUTurn[lastSegment]) ? true : false; RoadUI.CanLeftWaiting.text = Localization.Get("CAN_LEFT_WAITING"); RoadUI.CanUTurn.text = Localization.Get("CAN_UTURN_ON_RED"); refeshOnce = false; this.BringToFront(); } else { this.Hide(); } } }
private void RemoveVehicle(ushort vehicle, Boolean manual = false) { if (!remove_init) { if (WorldInfoPanel.AnyWorldInfoPanelOpen()) { _selected = WorldInfoPanel.GetCurrentInstanceID(); if (_selected.IsEmpty || _selected.Vehicle == 0) { _selected = default(InstanceID); } } else { _selected = default(InstanceID); } remove_init = true; } if (!_selected.IsEmpty && _selected.Vehicle == vehicle) { WorldInfoPanel.HideAllWorldInfoPanels(); if (!InstanceManager.IsValid(_dummy) || _dummy.Vehicle == vehicle) { _dummy = default(InstanceID); _dummy.Type = InstanceType.Vehicle; foreach (ushort i in SkylinesOverwatch.Data.Instance.Vehicles) { if (i == vehicle) { continue; } _dummy.Vehicle = i; break; } } Singleton <InstanceManager> .instance.SelectInstance(_dummy); Singleton <InstanceManager> .instance.FollowInstance(_dummy); } VehicleManager instance = Singleton <VehicleManager> .instance; HashSet <ushort> removals = new HashSet <ushort>(); ushort current = vehicle; while (current != 0) { removals.Add(current); current = instance.m_vehicles.m_buffer[(int)current].m_trailingVehicle; } current = instance.m_vehicles.m_buffer[(int)vehicle].m_firstCargo; while (current != 0) { removals.Add(current); current = instance.m_vehicles.m_buffer[(int)current].m_nextCargo; } foreach (ushort i in removals) { var targetVehicle = i; var thread = new System.Threading.Thread(() => { try { instance.ReleaseVehicle(i); } catch (Exception e) { string error = String.Format("Failed to release {0}\r\n", i); error += String.Format("Error: {0}\r\n", e.Message); error += "\r\n"; error += "==== STACK TRACE ====\r\n"; error += e.StackTrace; _helper.Log(error); if (manual) { _helper.NotifyPlayer($"Failed to remove vehicle: {i}{Environment.NewLine}{error}"); } } }); thread.Start(); thread.Join(); } SkylinesOverwatch.Helper.Instance.RequestVehicleRemoval(vehicle); if (manual) { _helper.NotifyPlayer($"Successfully removed vehicle: {vehicle}"); } }
private void UpdateChart() { var vehicleID = WorldInfoPanel.GetCurrentInstanceID().Vehicle; if (vehicleID != 0) { int guard = 0; Vehicle[] vehicles = VehicleManager.instance.m_vehicles.m_buffer; // Find leading vehicle that actually has all the cargo while (vehicles[vehicleID].m_leadingVehicle != 0) { vehicleID = vehicles[vehicleID].m_leadingVehicle; if (guard++ >= ushort.MaxValue) { if (Options.debugEnabled) { Debug.LogError("TransferInfo: CarriedCargoPanel.UpdateChart - Invalid list detected!"); } Hide(); return; } } var ai = vehicles[vehicleID].Info.m_vehicleAI; if (ai is CargoTrainAI || ai is CargoShipAI) { var cargoID = vehicles[vehicleID].m_firstCargo; var cargoItems = new Dictionary <TransferManager.TransferReason, int>(); guard = 0; while (cargoID != 0) { if (cargoItems.TryGetValue((TransferManager.TransferReason)vehicles[cargoID].m_transferType, out _)) { cargoItems[(TransferManager.TransferReason)vehicles[cargoID].m_transferType] += vehicles[cargoID].m_transferSize; } else { cargoItems.Add((TransferManager.TransferReason)vehicles[cargoID].m_transferType, vehicles[cargoID].m_transferSize); } cargoID = vehicles[cargoID].m_nextCargo; if (guard++ >= ushort.MaxValue) { if (Options.debugEnabled) { Debug.LogError("TransferInfo: CarriedCargoPanel.UpdateChart - Invalid list detected!"); } Hide(); return; } } var total = cargoItems.Values.Sum(); chart.tooltip = string.Format("{0:N3} {1}", total / 1000d, "ton(s)"); if (total == 0) { chart.SetValues(DataShared.TrackedCargoTypes.Select(t => 0f).ToArray()); return; } int[] result = new int[DataShared.TrackedCargoTypes.Count]; for (int i = 0; i < DataShared.TrackedCargoTypes.Count; i++) { cargoItems.TryGetValue((TransferManager.TransferReason)DataShared.TrackedCargoTypes.ElementAt(i), out int val); result[i] = val; } chart.SetValues(result.Select(v => v / (float)total).ToArray()); return; } } Hide(); }
private string GetLlamaSightings(double scale) => ((SimulationManager.instance.m_currentGameTime.DayOfYear * scale + WorldInfoPanel.GetCurrentInstanceID().Building) / 1000).ToString("F0");
public override void Awake() { backgroundSprite = "MenuPanel2"; opacity = 0.9f; autoLayout = true; autoLayoutDirection = LayoutDirection.Vertical; var handle = AddUIComponent <UIDragHandle>(); handle.size = new Vector2(Width, HandleHeight); windowLabel = handle.AddUIComponent <UILabel>(); windowLabel.anchor = UIAnchorStyle.CenterVertical | UIAnchorStyle.CenterHorizontal; var closeButton = handle.AddUIComponent <UIButton>(); closeButton.size = ExitButtonSize; closeButton.relativePosition = new Vector3(Width - ExitButtonSize.x, 0, 0); closeButton.anchor = UIAnchorStyle.Top | UIAnchorStyle.Right; closeButton.normalBgSprite = "buttonclose"; closeButton.pressedBgSprite = "buttonclosepressed"; closeButton.hoveredBgSprite = "buttonclosehover"; closeButton.eventClicked += (sender, e) => Hide(); var labelPanel = AddUIComponent <UIPanel>(); labelPanel.size = new Vector2(Width, LabelHeight); labelPanel.autoLayout = true; labelPanel.autoLayoutDirection = LayoutDirection.Horizontal; labelPanel.autoLayoutStart = LayoutStart.TopRight; labelPanel.autoLayoutPadding = Padding; localLabel = labelPanel.AddUIComponent <UILabel>(); localLabel.autoSize = false; localLabel.size = new Vector2(ChartSize.x, LabelHeight); localLabel.textAlignment = UIHorizontalAlignment.Center; importLabel = labelPanel.AddUIComponent <UILabel>(); importLabel.autoSize = false; importLabel.size = new Vector2(ChartSize.x, LabelHeight); importLabel.textAlignment = UIHorizontalAlignment.Center; exportLabel = labelPanel.AddUIComponent <UILabel>(); exportLabel.autoSize = false; exportLabel.size = new Vector2(ChartSize.x, LabelHeight); exportLabel.textAlignment = UIHorizontalAlignment.Center; var rcvdPanel = AddUIComponent <UIPanel>(); rcvdPanel.size = new Vector2(Width, ChartSize.y); rcvdPanel.autoLayout = true; rcvdPanel.autoLayoutDirection = LayoutDirection.Horizontal; rcvdPanel.autoLayoutStart = LayoutStart.TopRight; rcvdPanel.autoLayoutPadding = Padding; rcvdLabel = rcvdPanel.AddUIComponent <UILabel>(); rcvdLabel.textAlignment = UIHorizontalAlignment.Right; rcvdLabel.verticalAlignment = UIVerticalAlignment.Middle; rcvdLabel.autoSize = false; rcvdLabel.size = new Vector2(LabelWidth, ChartSize.y); var rcvdStatPanel = AddUIComponent <UIPanel>(); rcvdStatPanel.size = new Vector2(Width, StatPanelHeight); rcvdStatPanel.autoLayout = true; rcvdStatPanel.autoLayoutDirection = LayoutDirection.Horizontal; rcvdStatPanel.autoLayoutStart = LayoutStart.TopRight; rcvdStatPanel.autoLayoutPadding = Padding; var sentPanel = AddUIComponent <UIPanel>(); sentPanel.size = new Vector2(Width, ChartSize.y); sentPanel.autoLayout = true; sentPanel.autoLayoutDirection = LayoutDirection.Horizontal; sentPanel.autoLayoutStart = LayoutStart.TopRight; sentPanel.autoLayoutPadding = Padding; sentLabel = sentPanel.AddUIComponent <UILabel>(); sentLabel.textAlignment = UIHorizontalAlignment.Right; sentLabel.verticalAlignment = UIVerticalAlignment.Middle; sentLabel.autoSize = false; sentLabel.size = new Vector2(LabelWidth, ChartSize.y); var sentStatPanel = AddUIComponent <UIPanel>(); sentStatPanel.size = new Vector2(Width, StatPanelHeight); sentStatPanel.autoLayout = true; sentStatPanel.autoLayoutDirection = LayoutDirection.Horizontal; sentStatPanel.autoLayoutStart = LayoutStart.TopRight; sentStatPanel.autoLayoutPadding = Padding; resetButton = sentStatPanel.AddUIComponent <UIButton>(); resetButton.text = "Res"; resetButton.normalBgSprite = "ButtonMenu"; resetButton.pressedBgSprite = "ButtonMenuPressed"; resetButton.hoveredBgSprite = "ButtonMenuHovered"; resetButton.textScale = 0.6f; resetButton.autoSize = false; resetButton.size = ModeButtonSize; resetButton.eventClicked += (sender, e) => { if (!mod.data.TryGetEntry(WorldInfoPanel.GetCurrentInstanceID().Building, out CargoStats2 stats)) { return; } Array.Clear(stats.CarsCounted, 0, stats.CarsCounted.Length); }; modeButton = sentStatPanel.AddUIComponent <UIButton>(); modeButton.text = "Prev"; modeButton.normalBgSprite = "ButtonMenu"; modeButton.pressedBgSprite = "ButtonMenuPressed"; modeButton.hoveredBgSprite = "ButtonMenuHovered"; modeButton.textScale = 0.6f; modeButton.autoSize = false; modeButton.size = ModeButtonSize; modeButton.eventClicked += (sender, e) => { displayCurrent = !displayCurrent; modeButton.text = displayCurrent ? "Cur" : "Prev"; modeButton.tooltip = displayCurrent ? Localization.Get("SWITCH_MODES_TOOLTIP_CUR") : Localization.Get("SWITCH_MODES_TOOLTIP_PREV"); modeButton.RefreshTooltip(); }; for (int n = 0; n < cargoCategories.Count; n++) { var chart = (n > 2 ? sentPanel: rcvdPanel).AddUIComponent <UICargoChart>(); chart.size = ChartSize; charts.Add(chart); var label = (n > 2 ? sentStatPanel : rcvdStatPanel).AddUIComponent <UILabel>(); label.autoSize = false; label.size = new Vector2(ChartSize.x, StatPanelHeight); label.textScale = 0.8f; label.textColor = CargoUnitColor; label.textAlignment = UIHorizontalAlignment.Center; labels.Add(label); } FitChildren(new Vector2(Padding.top, Padding.left)); // Load the locale and update it if game locale changes UpdateLocale(); LocaleManager.eventLocaleChanged += UpdateLocale; base.Awake(); }
private void RefreshDisplayData() { if (refeshOnce || (BuildingData.lastBuildingID != WorldInfoPanel.GetCurrentInstanceID().Building)) { if (isVisible) { BuildingData.lastBuildingID = WorldInfoPanel.GetCurrentInstanceID().Building; Building buildingData = Singleton <BuildingManager> .instance.m_buildings.m_buffer[BuildingData.lastBuildingID]; if (buildingData.Info.m_class.m_service == ItemClass.Service.Residential) { Hide(); } else { float averageEmployeeFee = CaculateEmployeeOutcome(buildingData, out int totalWorkerCount); int landRentFee = CaculateLandFee(buildingData, BuildingData.lastBuildingID); string incomeType = RealCityPrivateBuildingAI.GetProductionType(false, BuildingData.lastBuildingID, buildingData); string outgoingType = RealCityPrivateBuildingAI.GetProductionType(true, BuildingData.lastBuildingID, buildingData); float incomePrice = RealCityPrivateBuildingAI.GetPrice(false, BuildingData.lastBuildingID, buildingData); float outgoingPrice = RealCityPrivateBuildingAI.GetPrice(true, BuildingData.lastBuildingID, buildingData); buildingMoney.text = string.Format(Localization.Get("BUILDING_MONEY") + " [{0}]", BuildingData.buildingMoney[BuildingData.lastBuildingID]); buildingNetAsset.text = string.Format(Localization.Get("BUILDING_NETASSET") + " [{0}]", (BuildingData.buildingMoney[BuildingData.lastBuildingID] + buildingData.m_customBuffer1 * RealCityIndustryBuildingAI.GetResourcePrice(RealCityPrivateBuildingAI.GetIncomingProductionType(BuildingData.lastBuildingID, buildingData)))); buildingIncomeBuffer.text = string.Format(Localization.Get("MATERIAL_BUFFER") + " [{0}]" + " " + incomeType, buildingData.m_customBuffer1); buildingOutgoingBuffer.text = string.Format(Localization.Get("PRODUCTION_BUFFER") + " [{0}]" + " " + outgoingType, buildingData.m_customBuffer2); employFee.text = Localization.Get("AVERAGE_EMPLOYFEE") + " " + averageEmployeeFee.ToString() + " " + Localization.Get("PROFIT_SHARING"); landRent.text = string.Format(Localization.Get("BUILDING_LANDRENT") + " [{0:N2}]", landRentFee); buyPrice.text = string.Format(Localization.Get("BUY_PRICE") + " " + incomeType + "[{0:N2}]", incomePrice); sellPrice.text = string.Format(Localization.Get("SELL_PRICE") + " " + outgoingType + " [{0:N2}]", outgoingPrice); float consumptionDivider = 0f; if (buildingData.Info.m_class.m_subService == ItemClass.SubService.IndustrialGeneric) { consumptionDivider = RealCityPrivateBuildingAI.GetComsumptionDivider(buildingData, BuildingData.lastBuildingID) * 4f; comsuptionDivide.text = string.Format(Localization.Get("MATERIAL_DIV_PRODUCTION") + " [1:{0:N2}]", consumptionDivider); } else { if ((buildingData.Info.m_buildingAI is IndustrialExtractorAI) || buildingData.Info.m_class.m_service == ItemClass.Service.Office) { comsuptionDivide.text = string.Format(Localization.Get("MATERIAL_DIV_PRODUCTION") + " N/A"); } else { consumptionDivider = RealCityPrivateBuildingAI.GetComsumptionDivider(buildingData, BuildingData.lastBuildingID); comsuptionDivide.text = string.Format(Localization.Get("MATERIAL_DIV_PRODUCTION") + " [1:{0:N2}]", consumptionDivider); } } int m_sellTax = RealCityPrivateBuildingAI.GetTaxRate(buildingData); sellTax.text = string.Format(Localization.Get("SELL_TAX") + " [{0}%]", m_sellTax); if (consumptionDivider == 0f) { profit.text = string.Format(Localization.Get("PROFIT") + " N/A"); } else { float profitRatio = (outgoingPrice * (1f - m_sellTax / 100f) - (incomePrice / consumptionDivider)) / outgoingPrice; if (buildingData.Info.m_class.m_service == ItemClass.Service.Commercial) { profit.text = string.Format(Localization.Get("PROFIT") + " [{0}%]" + Localization.Get("EXCLUDE_VISIT_INCOME"), (int)(profitRatio * 100f)); } else { profit.text = string.Format(Localization.Get("PROFIT") + " [{0}%]", (int)(profitRatio * 100f)); } } int usedCar = 0; int num = 0; int num1 = 0; int num2 = 0; int car = 0; if (buildingData.Info.m_class.m_service == ItemClass.Service.Industrial) { TransferManager.TransferReason tempReason = default(TransferManager.TransferReason); if (buildingData.Info.m_buildingAI is IndustrialExtractorAI) { RealCityIndustrialExtractorAI.InitDelegate(); var industrialExtractorAI = (IndustrialExtractorAI)buildingData.Info.m_buildingAI; int productionCapacity = industrialExtractorAI.CalculateProductionCapacity((ItemClass.Level)buildingData.m_level, new Randomizer(BuildingData.lastBuildingID), buildingData.m_width, buildingData.m_length); car = Mathf.Max(1, productionCapacity / 6); tempReason = RealCityIndustrialExtractorAI.GetOutgoingTransferReason((IndustrialExtractorAI)buildingData.Info.m_buildingAI); RealCityCommonBuildingAI.InitDelegate(); RealCityCommonBuildingAI.CalculateOwnVehicles((IndustrialExtractorAI)buildingData.Info.m_buildingAI, BuildingData.lastBuildingID, ref buildingData, tempReason, ref usedCar, ref num, ref num1, ref num2); } else { RealCityIndustrialBuildingAI.InitDelegate(); var industrialBuildingAI = (IndustrialBuildingAI)buildingData.Info.m_buildingAI; int productionCapacity = industrialBuildingAI.CalculateProductionCapacity((ItemClass.Level)buildingData.m_level, new Randomizer(BuildingData.lastBuildingID), buildingData.m_width, buildingData.m_length); car = Mathf.Max(1, productionCapacity / 6); tempReason = RealCityIndustrialBuildingAI.GetOutgoingTransferReason((IndustrialBuildingAI)buildingData.Info.m_buildingAI); RealCityCommonBuildingAI.InitDelegate(); RealCityCommonBuildingAI.CalculateOwnVehicles((IndustrialBuildingAI)buildingData.Info.m_buildingAI, BuildingData.lastBuildingID, ref buildingData, tempReason, ref usedCar, ref num, ref num1, ref num2); } usedcar.text = string.Format(Localization.Get("CAR_USED") + " [{0}/{1}]", usedCar, car); } else if (buildingData.Info.m_class.m_service == ItemClass.Service.Commercial) { Citizen.BehaviourData behaviour = default; int aliveVisitCount = 0; int totalVisitCount = 0; RealCityCommercialBuildingAI.InitDelegate(); RealCityCommercialBuildingAI.GetVisitBehaviour((CommercialBuildingAI)(buildingData.Info.m_buildingAI), BuildingData.lastBuildingID, ref buildingData, ref behaviour, ref aliveVisitCount, ref totalVisitCount); var amount = buildingData.m_customBuffer2 / MainDataStore.maxGoodPurchase - totalVisitCount + aliveVisitCount; var commercialBuildingAI = buildingData.Info.m_buildingAI as CommercialBuildingAI; var maxCount = commercialBuildingAI.CalculateVisitplaceCount((ItemClass.Level)buildingData.m_level, new Randomizer(BuildingData.lastBuildingID), buildingData.m_width, buildingData.m_length); usedcar.text = string.Format("FORDEBUG" + " [{0}/{1}/{2}/{3}]", aliveVisitCount, totalVisitCount, maxCount, amount); } else { usedcar.text = Localization.Get("CAR_USED") + " 0/0"; } BringToFront(); refeshOnce = false; } } } }