added Configs

This commit is contained in:
Tim Nebel 2023-07-20 03:54:54 +02:00
commit 697018422c
9 changed files with 142 additions and 15 deletions

View file

@ -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)

42
src/Config/Configs.cpp Normal file
View file

@ -0,0 +1,42 @@
//
// Created by tv on 19.07.23.
//
#include"Configs.h"
#include<boost/filesystem.hpp>
namespace Configs {
static std::vector<std::string> loadStringListConfig(boost::filesystem::path path) {
std::vector<std::string> cfg;
YAML::Node Yaml = YAML::LoadFile(path.generic_string());
for (auto elem: Yaml) {
cfg.push_back(elem.as<std::string>());
}
return cfg;
}
template<typename t>
static std::vector<ValueDisplayOptions<t>> loadValueDisplayConfig(boost::filesystem::path path) {
std::vector<ValueDisplayOptions<t>> cfg;
YAML::Node Yaml = YAML::LoadFile(path.generic_string());
for (auto elem: Yaml) {
cfg.push_back({elem["Val"].as<t>(), elem["Display"].as<std::string>()});
}
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<long>(gameCfgPath / "DropIds.yaml");
}
}

58
src/Config/Configs.h Normal file
View file

@ -0,0 +1,58 @@
//
// Created by tv on 19.07.23.
//
#ifndef SPOONTOOL_CONFIGS_H
#define SPOONTOOL_CONFIGS_H
#include<string>
#include<yaml-cpp/yaml.h>
#include<imgui.h>
#include<algorithm>
namespace Configs {
void g_loadConfigs(std::string game);
template<typename t>
struct ValueDisplayOptions{
t m_val;
std::string m_display;
};
inline void imguiDrawOpts(std::string id,std::vector<std::string> 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<typename t>
inline void imguiDrawOpts(std::string id,std::vector<ValueDisplayOptions<t>> opts,t &val){
auto selOpt = std::find_if(opts.begin(), opts.end(),[&](const ValueDisplayOptions<t> &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<std::string> g_linkOpts;
inline std::vector<std::string> g_areas;
inline std::vector<ValueDisplayOptions<long>> g_dropIdOpts;
}
#endif //SPOONTOOL_CONFIGS_H

View file

@ -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<Graphics::Framebuffer>(
std::vector<Graphics::FramebufferTextureInfo>{
{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();
}

View file

@ -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<std::vector<unsigned int>> PixelToObjNum;
float speed = 100.0f;

View file

@ -8,6 +8,7 @@
#include<imgui.h>
#include <IconsFontAwesome6.h>
#include<fstream>
#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() {

View file

@ -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){

View file

@ -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:

View file

@ -8,7 +8,7 @@
#include "misc/cpp/imgui_stdlib.h"
#include "IconsFontAwesome6.h"
#include<array>
#include "Config/Configs.h"
struct SimpleVec3{
float x,y,z;
template <typename t>
@ -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){