private bool DoButton(PurposeInfo purposeInfo, Rect rect, float scale = 1.0f) { if (!purposeInfo.IsUsed()) { return(false); } Texture icon = purposeInfo.icon; if (icon == null) { return(false); } if (Mouse.IsOver(rect)) { GUI.color = GenUI.MouseoverColor; } else { GUI.color = purposeInfo.color; } Verse.Sound.MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Command); //GUI.DrawTexture(rect, Command.BGTex); Widgets.DrawTextureFitted(rect, icon, scale * purposeInfo.scale, purposeInfo.proportions, purposeInfo.texCoords); if (Widgets.ButtonInvisible(rect, false) || Mouse.IsOver(rect) && Input.GetMouseButton(0)) { clickedPos = purposeInfo.pos; return(true); } return(false); }
public static void AddTargetToGizmo(Command_CenterOnTarget gizmo, LocalTargetInfo targetInfo, TargetIndex ind = TargetIndex.A) { PurposeInfo purposeInfo = Make(targetInfo); if (purposeInfo == null) return; if (targetInfo.HasThing && purposeInfo.pos == null) purposeInfo.pos = gizmo.selectedInfo.pos; if (purposeInfo.IsUsed()) { gizmo.SetTarget(ind, purposeInfo); } }
public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth) { bool clicked = false; clickedPos = null; Rect rect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), Height); GUI.color = Color.white; GUI.DrawTexture(rect, Command.BGTex); if (Find.Selector.SelectedObjects.Count == 1 && !targetB.IsUsed() && !targetC.IsUsed()) { clicked = DoButton(targetA.IsUsed() ? targetA : selectedInfo, rect, 0.85f); } else { topLeft.x += 1; topLeft.y += 1; float halfW = GetWidth(maxWidth) / 2 - 2; Rect rectPortrait = new Rect(topLeft.x, topLeft.y, halfW, halfW); Rect rectA = new Rect(topLeft.x + halfW, topLeft.y, halfW, halfW); Rect rectB = new Rect(topLeft.x, topLeft.y + halfW, halfW, halfW); Rect rectC = new Rect(topLeft.x + halfW, topLeft.y + halfW, halfW, halfW); GUI.color = Color.white; GUI.DrawTexture(rect, Command.BGTex); clicked |= DoButton(selectedInfo, rectPortrait); clicked |= DoButton(targetA, rectA); clicked |= DoButton(targetB, rectB); clicked |= DoButton(targetC, rectC); } //Label float num = Text.CalcHeight(LabelCap, rect.width); Rect rectLabel = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num); GUI.color = Color.white; GUI.DrawTexture(rectLabel, TexUI.GrayTextBG); Text.Anchor = TextAnchor.UpperCenter; Widgets.Label(rectLabel, LabelCap); Text.Anchor = TextAnchor.UpperLeft; if (Widgets.ButtonInvisible(rect, false) && Event.current.button == 1) return new GizmoResult(GizmoState.OpenedFloatMenu, Event.current); if (clicked) return new GizmoResult(GizmoState.Interacted, Event.current); else if (Mouse.IsOver(rect)) return new GizmoResult(GizmoState.Mouseover); else return new GizmoResult(GizmoState.Clear); }