public void Run() { SetupCSharpDefaults(); SetupParamStudioConfig(); //new StudioServer(); long previousFrameTicks = 0; Stopwatch sw = new Stopwatch(); sw.Start(); while (_window.Exists) { bool focused = _window.Focused; if (!focused) { _desiredFrameLengthSeconds = 1.0 / 20.0f; } else { _desiredFrameLengthSeconds = 1.0 / 60.0f; } long currentFrameTicks = sw.ElapsedTicks; double deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; while (_limitFrameRate && deltaSeconds < _desiredFrameLengthSeconds) { currentFrameTicks = sw.ElapsedTicks; deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; System.Threading.Thread.Sleep(focused ? 0 : 1); } previousFrameTicks = currentFrameTicks; InputSnapshot snapshot = null; Sdl2Events.ProcessEvents(); snapshot = _window.PumpEvents(); InputTracker.UpdateFrameInput(snapshot, _window); Update((float)deltaSeconds); if (!_window.Exists) { break; } if (_window.Focused) { Draw(); } else { // Flush the background queues Renderer.Frame(null, true); } } //DestroyAllObjects(); _gd.Dispose(); SaveParamStudioConfig(); CFG.Save(); System.Windows.Forms.Application.Exit(); }
private void Update(float deltaseconds) { ImguiRenderer.Update(deltaseconds, InputTracker.FrameSnapshot); //ImGui. var command = EditorCommandQueue.GetNextCommand(); string[] commandsplit = null; if (command != null) { commandsplit = command.Split($@"/"); } ImGui.BeginFrame(); // Imguizmo begin frame ApplyStyle(); var vp = ImGui.GetMainViewport(); ImGui.SetNextWindowPos(vp.Pos); ImGui.SetNextWindowSize(vp.Size); ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f); ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0.0f); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0.0f, 0.0f)); ImGuiWindowFlags flags = ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove; flags |= ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.MenuBar; flags |= ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoNavFocus; flags |= ImGuiWindowFlags.NoBackground; if (ImGui.Begin("DockSpace_W", flags)) { //Console.WriteLine("hi"); } var dsid = ImGui.GetID("DockSpace"); ImGui.DockSpace(dsid, new Vector2(0, 0), ImGuiDockNodeFlags.NoSplit); ImGui.PopStyleVar(1); ImGui.End(); bool newProject = false; ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 0.0f); if (ImGui.BeginMainMenuBar()) { if (ImGui.BeginMenu("File")) { if (_projectSettings == null || _projectSettings.ProjectName == null) { ImGui.MenuItem("No project open", false); } else { ImGui.MenuItem($@"Settings: {_projectSettings.ProjectName}"); } if (ImGui.MenuItem("Enable Texturing (alpha)", "", CFG.Current.EnableTexturing)) { CFG.Current.EnableTexturing = !CFG.Current.EnableTexturing; } if (ImGui.MenuItem("New Project", "CTRL+N") || InputTracker.GetControlShortcut(Key.I)) { newProject = true; } if (ImGui.MenuItem("Open Project", "")) { var browseDlg = new System.Windows.Forms.OpenFileDialog() { Filter = AssetLocator.JsonFilter, ValidateNames = true, CheckFileExists = true, CheckPathExists = true, }; if (browseDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var settings = MsbEditor.ProjectSettings.Deserialize(browseDlg.FileName); AttemptLoadProject(settings, browseDlg.FileName); } } if (ImGui.BeginMenu("Recent Projects")) { CFG.RecentProject recent = null; foreach (var p in CFG.Current.RecentProjects) { if (ImGui.MenuItem($@"{p.GameType.ToString()}:{p.Name}")) { if (File.Exists(p.ProjectFile)) { var settings = MsbEditor.ProjectSettings.Deserialize(p.ProjectFile); if (AttemptLoadProject(settings, p.ProjectFile, false)) { recent = p; } } } } if (recent != null) { CFG.Current.RecentProjects.Remove(recent); CFG.Current.RecentProjects.Insert(0, recent); CFG.Current.LastProjectFile = recent.ProjectFile; } ImGui.EndMenu(); } if (ImGui.MenuItem("Save", "Ctrl-S")) { if (_msbEditorFocused) { MSBEditor.Save(); } if (_modelEditorFocused) { ModelEditor.Save(); } if (_paramEditorFocused) { ParamEditor.Save(); } if (_textEditorFocused) { TextEditor.Save(); } } if (ImGui.MenuItem("Save All", "")) { MSBEditor.SaveAll(); ModelEditor.SaveAll(); ParamEditor.SaveAll(); TextEditor.SaveAll(); } if (Resource.FlverResource.CaptureMaterialLayouts && ImGui.MenuItem("Dump Flver Layouts (Debug)", "")) { DumpFlverLayouts(); } ImGui.EndMenu(); } if (_msbEditorFocused) { MSBEditor.DrawEditorMenu(); } else if (_modelEditorFocused) { ModelEditor.DrawEditorMenu(); } else if (_paramEditorFocused) { ParamEditor.DrawEditorMenu(); } else if (_textEditorFocused) { TextEditor.DrawEditorMenu(); } ImGui.EndMainMenuBar(); } ImGui.PopStyleVar(); // New project modal if (newProject) { _newProjectSettings = new MsbEditor.ProjectSettings(); _newProjectDirectory = ""; ImGui.OpenPopup("New Project"); } bool open = true; ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 7.0f); ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 1.0f); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(14.0f, 8.0f)); if (ImGui.BeginPopupModal("New Project", ref open, ImGuiWindowFlags.AlwaysAutoResize)) { ImGui.AlignTextToFramePadding(); ImGui.Text("Project Name: "); ImGui.SameLine(); var pname = _newProjectSettings.ProjectName; if (ImGui.InputText("##pname", ref pname, 255)) { _newProjectSettings.ProjectName = pname; } ImGui.AlignTextToFramePadding(); ImGui.Text("Project Directory: "); ImGui.SameLine(); ImGui.InputText("##pdir", ref _newProjectDirectory, 255); ImGui.SameLine(); if (ImGui.Button($@"{ForkAwesome.FileO}")) { var browseDlg = new System.Windows.Forms.FolderBrowserDialog(); if (browseDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _newProjectDirectory = browseDlg.SelectedPath; } } ImGui.AlignTextToFramePadding(); ImGui.Text("Game Executable: "); ImGui.SameLine(); var gname = _newProjectSettings.GameRoot; if (ImGui.InputText("##gdir", ref gname, 255)) { _newProjectSettings.GameRoot = gname; _newProjectSettings.GameType = _assetLocator.GetGameTypeForExePath(_newProjectSettings.GameRoot); } ImGui.SameLine(); ImGui.PushID("fd2"); if (ImGui.Button($@"{ForkAwesome.FileO}")) { var browseDlg = new System.Windows.Forms.OpenFileDialog() { Filter = AssetLocator.GameExecutatbleFilter, ValidateNames = true, CheckFileExists = true, CheckPathExists = true, //ShowReadOnly = true, }; if (browseDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _newProjectSettings.GameRoot = browseDlg.FileName; _newProjectSettings.GameType = _assetLocator.GetGameTypeForExePath(_newProjectSettings.GameRoot); } } ImGui.PopID(); ImGui.Text($@"Detected Game: {_newProjectSettings.GameType.ToString()}"); ImGui.NewLine(); ImGui.Separator(); ImGui.NewLine(); if (_newProjectSettings.GameType == GameType.DarkSoulsIISOTFS || _newProjectSettings.GameType == GameType.DarkSoulsIII) { ImGui.AlignTextToFramePadding(); ImGui.Text($@"Use Loose Params: "); ImGui.SameLine(); var looseparams = _newProjectSettings.UseLooseParams; if (ImGui.Checkbox("##looseparams", ref looseparams)) { _newProjectSettings.UseLooseParams = looseparams; } ImGui.NewLine(); } if (ImGui.Button("Create", new Vector2(120, 0))) { bool validated = true; if (_newProjectSettings.GameRoot == null || !File.Exists(_newProjectSettings.GameRoot)) { System.Windows.Forms.MessageBox.Show("Your game executable path does not exist. Please select a valid executable.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated && _newProjectSettings.GameType == GameType.Undefined) { System.Windows.Forms.MessageBox.Show("Your game executable is not a valid supported game.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated && (_newProjectDirectory == null || !Directory.Exists(_newProjectDirectory))) { System.Windows.Forms.MessageBox.Show("Your selected project directory is not valid.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated && File.Exists($@"{_newProjectDirectory}\project.json")) { System.Windows.Forms.MessageBox.Show("Your selected project directory is already a project.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated && (_newProjectSettings.ProjectName == null || _newProjectSettings.ProjectName == "")) { System.Windows.Forms.MessageBox.Show("You must specify a project name.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } string gameroot = Path.GetDirectoryName(_newProjectSettings.GameRoot); if (_newProjectSettings.GameType == GameType.Bloodborne) { gameroot = gameroot + @"\dvdroot_ps4"; } if (!_assetLocator.CheckFilesExpanded(gameroot, _newProjectSettings.GameType)) { System.Windows.Forms.MessageBox.Show($@"The files for {_newProjectSettings.GameType} do not appear to be unpacked. Please use UDSFM for DS1:PTDE and UXM for the rest of the games to unpack the files.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated) { _projectSettings = _newProjectSettings; _projectSettings.GameRoot = gameroot; _projectSettings.Serialize($@"{_newProjectDirectory}\project.json"); ChangeProjectSettings(_projectSettings, _newProjectDirectory); CFG.Current.LastProjectFile = $@"{_newProjectDirectory}\project.json"; var recent = new CFG.RecentProject(); recent.Name = _projectSettings.ProjectName; recent.GameType = _projectSettings.GameType; recent.ProjectFile = $@"{_newProjectDirectory}\project.json"; CFG.Current.RecentProjects.Insert(0, recent); if (CFG.Current.RecentProjects.Count > CFG.MAX_RECENT_PROJECTS) { CFG.Current.RecentProjects.RemoveAt(CFG.Current.RecentProjects.Count - 1); } ImGui.CloseCurrentPopup(); } } ImGui.SameLine(); if (ImGui.Button("Cancel", new Vector2(120, 0))) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } ImGui.PopStyleVar(3); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0.0f, 0.0f)); if (FirstFrame) { ImGui.SetNextWindowFocus(); } string[] mapcmds = null; if (commandsplit != null && commandsplit[0] == "map") { mapcmds = commandsplit.Skip(1).ToArray(); ImGui.SetNextWindowFocus(); } if (ImGui.Begin("Map Editor")) { ImGui.PopStyleVar(1); MSBEditor.OnGUI(mapcmds); ImGui.End(); _msbEditorFocused = true; MSBEditor.Update(deltaseconds); } else { ImGui.PopStyleVar(1); _msbEditorFocused = false; ImGui.End(); } ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0.0f, 0.0f)); if (ImGui.Begin("Model Editor")) { ImGui.PopStyleVar(1); ModelEditor.OnGUI(); _modelEditorFocused = true; ModelEditor.Update(deltaseconds); } else { ImGui.PopStyleVar(1); _modelEditorFocused = false; } ImGui.End(); string[] paramcmds = null; if (commandsplit != null && commandsplit[0] == "param") { paramcmds = commandsplit.Skip(1).ToArray(); ImGui.SetNextWindowFocus(); } if (ImGui.Begin("Param Editor")) { ParamEditor.OnGUI(paramcmds); _paramEditorFocused = true; } else { _paramEditorFocused = false; } ImGui.End(); string[] textcmds = null; if (commandsplit != null && commandsplit[0] == "text") { textcmds = commandsplit.Skip(1).ToArray(); ImGui.SetNextWindowFocus(); } ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(4, 4)); if (ImGui.Begin("Text Editor")) { TextEditor.OnGUI(textcmds); _textEditorFocused = true; } else { _textEditorFocused = false; } ImGui.End(); ImGui.PopStyleVar(); ImGui.PopStyleVar(2); UnapplyStyle(); Resource.ResourceManager.UpdateTasks(); if (!_firstframe) { FirstFrame = false; } _firstframe = false; }
public void Run() { /*Task.Run(() => * { * while (true) * { * Thread.Sleep(5000); * GC.Collect(); * GC.WaitForPendingFinalizers(); * * GC.Collect(); * } * });*/ // Flush geometry megabuffers for editor geometry //Renderer.GeometryBufferAllocator.FlushStaging(); long previousFrameTicks = 0; Stopwatch sw = new Stopwatch(); sw.Start(); while (_window.Exists) { bool focused = _window.Focused; if (!focused) { _desiredFrameLengthSeconds = 1.0 / 20.0f; } else { _desiredFrameLengthSeconds = 1.0 / 60.0f; } long currentFrameTicks = sw.ElapsedTicks; double deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; while (_limitFrameRate && deltaSeconds < _desiredFrameLengthSeconds) { currentFrameTicks = sw.ElapsedTicks; deltaSeconds = (currentFrameTicks - previousFrameTicks) / (double)Stopwatch.Frequency; System.Threading.Thread.Sleep(focused ? 0 : 1); } previousFrameTicks = currentFrameTicks; InputSnapshot snapshot = null; Sdl2Events.ProcessEvents(); snapshot = _window.PumpEvents(); InputTracker.UpdateFrameInput(snapshot, _window); Update((float)deltaSeconds); if (!_window.Exists) { break; } if (_window.Focused) { Draw(); } else { // Flush the background queues Renderer.Frame(null, true); } } //DestroyAllObjects(); Resource.ResourceManager.Shutdown(); _gd.Dispose(); CFG.Save(); System.Windows.Forms.Application.Exit(); }
public bool UpdateInput(Sdl2Window window, float dt) { if (DisableAllInput) { //oldWheel = Mouse.GetState(game.Window).ScrollWheelValue; return false; } float clampedLerpF = Utils.Clamp(30 * dt, 0, 1); mousePos = new Vector2(Utils.Lerp(oldMouse.X, InputTracker.MousePosition.X, clampedLerpF), Utils.Lerp(oldMouse.Y, InputTracker.MousePosition.Y, clampedLerpF)); //KeyboardState keyboard = DBG.EnableKeyboardInput ? Keyboard.GetState() : DBG.DisabledKeyboardState; //int currentWheel = mouse.ScrollWheelValue; //bool mouseInWindow = MapStudio.Active && mousePos.X >= game.ClientBounds.Left && mousePos.X < game.ClientBounds.Right && mousePos.Y > game.ClientBounds.Top && mousePos.Y < game.ClientBounds.Bottom; currentClickType = MouseClickType.None; if (InputTracker.GetMouseButton(Veldrid.MouseButton.Left)) currentClickType = MouseClickType.Left; else if (InputTracker.GetMouseButton(Veldrid.MouseButton.Right)) currentClickType = MouseClickType.Right; else if (InputTracker.GetMouseButton(Veldrid.MouseButton.Middle)) currentClickType = MouseClickType.Middle; else if (InputTracker.GetMouseButton(Veldrid.MouseButton.Button1)) currentClickType = MouseClickType.Extra1; else if (InputTracker.GetMouseButton(Veldrid.MouseButton.Button2)) currentClickType = MouseClickType.Extra2; else currentClickType = MouseClickType.None; currentMouseClickL = currentClickType == MouseClickType.Left; currentMouseClickR = currentClickType == MouseClickType.Right; currentMouseClickM = currentClickType == MouseClickType.Middle; if (currentClickType != MouseClickType.None && oldClickType == MouseClickType.None) currentMouseClickStartedInWindow = true; if (currentClickType == MouseClickType.None) { // If nothing is pressed, just dont bother lerping //mousePos = new Vector2(mouse.X, mouse.Y); if (MousePressed) { mousePos = InputTracker.MousePosition; Sdl2Native.SDL_WarpMouseInWindow(window.SdlWindowHandle, (int)MousePressedPos.X, (int)MousePressedPos.Y); Sdl2Native.SDL_SetWindowGrab(window.SdlWindowHandle, false); Sdl2Native.SDL_ShowCursor(1); MousePressed = false; } return false; } bool isSpeedupKeyPressed = InputTracker.GetKey(Veldrid.Key.LShift) || InputTracker.GetKey(Veldrid.Key.RShift); bool isSlowdownKeyPressed = InputTracker.GetKey(Veldrid.Key.LControl) || InputTracker.GetKey(Veldrid.Key.RControl); bool isResetKeyPressed = InputTracker.GetKey(Veldrid.Key.R); bool isMoveLightKeyPressed = InputTracker.GetKey(Veldrid.Key.Space); bool isOrbitCamToggleKeyPressed = false;// keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F); bool isPointCamAtObjectKeyPressed = false;// keyboard.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.T); if (!currentMouseClickStartedInWindow) { oldMouse = mousePos; if (IsOrbitCam) { OrbitCamDistance = Math.Max(OrbitCamDistance, SHITTY_CAM_ZOOM_MIN_DIST); var distanceVectorAfterMove = -Vector3.Transform(Vector3.UnitX, CameraTransform.RotationMatrixXYZ * Matrix4x4.CreateRotationY(Utils.Pi)) * new Vector3(-1, 1, 1); CameraTransform.Position = (OrbitCamCenter + (distanceVectorAfterMove * (OrbitCamDistance * OrbitCamDistance))); } else { var eu = CameraTransform.EulerRotation; eu.X = Utils.Clamp(CameraTransform.EulerRotation.X, -Utils.PiOver2, Utils.PiOver2); CameraTransform.EulerRotation = eu; } LightRotation.X = Utils.Clamp(LightRotation.X, -Utils.PiOver2, Utils.PiOver2); oldClickType = currentClickType; oldMouseClickL = currentMouseClickL; oldMouseClickR = currentMouseClickR; oldMouseClickM = currentMouseClickM; oldOrbitCamToggleKeyPressed = isOrbitCamToggleKeyPressed; return true; } if (currentMouseClickM && !oldMouseClickM && IsOrbitCam) { OrbitCamReset(); } if (isResetKeyPressed && !oldResetKeyPressed) { ResetCameraLocation(); } oldResetKeyPressed = isResetKeyPressed; if (isOrbitCamToggleKeyPressed && !oldOrbitCamToggleKeyPressed) { if (!IsOrbitCam) { CameraOrigin.Position.Y = CameraPositionDefault.Position.Y; OrbitCamDistance = (CameraOrigin.Position - (CameraTransform.Position)).Length(); } IsOrbitCam = !IsOrbitCam; } if (isPointCamAtObjectKeyPressed) { PointCameraToLocation(CameraPositionDefault.Position); } float moveMult = dt * CameraMoveSpeed; if (isSpeedupKeyPressed) { moveMult = dt * CameraMoveSpeedFast; } if (isSlowdownKeyPressed) { moveMult = dt * CameraMoveSpeedSlow; } var cameraDist = CameraOrigin.Position - CameraTransform.Position; if (IsOrbitCam) { if (currentMouseClickL) { float x = 0; float z = 0; float y = 0; if (InputTracker.GetKeyDown(Veldrid.Key.W) && Math.Abs(cameraDist.Length()) > 0.1f) z += 1; if (InputTracker.GetKeyDown(Veldrid.Key.S)) z -= 1; if (InputTracker.GetKeyDown(Veldrid.Key.E)) y += 1; if (InputTracker.GetKeyDown(Veldrid.Key.Q)) y -= 1; if (InputTracker.GetKeyDown(Veldrid.Key.A)) x -= 1; if (InputTracker.GetKeyDown(Veldrid.Key.D)) x += 1; if (Math.Abs(cameraDist.Length()) <= SHITTY_CAM_ZOOM_MIN_DIST) { z = Math.Min(z, 0); } } else if (currentMouseClickR) { MoveCamera_OrbitCenterPoint_MouseDelta(mousePos, oldMouse); //Vector2 mouseDelta = mousePos - oldMouse; //MoveCamera_OrbitCenterPoint(-mouseDelta.X, mouseDelta.Y, 0, moveMult); } //if (GFX.LastViewport.Bounds.Contains(mouse.Position)) // OrbitCamDistance -= ((currentWheel - oldWheel) / 150f) * 0.25f; } else { float x = 0; float y = 0; float z = 0; if (InputTracker.GetKey(Veldrid.Key.D)) x += 1; if (InputTracker.GetKey(Veldrid.Key.A)) x -= 1; if (InputTracker.GetKey(Veldrid.Key.E)) y += 1; if (InputTracker.GetKey(Veldrid.Key.Q)) y -= 1; if (InputTracker.GetKey(Veldrid.Key.W)) z += 1; if (InputTracker.GetKey(Veldrid.Key.S)) z -= 1; MoveCamera(x, y, z, moveMult); } if (currentMouseClickR) { if (!MousePressed) { var x = InputTracker.MousePosition.X; var y = InputTracker.MousePosition.Y; if (x >= BoundingRect.Left && x < BoundingRect.Right && y >= BoundingRect.Top && y < BoundingRect.Bottom) { MousePressed = true; MousePressedPos = InputTracker.MousePosition; Sdl2Native.SDL_ShowCursor(0); Sdl2Native.SDL_SetWindowGrab(window.SdlWindowHandle, true); } } else { Vector2 mouseDelta = MousePressedPos - InputTracker.MousePosition; Sdl2Native.SDL_WarpMouseInWindow(window.SdlWindowHandle, (int)MousePressedPos.X, (int)MousePressedPos.Y); if (mouseDelta.LengthSquared() == 0) { // Prevents a meme //oldWheel = currentWheel; return true; } //Mouse.SetPosition(game.ClientBounds.X + game.ClientBounds.Width / 2, game.ClientBounds.Y + game.ClientBounds.Height / 2); float camH = mouseDelta.X * 1 * CameraTurnSpeedMouse * 0.0160f; float camV = mouseDelta.Y * -1 * CameraTurnSpeedMouse * 0.0160f; if (IsOrbitCam && !isMoveLightKeyPressed) { if (CameraTransform.EulerRotation.X >= Utils.PiOver2 * SHITTY_CAM_PITCH_LIMIT_FATCAT) { camV = Math.Min(camV, 0); } if (CameraTransform.EulerRotation.X <= -Utils.PiOver2 * SHITTY_CAM_PITCH_LIMIT_FATCAT) { camV = Math.Max(camV, 0); } RotateCameraOrbit(camH, camV, Utils.PiOver2); //PointCameraToModel(); } else if (isMoveLightKeyPressed) { LightRotation.Y += camH; LightRotation.X -= camV; } else { var eu = CameraTransform.EulerRotation; eu.Y -= camH; eu.X += camV; CameraTransform.EulerRotation = eu; } } //CameraTransform.Rotation.Z -= (float)Math.Cos(MathHelper.PiOver2 - CameraTransform.Rotation.Y) * camV; //RotateCamera(mouseDelta.Y * -0.01f * (float)moveMult, 0, 0, moveMult); //RotateCamera(0, mouseDelta.X * 0.01f * (float)moveMult, 0, moveMult); } else { if (MousePressed) { Sdl2Native.SDL_WarpMouseInWindow(window.SdlWindowHandle, (int)MousePressedPos.X, (int)MousePressedPos.Y); Sdl2Native.SDL_SetWindowGrab(window.SdlWindowHandle, false); Sdl2Native.SDL_ShowCursor(1); MousePressed = false; } if (IsOrbitCam) { RotateCameraOrbit(0, 0, Utils.PiOver2); } if (oldMouseClickL) { //Mouse.SetPosition((int)oldMouse.X, (int)oldMouse.Y); } //game.IsMouseVisible = true; } if (IsOrbitCam) { OrbitCamDistance = Math.Max(OrbitCamDistance, SHITTY_CAM_ZOOM_MIN_DIST); var distanceVectorAfterMove = -Vector3.Transform(Vector3.UnitX, CameraTransform.RotationMatrixXYZ * Matrix4x4.CreateRotationY(Utils.Pi)) * new Vector3(-1, 1, 1); CameraTransform.Position = (OrbitCamCenter + (distanceVectorAfterMove * (OrbitCamDistance * OrbitCamDistance))); } else { var eu = CameraTransform.EulerRotation; eu.X = Utils.Clamp(CameraTransform.EulerRotation.X, -Utils.PiOver2, Utils.PiOver2); CameraTransform.EulerRotation = eu; } LightRotation.X = Utils.Clamp(LightRotation.X, -Utils.PiOver2, Utils.PiOver2); oldClickType = currentClickType; oldMouseClickL = currentMouseClickL; oldMouseClickR = currentMouseClickR; oldMouseClickM = currentMouseClickM; oldOrbitCamToggleKeyPressed = isOrbitCamToggleKeyPressed; oldMouse = mousePos; return true; }
private void Update(float deltaseconds) { ImguiRenderer.Update(deltaseconds, InputTracker.FrameSnapshot); //ImGui. List <string> tasks = TaskManager.GetLiveThreads(); _window.Title = tasks.Count == 0 ? "Dark Souls Param Studio " + _version : String.Join(", ", tasks); var command = EditorCommandQueue.GetNextCommand(); string[] commandsplit = null; if (command != null) { commandsplit = command.Split($@"/"); } if (commandsplit != null && commandsplit[0] == "windowFocus") { //this is a hack, cannot grab focus except for when un-minimising _user32_ShowWindow(_window.Handle, 6); _user32_ShowWindow(_window.Handle, 9); } ImGui.BeginFrame(); // Imguizmo begin frame ApplyStyle(); var vp = ImGui.GetMainViewport(); ImGui.SetNextWindowPos(vp.Pos); ImGui.SetNextWindowSize(vp.Size); ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f); ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0.0f); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0.0f, 0.0f)); ImGuiWindowFlags flags = ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove; flags |= ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.MenuBar; flags |= ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoNavFocus; flags |= ImGuiWindowFlags.NoBackground; if (ImGui.Begin("DockSpace_W", flags)) { //Console.WriteLine("hi"); } var dsid = ImGui.GetID("DockSpace"); ImGui.DockSpace(dsid, new Vector2(0, 0), ImGuiDockNodeFlags.NoSplit); ImGui.PopStyleVar(3); ImGui.End(); bool newProject = false; ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 0.0f); if (ImGui.BeginMainMenuBar()) { if (ImGui.BeginMenu("File")) { if (_projectSettings == null || _projectSettings.ProjectName == null) { ImGui.MenuItem("No project open", false); } else { ImGui.MenuItem($@"Settings: {_projectSettings.ProjectName}"); } if (ImGui.MenuItem("New Project", "CTRL+N", false, TaskManager.GetLiveThreads().Count == 0)) { newProject = true; } if (ImGui.MenuItem("Open Project", "", false, TaskManager.GetLiveThreads().Count == 0)) { var browseDlg = new System.Windows.Forms.OpenFileDialog() { Filter = AssetLocator.JsonFilter, ValidateNames = true, CheckFileExists = true, CheckPathExists = true, }; if (browseDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var settings = ProjectSettings.Deserialize(browseDlg.FileName); AttemptLoadProject(settings, browseDlg.FileName); } } if (ImGui.BeginMenu("Recent Projects")) { CFG.RecentProject recent = null; foreach (var p in CFG.Current.RecentProjects) { if (ImGui.MenuItem($@"{p.GameType.ToString()}:{p.Name}", null, false, TaskManager.GetLiveThreads().Count == 0)) { if (File.Exists(p.ProjectFile)) { var settings = ProjectSettings.Deserialize(p.ProjectFile); if (AttemptLoadProject(settings, p.ProjectFile, false)) { recent = p; } } } } if (recent != null) { CFG.Current.RecentProjects.Remove(recent); CFG.Current.RecentProjects.Insert(0, recent); CFG.Current.LastProjectFile = recent.ProjectFile; } ImGui.EndMenu(); } if (ImGui.MenuItem("Save", "Ctrl-S")) { _paramEditor.SaveAll(); _textEditor.SaveAll(); SaveParamStudioConfig(); } ImGui.EndMenu(); } if (InputTracker.GetControlShortcut(Key.N)) { newProject = true; } if (InputTracker.GetControlShortcut(Key.S)) { _paramEditor.SaveAll(); _textEditor.SaveAll(); } if (_paramEditorFocused) { _paramEditor.DrawEditorMenu(); } else if (_textEditorFocused) { _textEditor.DrawEditorMenu(); } if (ImGui.BeginMenu("Help")) { if (ImGui.BeginMenu("About")) { ImGui.Text("DSParamStudio is forked from Katalash's DSMapStudio and is currently maintained by Philiquaz.\nFor bug reports and feature requests, ping the right person please."); ImGui.EndMenu(); } if (ImGui.BeginMenu("Edits aren't sticking!")) { ImGui.Text("The mechanism that is used to detect if a field has been changed can stop existing before registering a change.\nThis occurs when switching param, row or using tab between fields.\nI hope to have this fixed soon, however it is a complicated issue.\nTo ensure a change sticks, simply click off the field you are editing."); ImGui.EndMenu(); } ImGui.EndMenu(); } ImGui.EndMainMenuBar(); } ImGui.PopStyleVar(); // New project modal if (newProject) { _newProjectSettings = new ProjectSettings(); _newProjectDirectory = ""; ImGui.OpenPopup("New Project"); } bool open = true; ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 7.0f); ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 1.0f); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(14.0f, 8.0f)); if (ImGui.BeginPopupModal("New Project", ref open, ImGuiWindowFlags.AlwaysAutoResize)) { ImGui.AlignTextToFramePadding(); ImGui.Text("Project Name: "); ImGui.SameLine(); var pname = _newProjectSettings.ProjectName; if (ImGui.InputText("##pname", ref pname, 255)) { _newProjectSettings.ProjectName = pname; } ImGui.AlignTextToFramePadding(); ImGui.Text("Project Directory: "); ImGui.SameLine(); ImGui.InputText("##pdir", ref _newProjectDirectory, 255); ImGui.SameLine(); if (ImGui.Button($@"{ForkAwesome.FileO}")) { var browseDlg = new System.Windows.Forms.FolderBrowserDialog(); if (browseDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _newProjectDirectory = browseDlg.SelectedPath; } } ImGui.AlignTextToFramePadding(); ImGui.Text("Game Executable: "); ImGui.SameLine(); var gname = _newProjectSettings.GameRoot; if (ImGui.InputText("##gdir", ref gname, 255)) { _newProjectSettings.GameRoot = gname; _newProjectSettings.GameType = _assetLocator.GetGameTypeForExePath(_newProjectSettings.GameRoot); } ImGui.SameLine(); ImGui.PushID("fd2"); if (ImGui.Button($@"{ForkAwesome.FileO}")) { var browseDlg = new System.Windows.Forms.OpenFileDialog() { Filter = AssetLocator.GameExecutatbleFilter, ValidateNames = true, CheckFileExists = true, CheckPathExists = true, //ShowReadOnly = true, }; if (browseDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _newProjectSettings.GameRoot = browseDlg.FileName; _newProjectSettings.GameType = _assetLocator.GetGameTypeForExePath(_newProjectSettings.GameRoot); } } ImGui.PopID(); ImGui.Text($@"Detected Game: {_newProjectSettings.GameType.ToString()}"); ImGui.NewLine(); ImGui.Separator(); ImGui.NewLine(); if (_newProjectSettings.GameType == GameType.DarkSoulsIISOTFS || _newProjectSettings.GameType == GameType.DarkSoulsIII) { ImGui.AlignTextToFramePadding(); ImGui.Text($@"Use Loose Params: "); ImGui.SameLine(); var looseparams = _newProjectSettings.UseLooseParams; if (ImGui.Checkbox("##looseparams", ref looseparams)) { _newProjectSettings.UseLooseParams = looseparams; } ImGui.NewLine(); } if (_newProjectSettings.GameType == GameType.DarkSoulsPTDE || _newProjectSettings.GameType == GameType.DarkSoulsIISOTFS || _newProjectSettings.GameType == GameType.DarkSoulsIII || _newProjectSettings.GameType == GameType.Sekiro) { ImGui.AlignTextToFramePadding(); ImGui.Text($@"Load default row names: "); ImGui.SameLine(); ImGui.Checkbox("##loadDefaultNames", ref _newProjectLoadDefaultNames); ImGui.NewLine(); } if (ImGui.Button("Create", new Vector2(120, 0))) { bool validated = true; if (_newProjectSettings.GameRoot == null || !File.Exists(_newProjectSettings.GameRoot)) { System.Windows.Forms.MessageBox.Show("Your game executable path does not exist. Please select a valid executable.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated && _newProjectSettings.GameType == GameType.Undefined) { System.Windows.Forms.MessageBox.Show("Your game executable is not a valid supported game.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated && (_newProjectDirectory == null || !Directory.Exists(_newProjectDirectory))) { System.Windows.Forms.MessageBox.Show("Your selected project directory is not valid.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated && File.Exists($@"{_newProjectDirectory}\project.json")) { System.Windows.Forms.MessageBox.Show("Your selected project directory is already a project.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated && (_newProjectSettings.ProjectName == null || _newProjectSettings.ProjectName == "")) { System.Windows.Forms.MessageBox.Show("You must specify a project name.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } string gameroot = Path.GetDirectoryName(_newProjectSettings.GameRoot); if (_newProjectSettings.GameType == GameType.Bloodborne) { gameroot = gameroot + @"\dvdroot_ps4"; } if (!_assetLocator.CheckFilesExpanded(gameroot, _newProjectSettings.GameType)) { System.Windows.Forms.MessageBox.Show($@"The files for {_newProjectSettings.GameType} do not appear to be unpacked. Please use UDSFM for DS1:PTDE and UXM for the rest of the games to unpack the files.", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); validated = false; } if (validated) { _projectSettings = _newProjectSettings; _projectSettings.GameRoot = gameroot; _projectSettings.Serialize($@"{_newProjectDirectory}\project.json"); ChangeProjectSettings(_projectSettings, _newProjectDirectory); CFG.Current.LastProjectFile = $@"{_newProjectDirectory}\project.json"; var recent = new CFG.RecentProject(); recent.Name = _projectSettings.ProjectName; recent.GameType = _projectSettings.GameType; recent.ProjectFile = $@"{_newProjectDirectory}\project.json"; CFG.Current.RecentProjects.Insert(0, recent); if (CFG.Current.RecentProjects.Count > CFG.MAX_RECENT_PROJECTS) { CFG.Current.RecentProjects.RemoveAt(CFG.Current.RecentProjects.Count - 1); } if (_newProjectLoadDefaultNames) { ParamEditor.ParamBank.LoadParamDefaultNames(); } ImGui.CloseCurrentPopup(); } } ImGui.SameLine(); if (ImGui.Button("Cancel", new Vector2(120, 0))) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } ImGui.PopStyleVar(3); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(8, 8)); if (FirstFrame) { ImGui.SetNextWindowFocus(); } string[] paramcmds = null; if (commandsplit != null && commandsplit[0] == "param") { paramcmds = commandsplit.Skip(1).ToArray(); ImGui.SetNextWindowFocus(); } if (ImGui.Begin("Param Editor")) { _paramEditor.OnGUI(paramcmds); _paramEditorFocused = true; } else { _paramEditorFocused = false; } ImGui.End(); string[] textcmds = null; if (commandsplit != null && commandsplit[0] == "text") { textcmds = commandsplit.Skip(1).ToArray(); ImGui.SetNextWindowFocus(); } if (ImGui.Begin("Text Editor")) { _textEditor.OnGUI(textcmds); _textEditorFocused = true; } else { _textEditorFocused = false; } ImGui.End(); ImGui.PopStyleVar(); UnapplyStyle(); if (!_firstframe) { FirstFrame = false; } _firstframe = false; }