Esempio n. 1
0
 private void MovementListSelectionChange()
 {
     lock (instanceMutationLock) {
         selectedMovementStep      = ((LevelEntityMovementStep)movementFrameList.SelectedItem);
         travelTimeField.Value     = (decimal)selectedMovementStep.TravelTime;
         smoothingCheckbox.Checked = selectedMovementStep.SmoothTransition;
         if (!ignoreStepChanges)
         {
             EditorToolbar.SetEntityMovementStep(editTarget, selectedMovementStep);
         }
     }
 }
Esempio n. 2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            radiusUpDown.Minimum   = (decimal)PhysicsManager.ONE_METRE_SCALED * 0.1m;
            radiusUpDown.Maximum   = (decimal)PhysicsManager.ONE_METRE_SCALED * 7m;
            radiusUpDown.Increment = (decimal)PhysicsManager.ONE_METRE_SCALED * 0.1m;

            lightList.SelectedIndexChanged += (sender, args) => UpdateSelectedItem();
            RefreshSkyLightList();

            addButton.MouseClick += (sender, args) => {
                LevelSkyLight newLight = EditorToolbar.AddSkyLightAtCamera();
                RefreshSkyLightList();
                lightList.SelectedItem = newLight;
            };

            colorButton.MouseClick += (sender, args) => {
                colorPickerDialog.Color = colorButton.BackColor;
                colorPickerDialog.ShowDialog(this);
                colorButton.BackColor = colorPickerDialog.Color;
                ReplaceCurrentLight(Vector3.ZERO);
            };

            radiusUpDown.ValueChanged += (sender, args) => ReplaceCurrentLight(Vector3.ZERO);
            lumMulUpDown.ValueChanged += (sender, args) => ReplaceCurrentLight(Vector3.ZERO);

            leftButton.MouseClick  += (sender, args) => ReplaceCurrentLight(Vector3.LEFT * POSITION_ADJUSTMENT_AMOUNT);
            rightButton.MouseClick += (sender, args) => ReplaceCurrentLight(Vector3.RIGHT * POSITION_ADJUSTMENT_AMOUNT);
            upButton.MouseClick    += (sender, args) => ReplaceCurrentLight(Vector3.UP * POSITION_ADJUSTMENT_AMOUNT);
            downButton.MouseClick  += (sender, args) => ReplaceCurrentLight(Vector3.DOWN * POSITION_ADJUSTMENT_AMOUNT);
            backButton.MouseClick  += (sender, args) => ReplaceCurrentLight(Vector3.BACKWARD * POSITION_ADJUSTMENT_AMOUNT);
            foreButton.MouseClick  += (sender, args) => ReplaceCurrentLight(Vector3.FORWARD * POSITION_ADJUSTMENT_AMOUNT);

            deleteButton.MouseClick += (sender, args) => {
                LevelSkyLight selectedSkyLight = lightList.SelectedItem as LevelSkyLight;
                if (selectedSkyLight == null)
                {
                    Logger.Warn("Tried to delete null skylight.");
                    return;
                }
                if (MessageBox.Show(this, "Are you sure you wish to delete this skylight?", "Delete light?", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    return;
                }
                skyLevel.RemoveSkyLight(selectedSkyLight);
                RefreshSkyLightList();
                UpdateSelectedItem();
            };

            UpdateSelectedItem();
        }
