/// <summary> /// Creates a FloatMenu based on Primary/PawnSurface options. /// </summary> public static FloatMenu WorkMenu(PawnSurface surface) { List <FloatMenuOption> floatOptions = new List <FloatMenuOption>(); if (surface == null) { floatOptions.Add(WorkOption(WorkFunction.AllPawns_EnableWork, null)); floatOptions.Add(WorkOption(WorkFunction.AllPawns_DisableWork, null)); floatOptions.Add(WorkOption(WorkFunction.AllPawns_ResetWork, null)); } else { floatOptions.Add(WorkOption(WorkFunction.EnableWork, surface)); floatOptions.Add(WorkOption(WorkFunction.DisableWork, surface)); floatOptions.Add(WorkOption(WorkFunction.ResetWork, surface)); floatOptions.Add(WorkOption(WorkFunction.CopySettings, surface)); floatOptions.Add(WorkOption(WorkFunction.PasteSettings, surface)); } return(new FloatMenu(floatOptions)); }
/// <summary> /// A master button for all WorkFunction options. /// </summary> public static void WorkButton(Rect buttonRect, PawnSurface surface) { if (Event.current.type == EventType.Repaint) { DraggableOutline(buttonRect, MediumSkillColour); GUI.DrawTexture(buttonRect.ContractedBy(2f), WorkButtonTexture); } if (buttonRect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.Repaint) { Widgets.DrawHighlight(buttonRect); TooltipHandler.TipRegion(buttonRect, "DD_WorkTab_Tooltip_WorkButton".CachedTranslation()); } else if (Event.current.type == EventType.MouseDown) { Find.WindowStack.Add(WorkMenu(surface)); } } }
/// <summary> /// Open a pop-up prompt window for button functions. /// </summary> public static void WorkPrompt(WorkFunction function, Action buttonAction, string title, PawnSurface surface) { string text = ""; switch (function) { case WorkFunction.AllPawns_EnableWork: text = "DD_WorkTab_PromptText_AllPawns_EnableWork".CachedTranslation(); break; case WorkFunction.AllPawns_DisableWork: text = "DD_WorkTab_PromptText_AllPawns_DisableWork".CachedTranslation(); break; case WorkFunction.AllPawns_ResetWork: text = "DD_WorkTab_PromptText_AllPawns_ResetWork".CachedTranslation(); break; case WorkFunction.EnableWork: text = "DD_WorkTab_PromptText_EnableWork".CachedTranslation().AdjustedFor(surface.pawn); break; case WorkFunction.DisableWork: text = "DD_WorkTab_PromptText_DisableWork".CachedTranslation().AdjustedFor(surface.pawn); break; case WorkFunction.ResetWork: text = "DD_WorkTab_PromptText_ResetWork".CachedTranslation().AdjustedFor(surface.pawn); break; } DiaOption accept = new DiaOption("DD_WorkTab_PromptOption_Accept".CachedTranslation()) { action = buttonAction, resolveTree = true }; DiaOption cancel = new DiaOption("DD_WorkTab_PromptOption_Cancel".CachedTranslation()) { resolveTree = true }; DiaOption acceptDisablePrompt = new DiaOption("DD_WorkTab_PromptOption_AcceptDisablePrompt".CachedTranslation()) { action = delegate { Controller.ShowPrompts.Value = false; buttonAction(); }, resolveTree = true }; DiaNode prompt = new DiaNode(text + "DD_WorkTab_PromptText_DisablePrompt".CachedTranslation()) { options = new List <DiaOption> { accept, cancel, acceptDisablePrompt } }; Find.WindowStack.Add(new Dialog_NodeTree(prompt, false, false, title)); }
/// <summary> /// Builds a Float Menu entry to perform various work functions. /// </summary> public static FloatMenuOption WorkOption(WorkFunction function, PawnSurface surface) { string title = ""; Action buttonAction = default(Action); switch (function) { case WorkFunction.AllPawns_EnableWork: title = "DD_WorkTab_Title_AllPawns_EnableWork".CachedTranslation(); buttonAction = delegate { foreach (Pawn p in Find.VisibleMap.mapPawns.FreeColonists) { Controller.GetManager.GetPawnSurface(p).EnableAllPawnWork(); } }; break; case WorkFunction.AllPawns_DisableWork: title = "DD_WorkTab_Title_AllPawns_DisableWork".CachedTranslation(); buttonAction = delegate { foreach (Pawn p in Find.VisibleMap.mapPawns.FreeColonists) { Controller.GetManager.GetPawnSurface(p).DisableAllPawnWork(); } }; break; case WorkFunction.AllPawns_ResetWork: title = "DD_WorkTab_Title_AllPawns_ResetWork".CachedTranslation(); buttonAction = delegate { foreach (Pawn p in Find.VisibleMap.mapPawns.FreeColonists) { Controller.GetManager.GetPawnSurface(p).ResetAllPawnWork(); } }; break; case WorkFunction.EnableWork: title = "DD_WorkTab_Title_EnableWork".CachedTranslation(); buttonAction = delegate { surface.EnableAllPawnWork(); }; break; case WorkFunction.DisableWork: title = "DD_WorkTab_Title_DisableWork".CachedTranslation(); buttonAction = delegate { surface.DisableAllPawnWork(); }; break; case WorkFunction.ResetWork: title = "DD_WorkTab_Title_ResetWork".CachedTranslation(); buttonAction = delegate { surface.ResetAllPawnWork(); }; break; case WorkFunction.CopySettings: title = "DD_WorkTab_Title_CopyWorkPriorities".CachedTranslation(); buttonAction = delegate { surface.CopyPriorities(); }; break; case WorkFunction.PasteSettings: title = "DD_WorkTab_Title_PasteWorkPriorities".CachedTranslation(); buttonAction = delegate { surface.PastePriorities(Controller.CopyPrioritiesReference); }; break; } if (Controller.ShowPrompts && function != WorkFunction.CopySettings && function != WorkFunction.PasteSettings) { return(new FloatMenuOption(title, delegate { WorkPrompt(function, buttonAction, title, surface); })); } return(new FloatMenuOption(title, delegate { buttonAction(); UserFeedbackChain(WorkSound.TaskCompleted); })); }
public override void DoWindowContents(Rect inRect) { this.SetSizeAndPosition(); List <PrimaryWork> primariesList = Controller.GetPrimaries.PrimaryWorkList; //Build rects Rect toggleButtonRect = new Rect(inRect.x - this.horizontalOffset, inRect.y + Utilities.TinyTextLineHeight, Utilities.ShortSpacing + Utilities.SpaceForPawnLabel, Utilities.SmallRowHeight); Rect primariesRect = new Rect(toggleButtonRect.xMax, toggleButtonRect.y, inRect.width - toggleButtonRect.width, Utilities.SmallRowHeight); Rect scrollViewBox = new Rect(inRect.x, primariesRect.yMax, inRect.width, inRect.height - Utilities.SmallRowHeight - Utilities.TinyTextLineHeight); Rect scrollViewOuterRect = scrollViewBox.ContractedBy(Utilities.ShortSpacing); Rect scrollViewInnerRect = new Rect(scrollViewOuterRect.x, scrollViewOuterRect.y, Utilities.SpaceForPawnLabel + Utilities.SmallSurfaceWidth, this.cachedPawnSurfaces.Count * Utilities.SmallRowHeight); if (scrollViewInnerRect.width > scrollViewOuterRect.width) { scrollViewInnerRect.yMax += Utilities.SpaceForScrollBar; } //Draw window title and list outline if (Event.current.type == EventType.Repaint) { this.DrawWindowTitle(inRect); Utilities.BoxOutline(scrollViewBox); } //Toggle Displayed Pawns button if (Widgets.ButtonText(toggleButtonRect.ContractedBy(Utilities.ShortSpacing), this.ToggleButtonText, true, false, true)) { Controller.ColonistSkillsVisibleMap = !Controller.ColonistSkillsVisibleMap; this.mustRecacheColonists = true; Utilities.UserFeedbackChain(WorkSound.CompareSkillsMapChanged); } //Draw primaries Vector2 positionSetter = new Vector2(primariesRect.x + Utilities.ShortSpacing + Utilities.SmallDraggableDiameter / 2f, primariesRect.center.y); for (int i = 0; i < primariesList.Count; i++) { PrimaryWork primary = primariesList[i]; this.primariesPositions[primary.def] = positionSetter.x; Rect drawRect = positionSetter.ToWorkRect(Utilities.SmallDraggableDiameter); if (Event.current.type == EventType.Repaint) { primary.DrawTexture(drawRect); if (drawRect.Contains(Event.current.mousePosition)) { primary.OnHover(drawRect, true); } //Draw little arrow indicator below work type if (this.sortingOrder != SortOrder.Undefined && this.sortingDef == primary.def) { Texture2D icon = this.sortingOrder == SortOrder.Descending ? Utilities.SortingDescendingIcon : Utilities.SortingAscendingIcon; Rect iconRect = new Rect(drawRect.xMax - icon.width, drawRect.yMax + 1f, icon.width, icon.height); Rect highlightRect = new Rect(drawRect.xMin - 3f, drawRect.yMin - 3f, drawRect.width + 6f, drawRect.height + 6f); GUI.DrawTexture(iconRect, icon); Widgets.DrawHighlight(highlightRect); } } else if (Event.current.type == EventType.MouseDown && drawRect.Contains(Event.current.mousePosition)) { this.DoSortingChecks(primary.def); } positionSetter.x += Utilities.SmallDraggableDiameter + Utilities.ShortSpacing; } Widgets.BeginScrollView(scrollViewOuterRect, ref this.scrollPosition, scrollViewInnerRect, true); float dynamicVerticalY = scrollViewInnerRect.yMin; //Determine which surfaces will actually be seen DingoUtils.CacheScrollview(false, this.scrollPosition.y, scrollViewOuterRect.height, Utilities.SmallRowHeight, this.cachedPawnSurfaces.Count, ref dynamicVerticalY, out int firstItem, out int lastItem); for (int j = firstItem; j <= lastItem; j++) { PawnSurface surface = this.cachedPawnSurfaces[j]; Rect nameRect = new Rect(scrollViewInnerRect.x, dynamicVerticalY, Utilities.SpaceForPawnLabel, Utilities.SmallRowHeight); Rect surfaceRect = new Rect(nameRect.xMax, dynamicVerticalY, Utilities.SmallSurfaceWidth, Utilities.SmallRowHeight); float surfaceRectCenterY = surfaceRect.center.y; if (Event.current.type == EventType.Repaint) { if (j != 0) { Utilities.ListSeparator(scrollViewInnerRect, dynamicVerticalY); } //Draw surface for (int p = 0; p < primariesList.Count; p++) { WorkTypeDef def = primariesList[p].def; DraggableWork draggable = surface.childByDef[def]; Vector2 draggablePosition = new Vector2(this.primariesPositions[def], surfaceRectCenterY); Rect drawRect = draggablePosition.ToWorkRect(Utilities.SmallDraggableDiameter); draggable.DrawTexture(drawRect); if (drawRect.Contains(Event.current.mousePosition)) { draggable.OnHover(drawRect, true); } } } Utilities.PawnLabel(nameRect, surface.pawn); dynamicVerticalY += Utilities.SmallRowHeight; } Widgets.EndScrollView(); }
public override void DoWindowContents(Rect inRect) { base.DoWindowContents(inRect); //Build rects Rect indicatorsRect = new Rect(inRect.xMax - Utilities.PawnSurfaceWidth - Utilities.SpaceForScrollBar + Utilities.ShortSpacing, inRect.y, Utilities.PawnSurfaceWidth - 3f * Utilities.ShortSpacing, Utilities.TinyTextLineHeight); float topControlsY = indicatorsRect.yMax + Utilities.ShortSpacing; Rect compareSkillsButtonRect = new Rect(inRect.x - this.horizontalOffset + Utilities.ShortSpacing, topControlsY, Utilities.SpaceForPawnLabel, Utilities.DraggableDiameter); Rect primaryWorkButtonRect = new Rect(compareSkillsButtonRect.xMax + 2f * Utilities.ShortSpacing, topControlsY, Utilities.DraggableDiameter, Utilities.DraggableDiameter); Rect primariesRect = new Rect(primaryWorkButtonRect.xMax, topControlsY, Utilities.PawnSurfaceWidth, Utilities.DraggableDiameter); Rect scrollViewBox = new Rect(inRect.x, indicatorsRect.yMax + Utilities.StandardRowHeight, inRect.width, inRect.height - indicatorsRect.height - Utilities.StandardRowHeight); Rect scrollViewOuterRect = scrollViewBox.ContractedBy(Utilities.ShortSpacing); Rect scrollViewInnerRect = new Rect(scrollViewOuterRect.x, scrollViewOuterRect.y, Utilities.SpaceForPawnLabel + Utilities.SpaceForWorkButton + Utilities.PawnSurfaceWidth, this.cachedPawnSurfaces.Count * Utilities.StandardRowHeight); if (scrollViewInnerRect.width > scrollViewOuterRect.width) { scrollViewInnerRect.yMax += Utilities.SpaceForScrollBar; } //Draw indicators, primaries and list outline if (Event.current.type == EventType.Repaint) { this.DrawPriorityIndicators(indicatorsRect); Controller.GetPrimaries.DrawSurface(primariesRect); Utilities.BoxOutline(scrollViewBox); } //Compare Skills button if (Widgets.ButtonText(compareSkillsButtonRect, "DD_WorkTab_Work_CompareSkills".CachedTranslation(), true, false, true)) { Find.WindowStack.Add(new Window_ColonistSkills()); Utilities.UserFeedbackChain(WorkSound.CompareSkillsMapChanged); } //Float menu button Utilities.WorkButton(primaryWorkButtonRect, null); //Check for primary-related GUI triggers Controller.GetPrimaries.DoWorkTabEventChecks(primariesRect); Widgets.BeginScrollView(scrollViewOuterRect, ref this.scrollPosition, scrollViewInnerRect, true); Controller.CurrentDraggable?.OnDrag(); //Update draggable position within the list float dynamicVerticalY = scrollViewInnerRect.yMin; //Determine which surfaces will actually be seen DingoUtils.CacheScrollview(false, this.scrollPosition.y, scrollViewOuterRect.height, Utilities.StandardRowHeight, this.cachedPawnSurfaces.Count, ref dynamicVerticalY, out int firstItem, out int lastItem); for (int i = firstItem; i <= lastItem; i++) { PawnSurface surface = this.cachedPawnSurfaces[i]; Rect labelRect = new Rect(scrollViewInnerRect.x, dynamicVerticalY, Utilities.SpaceForPawnLabel, Utilities.StandardRowHeight); Rect buttonRect = new Rect(labelRect.xMax + 2f * Utilities.ShortSpacing, dynamicVerticalY + Utilities.ShortSpacing, Utilities.DraggableDiameter, Utilities.DraggableDiameter); Rect surfaceRect = new Rect(buttonRect.xMax, dynamicVerticalY, Utilities.PawnSurfaceWidth, Utilities.StandardRowHeight); if (Event.current.type == EventType.Repaint) { if (i != 0) { Utilities.ListSeparator(scrollViewInnerRect, dynamicVerticalY); } surface.DrawSurface(surfaceRect); } Utilities.PawnLabel(labelRect, surface.pawn); Utilities.WorkButton(buttonRect, surface); surface.DoWorkTabEventChecks(surfaceRect); dynamicVerticalY += Utilities.StandardRowHeight; } //Render current Draggable on top of other textures DraggableWork currentDraggable = Controller.CurrentDraggable; if (Event.current.type == EventType.Repaint && currentDraggable != null) { Rect drawRect = currentDraggable.position.ToWorkRect(); currentDraggable.DrawTexture(drawRect); } Widgets.EndScrollView(); }