Skip to content

Commit

Permalink
Added fontMul, import logging, auto save
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Feb 14, 2022
1 parent 3e4eeb8 commit 1411f5f
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/d3dhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void D3dHook::ProcessFrame(void* ptr)
// Scale the menu if game resolution changed
static ImVec2 fScreenSize = ImVec2(-1, -1);
ImVec2 size(screen::GetScreenWidth(), screen::GetScreenHeight());
if (fScreenSize.x != size.x && fScreenSize.y != size.y)
if ((fScreenSize.x != size.x && fScreenSize.y != size.y) || FontMgr::IsReloadNeeded())
{
FontMgr::ReloadFonts();

Expand Down
14 changes: 14 additions & 0 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "hotkeys.h"
#include <CHud.h>
#include <CMenuManager.h>
#include "filemgr.h"

void Editor::Init()
{
Expand All @@ -21,6 +22,7 @@ void Editor::Init()
ObjManager::m_bDrawAxisLines = gConfig.GetValue("editor.drawAxisLines", true);
Viewport::m_bShowHoverMenu = gConfig.GetValue("editor.showHoverMenu", true);
Interface::m_bWelcomeScreenDisplayed = gConfig.GetValue("editor.welcomeDisplayed", false);
FontMgr::SetMultiplier(gConfig.GetValue("editor.fontMul", 1.0f));

if (!Interface::m_bWelcomeScreenDisplayed)
{
Expand Down Expand Up @@ -75,6 +77,18 @@ void Editor::DrawWindow()
Interface::DrawPopupMenu();
Interface::DrawInfoMenu();
Viewport::DrawHoverMenu();

if (Interface::m_bAutoSave)
{
static size_t timer = CTimer::m_snTimeInMilliseconds;
size_t curTimer = CTimer::m_snTimeInMilliseconds;

if (curTimer - timer > 60000)
{
FileMgr::ExportIPL("auto_save.ipl");
timer = curTimer;
}
}
}
}
else
Expand Down
9 changes: 7 additions & 2 deletions src/filemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <fstream>
#include <CHud.h>

void FileMgr::ImportIPL(std::string fileName)
void FileMgr::ImportIPL(std::string fileName, bool logImports)
{
static int counter = 0;
std::fstream file;
Expand All @@ -28,7 +28,12 @@ void FileMgr::ImportIPL(std::string fileName)
if (sscanf(line.c_str(), "%d %s %d %f %f %f %f %f %f %f %d", &model, modelName, &interior,
&pos.x, &pos.y, &pos.z, &rx, &ry, &rz, &rw, &unk) == 11)
{
int hObj;
if (logImports)
{
gLog << "Pasing line: " << line << std::endl;
}

int hObj;
Command<Commands::REQUEST_MODEL>(model);
Command<Commands::LOAD_ALL_MODELS_NOW>();
Command<Commands::CREATE_OBJECT>(model, pos.x, pos.y, pos.z, &hObj);
Expand Down
2 changes: 1 addition & 1 deletion src/filemgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class FileMgr
FileMgr(FileMgr&) = delete;

static void ExportIPL(const char* fileName);
static void ImportIPL(std::string fileName);
static void ImportIPL(std::string fileName, bool logImports);
};

19 changes: 17 additions & 2 deletions src/fontmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ImFont* FontMgr::LoadFont(const char* fontName, float fontMul)
size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * fontMul;

std::string fullPath = std::string(PLUGIN_PATH((char*)"CheatMenu/fonts/")) + fontName + ".ttf";
m_vecFonts.push_back({io.Fonts->AddFontFromFileTTF(fullPath.c_str(), fontSize), fontSize, fontMul,
m_vecFonts.push_back({io.Fonts->AddFontFromFileTTF(fullPath.c_str(), fontSize), fontMul,
std::string(fontName)});
io.Fonts->Build();

Expand All @@ -41,8 +41,23 @@ void FontMgr::ReloadFonts()
{
size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * data.m_fMul;
std::string fullPath = PLUGIN_PATH((char*)"CheatMenu/fonts/") + data.m_path + ".ttf";
data.m_pFont = io.Fonts->AddFontFromFileTTF(fullPath.c_str(), data.m_nSize);
data.m_pFont = io.Fonts->AddFontFromFileTTF(fullPath.c_str(), fontSize);
}
io.FontDefault = GetFont("text");
io.Fonts->Build();
m_bMulChangedExternal = false;
}

void FontMgr::SetMultiplier(float fontMul)
{
for (auto &data : m_vecFonts)
{
data.m_fMul = fontMul;
}
m_bMulChangedExternal = true;
}

bool FontMgr::IsReloadNeeded()
{
return m_bMulChangedExternal;
}
6 changes: 4 additions & 2 deletions src/fontmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ class FontMgr
struct FontInfo
{
ImFont *m_pFont;
size_t m_nSize;
float m_fMul;
std::string m_path;
};
static inline std::vector<FontInfo> m_vecFonts;

static inline bool m_bMulChangedExternal;

public:
FontMgr() = delete;
FontMgr(FontMgr&) = delete;

static ImFont* GetFont(const char* fontName);
static ImFont* LoadFont(const char* fontName, float fontMul = 1.0f);
static void SetMultiplier(float fontMul);

// ImGui::GetIO().Default font must be loaded after unloading all fonts
static void UnloadFonts();
static void ReloadFonts();
static bool IsReloadNeeded();
};


27 changes: 26 additions & 1 deletion src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ void Interface::ImportMenu()
ImGui::Dummy(ImVec2(0, 20));
static std::string selectedFileName = "";

ImGui::Checkbox("Log imports", &logImports);
Widgets::ShowTooltip("Logs imports line by line in MapEditor.log.\nEnable this if the game crashes while importing\nand you want to know the error line.\n\nNote: Has performance impact!");

if (ImGui::Button("Import IPL", Utils::GetSize(2)))
{
FileMgr::ImportIPL(selectedFileName.c_str());
FileMgr::ImportIPL(selectedFileName.c_str(), logImports);
m_bShowPopup = false;
}
ImGui::SameLine();
Expand Down Expand Up @@ -502,6 +505,10 @@ void Interface::DrawMainMenuBar()
{
static bool bNoPeds, bNoVehicles;

if (ImGui::MenuItem("Auto save every minute", NULL, &Interface::m_bAutoSave))
{
gConfig.SetValue("editor.autoSave", Interface::m_bAutoSave);
}
if (ImGui::MenuItem("Auto snap to ground", NULL, &Interface::m_bAutoSnapToGround))
{
gConfig.SetValue("editor.autoSnap", Interface::m_bAutoSnapToGround);
Expand Down Expand Up @@ -556,6 +563,24 @@ void Interface::DrawMainMenuBar()
}
ImGui::EndMenu();
}
ImGui::Dummy(ImVec2(0, 10));
static float mul = 1;
static bool sliderClicked = false;
ImGui::Text("Font mul");
ImGui::SameLine();
ImGui::Spacing();
ImGui::SameLine();
if (ImGui::SliderFloat("##FontMul", &mul, 1, 5))
{
sliderClicked = true;
}
if (ImGui::IsMouseReleased(0) && sliderClicked)
{
gConfig.SetValue("editor.fontMul", mul);
FontMgr::SetMultiplier(mul);
sliderClicked = false;
}

ImGui::EndMenu();
}
if (ImGui::BeginMenu("View"))
Expand Down
3 changes: 3 additions & 0 deletions src/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class Interface
std::string rootKey;
std::string value;
};
static inline bool logImports;

