public static void Postfix(ref DragTool __instance, ref Vector3 cursorPos) { if (__instance.Dragging) { DragTool.Mode mode = (DragTool.Mode)AccessTools.Field(typeof(DragTool), "mode").GetValue(__instance); Vector3 downPos = (Vector3)AccessTools.Field(typeof(DragTool), "downPos").GetValue(__instance); if (mode == DragTool.Mode.Box) { HoverTextConfiguration hoverText = __instance.GetComponent <HoverTextConfiguration>(); int index = hoverText.ToolName.IndexOf('['); if (index != -1) { hoverText.ToolName = hoverText.ToolName.Remove(index - 1); } var downPosXY = Grid.PosToXY(downPos); var cursorPosXY = Grid.PosToXY(cursorPos); int x = Mathf.Abs(downPosXY.X - cursorPosXY.X) + 1; int y = Mathf.Abs(downPosXY.Y - cursorPosXY.Y) + 1; string boxSizeInfo = $" [{x}x{y}, {x*y} tiles total]"; hoverText.ToolName += boxSizeInfo; } } }
/// <summary> /// Adds the coordinates and cell number to the select tool. /// </summary> private static HoverTextDrawer DrawCoordinates(HoverTextDrawer drawer, HoverTextConfiguration instance) { int cell = Grid.PosToCell(Camera.main.ScreenToWorldPoint( KInputManager.GetMousePos())); if (Grid.IsValidCell(cell)) { Grid.CellToXY(cell, out int x, out int y); drawer.BeginShadowBar(); drawer.DrawText(string.Format(DebugNotIncludedStrings.UI.TOOLTIPS.DNI_CELL, cell, x, y), instance.Styles_BodyText.Standard); drawer.EndShadowBar(); } return(drawer); }
public static void DrawPanel(HoverTextConfiguration instance) { var toolInst = ToolMenu.Instance; if (toolInst == null) { return; } var tool = toolInst.activeTool; if (tool != null && tool.GetType().IsSubclassOf(typeof(DragTool))) { if ((DragTool.Mode)Traverse.Create(tool).Method("GetMode").GetValue() == DragTool.Mode.Box) { var roundedSizeVector = Vector2I.zero; if (((DragTool)tool).Dragging) { var sizeVector = ((SpriteRenderer)AccessTools .Field(typeof(DragTool), "areaVisualizerSpriteRenderer") .GetValue(tool)).size; roundedSizeVector = new Vector2I( Mathf.RoundToInt(sizeVector.x), Mathf.RoundToInt(sizeVector.y) ); } const string areaFormat = "Selection Size: {0} x {1} : {2} cells"; var text = string.Format( areaFormat, roundedSizeVector.x, roundedSizeVector.y, roundedSizeVector.x * roundedSizeVector.y ); var drawer = HoverTextScreen.Instance.drawer; drawer.NewLine(); drawer.DrawText(text, instance.Styles_Title.Standard); } } }
public static void Postfix(HoverTextConfiguration __instance, HoverTextDrawer drawer) { if (__instance == null) { return; } if (!(__instance is BuildToolHoverTextCard)) { return; } BuildToolHoverTextCard hover_text_card = (BuildToolHoverTextCard)__instance; if (hover_text_card.currentDef == null) { return; } if (hover_text_card.currentDef.BuildingComplete == null) { return; } ZTransporter possible_ztransport = hover_text_card.currentDef.BuildingComplete.GetComponent <ZTransporter>(); if (possible_ztransport != null) { drawer.NewLine(26); // All the cool kids are doing it -SB drawer.AddIndent(8); // I LEARNED IT FROM WATCHING [Klei] -SB int x, y; var pos = KInputManager.GetMousePos(); var point = Camera.main.ScreenToWorldPoint(pos); var cell = Grid.PosToCell(point); Grid.CellToXY(cell, out x, out y); var coords_string = STRINGS.ZTRANSPORT.STATUSITEMS.ZCOORDINATES.NAME.Replace("{X}", x.ToString()).Replace("{Y}", y.ToString()); drawer.DrawText(coords_string, hover_text_card.Styles_Instruction.Standard); } }
protected override void OnSpawn() { base.OnSpawn(); hoverTextConfiguration = GetComponent <HoverTextConfiguration>(); }