Skip to content

Commit

Permalink
SystemEditor: improve new system modal
Browse files Browse the repository at this point in the history
- Better interaction for creating new system / loading existing from Galaxy
- Set minimum vertical size for new system modal
- Fix crash when sorting bodies without system loaded
- Don't clear the current system unless replacing it with a new/loaded system
  • Loading branch information
sturnclaw committed Oct 14, 2023
1 parent 3ef35f1 commit 20d0a7b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
37 changes: 20 additions & 17 deletions src/editor/system/SystemEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,28 @@ void SystemEditor::RegisterMenuActions()

m_menuBinder->AddAction("New", {
"New System", ImGuiKey_N | ImGuiKey_ModCtrl,
sigc::mem_fun(this, &SystemEditor::ActivateNewSystemDialog)
[&]() {
if (HasUnsavedChanges()) {
m_unsavedFileModal = m_app->PushModal<UnsavedFileModal>();
m_pendingFileReq = FileRequest_New;
return;
}

ActivateNewSystemDialog();
}
});

m_menuBinder->AddAction("Open", {
"Open File", ImGuiKey_O | ImGuiKey_ModCtrl,
sigc::mem_fun(this, &SystemEditor::ActivateOpenDialog)
[&]() {
if (HasUnsavedChanges()) {
m_unsavedFileModal = m_app->PushModal<UnsavedFileModal>();
m_pendingFileReq = FileRequest_Open;
return;
}

ActivateOpenDialog();
}
});

m_menuBinder->AddAction("Save", {
Expand Down Expand Up @@ -457,7 +473,8 @@ void SystemEditor::RegisterMenuActions()
m_menuBinder->EndGroup();

m_menuBinder->AddAction("Sort", {
"Sort Bodies", {},
"Sort Bodies", ImGuiKey_None,
[&]() { return m_system.Valid(); },
[&]() { m_pendingOp.type = BodyRequest::TYPE_Resort; }
});

Expand Down Expand Up @@ -496,12 +513,6 @@ void SystemEditor::OnSaveComplete(bool success)

void SystemEditor::ActivateOpenDialog()
{
if (HasUnsavedChanges()) {
m_unsavedFileModal = m_app->PushModal<UnsavedFileModal>();
m_pendingFileReq = FileRequest_Open;
return;
}

// FIXME: need to handle loading files outside of game data dir
m_openFile.reset(new pfd::open_file(
"Open Custom System File",
Expand Down Expand Up @@ -531,12 +542,6 @@ void SystemEditor::ActivateSaveDialog()

void SystemEditor::ActivateNewSystemDialog()
{
if (HasUnsavedChanges()) {
m_unsavedFileModal = m_app->PushModal<UnsavedFileModal>();
m_pendingFileReq = FileRequest_New;
return;
}

m_newSystemModal = m_app->PushModal<NewSystemModal>(this, &m_newSystemPath);
}

Expand Down Expand Up @@ -615,12 +620,10 @@ void SystemEditor::Update(float deltaTime)
void SystemEditor::HandlePendingFileRequest()
{
if (m_pendingFileReq == FileRequest_New) {
ClearSystem();
ActivateNewSystemDialog();
}

if (m_pendingFileReq == FileRequest_Open) {
ClearSystem();
ActivateOpenDialog();
}

Expand Down
30 changes: 18 additions & 12 deletions src/editor/system/SystemEditorModals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ NewSystemModal::NewSystemModal(EditorApp *app, SystemEditor *editor, SystemPath

void NewSystemModal::Draw()
{
ImVec2 windSize = ImVec2(ImGui::GetMainViewport()->Size.x * 0.5, -1);
ImGui::SetNextWindowSizeConstraints(windSize, windSize);
ImVec2 vpSize = ImGui::GetMainViewport()->Size;
ImVec2 windSize = ImVec2(vpSize.x * 0.5, vpSize.y * 0.333);
ImVec2 windSizeMax = ImVec2(vpSize.x * 0.5, vpSize.y * 0.5);
ImGui::SetNextWindowSizeConstraints(windSize, windSizeMax);

Modal::Draw();
}
Expand All @@ -89,9 +91,9 @@ void NewSystemModal::DrawInternal()
{
if (Draw::LayoutHorizontal("Sector", 3, ImGui::GetFontSize())) {
bool changed = false;
changed |= ImGui::InputInt("X", &m_path->sectorX, 0, 0);
changed |= ImGui::InputInt("Y", &m_path->sectorY, 0, 0);
changed |= ImGui::InputInt("Z", &m_path->sectorZ, 0, 0);
changed |= ImGui::InputInt("X", &m_path->sectorX, 1, 0);
changed |= ImGui::InputInt("Y", &m_path->sectorY, 1, 0);
changed |= ImGui::InputInt("Z", &m_path->sectorZ, 1, 0);

if (changed)
m_path->systemIndex = 0;
Expand Down Expand Up @@ -127,6 +129,17 @@ void NewSystemModal::DrawInternal()
ImGui::CloseCurrentPopup();
}

ImGui::SetItemTooltip("Create a new empty system in this sector.");

ImGui::SameLine();

if (ImGui::Button("Edit Selected")) {
m_editor->LoadSystem(m_path->SystemOnly());
ImGui::CloseCurrentPopup();
}

ImGui::SetItemTooltip("Load the selected system as a template.");

ImGui::EndGroup();

ImGui::SameLine();
Expand All @@ -140,13 +153,6 @@ void NewSystemModal::DrawInternal()
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted(system.GetName().c_str());

ImGui::SameLine();
ImGui::SameLine(0.f, ImGui::GetContentRegionAvail().x - ImGui::GetFrameHeight());
if (ImGui::Button(EICON_FORWARD1)) {
m_editor->LoadSystem(m_path->SystemOnly());
ImGui::CloseCurrentPopup();
}

ImGui::PopFont();

ImGui::Spacing();
Expand Down

0 comments on commit 20d0a7b

Please sign in to comment.