Esempio n. 3
0
 private void ApplyCustomProperties(LevelGameObject selectedGO)
 {
     if (selectedGO == null)
     {
         return;
     }
     if (selectedGO is DynamicLight)
     {
         (selectedGO as DynamicLight).LightRadius = (float)((NumericUpDown)specPropTable.GetControlFromPosition(1, 0)).Value;
         Color buttonBackColor = specPropTable.GetControlFromPosition(1, 1).BackColor;
         (selectedGO as DynamicLight).LightColor          = new Vector3(buttonBackColor.R / 255f, buttonBackColor.G / 255f, buttonBackColor.B / 255f);
         (selectedGO as DynamicLight).LuminanceMultiplier = (float)((NumericUpDown)specPropTable.GetControlFromPosition(1, 2)).Value;
     }
     else if (selectedGO is Shadowcaster)
     {
         (selectedGO as Shadowcaster).ResolutionMultiplier = (float)((NumericUpDown)specPropTable.GetControlFromPosition(1, 0)).Value;
         (selectedGO as Shadowcaster).DepthOffset          = ((TrackBar)specPropTable.GetControlFromPosition(1, 1)).Value;
     }
     EditorToolbar.RealtimeUpdateGO(selectedGO);
 }
 private static void ScaleEntities(float delta)
 {
     thisClickWasTransformAltering = true;
     Monitor.Exit(staticMutationLock);
     if (lmbIsDepressed && rmbIsDepressed)               // Y-Axis
     {
         EditorToolbar.ScaleEntities(new Vector3(1f, 1f + delta, 1f));
     }
     else if (lmbIsDepressed)               // X-Axis
     {
         EditorToolbar.ScaleEntities(new Vector3(1f + delta, 1f, 1f));
     }
     else if (rmbIsDepressed)               // Z-Axis
     {
         EditorToolbar.ScaleEntities(new Vector3(1f, 1f, 1f + delta));
     }
     else
     {
         thisClickWasTransformAltering = false;
     }
     Monitor.Enter(staticMutationLock);
 }
 private static void TranslateEntities(float distance)
 {
     thisClickWasTransformAltering = true;
     Monitor.Exit(staticMutationLock);
     if (lmbIsDepressed && rmbIsDepressed)               // Y-Axis
     {
         EditorToolbar.TranslateEntities(distance * Vector3.UP);
     }
     else if (lmbIsDepressed)               // X-Axis
     {
         EditorToolbar.TranslateEntities(distance * Vector3.RIGHT);
     }
     else if (rmbIsDepressed)               // Z-Axis
     {
         EditorToolbar.TranslateEntities(distance * Vector3.FORWARD);
     }
     else
     {
         thisClickWasTransformAltering = false;
     }
     Monitor.Enter(staticMutationLock);
 }
 private static void RotateEntities(float rotRads)
 {
     thisClickWasTransformAltering = true;
     Monitor.Exit(staticMutationLock);
     if (lmbIsDepressed && rmbIsDepressed)               // Y-Axis
     {
         EditorToolbar.RotateEntities(Quaternion.FromAxialRotation(Vector3.UP, rotRads));
     }
     else if (lmbIsDepressed)               // X-Axis
     {
         EditorToolbar.RotateEntities(Quaternion.FromAxialRotation(Vector3.RIGHT, rotRads));
     }
     else if (rmbIsDepressed)               // Z-Axis
     {
         EditorToolbar.RotateEntities(Quaternion.FromAxialRotation(Vector3.FORWARD, rotRads));
     }
     else
     {
         thisClickWasTransformAltering = false;
     }
     Monitor.Enter(staticMutationLock);
 }
        private static void InitInput()
        {
            InputBindingRegistry ipb = AssetLocator.GameLayer.GetResource <InputBindingRegistry>();

            ipb.RegisterKeyEvent(
                new HashSet <VirtualKey>()
            {
                VirtualKey.ControlKey, VirtualKey.ShiftKey
            },
                VirtualKeyState.KeyDown | VirtualKeyState.KeyUp,
                (key, state) => {
                lock (staticMutationLock) {
                    switch (key)
                    {
                    case VirtualKey.ControlKey: ctrlIsDepressed = state == VirtualKeyState.KeyDown; break;

                    case VirtualKey.ShiftKey: shiftIsDepressed = state == VirtualKeyState.KeyDown; break;
                    }
                }
                EditorToolbar.Instance.BeginInvoke(new Action(EditorToolbar.Instance.UpdateSelectedEntities));
                EditorToolbar.StartNewReversionStep();
            }
                );

            ipb.RegisterKeyEvent(
                new HashSet <VirtualKey> {
                VirtualKey.W, VirtualKey.Z, VirtualKey.B
            },
                VirtualKeyState.KeyDown,
                (key, _) => {
                lock (staticMutationLock) {
                    if (!ctrlIsDepressed)
                    {
                        return;
                    }
                }
                switch (key)
                {
                case VirtualKey.W:
                    EditorToolbar.CloneSelectedEntities();
                    break;

                case VirtualKey.Z:
                    EditorToolbar.UndoLast();
                    break;

                case VirtualKey.B:
                    EditorToolbar.BakeAll();
                    break;
                }
            }
                );

            ipb.RegisterKeyEvent(
                new HashSet <VirtualKey>()
            {
                VirtualKey.LButton, VirtualKey.RButton
            },
                VirtualKeyState.KeyDown | VirtualKeyState.KeyUp,
                (key, state) => {
                lock (staticMutationLock) {
                    Window mainWindow = AssetLocator.MainWindow;
                    switch (state)
                    {
                    case VirtualKeyState.KeyDown:
                        switch (key)
                        {
                        case VirtualKey.LButton:
                            lmbIsDepressed  = true;
                            lmbMoveDistance = Vector2.ZERO;
                            lmbInitialClick = InputModule.CursorPosition;
                            break;

                        case VirtualKey.RButton:
                            rmbIsDepressed  = true;
                            rmbMoveDistance = Vector2.ZERO;
                            rmbInitialClick = InputModule.CursorPosition;
                            break;
                        }
                        if (InputModule.CursorIsWithinWindow(mainWindow))
                        {
                            InputModule.LockCursorToWindow(mainWindow);
                            mainWindow.ShowCursor = false;
                            windowLocked          = true;
                        }
                        break;

                    case VirtualKeyState.KeyUp:
                        cumulativeTransformDelta = 0f;
                        if (windowLocked && (!lmbIsDepressed || key == VirtualKey.LButton) && (!rmbIsDepressed || key == VirtualKey.RButton))
                        {
                            InputModule.UnlockCursorFromWindow(mainWindow);
                            mainWindow.ShowCursor = true;
                        }
                        switch (key)
                        {
                        case VirtualKey.LButton:
                            lmbIsDepressed = false;
                            if (InputModule.CursorIsWithinWindow(mainWindow) && !thisClickWasTransformAltering)
                            {
                                float lmbDistanceSq = lmbMoveDistance.LengthSquared;
                                if (lmbDistanceSq <= MAX_CURSOR_MOVE_DISTANCE_FOR_PICKING_SQ)
                                {
                                    Vector2 curPosRelative = lmbInitialClick - mainWindow.Position;
                                    curPosRelative         = new Vector2(
                                        curPosRelative.X - mainWindow.Width * 0.5f,
                                        curPosRelative.Y - mainWindow.Height * 0.5f
                                        );
                                    InputModule.CursorPosition = lmbInitialClick + lmbMoveDistance;

                                    // Disgusting anti-deadlock hax now, sorry
                                    Window mainWindowLocal = mainWindow;
                                    Monitor.Exit(staticMutationLock);
                                    try {
                                        EditorToolbar.SelectEntityViaRay(AssetLocator.MainCamera.PixelRayCast(mainWindowLocal, curPosRelative));
                                    }
                                    finally {
                                        Monitor.Enter(staticMutationLock);
                                    }
                                }
                            }
                            thisClickWasTransformAltering = false;
                            break;

                        case VirtualKey.RButton:
                            rmbIsDepressed = false;
                            if (InputModule.CursorIsWithinWindow(mainWindow) && !thisClickWasTransformAltering)
                            {
                                float rmbDistanceSq = rmbMoveDistance.LengthSquared;
                                if (rmbDistanceSq <= MAX_CURSOR_MOVE_DISTANCE_FOR_PICKING_SQ)
                                {
                                    Vector2 curPosRelative = rmbInitialClick - mainWindow.Position;
                                    curPosRelative         = new Vector2(
                                        curPosRelative.X - mainWindow.Width * 0.5f,
                                        curPosRelative.Y - mainWindow.Height * 0.5f
                                        );
                                    InputModule.CursorPosition = rmbInitialClick + rmbMoveDistance;
                                    // Disgusting anti-deadlock hax #2
                                    Window mainWindowLocal = mainWindow;
                                    Monitor.Exit(staticMutationLock);
                                    try {
                                        EditorToolbar.AddGameObject(AssetLocator.MainCamera.PixelRayCast(mainWindowLocal, curPosRelative));
                                    }
                                    finally {
                                        Monitor.Enter(staticMutationLock);
                                    }
                                }
                            }
                            break;
                        }
                        break;
                    }
                }
                EditorToolbar.StartNewReversionStep();
            }
                );

            ipb.RegisterMouseMoveEvent((_, curDelta) => {
                bool lockTranslationsToGrid = EditorToolbar.LockTranslationsToGrid;
                float maxDelta = curDelta.X;
                if (Math.Abs(curDelta.Y) > Math.Abs(curDelta.X))
                {
                    maxDelta = curDelta.Y;
                }
                lock (staticMutationLock) {
                    if (!InputModule.CursorIsWithinWindow(AssetLocator.MainWindow))
                    {
                        return;
                    }
                    if (shiftIsDepressed && ctrlIsDepressed)
                    {
                        float delta = (maxDelta * -0.0025f);
                        if (lockTranslationsToGrid)
                        {
                            cumulativeTransformDelta += delta;
                            if (Math.Abs(cumulativeTransformDelta) > TRANS_GRID_MIN_SCALE_DELTA)
                            {
                                float remainder          = (cumulativeTransformDelta % TRANS_GRID_MIN_SCALE_DELTA);
                                delta                    = cumulativeTransformDelta - remainder;
                                cumulativeTransformDelta = remainder;
                            }
                            else
                            {
                                return;
                            }
                        }
                        ScaleEntities(delta);
                    }
                    else if (shiftIsDepressed)
                    {
                        float rotRads = maxDelta / -350f;
                        if (lockTranslationsToGrid)
                        {
                            cumulativeTransformDelta += rotRads;
                            if (Math.Abs(cumulativeTransformDelta) > TRANS_GRID_MIN_ROT_RADS)
                            {
                                float remainder          = (cumulativeTransformDelta % TRANS_GRID_MIN_ROT_RADS);
                                rotRads                  = cumulativeTransformDelta - remainder;
                                cumulativeTransformDelta = remainder;
                            }
                            else
                            {
                                return;
                            }
                        }
                        RotateEntities(rotRads);
                    }
                    else if (ctrlIsDepressed)
                    {
                        float distance = maxDelta * -0.25f;
                        if (lockTranslationsToGrid)
                        {
                            cumulativeTransformDelta += distance;
                            if (Math.Abs(cumulativeTransformDelta) > TRANS_GRID_MIN_TRANSLATION)
                            {
                                float remainder          = (cumulativeTransformDelta % TRANS_GRID_MIN_TRANSLATION);
                                distance                 = cumulativeTransformDelta - remainder;
                                cumulativeTransformDelta = remainder;
                            }
                            else
                            {
                                return;
                            }
                        }
                        TranslateEntities(distance);
                    }
                    else
                    {
                        thisClickWasTransformAltering = false;
                        MoveCamera(curDelta);
                    }
                }
            });

            InputModule.AlwaysNotifyOfInput = true;
        }
