Begin to prototype many things.
This commit is contained in:
parent
42530ce824
commit
84450d25af
@ -12,6 +12,7 @@ set(PRECOMPILE_HEADERS
|
|||||||
set(SOURCE_HEADERS
|
set(SOURCE_HEADERS
|
||||||
include/imgui/imconfig.h
|
include/imgui/imconfig.h
|
||||||
include/imgui/imgui.h
|
include/imgui/imgui.h
|
||||||
|
include/imgui/imgui_stdlib.h
|
||||||
include/imgui/imgui_impl_glfw.h
|
include/imgui/imgui_impl_glfw.h
|
||||||
include/imgui/imgui_impl_opengl3.h
|
include/imgui/imgui_impl_opengl3.h
|
||||||
include/imgui/imgui_impl_opengl3_loader.h
|
include/imgui/imgui_impl_opengl3_loader.h
|
||||||
@ -28,10 +29,14 @@ set(SOURCE_HEADERS
|
|||||||
include/characteristic/endurance.hpp
|
include/characteristic/endurance.hpp
|
||||||
include/characteristic/chance.hpp
|
include/characteristic/chance.hpp
|
||||||
include/gui/menu/menu.hpp
|
include/gui/menu/menu.hpp
|
||||||
include/gui/menu/menu_data.hpp include/characteristic/characteristic.hpp)
|
include/gui/menu/menu_data.hpp
|
||||||
|
include/characteristic/characteristic.hpp
|
||||||
|
include/controller.hpp
|
||||||
|
)
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
src/imgui/imgui.cpp
|
src/imgui/imgui.cpp
|
||||||
|
src/imgui/imgui_stdlib.cpp
|
||||||
src/imgui/imgui_draw.cpp
|
src/imgui/imgui_draw.cpp
|
||||||
src/imgui/imgui_impl_glfw.cpp
|
src/imgui/imgui_impl_glfw.cpp
|
||||||
src/imgui/imgui_impl_opengl3.cpp
|
src/imgui/imgui_impl_opengl3.cpp
|
||||||
@ -46,6 +51,7 @@ set(SOURCE_FILES
|
|||||||
src/characteristic/endurance.cpp
|
src/characteristic/endurance.cpp
|
||||||
src/characteristic/chance.cpp
|
src/characteristic/chance.cpp
|
||||||
src/gui/menu/menu.cpp
|
src/gui/menu/menu.cpp
|
||||||
|
src/controller.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
|
@ -7,9 +7,14 @@
|
|||||||
#include "characteristic/habilete.hpp"
|
#include "characteristic/habilete.hpp"
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
|
namespace gui {
|
||||||
|
class Gui;
|
||||||
|
}
|
||||||
|
|
||||||
namespace character {
|
namespace character {
|
||||||
class CharacterSheet final {
|
class CharacterSheet final {
|
||||||
private:
|
private:
|
||||||
|
friend gui::Gui;
|
||||||
std::mt19937_64 engine{ std::random_device{ "rdseed" }() };
|
std::mt19937_64 engine{ std::random_device{ "rdseed" }() };
|
||||||
|
|
||||||
std::string caractere{};
|
std::string caractere{};
|
||||||
@ -70,7 +75,7 @@ namespace character {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void to_json(json &j, const CharacterSheet &billy) {
|
static void to_json(json &j, const CharacterSheet &billy) {
|
||||||
j["caractere"] = billy.get_caractere();
|
j["caractere"] = billy.get_caractere();
|
||||||
j["adresse"] = billy.get_adresse();
|
j["adresse"] = billy.get_adresse();
|
||||||
j["endurance"] = billy.get_endurance();
|
j["endurance"] = billy.get_endurance();
|
||||||
|
@ -18,7 +18,7 @@ namespace character::characteristic {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void to_json(json &j, const Adresse &adresse) {
|
static void to_json(json &j, const Adresse &adresse) {
|
||||||
to_json(j, static_cast<Characteristic>(adresse));
|
to_json(j, static_cast<Characteristic>(adresse));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ namespace character::characteristic {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void to_json(json &j, const Chance &chance) {
|
static void to_json(json &j, const Chance &chance) {
|
||||||
to_json(j, static_cast<Characteristic>(chance));
|
to_json(j, static_cast<Characteristic>(chance));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ namespace character::characteristic {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void to_json(json &j, const Characteristic &charac) {
|
static void to_json(json &j, const Characteristic &charac) {
|
||||||
j["base"] = charac.get_base();
|
j["base"] = charac.get_base();
|
||||||
j["carac"] = charac.get_carac();
|
j["carac"] = charac.get_carac();
|
||||||
j["materiel"] = charac.get_materiel();
|
j["materiel"] = charac.get_materiel();
|
||||||
|
@ -20,7 +20,7 @@ namespace character::characteristic {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void to_json(json &j, const Endurance &endurance) {
|
static void to_json(json &j, const Endurance &endurance) {
|
||||||
to_json(j, static_cast<Characteristic>(endurance));
|
to_json(j, static_cast<Characteristic>(endurance));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace character::characteristic {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void to_json(json &j, const Habilete &habilete) {
|
static void to_json(json &j, const Habilete &habilete) {
|
||||||
to_json(j, static_cast<Characteristic>(habilete));
|
to_json(j, static_cast<Characteristic>(habilete));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
include/controller.hpp
Normal file
10
include/controller.hpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef BILLYSHEET_CONTROLLER_HPP
|
||||||
|
#define BILLYSHEET_CONTROLLER_HPP
|
||||||
|
|
||||||
|
|
||||||
|
class Controller {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //BILLYSHEET_CONTROLLER_HPP
|
@ -18,7 +18,7 @@ namespace gui {
|
|||||||
|
|
||||||
menu::Menu menu;
|
menu::Menu menu;
|
||||||
|
|
||||||
fs::path font;
|
const fs::path font;
|
||||||
|
|
||||||
bool initialized{ false };
|
bool initialized{ false };
|
||||||
public:
|
public:
|
||||||
|
22
include/imgui/imgui_stdlib.h
Normal file
22
include/imgui/imgui_stdlib.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.)
|
||||||
|
// This is also an example of how you may wrap your own similar types.
|
||||||
|
|
||||||
|
// Compatibility:
|
||||||
|
// - std::string support is only guaranteed to work from C++11.
|
||||||
|
// If you try to use it pre-C++11, please share your findings (w/ info about compiler/architecture)
|
||||||
|
|
||||||
|
// Changelog:
|
||||||
|
// - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace ImGui
|
||||||
|
{
|
||||||
|
// ImGui::InputText() with std::string
|
||||||
|
// Because text input needs dynamic resizing, we need to setup a callback to grow the capacity
|
||||||
|
IMGUI_API bool InputText(const char* label, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
|
||||||
|
IMGUI_API bool InputTextMultiline(const char* label, std::string* str, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
|
||||||
|
IMGUI_API bool InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
|
||||||
|
}
|
1
src/controller.cpp
Normal file
1
src/controller.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "controller.hpp"
|
@ -1,6 +1,7 @@
|
|||||||
#include "gui/gui.hpp"
|
#include "gui/gui.hpp"
|
||||||
#include "gui/gui_data.hpp"
|
#include "gui/gui_data.hpp"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
#include "imgui_stdlib.h"
|
||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
#include "imgui_impl_opengl3.h"
|
#include "imgui_impl_opengl3.h"
|
||||||
#include "imgui_impl_opengl3_loader.h"
|
#include "imgui_impl_opengl3_loader.h"
|
||||||
@ -47,6 +48,44 @@ void gui::Gui::render_gui() {
|
|||||||
|
|
||||||
ImGui::Text("Hello world!");
|
ImGui::Text("Hello world!");
|
||||||
ImGui::Text("Average framerate: %.3f ms/frame (%.1f FPS)", 1000.f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
ImGui::Text("Average framerate: %.3f ms/frame (%.1f FPS)", 1000.f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||||
|
{
|
||||||
|
ImGui::BeginChild("left pane",
|
||||||
|
ImVec2(ImGui::GetWindowWidth() / 2, -ImGui::GetFrameHeightWithSpacing() -
|
||||||
|
ImGui::GetStyle().ItemSpacing.y * 4 -
|
||||||
|
ImGui::GetStyle().ChildBorderSize -
|
||||||
|
ImGui::GetStyle().FrameBorderSize),
|
||||||
|
true);
|
||||||
|
ImGui::Text("Caractère");
|
||||||
|
// Remove label
|
||||||
|
ImGui::PushItemWidth(-1);
|
||||||
|
ImGui::InputTextMultiline("Caractère", &data.billy.caractere);
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::TreePop();
|
||||||
|
ImGui::EndChild();
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
{
|
||||||
|
ImGui::BeginChild("Right Pane",
|
||||||
|
ImVec2(0,
|
||||||
|
-ImGui::GetFrameHeightWithSpacing() -
|
||||||
|
ImGui::GetStyle().ItemSpacing.y * 4 -
|
||||||
|
ImGui::GetStyle().ChildBorderSize -
|
||||||
|
ImGui::GetStyle().FrameBorderSize),
|
||||||
|
true);
|
||||||
|
ImGui::Text("Hello");
|
||||||
|
ImGui::EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ImGui::BeginChild("Bottom pane", ImVec2(0, 0), true);
|
||||||
|
ImGui::Text("Bottom pane");
|
||||||
|
ImGui::Text("Bottom pane1");
|
||||||
|
ImGui::Text("Bottom pane2");
|
||||||
|
ImGui::Text("Bottom pane3");
|
||||||
|
ImGui::Text("Bottom pane4");
|
||||||
|
ImGui::EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
@ -1,14 +1,22 @@
|
|||||||
#include "gui/menu/menu.hpp"
|
#include "gui/menu/menu.hpp"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "gui/menu/menu_data.hpp"
|
#include "gui/menu/menu_data.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
void gui::menu::Menu::gui() const noexcept {
|
void gui::menu::Menu::gui() const noexcept {
|
||||||
if (ImGui::BeginMenuBar()) {
|
if (ImGui::BeginMenuBar()) {
|
||||||
if (ImGui::BeginMenu("File")) {
|
if (ImGui::BeginMenu("File")) {
|
||||||
if (ImGui::MenuItem("Save")) {
|
if (ImGui::MenuItem("Open file")) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Save")) {
|
||||||
|
std::ofstream file{ data.save_path / data.filename };
|
||||||
|
nlohmann::json j;
|
||||||
|
j.emplace("character_sheet", data)
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::MenuItem("Save as...")) {
|
if (ImGui::MenuItem("Save as...")) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
76
src/imgui/imgui_stdlib.cpp
Normal file
76
src/imgui/imgui_stdlib.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
// dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.)
|
||||||
|
// This is also an example of how you may wrap your own similar types.
|
||||||
|
|
||||||
|
// Compatibility:
|
||||||
|
// - std::string support is only guaranteed to work from C++11.
|
||||||
|
// If you try to use it pre-C++11, please share your findings (w/ info about compiler/architecture)
|
||||||
|
|
||||||
|
// Changelog:
|
||||||
|
// - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_stdlib.h"
|
||||||
|
|
||||||
|
struct InputTextCallback_UserData
|
||||||
|
{
|
||||||
|
std::string* Str;
|
||||||
|
ImGuiInputTextCallback ChainCallback;
|
||||||
|
void* ChainCallbackUserData;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int InputTextCallback(ImGuiInputTextCallbackData* data)
|
||||||
|
{
|
||||||
|
InputTextCallback_UserData* user_data = (InputTextCallback_UserData*)data->UserData;
|
||||||
|
if (data->EventFlag == ImGuiInputTextFlags_CallbackResize)
|
||||||
|
{
|
||||||
|
// Resize string callback
|
||||||
|
// If for some reason we refuse the new length (BufTextLen) and/or capacity (BufSize) we need to set them back to what we want.
|
||||||
|
std::string* str = user_data->Str;
|
||||||
|
IM_ASSERT(data->Buf == str->c_str());
|
||||||
|
str->resize(data->BufTextLen);
|
||||||
|
data->Buf = (char*)str->c_str();
|
||||||
|
}
|
||||||
|
else if (user_data->ChainCallback)
|
||||||
|
{
|
||||||
|
// Forward to user callback, if any
|
||||||
|
data->UserData = user_data->ChainCallbackUserData;
|
||||||
|
return user_data->ChainCallback(data);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui::InputText(const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
|
||||||
|
{
|
||||||
|
IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
|
||||||
|
flags |= ImGuiInputTextFlags_CallbackResize;
|
||||||
|
|
||||||
|
InputTextCallback_UserData cb_user_data;
|
||||||
|
cb_user_data.Str = str;
|
||||||
|
cb_user_data.ChainCallback = callback;
|
||||||
|
cb_user_data.ChainCallbackUserData = user_data;
|
||||||
|
return InputText(label, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui::InputTextMultiline(const char* label, std::string* str, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
|
||||||
|
{
|
||||||
|
IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
|
||||||
|
flags |= ImGuiInputTextFlags_CallbackResize;
|
||||||
|
|
||||||
|
InputTextCallback_UserData cb_user_data;
|
||||||
|
cb_user_data.Str = str;
|
||||||
|
cb_user_data.ChainCallback = callback;
|
||||||
|
cb_user_data.ChainCallbackUserData = user_data;
|
||||||
|
return InputTextMultiline(label, (char*)str->c_str(), str->capacity() + 1, size, flags, InputTextCallback, &cb_user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImGui::InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
|
||||||
|
{
|
||||||
|
IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
|
||||||
|
flags |= ImGuiInputTextFlags_CallbackResize;
|
||||||
|
|
||||||
|
InputTextCallback_UserData cb_user_data;
|
||||||
|
cb_user_data.Str = str;
|
||||||
|
cb_user_data.ChainCallback = callback;
|
||||||
|
cb_user_data.ChainCallbackUserData = user_data;
|
||||||
|
return InputTextWithHint(label, hint, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user