public EditorInputMapping(SceneEditor editor, float moveSpeed = 10.0f, float mouseSensitivity = 10.0f) { // Movement controls AddInput(new KeyInput { Key = RyneKey.W, Type = InputType.Down, Action = new InputMovementAction(new Float3(1, 0, 0), moveSpeed) }); AddInput(new KeyInput { Key = RyneKey.S, Type = InputType.Down, Action = new InputMovementAction(new Float3(-1, 0, 0), moveSpeed) }); AddInput(new KeyInput { Key = RyneKey.A, Type = InputType.Down, Action = new InputMovementAction(new Float3(0, -1, 0), moveSpeed) }); AddInput(new KeyInput { Key = RyneKey.D, Type = InputType.Down, Action = new InputMovementAction(new Float3(0, 1, 0), moveSpeed) }); AddInput(new KeyInput { Key = RyneKey.Q, Type = InputType.Down, Action = new InputMovementAction(new Float3(0, 0, -1), moveSpeed) }); AddInput(new KeyInput { Key = RyneKey.E, Type = InputType.Down, Action = new InputMovementAction(new Float3(0, 0, 1), moveSpeed) }); // View controls AddInput(new MouseAxisInput { Axis = new Float2(1, 0), Action = new InputRotationAction(new Float3(1, 0, 0), mouseSensitivity) }); AddInput(new MouseAxisInput { Axis = new Float2(0, 1), Action = new InputRotationAction(new Float3(0, 1, 0), mouseSensitivity, true) }); // FOV controls AddInput(new KeyInput { Key = RyneKey.C, Type = InputType.Down, Action = new FovInputAction(-10.0f) }); AddInput(new KeyInput { Key = RyneKey.Z, Type = InputType.Down, Action = new FovInputAction(10.0f) }); // Edit mode shortcuts AddInput(new KeyInput { Key = RyneKey.T, Type = InputType.Released, Action = new InputDelegateAction(() => editor.ChangeEditMode(EditMode.Translate)) }); AddInput(new KeyInput { Key = RyneKey.R, Type = InputType.Released, Action = new InputDelegateAction(() => editor.ChangeEditMode(EditMode.Rotate)) }); AddInput(new KeyInput { Key = RyneKey.S, Type = InputType.Released, Action = new InputDelegateAction(() => editor.ChangeEditMode(EditMode.Scale)) }); // Edit axis shortcuts AddInput(new KeyInput { Key = RyneKey.X, Type = InputType.Released, Action = new InputDelegateAction(() => editor.ChangeEditAxis(EditAxis.X)) }); AddInput(new KeyInput { Key = RyneKey.Y, Type = InputType.Released, Action = new InputDelegateAction(() => editor.ChangeEditAxis(EditAxis.Y)) }); AddInput(new KeyInput { Key = RyneKey.Z, Type = InputType.Released, Action = new InputDelegateAction(() => editor.ChangeEditAxis(EditAxis.Z)) }); // Scroll wheel changes movement speed AddInput(new MouseScrollInput { Key = RyneMouseWheel.WheelUp, Action = new InputDelegateAction(() => { foreach (var keyInput in KeyInputs) { if (keyInput.Action.GetType() == typeof(InputMovementAction)) { ((InputMovementAction)keyInput.Action).Length *= 1.1f; } } }) }); AddInput(new MouseScrollInput { Key = RyneMouseWheel.WheelDown, Action = new InputDelegateAction(() => { foreach (var keyInput in KeyInputs) { if (keyInput.Action.GetType() == typeof(InputMovementAction)) { ((InputMovementAction)keyInput.Action).Length /= 1.1f; } } }) }); // Edit Gui hide AddInput(new KeyInput { Key = RyneKey.H, Type = InputType.Released, Action = new InputDelegateAction(editor.HideGui) }); // Printscreen renders to image AddInput(new KeyInput { Key = RyneKey.PrintScreen, Type = InputType.Released , Action = new InputDelegateAction(() => editor.RenderScreenToImage("Renders/Render" + ++editor.Gui.RenderCount + ".tga")) }); // Rename AddInput(new KeyInput { Key = RyneKey.F2, Type = InputType.Released, Action = new InputDelegateAction(editor.TryRenameEntity) }); // Delete AddInput(new KeyInput { Key = RyneKey.Delete, Type = InputType.Pressed, Action = new InputDelegateAction(() => editor.DeleteActiveEntities()) }); // Copy AddInput(new ComboKeyInput { Key1 = RyneKey.LeftControl, Key2 = RyneKey.C, Type1 = InputType.Down, Type2 = InputType.Pressed, Action = new InputDelegateAction(editor.CopySelectedEntities), ConsumeInput = true }); // Paste AddInput(new ComboKeyInput { Key1 = RyneKey.LeftControl, Key2 = RyneKey.V, Type1 = InputType.Down, Type2 = InputType.Pressed, Action = new InputDelegateAction(editor.PasteSelectedEntities), ConsumeInput = true }); // Undo AddInput(new ComboKeyInput { Key1 = RyneKey.LeftControl, Key2 = RyneKey.Z, Type1 = InputType.Down, Type2 = InputType.Pressed, Action = new InputDelegateAction(editor.UndoLastAction), ConsumeInput = true }); // Save AddInput(new ComboKeyInput { Key1 = RyneKey.LeftControl, Key2 = RyneKey.S, Type1 = InputType.Down, Type2 = InputType.Pressed, Action = new InputDelegateAction(editor.SaveScene), ConsumeInput = true }); // Open AddInput(new ComboKeyInput { Key1 = RyneKey.RightControl, Key2 = RyneKey.O, Type1 = InputType.Down, Type2 = InputType.Pressed, Action = new InputDelegateAction(() => { var window = new FileExplorerGui(editor.Gui, "Scenes", ".fls", "Load scene"); window.Callback += result => { var fileName = ((FileExplorerGui)result).SelectedFile; var sceneName = Path.GetFileNameWithoutExtension(fileName); editor.LoadScene(sceneName); }; editor.Gui.AddPopup(window); }), ConsumeInput = true }); // Right mouse triggers the start and end of camera movement AddInput(new MouseInput { Key = RyneMouse.Button1, Type = InputType.Pressed, Action = new InputControllerAction(controller => { if (!editor.Gui.IsMouseInGui()) { controller.SetCaptureMouse(true); } }) }); AddInput(new MouseInput { Key = RyneMouse.Button1, Type = InputType.Released, Action = new InputControllerAction(controller => { controller.SetCaptureMouse(false); }) }); }
public void RenderGui(ImGuiWrapper gui, Entity owner) { if (!(gui is SceneEditorGui sceneGui)) { return; } if (gui.CollapsingHeader("Mesh component", true)) { if (ObjectType == RyneObjectType.ObjectTypeNone) { if (sceneGui.MenuItem("Load voxel mesh")) { var extensions = Global.ResourceManager.GetSupportedExtensions(RyneResourceType.ResourceTypeBsvDag); var window = new FileExplorerGui(sceneGui, "VoxelModels", extensions, "Select model"); window.Callback += result => { var fileExplorer = (FileExplorerGui)result; var type = RyneObjectType.ObjectTypeBsvDag; owner.Mesh.SetMeshData(fileExplorer.SelectedFile, type); owner.Mesh.LoadMesh(); owner.SetChangedInEditor(true); }; sceneGui.AddPopup(window); } } else { if (!Loaded || owner.RenderId == -1) { gui.Text("Mesh loaded: " + Loaded); return; } if (CustomMaterials.Count == 0) { if (gui.MenuItem("Create unique materials")) { SetCustomMaterials(owner); } } else { for (int i = 0; i < CustomMaterials.Count; i++) { var localIndex = i; var material = CustomMaterials[i]; var name = string.IsNullOrEmpty(material.Name) ? localIndex.ToString() : material.Name; if (gui.MenuItem("Edit Material " + name)) { var window = new MaterialGui(sceneGui, material, result => { owner.Mesh.UpdateMaterial(owner, sceneGui.SceneData, (Material)result.GetWindowObject, localIndex); }); sceneGui.AddWindow(window); } } } } } }