Esempio n. 8
0
        private void UpdateCustomPropertiesBox(LevelGameObject previous, LevelGameObject current)
        {
            ApplyCustomProperties(previous);

            specPropTable.Controls.Clear();
            specPropTable.RowStyles.Clear();

            if (current is DynamicLight)
            {
                Vector3 colorAsVec = (current as DynamicLight).LightColor;
                Color   lightColor = Color.FromArgb((int)(colorAsVec.X * 255f), (int)(colorAsVec.Y * 255f), (int)(colorAsVec.Z * 255f));
                specPropTable.Controls.AddRange(new Control[] {
                    new Label {
                        Text = "Light Radius"
                    },
                    new NumericUpDown {
                        Minimum   = (decimal)(PhysicsManager.ONE_METRE_SCALED * 0.5f),
                        Maximum   = (decimal)(PhysicsManager.ONE_METRE_SCALED * 10.0f),
                        Increment = (decimal)(PhysicsManager.ONE_METRE_SCALED * 0.5f),
                        Value     = (decimal)MathUtils.Clamp((current as DynamicLight).LightRadius, (PhysicsManager.ONE_METRE_SCALED * 0.5f), (PhysicsManager.ONE_METRE_SCALED * 10.0f))
                    },

                    new Label {
                        Text = "Light Colour"
                    },
                    new Button {
                        FlatStyle = FlatStyle.Flat,
                        BackColor = lightColor
                    },

                    new Label {
                        Text = "Lum. Mult."
                    },
                    new NumericUpDown {
                        Minimum       = 1.0m,
                        Maximum       = 100.0m,
                        Increment     = 0.3m,
                        Value         = (decimal)(current as DynamicLight).LuminanceMultiplier,
                        DecimalPlaces = 1
                    },
                });
                ((NumericUpDown)specPropTable.GetControlFromPosition(1, 0)).ValueChanged += (sender, args) => ApplyCustomProperties(current);
                Button lightColorButton = (Button)specPropTable.GetControlFromPosition(1, 1);
                ((NumericUpDown)specPropTable.GetControlFromPosition(1, 2)).ValueChanged += (sender, args) => ApplyCustomProperties(current);
                lightColorButton.MouseClick += (sender, args) => {
                    colorDialog.Color = lightColorButton.BackColor;
                    colorDialog.ShowDialog(this);
                    lightColorButton.BackColor = colorDialog.Color;
                    ApplyCustomProperties(current);
                };
            }
            else if (current is Shadowcaster)
            {
                specPropTable.Controls.AddRange(new Control[] {
                    new Label {
                        Text = "Res. Mult."
                    },
                    new NumericUpDown {
                        Minimum       = (decimal)0.1f,
                        Maximum       = (decimal)2f,
                        Increment     = (decimal)0.1f,
                        Value         = (decimal)(current as Shadowcaster).ResolutionMultiplier,
                        DecimalPlaces = 1
                    },
                    new Label {
                        Text = "Depth"
                    },
                    new TrackBar {
                        Minimum = 1,
                        Maximum = 300,
                        Value   = (int)(current as Shadowcaster).DepthOffset
                    },
                });
                ((NumericUpDown)specPropTable.GetControlFromPosition(1, 0)).ValueChanged += (sender, args) => ApplyCustomProperties(current);
                ((TrackBar)specPropTable.GetControlFromPosition(1, 1)).ValueChanged      += (sender, args) => ApplyCustomProperties(current);
            }

            EditorToolbar.RealtimeUpdateGO(current);
        }