示例#1
0
        // Copy-pasta from RimWorld.HandleRotationShortcuts()
        private void HandleRotationShortcuts()
        {
            RotationDirection 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 (rotationDirection == RotationDirection.Clockwise)
            {
                SoundDefOf.AmountIncrement.PlayOneShotOnCamera();
                Blueprint.Rotate(RotationDirection.Clockwise);
            }
            if (rotationDirection == RotationDirection.Counterclockwise)
            {
                SoundDefOf.AmountDecrement.PlayOneShotOnCamera();
                Blueprint.Rotate(RotationDirection.Counterclockwise);
            }
        }
        // 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;
            });
        }
示例#3
0
        // copy-pasta from RimWorld.Designator_Place, with minor changes.
        public override void DoExtraGuiControls(float leftX, float bottomY)
        {
            float height     = 90f;
            float width      = 200f;
            float button     = 64f;
            float numButtons = 2f;
            float margin     = (width - button * numButtons) / (numButtons + 1);
            float topmargin  = 15f;

            Rect winRect = new Rect(leftX, bottomY - height, width, height);

            HandleRotationShortcuts();

            Find.WindowStack.ImmediateWindow(73095, winRect, WindowLayer.GameUI, delegate
            {
                RotationDirection rotationDirection = RotationDirection.None;
                Text.Anchor = TextAnchor.MiddleCenter;
                Text.Font   = GameFont.Medium;

                Rect rotLeftRect = new Rect(margin, topmargin, button, button);
                if (Widgets.ButtonImage(rotLeftRect, Resources.RotLeftTex))
                {
                    SoundDefOf.AmountDecrement.PlayOneShotOnCamera();
                    rotationDirection = RotationDirection.Counterclockwise;
                    Event.current.Use();
                }
                Widgets.Label(rotLeftRect, KeyBindingDefOf.Designator_RotateLeft.MainKeyLabel);

                // todo; figure out blueprint flipping
                //Rect flipRect = new Rect( 2 * margin + button, topmargin, button, button );
                //if ( Widgets.ButtonImage( flipRect, Resources.FlipTex ) )
                //{
                //    SoundDefOf.FlickSwitch.PlayOneShotOnCamera();
                //    Blueprint.Flip();
                //    Event.current.Use();
                //}

                Rect rotRightRect = new Rect(2 * margin + button, topmargin, button, button);
                if (Widgets.ButtonImage(rotRightRect, Resources.RotRightTex))
                {
                    SoundDefOf.AmountIncrement.PlayOneShotOnCamera();
                    rotationDirection = RotationDirection.Clockwise;
                    Event.current.Use();
                }
                Widgets.Label(rotRightRect, KeyBindingDefOf.Designator_RotateRight.MainKeyLabel);
                if (rotationDirection != RotationDirection.None)
                {
                    Blueprint.Rotate(rotationDirection);
                }
                Text.Anchor = TextAnchor.UpperLeft;
                Text.Font   = GameFont.Small;
            });
        }