private void Update_GUI() { if (building.Is_Deleted) { Active = false; return; } Prototype_Container.SetActive(building.Is_Prototype); Instance_Container.SetActive(!building.Is_Prototype); Name_Text.text = building.Name; Image.sprite = SpriteManager.Instance.Get(building.Sprite.Name, building.Sprite.Type); if (current_row_id > 99999) { current_row_id = 0; } if (building.Is_Prototype) { foreach (GameObject row in cost_rows) { GameObject.Destroy(row); } cost_rows.Clear(); foreach (GameObject row in upkeep_rows) { GameObject.Destroy(row); } upkeep_rows.Clear(); Id_Text.text = string.Empty; Size_Text.text = string.Format("Size: {0}x{1}", building.Width, building.Height); Appeal_Text.text = string.Format("Appeal: {0}", Helper.Float_To_String(building.Appeal * (building.Width * building.Height), 2, true)); Appeal_Range_Text.text = string.Format("Appeal range: {0}", Helper.Float_To_String(building.Appeal_Range, 1)); //Cost if (building.Cash_Cost != 0) { GameObject cash_cost_row = GameObject.Instantiate( Cost_Row_Prototype, new Vector3( Cost_Row_Prototype.transform.position.x, Cost_Row_Prototype.transform.position.y, Cost_Row_Prototype.transform.position.z ), Quaternion.identity, Cost_Content.transform ); cash_cost_row.name = "cash_cost_row_#" + current_row_id; current_row_id++; cash_cost_row.SetActive(true); Update_Cash_Row(cash_cost_row, building.Cash_Cost, 0, false, false); cost_rows.Add(cash_cost_row); } foreach (KeyValuePair <Resource, int> cost in building.Cost.OrderByDescending(x => x.Value).ToArray()) { GameObject cost_row = GameObject.Instantiate( Cost_Row_Prototype, new Vector3( Cost_Row_Prototype.transform.position.x, Cost_Row_Prototype.transform.position.y - (15.0f * cost_rows.Count), Cost_Row_Prototype.transform.position.z ), Quaternion.identity, Cost_Content.transform ); cost_row.name = string.Format("{0}_cost_row_#{1}", cost.Key.ToString().ToLower(), current_row_id); current_row_id++; cost_row.SetActive(true); Update_Resource_Row(cost_row, cost.Key, cost.Value, 0, false, false); cost_rows.Add(cost_row); } if (cost_rows.Count == 0) { GameObject free_cost_row = GameObject.Instantiate( Cost_Row_Prototype, new Vector3( Cost_Row_Prototype.transform.position.x, Cost_Row_Prototype.transform.position.y, Cost_Row_Prototype.transform.position.z ), Quaternion.identity, Cost_Content.transform ); free_cost_row.name = "free_cost_row_#" + current_row_id; current_row_id++; free_cost_row.SetActive(true); GameObject.Find(string.Format("{0}/AmountText", free_cost_row.name)).GetComponent <Text>().text = "none"; GameObject.Find(string.Format("{0}/ResourceText", free_cost_row.name)).GetComponent <Text>().text = string.Empty; GameObject.Find(string.Format("{0}/IconImage", free_cost_row.name)).GetComponent <Image>().gameObject.SetActive(false); cost_rows.Add(free_cost_row); } Cost_Content.GetComponentInChildren <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (15.0f * cost_rows.Count) + 5.0f); //Upkeep if (building.Cash_Upkeep != 0.0f) { GameObject cash_upkeep_row = GameObject.Instantiate( Upkeep_Row_Prototype, new Vector3( Upkeep_Row_Prototype.transform.position.x, Upkeep_Row_Prototype.transform.position.y, Upkeep_Row_Prototype.transform.position.z ), Quaternion.identity, Upkeep_Content.transform ); cash_upkeep_row.name = "cash_upkeep_row_#" + current_row_id; current_row_id++; cash_upkeep_row.SetActive(true); Update_Cash_Row(cash_upkeep_row, building.Cash_Upkeep, 2, true, true); upkeep_rows.Add(cash_upkeep_row); } foreach (KeyValuePair <Resource, float> upkeep in building.Upkeep.OrderByDescending(x => x.Value).ToArray()) { GameObject upkeep_row = GameObject.Instantiate( Upkeep_Row_Prototype, new Vector3( Upkeep_Row_Prototype.transform.position.x, Upkeep_Row_Prototype.transform.position.y - (15.0f * upkeep_rows.Count), Upkeep_Row_Prototype.transform.position.z ), Quaternion.identity, Upkeep_Content.transform ); upkeep_row.name = string.Format("{0}_upkeep_row_#{1}", upkeep.Key.ToString().ToLower(), current_row_id); current_row_id++; upkeep_row.SetActive(true); Update_Resource_Row(upkeep_row, upkeep.Key, upkeep.Value, 2, true, true); upkeep_rows.Add(upkeep_row); } if (upkeep_rows.Count == 0) { GameObject free_upkeep_row = GameObject.Instantiate( Upkeep_Row_Prototype, new Vector3( Upkeep_Row_Prototype.transform.position.x, Upkeep_Row_Prototype.transform.position.y, Upkeep_Row_Prototype.transform.position.z ), Quaternion.identity, Upkeep_Content.transform ); free_upkeep_row.name = "free_cost_row_#" + current_row_id; current_row_id++; free_upkeep_row.SetActive(true); GameObject.Find(string.Format("{0}/AmountText", free_upkeep_row.name)).GetComponent <Text>().text = "none"; GameObject.Find(string.Format("{0}/ResourceText", free_upkeep_row.name)).GetComponent <Text>().text = string.Empty; GameObject.Find(string.Format("{0}/IconImage", free_upkeep_row.name)).GetComponent <Image>().gameObject.SetActive(false); upkeep_rows.Add(free_upkeep_row); } Upkeep_Content.GetComponentInChildren <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (15.0f * upkeep_rows.Count) + 5.0f); } else { Id_Text.text = string.Format("#{0}", building.Id); HP_Text.text = string.Format("HP: {0} / {1}", Helper.Float_To_String(building.HP, 0), building.Max_HP); if (!building.Is_Built) { Status_Text.text = string.Format("Construction: {0}%", Helper.Float_To_String(100.0f * (building.Construction_Progress / building.Construction_Time), 0)); } else if (building.Is_Deconstructing) { Status_Text.text = string.Format("Deconstruction: {0}%", Helper.Float_To_String(100.0f * (building.Deconstruction_Progress / building.Construction_Time), 0)); } else if (building.Is_Paused) { Status_Text.text = "Paused"; } else if (building.Requires_Connection && !building.Is_Connected) { Status_Text.text = "Disconnected"; } else if (building.Is_Operational) { Status_Text.text = "Operational"; } else { Status_Text.text = "ERROR"; } Efficency_Text.text = string.Format("Efficency: {0}%", Helper.Float_To_String(100.0f * building.Efficency, 0)); if (!string.IsNullOrEmpty(building.Special_Status_Text_1)) { Special_Status_1_Text.gameObject.SetActive(true); Special_Status_1_Text.text = building.Special_Status_Text_1; } else { Special_Status_1_Text.gameObject.SetActive(false); } if (!string.IsNullOrEmpty(building.Special_Status_Text_2)) { Special_Status_2_Text.gameObject.SetActive(true); Special_Status_2_Text.text = building.Special_Status_Text_2; } else { Special_Status_2_Text.gameObject.SetActive(false); } //Workers if (building.Is_Built && !building.Is_Deconstructing && building.Max_Workers_Total != 0) { Workers_Container.SetActive(true); Residents_Container.SetActive(false); Taxed_By_Text.gameObject.SetActive(false); Worker_Peasant_Current.text = building.Current_Workers[Building.Resident.Peasant].ToString(); Worker_Peasant_Max.text = building.Worker_Settings[Building.Resident.Peasant].ToString(); Worker_Citizen_Current.text = building.Current_Workers[Building.Resident.Citizen].ToString(); Worker_Citizen_Max.text = building.Worker_Settings[Building.Resident.Citizen].ToString(); Worker_Noble_Current.text = building.Current_Workers[Building.Resident.Noble].ToString(); Worker_Noble_Max.text = building.Worker_Settings[Building.Resident.Noble].ToString(); Worker_Allocated_Current.text = building.Workers_Allocated.ToString(); Worker_Allocated_Max.text = building.Max_Workers_Total.ToString(); Worker_Peasant_Plus_Button.interactable = !building.Lock_Workers && building.Workers_Allocated < building.Max_Workers_Total && building.Worker_Settings[Building.Resident.Peasant] < building.Max_Workers[Building.Resident.Peasant]; Worker_Citizen_Plus_Button.interactable = !building.Lock_Workers && building.Workers_Allocated < building.Max_Workers_Total && building.Worker_Settings[Building.Resident.Citizen] < building.Max_Workers[Building.Resident.Citizen]; Worker_Noble_Plus_Button.interactable = !building.Lock_Workers && building.Workers_Allocated < building.Max_Workers_Total && building.Worker_Settings[Building.Resident.Noble] < building.Max_Workers[Building.Resident.Noble]; Worker_Peasant_Minus_Button.interactable = !building.Lock_Workers && building.Workers_Allocated > 1 && building.Worker_Settings[Building.Resident.Peasant] > 0; Worker_Citizen_Minus_Button.interactable = !building.Lock_Workers && building.Workers_Allocated > 1 && building.Worker_Settings[Building.Resident.Citizen] > 0; Worker_Noble_Minus_Button.interactable = !building.Lock_Workers && building.Workers_Allocated > 1 && building.Worker_Settings[Building.Resident.Noble] > 0; } else if (building is Residence) { Workers_Container.SetActive(false); Residents_Container.SetActive(true); Taxed_By_Text.gameObject.SetActive(true); Residence residence = (Building as Residence); Residents_Peasant_Current.text = residence.Current_Residents[Building.Resident.Peasant].ToString(); Residents_Peasant_Max.text = residence.Resident_Space[Building.Resident.Peasant].ToString(); Residents_Peasant_Happiness.text = Helper.Float_To_String(100.0f * residence.Happiness[Building.Resident.Peasant], 0); if (residence.Happiness_Info[Building.Resident.Peasant].Count != 0) { TooltipManager.Instance.Register_Tooltip(Residents_Peasant_Happiness.gameObject, Parse_Happiness_Tooltip(residence.Happiness_Info[Building.Resident.Peasant]), gameObject); } else { TooltipManager.Instance.Unregister_Tooltip(Residents_Peasant_Happiness.gameObject); } Residents_Citizen_Current.text = residence.Current_Residents[Building.Resident.Citizen].ToString(); Residents_Citizen_Max.text = residence.Resident_Space[Building.Resident.Citizen].ToString(); Residents_Citizen_Happiness.text = Helper.Float_To_String(100.0f * residence.Happiness[Building.Resident.Citizen], 0); if (residence.Happiness_Info[Building.Resident.Citizen].Count != 0) { TooltipManager.Instance.Register_Tooltip(Residents_Citizen_Happiness.gameObject, Parse_Happiness_Tooltip(residence.Happiness_Info[Building.Resident.Citizen]), gameObject); } else { TooltipManager.Instance.Unregister_Tooltip(Residents_Citizen_Happiness.gameObject); } Residents_Noble_Current.text = residence.Current_Residents[Building.Resident.Noble].ToString(); Residents_Noble_Max.text = residence.Resident_Space[Building.Resident.Noble].ToString(); Residents_Noble_Happiness.text = Helper.Float_To_String(100.0f * residence.Happiness[Building.Resident.Noble], 0); if (residence.Happiness_Info[Building.Resident.Noble].Count != 0) { TooltipManager.Instance.Register_Tooltip(Residents_Noble_Happiness.gameObject, Parse_Happiness_Tooltip(residence.Happiness_Info[Building.Resident.Noble]), gameObject); } else { TooltipManager.Instance.Unregister_Tooltip(Residents_Noble_Happiness.gameObject); } if (residence.Taxed_By == -1) { Taxed_By_Text.text = "Taxed by: none"; } else { Building tax_office = City.Instance.Buildings.FirstOrDefault(x => x.Id == residence.Taxed_By); if (tax_office != null) { Taxed_By_Text.text = string.Format("Taxed by:{0}{1} #{2}", Environment.NewLine, tax_office.Name, tax_office.Id); } else { CustomLogger.Instance.Error(string.Format("Building not found #{0}", residence.Taxed_By)); Taxed_By_Text.text = "Taxed by: ERROR"; } } } else { Workers_Container.SetActive(false); Residents_Container.SetActive(false); Taxed_By_Text.gameObject.SetActive(false); } //Delta foreach (GameObject row in delta_rows) { GameObject.Destroy(row); } delta_rows.Clear(); if (building.Per_Day_Cash_Delta != 0.0f) { GameObject delta_row = GameObject.Instantiate( Delta_Row_Prototype, new Vector3( Delta_Row_Prototype.transform.position.x, Delta_Row_Prototype.transform.position.y - (15.0f * delta_rows.Count), Delta_Row_Prototype.transform.position.z ), Quaternion.identity, Delta_Content.transform ); delta_row.name = "cash_delta_row_#" + current_row_id; current_row_id++; delta_row.SetActive(true); Update_Cash_Row(delta_row, building.Per_Day_Cash_Delta, 2, true, false); delta_rows.Add(delta_row); } foreach (KeyValuePair <Resource, float> resource in building.Per_Day_Resource_Delta) { if (resource.Value == 0.0f) { continue; } GameObject delta_row = GameObject.Instantiate( Delta_Row_Prototype, new Vector3( Delta_Row_Prototype.transform.position.x, Delta_Row_Prototype.transform.position.y - (15.0f * delta_rows.Count), Delta_Row_Prototype.transform.position.z ), Quaternion.identity, Delta_Content.transform ); delta_row.name = string.Format("{0}_delta_row_#{1}", resource.Key.ToString().ToLower(), current_row_id); current_row_id++; delta_row.SetActive(true); Update_Resource_Row(delta_row, resource.Key, resource.Value, 2, true, false); delta_rows.Add(delta_row); } Delta_Content.GetComponentInChildren <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (15.0f * delta_rows.Count) + 5.0f); Storage_Container.SetActive(!(Building is Residence)); Services_Container.SetActive(Building is Residence); //Storage if (!(Building is Residence)) { foreach (GameObject row in storage_rows) { GameObject.Destroy(row); } storage_rows.Clear(); Storage_Text.text = building.Is_Storehouse ? string.Format("Storage ({0} / {1})", Helper.Float_To_String(building.Current_Storage_Amount, 0), building.Storage_Limit) : "Storage"; foreach (KeyValuePair <Resource, float> resource in building.All_Resources) { if (resource.Value == 0.0f) { continue; } GameObject resource_row = GameObject.Instantiate( Storage_Row_Prototype, new Vector3( Storage_Row_Prototype.transform.position.x, Storage_Row_Prototype.transform.position.y - (15.0f * storage_rows.Count), Storage_Row_Prototype.transform.position.z ), Quaternion.identity, Storage_Content.transform ); resource_row.name = string.Format("{0}_resource_row_#{1}", resource.Key.ToString().ToLower(), current_row_id); current_row_id++; resource_row.SetActive(true); Update_Resource_Row(resource_row, resource.Key, resource.Value, 1, false, false); storage_rows.Add(resource_row); } Storage_Content.GetComponentInChildren <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (15.0f * storage_rows.Count) + 5.0f); } else { Residence residence = building as Residence; //Services foreach (GameObject row in service_rows) { GameObject.Destroy(row); } service_rows.Clear(); foreach (Residence.ServiceType service in Enum.GetValues(typeof(Residence.ServiceType))) { if (!residence.Consumes_Service(service)) { continue; } GameObject service_row = GameObject.Instantiate( Services_Row_Prototype, new Vector3( Services_Row_Prototype.transform.position.x, Services_Row_Prototype.transform.position.y - (15.0f * service_rows.Count), Services_Row_Prototype.transform.position.z ), Quaternion.identity, Services_Content.transform ); service_row.name = string.Format("{0}_service_row", service.ToString().ToLower()); service_row.SetActive(true); service_row.GetComponentInChildren <Text>().text = string.Format("{0} {1} / 100 {2}%", Helper.Snake_Case_To_UI(service.ToString(), true), Helper.Float_To_String(100.0f * residence.Service_Level(service), 0), Helper.Float_To_String(100.0f * residence.Service_Quality(service), 0)); service_rows.Add(service_row); } Services_Content.GetComponentInChildren <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (15.0f * service_rows.Count) + 5.0f); } Pause_Button.interactable = building.Can_Be_Paused; Pause_Button.GetComponentInChildren <Text>().text = building.Is_Paused ? "Unpause" : "Pause"; Delete_Button.interactable = building.Can_Be_Deleted; Settings_Button.interactable = building.Is_Complete && (building.Is_Storehouse || building.Special_Settings.Count > 0 || building.Tags.Contains(Building.Tag.Land_Trade) || building.Tags.Contains(Building.Tag.Water_Trade) || building.Tags.Contains(Building.Tag.Is_Distribution_Depot) || (building.Tags.Contains(Building.Tag.Creates_Expeditions) && building.Has_Functional_Dock() && building.Is_Operational)); //Highlights float range = Mathf.Max(new float[3] { building.Range, building.Construction_Range, (building is Residence) ? ((building as Residence).Peasants_Only ? 0.0f : Residence.DIRT_ROAD_RANGE) : 0.0f }); if (range > 0.0f) { List <Tile> tiles_in_range = building.Get_Tiles_In_Circle(range); List <Tile> special_highlight_tiles = building.On_Highlight != null?building.On_Highlight(building) : new List <Tile>(); foreach (Tile t in tiles_in_range) { if (t.Building != building) { t.Highlight = special_highlight_tiles.Contains(t) ? new Color(0.35f, 0.35f, 1.0f, 1.0f) : new Color(0.45f, 0.45f, 1.0f, 1.0f); highlighted_tiles.Add(t); } } } if (building.Road_Range > 0) { Dictionary <Building, int> connected_buildings = building.Get_Connected_Buildings(building.Road_Range); foreach (KeyValuePair <Building, int> pair in connected_buildings) { if (pair.Key != building) { foreach (Tile t in pair.Key.Tiles) { t.Highlight = new Color(0.35f, 0.35f, 0.35f, 1.0f); t.Show_Text(pair.Value.ToString()); highlighted_tiles.Add(t); } } } } } }