private void CreateMeter() { if (hasMeter) { meter = new MeterController(root.GetComponent <KBatchedAnimController>(), "meter_target", "meter", Meter.Offset.Infront, Grid.SceneLayer.NoLayer, "meter_frame", "meter_level"); } }
public Context(KMonoBehaviour cmp) { cell = Grid.PosToCell(cmp); navigator = cmp.GetComponent <Navigator>(); oxygenBreather = cmp.GetComponent <OxygenBreather>(); minionBrain = cmp.GetComponent <MinionBrain>(); temperatureTransferer = cmp.GetComponent <SimTemperatureTransfer>(); primaryElement = cmp.GetComponent <PrimaryElement>(); }
private void FindClimbableTree() { climbTarget = null; ListPool <ScenePartitionerEntry, GameScenePartitioner> .PooledList pooledList = ListPool <ScenePartitionerEntry, GameScenePartitioner> .Allocate(); ListPool <KMonoBehaviour, ClimbableTreeMonitor> .PooledList pooledList2 = ListPool <KMonoBehaviour, ClimbableTreeMonitor> .Allocate(); Vector3 position = base.master.transform.GetPosition(); Extents extents = new Extents(Grid.PosToCell(position), 10); GameScenePartitioner.Instance.GatherEntries(extents, GameScenePartitioner.Instance.plants, pooledList); GameScenePartitioner.Instance.GatherEntries(extents, GameScenePartitioner.Instance.completeBuildings, pooledList); Navigator component = GetComponent <Navigator>(); foreach (ScenePartitionerEntry item in pooledList) { KMonoBehaviour kMonoBehaviour = item.obj as KMonoBehaviour; if (!kMonoBehaviour.HasTag(GameTags.Creatures.ReservedByCreature)) { int cell = Grid.PosToCell(kMonoBehaviour); if (component.CanReach(cell)) { BuddingTrunk component2 = kMonoBehaviour.GetComponent <BuddingTrunk>(); StorageLocker component3 = kMonoBehaviour.GetComponent <StorageLocker>(); if ((Object)component2 != (Object)null) { if (!component2.ExtraSeedAvailable) { continue; } } else { if (!((Object)component3 != (Object)null)) { continue; } Storage component4 = component3.GetComponent <Storage>(); if (!component4.allowItemRemoval || component4.IsEmpty()) { continue; } } pooledList2.Add(kMonoBehaviour); } } } if (pooledList2.Count > 0) { int index = Random.Range(0, pooledList2.Count); KMonoBehaviour kMonoBehaviour2 = pooledList2[index]; climbTarget = kMonoBehaviour2.gameObject; } pooledList.Recycle(); pooledList2.Recycle(); }
private void CreateMeter() { if (!hasMeter) { return; } meter = new MeterController(root.GetComponent <KBatchedAnimController>(), "meter_target", "meter", Meter.Offset.Infront, Grid.SceneLayer.NoLayer, new string[2] { "meter_frame", "meter_level" }); }
public void Refresh(object data = null) { if (!sideScreen.targetAssignable.CanAssignTo(targetIdentity)) { currentState = AssignableState.Disabled; assignmentText.text = UI.UISIDESCREENS.ASSIGNABLESIDESCREEN.DISABLED; } else if (sideScreen.targetAssignable.assignee == targetIdentity) { currentState = AssignableState.Selected; assignmentText.text = UI.UISIDESCREENS.ASSIGNABLESIDESCREEN.ASSIGNED; } else { bool flag = false; KMonoBehaviour kMonoBehaviour = targetIdentity as KMonoBehaviour; if ((UnityEngine.Object)kMonoBehaviour != (UnityEngine.Object)null) { Ownables component = kMonoBehaviour.GetComponent <Ownables>(); if ((UnityEngine.Object)component != (UnityEngine.Object)null) { AssignableSlotInstance slot = component.GetSlot(sideScreen.targetAssignable.slot); if (slot != null && slot.IsAssigned()) { currentState = AssignableState.AssignedToOther; assignmentText.text = slot.assignable.GetProperName(); flag = true; } } Equipment component2 = kMonoBehaviour.GetComponent <Equipment>(); if ((UnityEngine.Object)component2 != (UnityEngine.Object)null) { AssignableSlotInstance slot2 = component2.GetSlot(sideScreen.targetAssignable.slot); if (slot2 != null && slot2.IsAssigned()) { currentState = AssignableState.AssignedToOther; assignmentText.text = slot2.assignable.GetProperName(); flag = true; } } } if (!flag) { currentState = AssignableState.Unassigned; assignmentText.text = UI.UISIDESCREENS.ASSIGNABLESIDESCREEN.UNASSIGNED; } } toggle.ChangeState((int)currentState); }
public static void Postfix(KMonoBehaviour ___root, Tag[] tags) { if (!IsActive(tags)) { return; } try{ KAnimControllerBase kanim = ___root.GetComponent <KAnimControllerBase>(); if (kanim != null) { if (___root.name.ToString().StartsWith("BigSolidStorage")) { kanim.TintColour = defaultColor; CaiLib.Logger.Logger.Log(string.Concat("Updating Filterable Object Color:", ___root.name.ToString())); } if (___root.name.ToString().StartsWith("BigBeautifulStorage")) { kanim.TintColour = beautifulColor; CaiLib.Logger.Logger.Log(string.Concat("Updating Filterable Object Color:", ___root.name.ToString())); } } } catch (Exception ex) { CaiLib.Logger.Logger.Log(ex.ToString()); } }
private static void AddPlant(List <KMonoBehaviour> list, KMonoBehaviour plant) { if (plant?.GetComponent <ExtraSeedProducer>()?.ExtraSeedAvailable ?? false) { list.Add(plant); } }
public UncategorizedFilteredStorage( KMonoBehaviour root, Tag[] required_tags, Tag[] forbidden_tags, IUserControlledCapacity capacity_control, bool use_logic_meter, ChoreType fetch_chore_type) { this.root = root; this.requiredTags = required_tags; this.forbiddenTags = forbidden_tags; this.capacityControl = capacity_control; this.useLogicMeter = use_logic_meter; this.choreType = fetch_chore_type; root.Subscribe(-1697596308, new Action <object>(OnStorageChanged)); root.Subscribe(-543130682, new Action <object>(OnUserSettingsChanged)); this.filterable = root.FindOrAdd <UncategorizedFilterable>(); filterable.OnFilterChanged += new Action <Tag[]>(OnFilterChanged); this.storage = root.GetComponent <Storage>(); storage.Subscribe(644822890, new Action <object>(OnOnlyFetchMarkedItemsSettingChanged)); if (capacityStatusItem == null) { capacityStatusItem = new StatusItem("StorageLocker", "BUILDING", string.Empty, StatusItem.IconType.Info, NotificationType.Neutral, false, OverlayModes.None.ID, true, 129022); capacityStatusItem.resolveStringCallback = (str, data) => { UncategorizedFilteredStorage filteredStorage = (UncategorizedFilteredStorage)data; float amountStored = filteredStorage.GetAmountStored(); float b = filteredStorage.storage.capacityKg; string newValue1 = Util.FormatWholeNumber(amountStored <= b - filteredStorage.storage.storageFullMargin || amountStored >= b ? Mathf.Floor(amountStored) : b); IUserControlledCapacity component = filteredStorage.root.GetComponent <IUserControlledCapacity>(); if (component != null) { b = Mathf.Min(component.UserMaxCapacity, b); } string newValue2 = Util.FormatWholeNumber(b); str = str.Replace("{Stored}", newValue1); str = str.Replace("{Capacity}", newValue2); str = component == null?str.Replace("{Units}", (string)GameUtil.GetCurrentMassUnit(false)) : str.Replace("{Units}", (string)component.CapacityUnits); return(str); }; noFilterStatusItem = new StatusItem("NoStorageFilterSet", "BUILDING", "status_item_no_filter_set", StatusItem.IconType.Custom, NotificationType.BadMinor, false, OverlayModes.None.ID, true, 129022); } root.GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, capacityStatusItem, this); }
public MeterController(KMonoBehaviour target, Meter.Offset front_back, Grid.SceneLayer user_specified_render_layer, params string[] symbols_to_hide) { string[] array = new string[symbols_to_hide.Length + 1]; Array.Copy(symbols_to_hide, array, symbols_to_hide.Length); array[array.Length - 1] = "meter_target"; KBatchedAnimController component = target.GetComponent <KBatchedAnimController>(); Initialize(component, "meter_target", "meter", front_back, user_specified_render_layer, Vector3.zero, array); }
public FilteredStorage(KMonoBehaviour root, Tag[] required_tags, Tag[] forbidden_tags, IUserControlledCapacity capacity_control, bool use_logic_meter, ChoreType fetch_chore_type) { this.root = root; requiredTags = required_tags; forbiddenTags = forbidden_tags; capacityControl = capacity_control; useLogicMeter = use_logic_meter; choreType = fetch_chore_type; root.Subscribe(-1697596308, OnStorageChanged); root.Subscribe(-543130682, OnUserSettingsChanged); filterable = root.FindOrAdd <TreeFilterable>(); TreeFilterable treeFilterable = filterable; treeFilterable.OnFilterChanged = (Action <Tag[]>)Delegate.Combine(treeFilterable.OnFilterChanged, new Action <Tag[]>(OnFilterChanged)); storage = root.GetComponent <Storage>(); storage.Subscribe(644822890, OnOnlyFetchMarkedItemsSettingChanged); if (capacityStatusItem == null) { capacityStatusItem = new StatusItem("StorageLocker", "BUILDING", string.Empty, StatusItem.IconType.Info, NotificationType.Neutral, false, OverlayModes.None.ID, true, 129022); capacityStatusItem.resolveStringCallback = delegate(string str, object data) { FilteredStorage filteredStorage = (FilteredStorage)data; float amountStored = filteredStorage.GetAmountStored(); float num = filteredStorage.storage.capacityKg; amountStored = ((!(amountStored > num - filteredStorage.storage.storageFullMargin) || !(amountStored < num)) ? Mathf.Floor(amountStored) : num); string newValue = Util.FormatWholeNumber(amountStored); IUserControlledCapacity component = filteredStorage.root.GetComponent <IUserControlledCapacity>(); if (component != null) { num = Mathf.Min(component.UserMaxCapacity, num); } string newValue2 = Util.FormatWholeNumber(num); str = str.Replace("{Stored}", newValue); str = str.Replace("{Capacity}", newValue2); str = ((component == null) ? str.Replace("{Units}", GameUtil.GetCurrentMassUnit(false)) : str.Replace("{Units}", component.CapacityUnits)); return(str); }; noFilterStatusItem = new StatusItem("NoStorageFilterSet", "BUILDING", "status_item_no_filter_set", StatusItem.IconType.Custom, NotificationType.BadMinor, false, OverlayModes.None.ID, true, 129022); } root.GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, capacityStatusItem, this); }
private static void UpdateSweepBotStationStorage(KMonoBehaviour kMonoBehaviour) { var sweepBotStation = kMonoBehaviour.GetComponent <SweepBotStation>(); if (sweepBotStation != null) { var storage = SWEEP_STORAGE.Get(sweepBotStation); if (storage != null) { FixSweepBotStationStorage(storage); } } }
public static void Postfix(KMonoBehaviour ___root, Tag[] tags) { Color color = ColorHelper.GetComponentMaterialColor(___root); bool active = tags != null && tags.Length != 0; if (active) { KAnimControllerBase animBase = ___root.GetComponent <KAnimControllerBase>(); if (animBase != null) { animBase.TintColour = color; } } }
// TODO allow Meter.Offset public VariantController( KMonoBehaviour target, string variantTarget, string variantAnimation, int totalVariants, Grid.SceneLayer renderLayer ) : this( target.GetComponent <KBatchedAnimController>(), variantTarget, variantAnimation, totalVariants, renderLayer ) { }
public static ProgressBar CreateProgressBar(KMonoBehaviour entity, Func <float> updateFunc) { ProgressBar progressBar = Util.KInstantiateUI <ProgressBar>(ProgressBarsConfig.Instance.progressBarPrefab, null, false); progressBar.SetUpdateFunc(updateFunc); progressBar.transform.SetParent(GameScreenManager.Instance.worldSpaceCanvas.transform); progressBar.name = ((!((UnityEngine.Object)entity != (UnityEngine.Object)null)) ? string.Empty : (entity.name + "_")) + " ProgressBar"; progressBar.transform.Find("Bar").GetComponent <Image>().color = ProgressBarsConfig.Instance.GetBarColor("ProgressBar"); progressBar.Update(); Vector3 a = entity.transform.GetPosition() + Vector3.down * 0.5f; Building component = entity.GetComponent <Building>(); TransformExtensions.SetPosition(position: (!((UnityEngine.Object)component != (UnityEngine.Object)null)) ? (a - Vector3.right * 0.5f) : (a - Vector3.right * 0.5f * (float)(component.Def.WidthInCells % 2) + component.Def.placementPivot), transform: progressBar.transform); return(progressBar); }
public static void Postfix(KMonoBehaviour ___root, Tag[] tags) { try { Color color = ColorHelper.GetComponentMaterialColor(___root); bool active = tags != null && tags.Length != 0; if (active) { KAnimControllerBase animBase = ___root.GetComponent <KAnimControllerBase>(); if (animBase != null) { animBase.TintColour = color; } } } catch (Exception e) { Common.Logger.LogOnce("FilteredStorage_OnFilterChanged.Postfix", e); } }
private void DecorCardDetail(HoverTextDrawer hoverTextDrawer) { List <EffectorEntry> positiveEffector = new List <EffectorEntry>(); List <EffectorEntry> negativeEffector = new List <EffectorEntry>(); // Decorの影響を集計する。同時に、影響を与えたもののハイライト表示をする List <DecorProvider> list = new List <DecorProvider>(); GameScenePartitioner.Instance.TriggerEvent(cellPos, GameScenePartitioner.Instance.decorProviderLayer, list); foreach (DecorProvider decorProvider in list) { float decorForCell = decorProvider.GetDecorForCell(cellPos); if (decorForCell == 0f) { continue; } string decorProviderName = decorProvider.GetName(); // Decorに関係するオブジェクトをハイライト表示する KMonoBehaviour component = decorProvider.GetComponent <KMonoBehaviour>(); if (component != null && component.gameObject != null) { SelectToolHoverTextCard.highlightedObjects.Add(component.gameObject); // 完成したモニュメントの場合 if (component.GetComponent <MonumentPart>() != null && component.GetComponent <MonumentPart>().IsMonumentCompleted()) { // 名前をoverrideする decorProviderName = MISC.MONUMENT_COMPLETE.NAME; // 連結したものも全てハイライトする SelectToolHoverTextCard.highlightedObjects.AddRange( AttachableBuilding.GetAttachedNetwork(component.GetComponent <AttachableBuilding>()) ); } } List <EffectorEntry> pos_or_neg = (decorForCell > 0f) ? positiveEffector : negativeEffector; EffectorEntry effector = pos_or_neg.FirstOrDefault(e => e.name == decorProviderName); if (effector == null) { effector = new EffectorEntry(decorProviderName); pos_or_neg.Add(effector); } effector.count++; effector.value += decorForCell; } // 光源効果 int lightDecorBonus = DecorProvider.GetLightDecorBonus(cellPos); if (lightDecorBonus > 0) { positiveEffector.Add(new EffectorEntry(UI.OVERLAYS.DECOR.LIGHTING, (float)lightDecorBonus)); } if (positiveEffector.Count > 0) { hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawText(UI.OVERLAYS.DECOR.HEADER_POSITIVE, __this.Styles_BodyText.Standard); } foreach (EffectorEntry entry in positiveEffector.OrderByDescending(e => e.value)) { hoverTextDrawer.NewLine(18); DecorCardEntry(hoverTextDrawer, entry); } if (negativeEffector.Count > 0) { hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawText(UI.OVERLAYS.DECOR.HEADER_NEGATIVE, __this.Styles_BodyText.Standard); } foreach (EffectorEntry entry in negativeEffector.OrderBy(e => e.value)) { hoverTextDrawer.NewLine(18); DecorCardEntry(hoverTextDrawer, entry); } }
/// <summary> /// Calculates if the specified plant should be tinted. /// </summary> /// <param name="plant">The plant that was found.</param> /// <returns>Whether the plant is in range of the cell under the cursor.</returns> private bool ShouldHighlight(KMonoBehaviour plant) { bool hl = false; int plantCell; if (plant != null && Grid.IsValidCell(plantCell = Grid.PosToCell(plant))) { // Same method as used by the decor overlay int mouseCell = Grid.PosToCell(CameraController.Instance.baseCamera. ScreenToWorldPoint(KInputManager.GetMousePos())); // It goes from [x - radius, y - radius] to (x + radius, y + radius) if (Grid.IsValidCell(mouseCell) && cells[mouseCell] != PipPlantFailedReasons. NoPlantablePlot) { int radius = PipPlantOverlayTests.PlantRadius, below = radius, above = radius; var area = plant.GetComponent <OccupyArea>(); Grid.CellToXY(mouseCell, out int mouseX, out int mouseY); Grid.CellToXY(plantCell, out int x, out int y); int startX = x, startY = y; // Need to expand the test area by the plant's size since the top tile is // just as valid of an obstruction as the bottom if (area != null) { var extents = area.GetExtents(); startX = extents.x; startY = extents.y; x = extents.x + extents.width - 1; y = extents.y + extents.height - 1; } if (PipPlantOverlayTests.SymmetricalRadius) { startX--; startY--; } // Pips check the foundation tile, not the plant tile, so find out if top // or bottom is valid and adjust the highlight radius bool solidBelow = PipPlantOverlayTests.IsAcceptableCell(Grid. CellBelow(mouseCell), ReceptacleDirection.Top); if (PipPlantOverlayTests.IsAcceptableCell(Grid.CellAbove(mouseCell), ReceptacleDirection.Bottom)) { above++; if (solidBelow) { below++; } else { below--; } } else if (solidBelow) { above--; below++; } // Symmetrical radius adds another tile on the right and top to match hl = mouseX > startX - radius && mouseX <= x + radius && mouseY > startY - above && mouseY <= y + below; } } return(hl); }