Skip to content

Commit

Permalink
Add translations and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
angryzor committed Nov 15, 2023
1 parent 13e898b commit 44a8b91
Show file tree
Hide file tree
Showing 12 changed files with 8,167 additions and 17 deletions.
17 changes: 13 additions & 4 deletions devtools/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Desktop.h"
#include "common/Theme.h"
#include "imgui/imgui_freetype.h"
#include "SettingsManager.h"

static ID3D11Device* device;
static ID3D11DeviceContext* deviceContext;
Expand Down Expand Up @@ -131,17 +132,17 @@ void Context::init() {
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // IF using Docking Branch
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;

SettingsManager::Init();

//static ImWchar ranges[] = { 0x1, 0xffff, 0 };
ImFontConfig fontConfig;
ImFontConfig fontConfig{};
//fontConfig.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_NoHinting;
//fontConfig.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_NoAutoHint;
//fontConfig.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_Bitmap;
//fontConfig.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor;
ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF((void*)inter_compressed_data, inter_compressed_size, 14, &fontConfig);// , ranges);
font = io.Fonts->AddFontFromMemoryCompressedTTF((void*)inter_compressed_data, inter_compressed_size, SettingsManager::settings.fontSize, &fontConfig);// , ranges);
io.Fonts->Build();

Theme::themes[0].Load();

auto allocator = app::fnd::AppHeapManager::GetResidentAllocator();
Desktop::instance = new (allocator) Desktop(allocator);

Expand All @@ -154,6 +155,14 @@ void Context::init() {

void Context::update()
{
//if (font != nullptr && font->FontSize != SettingsManager::settings.fontSize) {
// ImFontConfig fontConfig{};
// ImGuiIO& io = ImGui::GetIO();
// io.Fonts->Clear();
// font = io.Fonts->AddFontFromMemoryCompressedTTF((void*)inter_compressed_data, inter_compressed_size, SettingsManager::settings.fontSize, &fontConfig);
// io.Fonts->Build();
//}

ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();

Expand Down
5 changes: 5 additions & 0 deletions devtools/Desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Desktop.h"
#include "ToolBar.h"
#include "common/Icons.h"
#include "SettingsManager.h"
#include "ResourceBrowser.h"

Desktop* Desktop::instance{};
Expand All @@ -10,6 +11,8 @@ Desktop::Desktop(csl::fnd::IAllocator* allocator) : BaseObject{ allocator }
{
resourceLoader = hh::fnd::ResourceLoader::Create(allocator);
resourceLoader->LoadPackfile("mods/angryzor_devtools/devtools.pac", 0);

Translations::Init(allocator);
//iconTexture = (*rangerssdk::GetAddress(&hh::fnd::ResourceManager::instance))->GetResource<hh::gfnd::ResTexture>("devtools_icons.dds");
//iconView = static_cast<
// hh::needle::ImplDX11::NeedleResourceContainer<hh::needle::Texture, hh::needle::ImplDX11::TextureDX11Impl<hh::needle::ImplDX11::SBufferTexture2D, hh::needle::ImplDX11::SViewTexture2D>>*
Expand All @@ -30,6 +33,8 @@ void Desktop::Render() {
for (auto* window : windowsThatWantToClose) {
RemoveStandaloneWindow(window);
}

SettingsManager::Render();
}

void Desktop::AddStandaloneWindow(StandaloneWindow* window) {
Expand Down
2 changes: 1 addition & 1 deletion devtools/Mod.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Desc]
Version=0.0.4
Version=0.0.5
Author="angryzor"
Title="Sonic Frontiers DevTools"
Description="In-engine development kit for Sonic Frontiers"
Expand Down
143 changes: 143 additions & 0 deletions devtools/SettingsManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include "Pch.h"
#include "SettingsManager.h"

ImGuiSettingsHandler SettingsManager::settingsHandler{};
SettingsManager::Settings SettingsManager::settings{ 0, Translations::Language::VAR_NAMES, 14, ImGuiConfigFlags_NavEnableKeyboard };
bool SettingsManager::showConfigDialog{ false };

bool SettingsManager::Settings::operator==(const SettingsManager::Settings& other) const {
return theme == other.theme && language == other.language && fontSize == other.fontSize && configFlags == other.configFlags;
}

bool SettingsManager::Settings::operator!=(const SettingsManager::Settings& other) const {
return !operator==(other);
}

void SettingsManager::Init() {
settingsHandler.TypeName = "DevTools";
settingsHandler.TypeHash = ImHashStr(settingsHandler.TypeName);
settingsHandler.ClearAllFn = ClearAllFn;
settingsHandler.ReadInitFn = ReadInitFn;
settingsHandler.ReadOpenFn = ReadOpenFn;
settingsHandler.ReadLineFn = ReadLineFn;
settingsHandler.ApplyAllFn = ApplyAllFn;
settingsHandler.WriteAllFn = WriteAllFn;
settingsHandler.UserData = &settings;
ImGui::AddSettingsHandler(&settingsHandler);
}

void SettingsManager::Render() {
const ImGuiWindowFlags windowFlags
= 0;

ImGui::SetNextWindowSize(ImVec2(600, 400), ImGuiCond_Once);
if (showConfigDialog) {
if (ImGui::Begin("Settings", &showConfigDialog, windowFlags)) {
Settings tempSettings{ settings };

if (ImGui::BeginTabBar("SettingsTabs")) {
if (ImGui::BeginTabItem("UI")) {
const char* themeComboStr = Theme::themes[tempSettings.theme].name;
if (ImGui::BeginCombo("Theme", themeComboStr)) {
for (unsigned int i = 0; i < 3; i++) {
bool is_selected = tempSettings.theme == i;

if (ImGui::Selectable(Theme::themes[i].name, is_selected)) {
tempSettings.theme = i;
}

if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}

//ImGui::DragFloat("Font size", &tempSettings.fontSize, 1.0f, 6.0f, 30.0f);

const char* languageComboStr = Translations::GetLanguageName(Translations::GetCurrentLanguage());
if (ImGui::BeginCombo("Reflections description language", languageComboStr)) {
for (size_t i = 0; i < 3; i++) {
Translations::Language language = static_cast<Translations::Language>(i);
bool is_selected = tempSettings.language == language;

if (ImGui::Selectable(Translations::GetLanguageName(language), is_selected)) {
tempSettings.language = language;
}

if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::EndTabItem();
}

if (ImGui::BeginTabItem("Controls")) {
ImGui::CheckboxFlags("Allow keyboard navigation", &tempSettings.configFlags, ImGuiConfigFlags_NavEnableKeyboard);
ImGui::CheckboxFlags("Allow gamepad navigation", &tempSettings.configFlags, ImGuiConfigFlags_NavEnableGamepad);
ImGui::EndTabItem();
}

ImGui::EndTabBar();
}
if (tempSettings != settings) {
settings = tempSettings;
ApplySettings();
ImGui::SaveIniSettingsToDisk(ImGui::GetIO().IniFilename);
}
}
ImGui::End();
}
}

void SettingsManager::OpenConfigDialog() {
showConfigDialog = true;
}

void SettingsManager::ApplySettings() {
Theme::themes[settings.theme].Load();
Translations::SetCurrentLanguage(settings.language);
ImGui::GetIO().ConfigFlags = settings.configFlags;
}

void SettingsManager::ClearAllFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler)
{
settings.theme = 0;
settings.language = Translations::Language::VAR_NAMES;
//settings.fontSize = 14;
settings.configFlags = ImGuiConfigFlags_NavEnableKeyboard;
}

void SettingsManager::ReadInitFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler)
{
}

void* SettingsManager::ReadOpenFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name)
{
return &settings;
}

void SettingsManager::ReadLineFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line)
{
unsigned int i;
//float f;
if (sscanf_s(line, "Theme=%i", &i) == 1) { settings.theme = i; }
else if (sscanf_s(line, "Translations=%i", &i) == 1) { settings.language = static_cast<Translations::Language>(i); }
//else if (sscanf_s(line, "FontSize=%f", &f) == 1) { settings.fontSize = f; }
else if (sscanf_s(line, "ConfigFlags=%i", &i) == 1) { settings.configFlags = i; }
}

void SettingsManager::ApplyAllFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler)
{
ApplySettings();
}

void SettingsManager::WriteAllFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf)
{
//buf->reserve(buf->size() + sizeof(Settings) * 6);
out_buf->appendf("[DevTools][]\n");
out_buf->appendf("Theme=%i\n", settings.theme);
out_buf->appendf("Translations=%i\n", settings.language);
//out_buf->appendf("FontSize=%f\n", settings.fontSize);
out_buf->appendf("ConfigFlags=%i\n", settings.configFlags);
}
39 changes: 39 additions & 0 deletions devtools/SettingsManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once
#include "imgui/imgui_internal.h"
#include "common/Translations.h"
#include "common/Theme.h"

class SettingsManager
{
struct Settings {
unsigned int theme;
Translations::Language language;
float fontSize;
ImGuiConfigFlags configFlags;

bool operator==(const Settings& other) const;
bool operator!=(const Settings& other) const;
};

static ImGuiSettingsHandler settingsHandler;

static bool showConfigDialog;

Settings SerializeSettings();
void LoadSerializedSettings(const Settings& settings);
static void ClearAllFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler);
static void ReadInitFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler);
static void* ReadOpenFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name);
static void ReadLineFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line);
static void ApplyAllFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler);
static void WriteAllFn(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf);

