private void DoAddStatusItem(StatusItemGroup.Entry status_item, StatusItemCategory category, bool show_immediate = false) { GameObject gameObject = statusItemsFolder; Color color = (status_item.item.notificationType != NotificationType.BadMinor && status_item.item.notificationType != NotificationType.Bad && status_item.item.notificationType != NotificationType.DuplicantThreatening) ? statusItemTextColor_regular : statusItemTextColor_bad; TextStyleSetting style = (category != Db.Get().StatusItemCategories.Main) ? StatusItemStyle_Other : StatusItemStyle_Main; StatusItemEntry statusItemEntry = new StatusItemEntry(status_item, category, StatusItemPrefab, gameObject.transform, ToolTipStyle_Property, color, style, show_immediate, OnStatusItemDestroy); statusItemEntry.SetSprite(status_item.item.sprite); if (category != null) { int num = -1; List <StatusItemEntry> list = oldStatusItems.FindAll((StatusItemEntry e) => e.category == category); foreach (StatusItemEntry item in list) { num = item.GetIndex(); item.Destroy(true); oldStatusItems.Remove(item); } if (category == Db.Get().StatusItemCategories.Main) { num = 0; } if (num != -1) { statusItemEntry.SetIndex(num); } } statusItems.Add(statusItemEntry); }
public StatusItemEntry(StatusItemGroup.Entry item, StatusItemCategory category, GameObject status_item_prefab, Transform parent, TextStyleSetting tooltip_style, Color color, TextStyleSetting style, bool skip_fade, Action <StatusItemEntry> onDestroy) { this.item = item; this.category = category; tooltipStyle = tooltip_style; this.onDestroy = onDestroy; this.color = color; this.style = style; widget = Util.KInstantiateUI(status_item_prefab, parent.gameObject, false); text = widget.GetComponentInChildren <LocText>(true); SetTextStyleSetting.ApplyStyle(text, style); toolTip = widget.GetComponentInChildren <ToolTip>(true); image = widget.GetComponentInChildren <Image>(true); item.SetIcon(image); widget.SetActive(true); toolTip.OnToolTip = OnToolTip; button = widget.GetComponentInChildren <KButton>(); if (item.item.statusItemClickCallback != null) { button.onClick += OnClick; } else { button.enabled = false; } fadeStage = (skip_fade ? FadeStage.WAIT : FadeStage.IN); SimAndRenderScheduler.instance.Add(this, false); Refresh(); SetColor(1f); }
public Guid SetStatusItem(StatusItemCategory category, StatusItem status_item, object data = null) { if (statusItemGroup == null) { return(Guid.Empty); } return(statusItemGroup.SetStatusItem(category, status_item, data)); }
public override void InitializeStates(out BaseState defaultState) { serializable = true; defaultState = Alive; string plantname = CREATURES.STATUSITEMS.DEAD.NAME; string tooltip = CREATURES.STATUSITEMS.DEAD.TOOLTIP; StatusItemCategory main = Db.Get().StatusItemCategories.Main; Dead.ToggleStatusItem(plantname, tooltip, string.Empty, StatusItem.IconType.Info, 0, false, SimViewMode.None, 0, null, null, main) .Enter(smi => { if (!UprootedMonitor.IsObjectUprooted(masterTarget.Get(smi))) { smi.master.gameObject.AddOrGet <Notifier>().Add(smi.master.CreateDeathNotification(), string.Empty); } GameUtil.KInstantiate(Assets.GetPrefab(EffectConfigs.PlantDeathId), smi.master.transform.GetPosition(), Grid.SceneLayer.FXFront).SetActive(true); smi.master.Trigger((int)GameHashes.Died); smi.master.GetComponent <KBatchedAnimController>().StopAndClear(); Destroy(smi.master.GetComponent <KBatchedAnimController>()); smi.Schedule(0.5f, smi.master.DestroySelf); }); Alive .InitializeStates(masterTarget, Dead) .DefaultState(Alive.Closed); Alive.Closed .PlayAnim("close") .Update("closed", (smi, dt) => { AbsorbHeat(smi, dt); if (smi.master._kjConsumed > smi.master._openEnergyThreshold) { smi.GoTo(Alive.Open); } }, UpdateRate.SIM_1000ms); Alive.Open.PlayAnim("open", KAnim.PlayMode.Once) .Enter(smi => smi.master._lightSource.enabled = true) .Update("open", (smi, dt) => { AbsorbHeat(smi, dt); smi.master._kjConsumed -= smi.master._lightKjConsumptionRate; if (smi.master._kjConsumed < smi.master._lightKjConsumptionRate) { smi.GoTo(Alive.Closed); } }, UpdateRate.SIM_1000ms) .Exit(smi => smi.master._lightSource.enabled = false); }
public override void InitializeStates(out BaseState default_state) { serializable = true; default_state = alive; string plantname = CREATURES.STATUSITEMS.DEAD.NAME; string tooltip = CREATURES.STATUSITEMS.DEAD.TOOLTIP; StatusItemCategory main = Db.Get().StatusItemCategories.Main; dead.ToggleStatusItem(plantname, tooltip, string.Empty, StatusItem.IconType.Info, 0, false, SimViewMode.None, 0, null, null, main) .Enter(smi => { if (smi.master.growing.Replanted && !UprootedMonitor.IsObjectUprooted(masterTarget.Get(smi))) { smi.master.gameObject.AddOrGet <Notifier>().Add(smi.master.CreateDeathNotification(), string.Empty); } GameUtil.KInstantiate(Assets.GetPrefab(EffectConfigs.PlantDeathId), smi.master.transform.GetPosition(), Grid.SceneLayer.FXFront).SetActive(true); smi.master.Trigger((int)GameHashes.Died); smi.master.GetComponent <KBatchedAnimController>().StopAndClear(); Destroy(smi.master.GetComponent <KBatchedAnimController>()); smi.Schedule(0.5f, smi.master.DestroySelf); }); alive .InitializeStates(masterTarget, dead) .DefaultState(alive.seed_grow).ToggleComponent <Growing>(); alive.seed_grow .QueueAnim("seed_grow") .OnAnimQueueComplete(alive.idle); alive.idle .Enter(smi => smi.master.elementConsumer.EnableConsumption(true)) .EventTransition(GameHashes.Wilt, alive.wilting_pre, smi => smi.master.wiltCondition.IsWilting()) .EventTransition(GameHashes.Grow, alive.pre_fruiting, smi => smi.master.growing.ReachedNextHarvest()) .PlayAnim("idle_loop", KAnim.PlayMode.Loop) .Exit(smi => smi.master.elementConsumer.EnableConsumption(false)); alive.pre_fruiting .PlayAnim("grow", KAnim.PlayMode.Once) .EventTransition(GameHashes.AnimQueueComplete, alive.fruiting); alive.fruiting_lost .Enter(smi => smi.master.harvestable.SetCanBeHarvested(false)) .GoTo(alive.idle); alive.wilting_pre .QueueAnim("wilt_pre") .OnAnimQueueComplete(alive.wilting); alive.wilting .PlayAnim("idle_wilt_loop", KAnim.PlayMode.Loop) .EventTransition(GameHashes.WiltRecover, alive.idle, smi => !smi.master.wiltCondition.IsWilting()) .EventTransition(GameHashes.Harvest, alive.harvest); alive.fruiting .DefaultState(alive.fruiting.fruiting_idle) .EventTransition(GameHashes.Wilt, alive.wilting_pre) .EventTransition(GameHashes.Harvest, alive.harvest) .EventTransition(GameHashes.Grow, alive.fruiting_lost, smi => !smi.master.growing.ReachedNextHarvest()); alive.fruiting.fruiting_idle.PlayAnim("idle_bloom_loop", KAnim.PlayMode.Loop) .Enter(smi => smi.master.harvestable.SetCanBeHarvested(true)) .Enter(smi => smi.master.elementConsumer.EnableConsumption(true)) .Enter(smi => smi.master.elementEmitter.SetEmitting(true)) .Update("fruiting_idle", (smi, dt) => { if (!smi.IsOld()) { return; } smi.GoTo(alive.fruiting.fruiting_old); }, UpdateRate.SIM_4000ms) .Exit(smi => smi.master.elementEmitter.SetEmitting(false)) .Exit(smi => smi.master.elementConsumer.EnableConsumption(false)); alive.fruiting.fruiting_old .PlayAnim("wilt", KAnim.PlayMode.Loop) .Enter(smi => smi.master.harvestable.SetCanBeHarvested(true)) .Update("fruiting_old", (smi, dt) => { if (smi.IsOld()) { return; } smi.GoTo(alive.fruiting.fruiting_idle); }, UpdateRate.SIM_4000ms); alive.harvest .PlayAnim("harvest", KAnim.PlayMode.Once) .Enter(smi => { if (GameScheduler.Instance != null && smi.master != null) { GameScheduler.Instance.Schedule("SpawnFruit", 0.2f, smi.master.crop.SpawnFruit); } smi.master.harvestable.SetCanBeHarvested(false); }) .OnAnimQueueComplete(alive.idle); }
private void OnAddStatusItem(StatusItemGroup.Entry status_item, StatusItemCategory category) { DoAddStatusItem(status_item, category, false); }
public StatusItemGroup.Entry GetStatusItem(StatusItemCategory category) { return(statusItemGroup.GetStatusItem(category)); }
/// <summary> /// Updates an active building's exhaust and self-heat. /// </summary> /// <param name="payload">The building being updated.</param> /// <param name="dt">The time since the last update in seconds.</param> /// <param name="energyCategory">The status item category for heat emission.</param> /// <param name="operatingEnergy">The status item to display when emitting heat.</param> /// <returns></returns> private static bool UpdateActive(ref StructureTemperaturePayload payload, float dt, StatusItemCategory energyCategory, StatusItem operatingEnergy) { bool dirty = false; const float MAX_PRESSURE = StructureTemperatureComponents.MAX_PRESSURE; var operational = payload.operational; if (operational == null || operational.IsActive) { float exhaust = payload.ExhaustKilowatts; if (!payload.isActiveStatusItemSet) { // Turn on the "active" status item if (payload.primaryElement.TryGetComponent(out KSelectable selectable)) { selectable.SetStatusItem(energyCategory, operatingEnergy, payload.simHandleCopy); } payload.isActiveStatusItemSet = true; } AccumulateProducedEnergy(ref payload.energySourcesKW, payload. OperatingKilowatts, STRINGS.BUILDING.STATUSITEMS.OPERATINGENERGY. OPERATING); if (exhaust != 0.0f) { var extents = payload.GetExtents(); int h = extents.height, w = extents.width; float kjPerM2 = exhaust * dt / (w * h); int gw = Grid.WidthInCells, cell = extents.y * gw + extents.x; // Going up one row is +grid width -building width from the last cell of // the previous row gw -= w; for (int y = h; y > 0; y--) { for (int x = w; x > 0; x--) { float mass = Grid.Mass[cell]; // Avoid emitting into Vacuum if (mass > 0.0f) { SimMessages.ModifyEnergy(cell, kjPerM2 * Mathf.Min(mass, MAX_PRESSURE) / MAX_PRESSURE, payload.maxTemperature, SimMessages.EnergySourceID.StructureTemperature); } cell++; } cell += gw; } AccumulateProducedEnergy(ref payload.energySourcesKW, exhaust, STRINGS. BUILDING.STATUSITEMS.OPERATINGENERGY.EXHAUSTING); } dirty = true; } else if (payload.isActiveStatusItemSet) { // Turn off the "active" status item if (payload.primaryElement.TryGetComponent(out KSelectable selectable)) { selectable.SetStatusItem(energyCategory, null, null); } payload.isActiveStatusItemSet = false; dirty = true; } return(dirty); }