diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cd16ff..891b385 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ 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) +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) target_link_libraries(SpoonEdit PUBLIC GCore SpoonMapTools Boost::thread Boost::chrono) diff --git a/src/Config/Configs.cpp b/src/Config/Configs.cpp new file mode 100644 index 0000000..67e69ad --- /dev/null +++ b/src/Config/Configs.cpp @@ -0,0 +1,42 @@ +// +// Created by tv on 19.07.23. +// +#include"Configs.h" +#include + +namespace Configs { + static std::vector loadStringListConfig(boost::filesystem::path path) { + std::vector cfg; + + YAML::Node Yaml = YAML::LoadFile(path.generic_string()); + + for (auto elem: Yaml) { + cfg.push_back(elem.as()); + } + + return cfg; + } + + template + static std::vector> loadValueDisplayConfig(boost::filesystem::path path) { + std::vector> cfg; + + YAML::Node Yaml = YAML::LoadFile(path.generic_string()); + + for (auto elem: Yaml) { + cfg.push_back({elem["Val"].as(), elem["Display"].as()}); + } + + return cfg; + } + + void g_loadConfigs(std::string game) { + boost::filesystem::path gameCfgPath = boost::filesystem::current_path() / "Configs" / game; + + g_linkOpts = loadStringListConfig(gameCfgPath / "Links.yaml"); + g_areas = loadStringListConfig(gameCfgPath / "Areas.yaml"); + g_dropIdOpts = loadValueDisplayConfig(gameCfgPath / "DropIds.yaml"); + } + + +} \ No newline at end of file diff --git a/src/Config/Configs.h b/src/Config/Configs.h new file mode 100644 index 0000000..36a6e8a --- /dev/null +++ b/src/Config/Configs.h @@ -0,0 +1,58 @@ +// +// Created by tv on 19.07.23. +// + +#ifndef SPOONTOOL_CONFIGS_H +#define SPOONTOOL_CONFIGS_H + +#include +#include +#include +#include + +namespace Configs { + void g_loadConfigs(std::string game); + + template + struct ValueDisplayOptions{ + t m_val; + std::string m_display; + }; + + inline void imguiDrawOpts(std::string id,std::vector opts,std::string &val){ + if(ImGui::BeginCombo(id.c_str(),val.c_str())){ + for(const std::string &opt: opts) { + if (ImGui::Selectable((opt + "##" + id).c_str())) + val = opt; + } + + ImGui::EndCombo(); + } + } + + template + inline void imguiDrawOpts(std::string id,std::vector> opts,t &val){ + auto selOpt = std::find_if(opts.begin(), opts.end(),[&](const ValueDisplayOptions &opt){ + return val == opt.m_val; + }); + + if(ImGui::BeginCombo(id.c_str(),selOpt->m_display.c_str())){ + for(const auto &opt: opts) { + if (ImGui::Selectable((opt.m_display + "##" + id).c_str())) + val = opt.m_val; + } + + ImGui::EndCombo(); + } + } + + inline std::vector g_linkOpts; + inline std::vector g_areas; + inline std::vector> g_dropIdOpts; + + + +} + + +#endif //SPOONTOOL_CONFIGS_H diff --git a/src/MainViewport.cpp b/src/MainViewport.cpp index 001e235..08d6997 100644 --- a/src/MainViewport.cpp +++ b/src/MainViewport.cpp @@ -46,7 +46,7 @@ bool IsArea(const std::string& Type) { return false; } -MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true), VP(1.0f) { +MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true), VP(1.0f), defaultShader("ForwardPass"), flatShader("FlatForwardPass") { MainVP = this; @@ -57,14 +57,14 @@ MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true), {GL_RGBA16F, GL_RGBA, GL_FLOAT, GL_COLOR_ATTACHMENT2}, {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL_ATTACHMENT} }, - Graphics::Shader("ForwardPass")); + defaultShader); SunCam = std::make_unique( std::vector{ {GL_DEPTH_COMPONENT16,GL_DEPTH_COMPONENT,GL_FLOAT,GL_DEPTH_ATTACHMENT} }, Graphics::Shader("ShadowPass"), - Math::Vector2i(16384,16384)); + Math::Vector2i(8192,8192)); auto tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT); glBindTexture(GL_TEXTURE_2D, tex.m_texture.getId()); @@ -99,10 +99,11 @@ void MainViewport::RenderRail(Rail *rail) { void MainViewport::Draw() { -#ifndef NDEBUG - glClearColor(.2, .2, .2, 1); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -#endif + + if(greenScreen) { + glClearColor(0, 1, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + } m_internalFramebuf->m_shader.use(); @@ -192,6 +193,16 @@ void MainViewport::Draw() { //ImGui::SliderFloat("Shading Effectiveness", &ShadingEffectiveness, 0, 1); ImGui::DragFloat3("Light Direction", &LightDir.x, 0.01); ImGui::Checkbox("Draw All Areas", &drawAllAreas); + ImGui::Checkbox("Green Screen", &greenScreen); + if(ImGui::Button("Switch Shading Modes")){ + if(flatShading) + m_internalFramebuf->m_shader = defaultShader; + else + m_internalFramebuf->m_shader = flatShader; + + + flatShading = !flatShading; + } ImGui::EndPopup(); } diff --git a/src/MainViewport.h b/src/MainViewport.h index 1202d0c..7440003 100644 --- a/src/MainViewport.h +++ b/src/MainViewport.h @@ -29,8 +29,16 @@ public: float shadowArea = 750.0f; + Graphics::Shader flatShader; + Graphics::Shader defaultShader; + + bool flatShading = false; + + float fov = 90.0f; + bool greenScreen = false; + //std::vector> PixelToObjNum; float speed = 100.0f; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c64ff3c..a982433 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -8,6 +8,7 @@ #include #include #include +#include"Config/Configs.h" MainWindow* MainWindowInst = nullptr; @@ -88,12 +89,15 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") { AddMenu("Game"); AddMenuItem("Game", "Gambit(1)", [&](){ gameSetting = GameMode::Gambit; + Configs::g_loadConfigs(GameMode::ToString(gameSetting)); }); 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"); @@ -170,7 +174,12 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") { msgBoxes.push_back(new Graphics::MessageBox("Gizmos are currently broken beware of using them!")); //msgBoxes. - Graphics::EnableVsync(); + //Graphics::EnableVsync(); + + Configs::g_loadConfigs("Gambit"); + + glfwMakeContextCurrent(GetGlfwWindow()); + glfwSwapInterval(0); } void MainWindow::Update() { diff --git a/src/Model.cpp b/src/Model.cpp index 8b58bee..dfcada4 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -82,7 +82,7 @@ Model::Model(std::string modelname) { } } -void Model::Draw(Transform tf, Graphics::Shader &shader, glm::mat4 VP) { +void Model::Draw(const Transform &tf, Graphics::Shader &shader, const glm::mat4 &VP) { unsigned int texnum = 0; for(auto& mesh: Meshes){ diff --git a/src/Model.h b/src/Model.h index 6644418..740354c 100644 --- a/src/Model.h +++ b/src/Model.h @@ -22,7 +22,7 @@ public: unsigned *CopyCount; - void Draw(Transform tf, Graphics::Shader &shader, glm::mat4 VP); + void Draw(const Transform &tf, Graphics::Shader &shader, const glm::mat4 &VP); void DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP); protected: diff --git a/src/PropertiesWidget.cpp b/src/PropertiesWidget.cpp index 7fe1cf3..e3bfd82 100644 --- a/src/PropertiesWidget.cpp +++ b/src/PropertiesWidget.cpp @@ -8,7 +8,7 @@ #include "misc/cpp/imgui_stdlib.h" #include "IconsFontAwesome6.h" #include - +#include "Config/Configs.h" struct SimpleVec3{ float x,y,z; template @@ -107,8 +107,7 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){ auto &link = *linkIter; if (ImGui::CollapsingHeader(("Link " + std::to_string(i) + "##" + Id).c_str())) { ImGui::Indent(); - ImGuiDrawSelection("Link Type##" + std::to_string(i) + Id, link.Name, LinkTypes.begin(), LinkTypes.end(), - [](std::string s) { return s; }); + Configs::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)) { @@ -172,7 +171,7 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){ if(levelObject) { //ImGuiDrawTeamSelect(levelObject,Id); ImGuiDrawSelection("Team##"+Id,levelObject->Team,Teams::AllOptions.begin(), Teams::AllOptions.end(),Teams::TeamToText); - ImGuiDrawSelection("Drop##"+Id,levelObject->DropId,DropId::AllOptions.begin(), DropId::AllOptions.end(),DropId::DropIdToText); + Configs::imguiDrawOpts("Drop##"+Id, Configs::g_dropIdOpts,levelObject->DropId); } if(railPoint){