public:
static inline bool m_bAutoSave = true;
static inline bool m_bAutoSnapToGround;
static inline bool m_bWelcomeScreenDisplayed;
static inline bool m_bShowInfoMenu; // right hand menu
Expand All @@ -37,6 +39,7 @@ class Interface
static void DrawPopupMenu();
static void ImportMenu();
static void ExportMenu();
static void SettingsMenu();

// Custom popup menu codes
static void QuickObjectCreateMenu();
Expand Down
4 changes: 2 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#define EDITOR_NAME "Map Editor"
#define EDITOR_VERSION_NUMBER "0.4"
#define EDITOR_VERSION_NUMBER "0.7"
#define EDITOR_VERSION EDITOR_VERSION_NUMBER"-alpha"
#define BUILD_NUMBER "20220131"
#define BUILD_NUMBER "20220214"
#define EDITOR_TITLE EDITOR_NAME " v" EDITOR_VERSION_NUMBER
13 changes: 13 additions & 0 deletions src/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
#include "widgets.h"
#include "interface.h"

void Widgets::ShowTooltip(const char* text)
{
ImGui::SameLine();
ImGui::TextDisabled("?");

if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text(text);
ImGui::EndTooltip();
}
}

bool Widgets::ListBoxStr(const char* label, std::vector<std::string>& all_items, std::string& selected)
{
bool rtn = false;
Expand Down
1 change: 1 addition & 0 deletions src/widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ class Widgets
static void DrawJSON(ResourceStore& data,
std::function<void(std::string&, std::string&, std::string&)> func_left_click,
std::function<void(std::string&, std::string&, std::string&)> func_right_click);
static void ShowTooltip(const char* text);
};

0 comments on commit 1411f5f

Please sign in to comment.