public virtual void Draw() { if (Event.current.button == 0) { if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect)) { clicked = true; } else if (clicked && ResearchSelectPanel._instance.draggingDef == null) { if (Event.current.type == EventType.MouseUp) { clicked = false; ClickHandler(); } else if (Event.current.type == EventType.MouseDrag && canDrag) { clicked = false; ResearchSelectPanel._instance.draggingDef = this; ResearchSelectPanel._instance._mousePosition = Event.current.mousePosition; dragRect = new Rect(rect); Event.current.Use(); } } else if (canDrag && ResearchSelectPanel._instance.draggingDef == this && Event.current.type == EventType.MouseDrag) { var currentMousePosition = Event.current.mousePosition; dragRect.x = currentMousePosition.x; dragRect.y = currentMousePosition.y; ResearchSelectPanel._instance._mousePosition = currentMousePosition; } } else if (Event.current.button == 1) { if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect)) { List <FloatMenuOption> options = new List <FloatMenuOption> { new FloatMenuOption("Remove Unlock", () => ResearchProjectEditor.RemoveUnlockable(ResearchSelectPanel.selected, this.def), MenuOptionPriority.Default, null) }; Find.WindowStack.Add(new FloatMenu(options)); Event.current.Use(); } } if (canDrag && ResearchSelectPanel._instance.draggingDef == this) { def.DrawColouredIcon(dragRect); } else { def.DrawColouredIcon(rect); TooltipHandler.TipRegion(rect, description); } if (!canDrag) { Rect lockRect = new Rect(rect.xMax - 10f, rect.yMin, 10f, 10f); GUI.DrawTexture(lockRect, Assets.Lock, ScaleMode.ScaleToFit); } }
public static void DoSelectedView(Rect canvas) { Rect selectedRect = new Rect( canvas.xMin, canvas.yMin, NodeSize.x + 2 * Margin, NodeSize.y + 2 * Margin ); selected.DrawAt(selectedRect.min, selectedRect, true); float infoHeight = NodeSize.y / 3f; Rect editRect = new Rect(selectedRect.xMax + Margin, canvas.yMin, NodeSize.x, NodeSize.y + Margin * 2); Rect nameRect = editRect.TopPartPixels(infoHeight); newName = Widgets.TextField(nameRect, newName); Rect labelRect = new Rect(editRect); labelRect.y = labelRect.y + infoHeight + Margin / 2; labelRect.x = editRect.xMin; labelRect.height = infoHeight + Margin; GUI.Label(labelRect, selected.Research.defName); Rect buttonRect = editRect.BottomPartPixels(infoHeight); buttonRect.width /= 3f; bool saveClicked = Widgets.ButtonText(buttonRect, "Save"); Rect newUnlockRect = new Rect(buttonRect.xMax + Margin, buttonRect.yMin, editRect.width * 2f / 3f - Margin, buttonRect.height); bool newClicked = Widgets.ButtonText(newUnlockRect, "Add unlockable..."); if (saveClicked) { ResearchProjectEditor.SetName(selected, newName); } if (newClicked) { ResearchProjectEditor.AddUnlockable(selected); } }
public void DoClick() { if (Event.current.button == 0) { if (ResearchSelectPanel.selected == this) { ResearchWindow.Instance.CenterOn(this); } else { ResearchSelectPanel.Select(this); } } else if (Event.current.button == 1) { var options = new List <FloatMenuOption>(); options.Add(new FloatMenuOption("Open in Def Explorer...", () => ClickHandler(), MenuOptionPriority.High, null)); if (ResearchSelectPanel.selected != null) { if (ResearchSelectPanel.selected == this) { } else { if (GetPrereqs().Contains(ResearchSelectPanel.selected)) { // this is a direct child for selected, can remove child options.Add(new FloatMenuOption("Remove Child from " + ResearchSelectPanel.selected.Label, () => ResearchProjectEditor.RemoveChild(node: ResearchSelectPanel.selected, child: this), MenuOptionPriority.Default, null)); } else if (!AllChildren.Contains(ResearchSelectPanel.selected)) // this is not a prereq for selected or a direct child, can add child { options.Add(new FloatMenuOption("Add Child to " + ResearchSelectPanel.selected.Label, () => ResearchProjectEditor.AddChild(node: ResearchSelectPanel.selected, child: this), MenuOptionPriority.Default, null)); } else // this is a prereq, can't add child { options.Add(new FloatMenuOption("(Can't add child, would create cycle)", null, MenuOptionPriority.Default, null)); } if (Children.Contains(ResearchSelectPanel.selected)) // this is a direct prereq for selected, can remove prereq { options.Add(new FloatMenuOption("Remove Prerequisite from " + ResearchSelectPanel.selected.Label, () => ResearchProjectEditor.RemovePrereq(node: ResearchSelectPanel.selected, prereq: this), MenuOptionPriority.Default, null)); } else if (!GetPrereqsRecursive().Contains(ResearchSelectPanel.selected)) // this is not a child for selected or a direct prereq, can add prereq { options.Add(new FloatMenuOption("Add Prerequisite to " + ResearchSelectPanel.selected.Label, () => ResearchProjectEditor.AddPrereq(node: ResearchSelectPanel.selected, prereq: this), MenuOptionPriority.Default, null)); } else { options.Add(new FloatMenuOption("(Can't add prerequisite, would create cycle)", null, MenuOptionPriority.High, null)); } } } options.Add(new FloatMenuOption("Delete Research Project", () => ResearchProjectEditor.Delete(this), MenuOptionPriority.Low, null)); /* * if (options.Count == 0) // can't do anything with this KEKWait * { * options.Add(new FloatMenuOption("(No actions available)", null, MenuOptionPriority.Default, null)); * } */ options.Add(new FloatMenuOption("Set tech level...", () => ResearchProjectEditor.SetTechLevel(this), MenuOptionPriority.Low, null)); options.Add(new FloatMenuOption("Set techprint count...", () => ResearchProjectEditor.SetTechprintCount(this), MenuOptionPriority.Low, null)); Find.WindowStack.Add(new FloatMenu(options)); //Event.current.Use(); } }
public void DoDraw(Rect visibleRect, bool forceDetailedMode = false, bool notDrawingSelected = true) { if (!IsVisible(visibleRect)) { Highlighted = false; DarkHighlighted = false; return; } var detailedMode = forceDetailedMode || ResearchWindow.Instance.ZoomLevel < DetailedModeZoomLevelCutoff; var mouseOver = Mouse.IsOver(Rect); if (Event.current.type == EventType.Repaint) { // researches that are completed or could be started immediately, and that have the required building(s) available //GUI.color = mouseOver && ResearchSelectPanel.selected != this ? GenUI.MouseoverColor : Color; GUI.color = Color; if (notDrawingSelected && (mouseOver || Highlighted)) { GUI.DrawTexture(Rect, Assets.ButtonActive); } else { GUI.DrawTexture(Rect, Assets.Button); } // grey out center to create a progress bar effect, completely greying out research not started. var progressBarRect = Rect.ContractedBy(3f); GUI.color = Assets.ColorAvailable[Research.techLevel]; progressBarRect.xMin += progressBarRect.width; GUI.DrawTexture(progressBarRect, BaseContent.WhiteTex); Highlighted = false; DarkHighlighted = false; GUI.color = Color.white; if (detailedMode) { Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = false; Text.Font = _largeLabel && notDrawingSelected ? GameFont.Tiny : GameFont.Small; Widgets.Label(LabelRect, Research.LabelCap); } else { Text.Anchor = TextAnchor.MiddleCenter; Text.WordWrap = false; Text.Font = GameFont.Medium; Widgets.Label(Rect, Research.LabelCap); } // draw research cost and icon if (detailedMode) { Text.Anchor = TextAnchor.UpperRight; Text.Font = Research.baseCost > 1000000 ? GameFont.Tiny : GameFont.Small; if (Research.techprintCount == 0) { Widgets.Label(CostLabelRect, Research.baseCost.ToStringByStyle(ToStringStyle.Integer)); GUI.DrawTexture(CostIconRect, Assets.ResearchIcon, ScaleMode.ScaleToFit); } else { int printsNeeded = Research.techprintCount; string label = printsNeeded.ToString(); Text.Font = GameFont.Tiny; Widgets.Label(CostLabelRect, label); GUI.DrawTexture(CostIconRect, shardTex, ScaleMode.ScaleToFit); if (!notDrawingSelected) { Rect selectedCostIconRect = new Rect(CostIconRect.x, CostIconRect.yMax + 2f, CostIconRect.width, CostIconRect.height); GUI.DrawTexture(selectedCostIconRect, Assets.ResearchIcon, ScaleMode.ScaleToFit); Rect selectedCostLabelRect = new Rect(CostLabelRect.x, selectedCostIconRect.y, CostLabelRect.width, CostLabelRect.height); Widgets.Label(selectedCostLabelRect, Research.baseCost.ToStringByStyle(ToStringStyle.Integer)); } } } Text.WordWrap = true; // attach description and further info to a tooltip TooltipHandler.TipRegion(Rect, GetResearchTooltipString, Research.GetHashCode()); /* if ( !BuildingPresent() ) * { * TooltipHandler.TipRegion( Rect, * ResourceBank.String.MissingFacilities( string.Join( ", ", * MissingFacilities().Select( td => td.LabelCap ).ToArray() ) ) ); * } else if (!TechprintAvailable()) { * TooltipHandler.TipRegion(Rect, * ResourceBank.String.MissingTechprints(Research.TechprintsApplied, Research.techprintCount)); * } */ // draw unlock icons if (detailedMode && notDrawingSelected) { var unlocks = Research.GetUnlockDefsAndDescs(); for (var i = 0; i < unlocks.Count; i++) { var iconRect = new Rect( IconsRect.xMax - (i + 1) * (IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - IconSize.y) / 2f, IconSize.x, IconSize.y); if (iconRect.xMin - IconSize.x < IconsRect.xMin && i + 1 < unlocks.Count) { // stop the loop if we're about to overflow and have 2 or more unlocks yet to print. iconRect.x = IconsRect.x + 4f; GUI.DrawTexture(iconRect, Assets.MoreIcon, ScaleMode.ScaleToFit); var tip = string.Join("\n", unlocks.GetRange(i, unlocks.Count - i).Select(p => p.Second) .ToArray()); TooltipHandler.TipRegion(iconRect, tip); // new TipSignal( tip, Settings.TipID, TooltipPriority.Pawn ) ); break; } // draw icon unlocks[i].First.DrawColouredIcon(iconRect); // tooltip TooltipHandler.TipRegion(iconRect, unlocks[i].Second); } } } else if (mouseOver) { if (Event.current.button == 0 && Event.current.type == EventType.MouseUp && ResearchSelectPanel._instance.draggingDef != null && ResearchSelectPanel.selected != this) { ResearchProjectEditor.SwapUnlockable(ResearchSelectPanel.selected, this, ResearchSelectPanel._instance.draggingDef.def); } } // if clicked and not yet finished, queue up this research and all prereqs. if (Widgets.ButtonInvisible(Rect)) { DoClick(); } }
protected override void DoAccept(string s) { ResearchProjectEditor.AddResearchProject(location, s); }
protected override void DoAccept(string s) { ResearchProjectEditor.DoSetTechprintCount(researchNode, count); }
public override void DoAccept(string option) { ResearchProjectEditor.DoSetTechLevel(node, option); }