static void ApplySettings();

public:
static Settings settings;
static void Init();
static void Render();
static void OpenConfigDialog();
};

14 changes: 3 additions & 11 deletions devtools/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "common/Theme.h"
#include "Desktop.h"
#include "ResourceBrowser.h"
#include "SettingsManager.h"
#include "core-services/GameUpdaterInspector.h"
#include "core-services/GraphicsContextInspector.h"
#include "core-services/CameraManagerInspector.h"
Expand Down Expand Up @@ -49,18 +50,9 @@ void ToolBar::Render() {
ImGui::MenuItem("Object Inspection");
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Theme")) {
for (size_t i = 0; i < 3; i++) {
bool selected{ false };
if (ImGui::MenuItem("Settings"))
SettingsManager::OpenConfigDialog();

ImGui::MenuItem(Theme::themes[i].name, nullptr, &selected);

if (selected) {
Theme::themes[i].Load();
}
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}

Expand Down
8 changes: 7 additions & 1 deletion devtools/common/ReflectionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ReflectionEditor.h"
#include "../common/SimpleWidgets.h"
#include "../imgui/imgui_internal.h"
#include "../common/Translations.h"

using namespace hh::fnd;

Expand All @@ -10,7 +11,12 @@ const char* ReflectionEditor::GetRflMemberName(const RflClassMember* member) {
const char* caption = *reinterpret_cast<const char* const*>(member->GetAttribute("Caption")->GetData());
const char* name = member->GetName();

return name;// caption != nullptr ? caption : name;
if (caption == nullptr)
return name;

const char* translation = Translations::GetTranslation(caption);

return translation == nullptr ? name : translation;
}

// void EnumEditor(void* obj, const RflClassMember* member) {
Expand Down
Loading

0 comments on commit 44a8b91

Please sign in to comment.