diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cb9624..f718433 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,12 +9,16 @@ add_subdirectory(deps/vgcore) add_subdirectory(Tools/MapTools) -add_executable(SpoonEdit src/main.cpp src/MainWindow.cpp src/MainWindow.h src/PropertiesWidget.cpp src/PropertiesWidget.h src/ObjectSelectWidget.cpp src/ObjectSelectWidget.h src/MainViewport.cpp src/MainViewport.h src/Model.cpp src/Model.h src/RailSelectWidget.cpp src/RailSelectWidget.h src/Config/Configs.h src/Config/Configs.cpp) +add_executable(SpoonEdit src/main.cpp src/PropertiesWidget.cpp src/PropertiesWidget.h src/ObjectSelectWidget.cpp src/ObjectSelectWidget.h src/MainViewport.cpp src/MainViewport.h src/Model.cpp src/Model.h src/RailSelectWidget.cpp src/RailSelectWidget.h src/Config/Configs.h src/Config/Configs.cpp + src/InstanceVars.h + src/Objects.cpp) set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_RELEASE "-O3") target_link_libraries(SpoonEdit PUBLIC GCore SpoonMapTools Boost::thread Boost::chrono) +target_compile_definitions(SpoonEdit PRIVATE VMIRROR_ASSEMBLYNAME="SpoonEdit") + install(TARGETS SpoonEdit CONFIGURATIONS Debug RUNTIME DESTINATION Debug diff --git a/src/InstanceVars.h b/src/InstanceVars.h new file mode 100644 index 0000000..7c614b0 --- /dev/null +++ b/src/InstanceVars.h @@ -0,0 +1,13 @@ +// +// Created by tv on 28.08.23. +// + +#ifndef SPOONTOOL_INSTANCEVARS_H +#define SPOONTOOL_INSTANCEVARS_H + +#include + +inline Map loadedMap; +inline Element* selectedElem; + +#endif //SPOONTOOL_INSTANCEVARS_H diff --git a/src/MainViewport.cpp b/src/MainViewport.cpp index 3ad6afd..429e163 100644 --- a/src/MainViewport.cpp +++ b/src/MainViewport.cpp @@ -3,7 +3,6 @@ // #include "MainViewport.h" -#include "MainWindow.h" #include #include #include "IconsFontAwesome6.h" @@ -11,6 +10,8 @@ #include #include #include"Config/Configs.h" +#include "InstanceVars.h" +#include MainViewport *MainVP; @@ -38,6 +39,10 @@ bool IsArea(const std::string& Type) { }); } +MENU_ITEM_DISPLAY(Widgets,Viewport,ICON_FA_VIDEO " Viewport"){ + Graphics::window->WidgetByName.find("Main Viewport")->second->Active ^= true; +} + MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true), VP(1.0f), defaultShader("ForwardPass"), flatShader("FlatForwardPass") { MainVP = this; @@ -213,9 +218,6 @@ void MainViewport::Draw() { glUniform4f(ObjColPos, 1, 1, 1, 1); - - auto &map = GetMainWindow()->loadedMap; - glDrawBuffer(GL_COLOR_ATTACHMENT1); GLuint ClearID[] = {0}; glClearBufferuiv(GL_COLOR, 0, ClearID); @@ -251,7 +253,7 @@ void MainViewport::Draw() { glClear(GL_DEPTH_BUFFER_BIT); - for (auto &obj: map.Objects) { + for (auto &obj: loadedMap.Objects) { if (IsArea(obj.Type)) { continue; } @@ -298,7 +300,7 @@ void MainViewport::Draw() { glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - for (auto &obj: map.Objects) { + for (auto &obj: loadedMap.Objects) { if(!flatShading) glUniform1i(TeamId,(GLint)obj.Team); @@ -327,19 +329,19 @@ void MainViewport::Draw() { auto &mdl = MdlFromObj.find(obj.Type)->second; glUniform1ui(ObjIdPos, ObjID); - if (&obj == GetMainWindow()->selectedElem) + if (&obj == selectedElem) glUniform4f(ObjColPos, 1, .7, .7, 1); mdl.Draw(obj.TF, m_internalFramebuf->m_shader, VP); - if (&obj == GetMainWindow()->selectedElem) + if (&obj == selectedElem) glUniform4f(ObjColPos, 1, 1, 1, 1); ObjID++; } - if (GetMainWindow()->selectedElem != nullptr) { - auto selobj = GetMainWindow()->selectedElem; + if (selectedElem != nullptr) { + auto selobj = selectedElem; glUniform1ui(ObjIdPos, 0); if (IsArea(selobj->Type)) { @@ -350,8 +352,8 @@ void MainViewport::Draw() { glClear(GL_DEPTH_BUFFER_BIT); - for (Link &link: GetMainWindow()->selectedElem->Links) { - Element *elem = GetMainWindow()->loadedMap.GetElementById(link.Destination); + for (Link &link: selectedElem->Links) { + Element *elem = loadedMap.GetElementById(link.Destination); if (elem == nullptr) continue; @@ -360,7 +362,7 @@ void MainViewport::Draw() { } } - if (Rail *rail = dynamic_cast(GetMainWindow()->selectedElem)) { + if (Rail *rail = dynamic_cast(selectedElem)) { RenderRail(rail); } @@ -513,7 +515,7 @@ void MainViewport::HandleInput(InputEvent event) { static glm::vec3 GizmoDir = glm::vec3(1, 1, 1); static unsigned int SpecialObjCur = 0; - auto SelObj = GetMainWindow()->selectedElem; + auto SelObj = selectedElem; switch (event.EventType) { case (InputType::MouseHover): { @@ -622,7 +624,7 @@ void MainViewport::HandleInput(InputEvent event) { obj -= 16; - GetMainWindow()->selectedElem = &GetMainWindow()->loadedMap.Objects[obj]; + selectedElem = &loadedMap.Objects[obj]; } break; case (InputType::MouseHoldL): { @@ -837,14 +839,12 @@ void MainViewport::DrawOver() { glm::vec2 MainViewport::CalcGizmoDir(glm::vec3 dir) { - auto SelObj = GetMainWindow()->selectedElem; - auto DirPos = glm::vec4(dir, 1); auto ObjPos = glm::vec4(0, 0, 0, 1); - auto tf = SelObj->TF; + auto tf = selectedElem->TF; tf.Rotation = {0, 0, 0}; tf.Scale = {1, 1, 1}; @@ -868,8 +868,6 @@ void MainViewport::clearModels() { } void MainViewport::cleanUnnescessary() { - auto &map = GetMainWindow()->loadedMap; - for(auto mdlPairIter = MdlFromObj.begin(); mdlPairIter != MdlFromObj.end(); ){ auto nextiter = mdlPairIter; nextiter++; @@ -877,7 +875,7 @@ void MainViewport::cleanUnnescessary() { if(nextiter == MdlFromObj.end()) break; - if(std::none_of(map.Objects.begin(), map.Objects.end(),[&](const LevelObject &obj){ + if(std::none_of(loadedMap.Objects.begin(), loadedMap.Objects.end(),[&](const LevelObject &obj){ return obj.Type == nextiter->first; })){ MdlFromObj.erase(nextiter); @@ -889,4 +887,6 @@ void MainViewport::cleanUnnescessary() { MainViewport *g_getMainViewport() { return MainVP; -} \ No newline at end of file +} + +REGISTERVCLASS(MainViewport) \ No newline at end of file diff --git a/src/MainViewport.h b/src/MainViewport.h index 9d423d3..683c667 100644 --- a/src/MainViewport.h +++ b/src/MainViewport.h @@ -22,6 +22,7 @@ enum GizmoType{ class MainViewport : public Graphics::ViewportWidget { public: + VCLASS(MainViewport,ESC({&Graphics::ViewportWidget::classInfo,nullptr})) MainViewport(); glm::vec3 camPos = glm::vec3(0,0,0); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp deleted file mode 100644 index ee76dfe..0000000 --- a/src/MainWindow.cpp +++ /dev/null @@ -1,199 +0,0 @@ -#include "MainWindow.h" -#include "PropertiesWidget.h" -#include "ObjectSelectWidget.h" -#include "RailSelectWidget.h" -#include "MainViewport.h" -#include -#include -#include -#include -#include -#include"Config/Configs.h" - -MainWindow* MainWindowInst = nullptr; - -void ExportObj(LevelObject obj){ - YAML::Emitter emitter; - - obj.YamlInsert(emitter); - - auto fstr = std::ofstream((boost::filesystem::current_path() / "Presets" / (obj.Name + ".yaml")).string()); - - fstr << emitter.c_str(); - fstr.flush(); - fstr.close(); -} - -MainWindow::MainWindow(): Graphics::Window("SpoonEdit") { - - MainWindowInst = this; - - auto mapSelectSaveExplorer = addWidget(new Graphics::FileSelectDialog("Select/Save Map", {".yaml"},[&](boost::filesystem::path path){ - selectedElem = nullptr; - GetMainWindow()->loadedMap = ConvertFromYaml(path); - - MainViewport* vp = g_getMainViewport(); - vp->cleanUnnescessary(); - },[&](boost::filesystem::path path){ - loadedMap.Export(path); - })); - - std::vector strvec; - boost::algorithm::split(strvec,(boost::filesystem::current_path() / "Maps").string(),boost::is_any_of("/")); - - mapSelectSaveExplorer->Path = strvec; - - addWidget(new Graphics::FileSelectDialog("Load Object from Preset", {".yaml"},[](boost::filesystem::path path){ - auto file = YAML::LoadFile(path.string()); - MainWindowInst->selectedElem = nullptr; - MainWindowInst->loadedMap.Objects.emplace_back(LevelObject(file)); - })); - - addWidget(); - - addWidget(); - - addWidget(); - - addWidget(); - - AddMenu("File"); - - AddMenuItem("File",ICON_FA_FOLDER_OPEN " Open",[](){ - auto wid = dynamic_cast(MainWindowInst->WidgetByName.find("Select/Save Map")->second); - wid->fileSelectMode = Graphics::Open; - wid->Active = true; - }); - - AddMenuItem("File",ICON_FA_FLOPPY_DISK " Save",[](){ - auto wid = dynamic_cast(MainWindowInst->WidgetByName.find("Select/Save Map")->second); - wid->fileSelectMode = Graphics::Save; - wid->Active = true; - }); - - AddMenu("Widgets"); - - AddMenuItem("Widgets",ICON_FA_VIDEO " Viewport",[](){ - MainWindowInst->WidgetByName.find("Main Viewport")->second->Active ^= true; - }); - - AddMenuItem("Widgets",ICON_FA_CUBES " Objects",[](){ - MainWindowInst->WidgetByName.find("Object Select")->second->Active ^= true; - }); - - AddMenuItem("Widgets",ICON_FA_CIRCLE_NODES " Rails",[](){ - MainWindowInst->WidgetByName.find("Rails")->second->Active ^= true; - }); - - AddMenuItem("Widgets",ICON_FA_CLIPBOARD_LIST " Properties",[](){ - MainWindowInst->WidgetByName.find("Properties")->second->Active ^= true; - }); - - AddMenu("Game"); - AddMenuItem("Game", "Gambit(1)", [&](){ - gameSetting = GameMode::Gambit; - Configs::g_loadConfigs(GameMode::ToString(gameSetting)); - g_getMainViewport()->clearModels(); - }); - AddMenuItem("Game", "Blitz(2)", [&](){ - gameSetting = GameMode::Blitz; - Configs::g_loadConfigs(GameMode::ToString(gameSetting)); - }); - AddMenuItem("Game", "Thunder(3)", [&](){ - gameSetting = GameMode::Thunder; - Configs::g_loadConfigs(GameMode::ToString(gameSetting)); - }); - - AddMenu("Object"); - - AddMenuItem("Object", ICON_FA_PLUS " Add",[](){ - auto wid = dynamic_cast(MainWindowInst->WidgetByName.find("Load Object from Preset")->second); - std::vector strvec; - boost::algorithm::split(strvec,(boost::filesystem::current_path() / "Presets").string(),boost::algorithm::is_any_of("/\\")); - - wid->Path = strvec; - wid->fileSelectMode = Graphics::Open; - wid->Active = true; - }); - - AddMenuItem("Object", ICON_FA_ANCHOR " Kotzen[!]",[&](){ - for (LevelObject &obj: loadedMap.Objects) { - if(!boost::filesystem::exists(boost::filesystem::current_path() / "Presets" / (obj.Type + ".yaml"))){ - LevelObject ObjCpy = LevelObject(obj); - ObjCpy.Name = ObjCpy.Type; - ObjCpy.Links = std::vector(); - ObjCpy.TF.Scale = {1, 1, 1}; - ObjCpy.TF.Rotation = {0, 0, 0}; - ObjCpy.TF.Position = {0, 0, 0}; - - for(int ¶m: ObjCpy.Parameters){ - param = -99; - } - - for(float ¶m: ObjCpy.FloatParameters){ - param = -99.0f; - } - - ObjCpy.Layer = "Cmn"; - - ExportObj(ObjCpy); - } - } - }); - - AddMenuItem("Object", ICON_FA_ANCHOR " Durchfall[!]",[&](){ - - for(auto& entry : boost::make_iterator_range(boost::filesystem::directory_iterator(boost::filesystem::current_path() / "Maps"), {})) { - - std::cout << "Exporting all from " << entry << std::endl; - - MainWindowInst->selectedElem = nullptr; - MainWindowInst->loadedMap = ConvertFromYaml(entry); - - for (LevelObject &obj: loadedMap.Objects) { - if (!boost::filesystem::exists(boost::filesystem::current_path() / "Presets" / (obj.Type + ".yaml"))) { - LevelObject ObjCpy = LevelObject(obj); - ObjCpy.Name = ObjCpy.Type; - ObjCpy.Links = std::vector(); - - for(int ¶m: ObjCpy.Parameters){ - param = -99; - } - - for(float ¶m: ObjCpy.FloatParameters){ - param = -99.0f; - } - - ObjCpy.Layer = "Cmn"; - - ObjCpy.TF.Scale = {1, 1, 1}; - ObjCpy.TF.Rotation = {0, 0, 0}; - ObjCpy.TF.Position = {0, 0, 0}; - - ExportObj(ObjCpy); - } - } - } - }); - - msgBoxes.push_back(new Graphics::MessageBox("Gizmos are currently broken beware of using them!")); - //msgBoxes. - //Graphics::EnableVsync(); - - Configs::g_loadConfigs("Gambit"); - - //Graphics::EnableVsync(); -} - -void MainWindow::Update() { - -} - -void MainWindow::MenuExtraRender() { - ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::CalcTextSize(("Game: " + GameMode::ToString(gameSetting) + " ").c_str()).x); - ImGui::Text("%s", ("Game: " + GameMode::ToString(gameSetting)).c_str()); -} - -MainWindow* GetMainWindow(){ - return MainWindowInst; -} \ No newline at end of file diff --git a/src/MainWindow.h b/src/MainWindow.h deleted file mode 100644 index 970e590..0000000 --- a/src/MainWindow.h +++ /dev/null @@ -1,52 +0,0 @@ -// -// Created by tv on 20.05.23. -// - -#ifndef SPOONTOOL_MAINWINDOW_H -#define SPOONTOOL_MAINWINDOW_H - -#include -#include -namespace GameMode { - enum GameMode { - Gambit, - Blitz, - Thunder - }; - - inline std::string ToString(GameMode gameMode){ - switch(gameMode){ - case Gambit: - return "Gambit"; - case Blitz: - return "Blitz"; - case Thunder: - return "Thunder"; - default: - return "Invalid"; - } - } - - inline std::array gameModes = {Gambit, Blitz, Thunder}; -} - - -class MainWindow : public Graphics::Window { -public: - MainWindow(); - - Map loadedMap; - - void Update() override; - - Element* selectedElem = nullptr; - - GameMode::GameMode gameSetting = GameMode::Gambit; -protected: - void MenuExtraRender() override; -}; - -MainWindow* GetMainWindow(); - - -#endif //SPOONTOOL_MAINWINDOW_H diff --git a/src/ObjectSelectWidget.cpp b/src/ObjectSelectWidget.cpp index 921146e..ac9332c 100644 --- a/src/ObjectSelectWidget.cpp +++ b/src/ObjectSelectWidget.cpp @@ -3,31 +3,35 @@ // #include "ObjectSelectWidget.h" -#include "MainWindow.h" #include "imgui.h" #include "misc/cpp/imgui_stdlib.h" #include "boost/filesystem.hpp" #include #include +#include"InstanceVars.h" +#include +#include "IconsFontAwesome6.h" ObjectSelectWidget* ObjectSelectWidgetInstance = nullptr; +MENU_ITEM_DISPLAY(Widgets,Objects,ICON_FA_CUBES " Objects"){ + Graphics::window->WidgetByName.find("Objects")->second->Active ^= true; +} + ObjectSelectWidget::ObjectSelectWidget(): Graphics::Widget("Object Select",true) { } void ObjectSelectWidget::Draw() { - auto wind = GetMainWindow(); - static unsigned int counter = 0; counter = 0; - for(auto &obj: wind->loadedMap.Objects){ + for(auto &obj: loadedMap.Objects){ - if(ImGui::Selectable((obj.Name + ": " + obj.Type + "##" + std::to_string(obj.runtimeID)).c_str(),wind->selectedElem == &obj)){ - wind->selectedElem = &obj; + if(ImGui::Selectable((obj.Name + ": " + obj.Type + "##" + std::to_string(obj.runtimeID)).c_str(),selectedElem == &obj)){ + selectedElem = &obj; } if(ImGui::IsMouseClicked(ImGuiMouseButton_Right) && ImGui::IsItemHovered()){ @@ -39,16 +43,16 @@ void ObjectSelectWidget::Draw() { if(ImGui::MenuItem((std::string("Delete##: ObjSelect ") + std::to_string(obj.runtimeID)).c_str())){ std::cout << "Deleting " + obj.Name << std::endl; - wind->loadedMap.Objects.erase(wind->loadedMap.Objects.begin()+counter); - wind->selectedElem = nullptr; + loadedMap.Objects.erase(loadedMap.Objects.begin()+counter); + selectedElem = nullptr; } if(ImGui::MenuItem((std::string("Duplicate##: ObjSelect ") + std::to_string(obj.runtimeID)).c_str())){ LevelObject dublObj = LevelObject(obj); dublObj.runtimeID = rand(); - wind->loadedMap.Objects.emplace_back(dublObj); - wind->selectedElem = nullptr; + loadedMap.Objects.emplace_back(dublObj); + selectedElem = nullptr; } if(ImGui::MenuItem((std::string("Export##: ObjSelect ") + std::to_string(obj.runtimeID)).c_str())){ @@ -72,4 +76,6 @@ void ObjectSelectWidget::Draw() { ObjectSelectWidget* GetObjectSelectWidget(){ return ObjectSelectWidgetInstance; -} \ No newline at end of file +} + +REGISTERVCLASS(ObjectSelectWidget) \ No newline at end of file diff --git a/src/ObjectSelectWidget.h b/src/ObjectSelectWidget.h index 174357d..f1f7b15 100644 --- a/src/ObjectSelectWidget.h +++ b/src/ObjectSelectWidget.h @@ -10,6 +10,7 @@ class ObjectSelectWidget: public Graphics::Widget { public: + VCLASS(ObjectSelectWidget,ESC({&Graphics::Widget::classInfo,nullptr})) ObjectSelectWidget(); private: diff --git a/src/Objects.cpp b/src/Objects.cpp new file mode 100644 index 0000000..056eea9 --- /dev/null +++ b/src/Objects.cpp @@ -0,0 +1,15 @@ +#include +#include +#include +#include +#include "virintox/gcore/gui/FileSelectDialog.h" + +MENU_ITEM_DISPLAY(Object,Add,ICON_FA_PLUS " Add"){ + auto wid = dynamic_cast(Graphics::window->WidgetByName.find("Load Object from Preset")->second); + std::vector strvec; + boost::algorithm::split(strvec,(boost::filesystem::current_path() / "Presets").string(),boost::algorithm::is_any_of("/\\")); + + wid->Path = strvec; + wid->fileSelectMode = Graphics::Open; + wid->Active = true; +} \ No newline at end of file diff --git a/src/PropertiesWidget.cpp b/src/PropertiesWidget.cpp index 821f23f..6da1a6e 100644 --- a/src/PropertiesWidget.cpp +++ b/src/PropertiesWidget.cpp @@ -3,12 +3,17 @@ // #include "PropertiesWidget.h" -#include "MainWindow.h" #include #include "misc/cpp/imgui_stdlib.h" -#include "IconsFontAwesome6.h" #include #include "Config/Configs.h" +#include +#include +#include +#include +#include"InstanceVars.h" +#include +#include "IconsFontAwesome6.h" struct SimpleVec3 { float x, y, z; @@ -30,6 +35,10 @@ struct SimpleVec3 { PropertiesWidget *PropertiesWidgetInst = nullptr; +MENU_ITEM_DISPLAY(Widgets,Properties,ICON_FA_CLIPBOARD_LIST " Properties"){ + Graphics::window->WidgetByName.find("Properties")->second->Active ^= true; +} + template void ImGuiDrawSelection(std::string id, t &val, iter optsBegin, iter optsEnd, stringConv convert) { @@ -115,10 +124,10 @@ void ImGuiDrawElem(Element *elem, std::string Id = "") { Configs::g_imguiDrawOpts("Link Type##" + std::to_string(i) + Id, Configs::g_linkOpts, link.Name); ImGui::InputText(("Destination##PropWindLink" + std::to_string(i) + Id).c_str(), &link.Destination); - if (Element *gotoElem = GetMainWindow()->loadedMap.GetElementById(link.Destination)) { + if (Element *gotoElem = loadedMap.GetElementById(link.Destination)) { ImGui::SameLine(); if (ImGui::Button((ICON_FA_CHEVRON_RIGHT + std::string("##GotoDest") + std::to_string(i)).c_str())) { - GetMainWindow()->selectedElem = gotoElem; + selectedElem = gotoElem; } } @@ -174,13 +183,13 @@ void ImGuiDrawElem(Element *elem, std::string Id = "") { } if (rail->Points.empty()) { - auto &map = GetMainWindow()->loadedMap; + auto &map = loadedMap; std::erase_if(map.Rails, [&](const Rail &rail1) { return rail1.runtimeID == rail->runtimeID; }); - GetMainWindow()->selectedElem = nullptr; + selectedElem = nullptr; } ImGui::Unindent(); } @@ -267,17 +276,17 @@ void ImGuiDrawElem(Element *elem, std::string Id = "") { PropertiesWidget::PropertiesWidget() : Graphics::Widget("Properties", true) { PropertiesWidgetInst = this; - GetMainWindow()->selectedElem = nullptr; + selectedElem = nullptr; } void PropertiesWidget::Draw() { - auto wind = GetMainWindow(); - - if (wind->selectedElem != nullptr) { - ImGuiDrawElem(wind->selectedElem); + if (selectedElem != nullptr) { + ImGuiDrawElem(selectedElem); } } PropertiesWidget *GetPropertiesWidget() { return PropertiesWidgetInst; -} \ No newline at end of file +} + +REGISTERVCLASS(PropertiesWidget) \ No newline at end of file diff --git a/src/PropertiesWidget.h b/src/PropertiesWidget.h index 7a23fd2..e341480 100644 --- a/src/PropertiesWidget.h +++ b/src/PropertiesWidget.h @@ -10,6 +10,7 @@ class PropertiesWidget : public Graphics::Widget { public: + VCLASS(PropertiesWidget,ESC({&Graphics::Widget::classInfo,nullptr})) PropertiesWidget(); void Draw() override; diff --git a/src/RailSelectWidget.cpp b/src/RailSelectWidget.cpp index 4861d6b..a5dd634 100644 --- a/src/RailSelectWidget.cpp +++ b/src/RailSelectWidget.cpp @@ -3,22 +3,26 @@ // #include "RailSelectWidget.h" -#include "MainWindow.h" #include #include "IconsFontAwesome6.h" #include "MainViewport.h" +#include "InstanceVars.h" +#include +#include "IconsFontAwesome6.h" + +MENU_ITEM_DISPLAY(Widgets,Rails,ICON_FA_CIRCLE_NODES " Rails"){ + Graphics::window->WidgetByName.find("Rails")->second->Active ^= true; +} RailSelectWidget::RailSelectWidget(): Graphics::Widget("Rails",false) { } void RailSelectWidget::Draw() { - auto wind = GetMainWindow(); - - for(auto railIter = wind->loadedMap.Rails.begin();railIter != wind->loadedMap.Rails.end();railIter++){ + for(auto railIter = loadedMap.Rails.begin();railIter != loadedMap.Rails.end();railIter++){ Rail &rail = *railIter; - if(ImGui::Selectable((rail.Name + ": " + rail.Type + "##" + std::to_string(rail.runtimeID)).c_str(), wind->selectedElem == &rail)){ - wind->selectedElem = &rail; + if(ImGui::Selectable((rail.Name + ": " + rail.Type + "##" + std::to_string(rail.runtimeID)).c_str(), selectedElem == &rail)){ + selectedElem = &rail; } if(ImGui::IsMouseClicked(ImGuiMouseButton_Right) && ImGui::IsItemHovered()){ @@ -28,8 +32,8 @@ void RailSelectWidget::Draw() { if(ImGui::BeginPopup((std::string("Right Click Menu: RailSelect ") + std::to_string(rail.runtimeID)).c_str())){ if(ImGui::MenuItem((std::string("Delete##: RailSelect ") + std::to_string(rail.runtimeID)).c_str())){ std::cout << "Deleting " + rail.Name << std::endl; - wind->loadedMap.Rails.erase(railIter); - wind->selectedElem = nullptr; + loadedMap.Rails.erase(railIter); + selectedElem = nullptr; ImGui::EndPopup(); break; } @@ -39,10 +43,12 @@ void RailSelectWidget::Draw() { } if(ImGui::Button(ICON_FA_PLUS)){ - wind->selectedElem = nullptr; + selectedElem = nullptr; auto vp = g_getMainViewport(); Vector3 pos = {vp->camPos.x, -vp->camPos.y, vp->camPos.z}; - wind->loadedMap.Rails.emplace_back(pos); + loadedMap.Rails.emplace_back(pos); } } + +REGISTERVCLASS(RailSelectWidget) \ No newline at end of file diff --git a/src/RailSelectWidget.h b/src/RailSelectWidget.h index a9cd4b3..af3dd38 100644 --- a/src/RailSelectWidget.h +++ b/src/RailSelectWidget.h @@ -10,6 +10,7 @@ class RailSelectWidget: public Graphics::Widget { public: + VCLASS(RailSelectWidget,ESC({&Graphics::Widget::classInfo,nullptr})) RailSelectWidget(); void Draw() override; diff --git a/src/main.cpp b/src/main.cpp index 4b4ab9d..18c499a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,55 @@ #include -#include"MainWindow.h" #include"imgui.h" +#include "virintox/gcore/gui/FileSelectDialog.h" +#include "InstanceVars.h" +#include "Map.h" +#include "MainViewport.h" +#include "Config/Configs.h" +#include +#include + +VMIRRORASSEMBLYSELFREGISTER(SpoonEdit, VMIRRORVERSION(0,1,0,0),VMirror::AssemblyType::Executable) + +VGINIT_ACTION(LoadConfigs){ + Configs::g_loadConfigs("Gambit"); +} + +VGINIT_ACTION(AddMapSelector){ + Graphics::window->addWidget(new Graphics::FileSelectDialog("Select/Save Map", {".yaml"},[&](boost::filesystem::path path){ + selectedElem = nullptr; + loadedMap = ConvertFromYaml(path); + + MainViewport* vp = g_getMainViewport(); + vp->cleanUnnescessary(); + },[&](boost::filesystem::path path){ + loadedMap.Export(path); + })); +} + +VGINIT_ACTION(AddObjSelector){ + Graphics::window->addWidget(new Graphics::FileSelectDialog("Load Object from Preset", {".yaml"},[](boost::filesystem::path path){ + auto file = YAML::LoadFile(path.string()); + selectedElem = nullptr; + loadedMap.Objects.emplace_back(LevelObject(file)); + })); +} + +MENU_ITEM_DISPLAY(File,Open,ICON_FA_FOLDER_OPEN " Open"){ + auto wid = dynamic_cast(Graphics::window->WidgetByName.find("Select/Save Map")->second); + wid->fileSelectMode = Graphics::Open; + wid->Active = true; +} + +MENU_ITEM_DISPLAY(File,Save,ICON_FA_FLOPPY_DISK " Save"){ + auto wid = dynamic_cast(Graphics::window->WidgetByName.find("Select/Save Map")->second); + wid->fileSelectMode = Graphics::Save; + wid->Active = true; +} + +SORT_MENU(File,0) +SORT_MENU(Widgets,1) +SORT_MENU(Object,2) + int main(){ - Graphics::Init(); - Graphics::setWindow(); - - //auto &io = ImGui::GetIO(); - - //io.ConfigWindowsMoveFromTitleBarOnly = true; - Graphics::BeginLoop(); - Graphics::Terminate(); + Graphics::AutoInit("SpoonEdit"); } \ No newline at end of file