Skip to content

Commit

Permalink
add Open and Save As dialogs
Browse files Browse the repository at this point in the history
how was this basic shit missing for so long
  • Loading branch information
wootguy committed Apr 23, 2024
1 parent 28da71e commit 17d58ea
Show file tree
Hide file tree
Showing 6 changed files with 8,537 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ set(SOURCE_FILES
imgui/backends/imgui_impl_opengl3.cpp
src/util/lodepng.h
src/util/lodepng.cpp
src/util/tinyfiledialogs.c
src/util/tinyfiledialogs.h
)

include_directories(src)
Expand Down
33 changes: 28 additions & 5 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "globals.h"
#include <fstream>
#include <set>
#include "tinyfiledialogs.h"

// embedded binary data
#include "fonts/robotomono.h"
Expand Down Expand Up @@ -671,13 +672,38 @@ void Gui::drawMenuBar() {

if (ImGui::BeginMenu("File"))
{
static char const* bspFilterPatterns[1] = { "*.bsp" };

if (ImGui::MenuItem("Reload", 0, false, !app->isLoading)) {
app->reloadMaps();
refresh();
}

if (ImGui::MenuItem("Open", NULL)) {
char* fname = tinyfd_openFileDialog("Open Map", "",
1, bspFilterPatterns, "GoldSrc Map Files (*.bsp)", 1);

g_app->openMap(fname);
}
if (ImGui::MenuItem("Save", NULL)) {
Bsp* map = app->getMapContainingCamera()->map;
map->update_ent_lump();
//map->write("yabma_move.bsp");
//map->write("D:/Steam/steamapps/common/Sven Co-op/svencoop_addon/maps/yabma_move.bsp");
map->write(map->path);
}
if (ImGui::MenuItem("Save As...", NULL)) {
Bsp* map = app->getMapContainingCamera()->map;

char* fname = tinyfd_saveFileDialog("Save As", map->path.c_str(),
1, bspFilterPatterns, "GoldSrc Map Files (*.bsp)");

if (fname) {
map->update_ent_lump();
map->path = fname;
map->write(map->path);
}
}
/*
if (ImGui::BeginMenu("Export")) {
if (ImGui::MenuItem("Entity file", NULL)) {
Expand Down Expand Up @@ -802,10 +828,7 @@ void Gui::drawMenuBar() {
}
*/

if (ImGui::MenuItem("Reload", 0, false, !app->isLoading)) {
app->reloadMaps();
refresh();
}

if (ImGui::MenuItem("Validate")) {
for (int i = 0; i < app->mapRenderers.size(); i++) {
Bsp* map = app->mapRenderers[i]->map;
Expand Down Expand Up @@ -951,7 +974,7 @@ void Gui::drawMenuBar() {
logf("Transform the worldspawn origin first using the transform widget!\n");
}
}
tooltip(g, "Moves BSP data by the amount set in the worldspawn origin keyvalue. Useful for adjusting OOB deletes or for alignining maps before merging.");
tooltip(g, "Moves BSP data by the amount set in the worldspawn origin keyvalue. Useful for aligning maps before merging.");

if (ImGui::BeginMenu("Delete OOB Data", !app->isLoading && mapSelected)) {

Expand Down
23 changes: 21 additions & 2 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void Renderer::renderLoop() {
if (glfwGetTime( ) - lastTitleTime > 0.1)
{
lastTitleTime = glfwGetTime( );
glfwSetWindowTitle(window, std::string(std::string("bspguy - ") + getMapContainingCamera()->map->path).c_str());
glfwSetWindowTitle(window, (getMapContainingCamera()->map->path + std::string(std::string(" - bspguy"))).c_str());
}
glfwPollEvents();

Expand Down Expand Up @@ -534,6 +534,25 @@ void Renderer::reloadMaps() {
logf("Reloaded maps\n");
}

void Renderer::openMap(const char* fpath) {
if (!fpath) {
return;
}
if (!fileExists(fpath)) {
logf("File does not exist: %s\n", fpath);
return;
}

mapRenderers.clear();
pickInfo.valid = false;
addMap(new Bsp(fpath));

clearUndoCommands();
clearRedoCommands();

logf("Loaded map: %s\n", fpath);
}

void Renderer::saveSettings() {
g_settings.debug_open = gui->showDebugWidget;
g_settings.keyvalue_open = gui->showKeyvalueWidget;
Expand Down Expand Up @@ -2835,7 +2854,7 @@ void Renderer::saveLumpState(Bsp* map, int targetLumps, bool deleteOldState) {
}

void Renderer::pushEntityUndoState(string actionDesc) {
if (!pickInfo.valid || !pickInfo.ent) {
if (!pickInfo.valid || !pickInfo.ent || !undoEntityState) {
logf("Invalid entity undo state push\n");
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/editor/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Renderer {
void postLoadFgdsAndTextures();
void postLoadFgds();
void reloadMaps();
void openMap(const char* path);
void saveSettings();
void loadSettings();

Expand Down
Loading

0 comments on commit 17d58ea

Please sign in to comment.