virtual public UIObserver ShowOnGUI() { if (structureObserver == null) { structureObserver = UIStructureObserver.InitializeStructureObserverScript(); } else { structureObserver.gameObject.SetActive(true); } structureObserver.SetObservingStructure(this); return(structureObserver); }
public void SetObservingBuilding(Building b) { if (b == null) { SelfShutOff(); return; } UIStructureObserver us = Structure.structureObserver; if (us == null) { us = UIStructureObserver.InitializeStructureObserverScript(); } else { us.gameObject.SetActive(true); } observingBuilding = b; isObserving = true; us.SetObservingStructure(observingBuilding); // #redraw status_connectedToPowerGrid = b.connectedToPowerGrid; status_active = b.isActive; status_energySupplied = b.isEnergySupplied; if (status_active) { if (status_connectedToPowerGrid) { if (b.ID == Structure.ENERGY_CAPACITOR_1_ID | b.ID == Structure.ENERGY_CAPACITOR_2_ID) { chargeButton.SetActive(true); energyValue.enabled = false; } else { showingEnergySurplus = b.energySurplus; if (status_energySupplied) { if (observingBuilding.ID != Structure.QUANTUM_ENERGY_TRANSMITTER_5_ID) { if (showingEnergySurplus <= 0) { energyValue.text = string.Format("{0,1:F}", showingEnergySurplus); energyImage.uvRect = UIController.GetIconUVRect(observingBuilding.canBePowerSwitched ? Icons.PowerButton : Icons.PowerMinus); } else { energyValue.text = '+' + string.Format("{0,1:F}", showingEnergySurplus); energyImage.uvRect = UIController.GetIconUVRect(Icons.PowerPlus); } } else { energyValue.text = string.Format("{0,1:F}", showingEnergySurplus) + " / " + ((int)(GameConstants.ENERGY_IN_CRYSTAL)).ToString(); energyImage.uvRect = UIController.GetIconUVRect(Icons.PowerPlus); } } else { energyValue.text = Localization.GetWord(LocalizedWord.Offline); energyButton.GetComponent <RawImage>().uvRect = UIController.GetIconUVRect(Icons.OutOfPowerButton); } energyValue.enabled = true; chargeButton.SetActive(false); } energyImage.enabled = true; } else { energyValue.enabled = false; energyImage.enabled = false; } } else { chargeButton.SetActive(false); energyValue.text = Localization.GetPhrase(LocalizedPhrase.PressToTurnOn); energyValue.enabled = true; energyImage.uvRect = UIController.GetIconUVRect(Icons.TurnOn); energyImage.enabled = true; } energyButton.interactable = observingBuilding.canBePowerSwitched; //# eo redraw bool enableAdditionalElements = false; if (b is House) { showingHousing = (b as House).housing; housingValue.text = showingHousing.ToString(); housingValue.enabled = true; housingImage.enabled = true; if (b.ID == Structure.SETTLEMENT_CENTER_ID) { enableAdditionalElements = true; var st = b as Settlement; additionalText.text = st.pointsFilled.ToString() + " / " + st.maxPoints.ToString(); additionalButton.GetComponent <Button>().interactable = st.pointsFilled < Settlement.MAX_POINTS_COUNT; } } else { housingValue.enabled = false; housingImage.enabled = false; } if (enableAdditionalElements) { additionalButton.SetActive(true); additionalText.gameObject.SetActive(true); } else { if (additionalButton.activeSelf) { additionalButton.SetActive(false); additionalText.gameObject.SetActive(false); } } CheckUpgradeAvailability(); }
public void SetObservingBuilding(Building b) { if (b == null) { SelfShutOff(); return; } UIStructureObserver us = Structure.structureObserver; if (us == null) { us = UIStructureObserver.InitializeStructureObserverScript(); } else { us.gameObject.SetActive(true); } observingBuilding = b; isObserving = true; us.SetObservingStructure(observingBuilding); status_connectedToPowerGrid = b.connectedToPowerGrid; if (status_connectedToPowerGrid) { if (b.id == Structure.ENERGY_CAPACITOR_1_ID | b.id == Structure.ENERGY_CAPACITOR_2_ID | b.id == Structure.ENERGY_CAPACITOR_3_ID) { chargeButton.SetActive(true); energyValue.enabled = false; } else { showingEnergySurplus = b.energySurplus; status_energySupplied = b.energySupplied; if (status_energySupplied) { energyButton.GetComponent <RawImage>().uvRect = UIController.GetTextureUV(observingBuilding.isActive ? Icons.PowerOn : Icons.PowerOff); if (showingEnergySurplus <= 0) { energyValue.text = string.Format("{0,1:F}", showingEnergySurplus); } else { energyValue.text = '+' + string.Format("{0,1:F}", showingEnergySurplus); } } else { energyValue.text = Localization.GetWord(LocalizedWord.Offline); energyButton.GetComponent <RawImage>().uvRect = UIController.GetTextureUV(Icons.PowerOff); } energyValue.enabled = true; chargeButton.SetActive(false); } energyImage.enabled = true; } else { energyValue.enabled = false; energyImage.enabled = false; } energyButton.interactable = observingBuilding.canBePowerSwitched; if (b is House) { isHouse = true; showingHousing = (b as House).housing; housingValue.text = showingHousing.ToString(); housingValue.enabled = true; housingImage.enabled = true; } else { isHouse = false; housingValue.enabled = false; housingImage.enabled = false; } CheckUpgradeAvailability(); STATUS_UPDATE_TIME = 1.2f; timer = STATUS_UPDATE_TIME; }