// copy-pasta from RimWorld.Designator_Place, with minor changes. public override void DoExtraGuiControls(float leftX, float bottomY) { var height = 90f; var width = 200f; var margin = 9f; var topmargin = 15f; var numButtons = 3; var button = Mathf.Min((width - (numButtons + 1) * margin) / numButtons, height - topmargin); var winRect = new Rect(leftX, bottomY - height, width, height); HandleRotationShortcuts(); Find.WindowStack.ImmediateWindow(73095, winRect, WindowLayer.GameUI, delegate { var rotationDirection = RotationDirection.None; Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Medium; var rotLeftRect = new Rect(margin, topmargin, button, button); Widgets.Label(rotLeftRect, KeyBindingDefOf.Designator_RotateLeft.MainKeyLabel); if (Widgets.ButtonImage(rotLeftRect, Resources.RotLeftTex)) { SoundDefOf.AmountDecrement.PlayOneShotOnCamera(); rotationDirection = RotationDirection.Counterclockwise; Event.current.Use(); } var flipRect = new Rect(2 * margin + button, topmargin, button, button); Widgets.Label(flipRect, KeyBindingDefOf2.Blueprint_Flip.MainKeyLabel); if (Widgets.ButtonImage(flipRect, Resources.FlipTex)) { SoundDefOf.AmountIncrement.PlayOneShotOnCamera(); Blueprint.Flip(); Event.current.Use(); } var rotRightRect = new Rect(3 * margin + 2 * button, topmargin, button, button); Widgets.Label(rotRightRect, KeyBindingDefOf.Designator_RotateRight.MainKeyLabel); if (Widgets.ButtonImage(rotRightRect, Resources.RotRightTex)) { SoundDefOf.AmountIncrement.PlayOneShotOnCamera(); rotationDirection = RotationDirection.Clockwise; Event.current.Use(); } if (rotationDirection != RotationDirection.None) { Blueprint.Rotate(rotationDirection); } Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Small; }); }
// Copy-pasta from RimWorld.HandleRotationShortcuts() private void HandleRotationShortcuts() { var rotationDirection = RotationDirection.None; if (Event.current.button == 2) { if (Event.current.type == EventType.MouseDown) { Event.current.Use(); _middleMouseDownTime = Time.realtimeSinceStartup; } if (Event.current.type == EventType.MouseUp && Time.realtimeSinceStartup - _middleMouseDownTime < 0.15f) { rotationDirection = RotationDirection.Clockwise; } } if (KeyBindingDefOf.Designator_RotateRight.KeyDownEvent) { rotationDirection = RotationDirection.Clockwise; } if (KeyBindingDefOf.Designator_RotateLeft.KeyDownEvent) { rotationDirection = RotationDirection.Counterclockwise; } if (KeyBindingDefOf2.Blueprint_Flip.KeyDownEvent) { SoundDefOf.AmountIncrement.PlayOneShotOnCamera(); Blueprint.Flip(); } if (rotationDirection == RotationDirection.Clockwise) { SoundDefOf.AmountIncrement.PlayOneShotOnCamera(); Blueprint.Rotate(RotationDirection.Clockwise); } if (rotationDirection == RotationDirection.Counterclockwise) { SoundDefOf.AmountDecrement.PlayOneShotOnCamera(); Blueprint.Rotate(RotationDirection.Counterclockwise); } }