Skip to content

Commit

Permalink
Finish implementing new menu.
Browse files Browse the repository at this point in the history
Rename 2ship UIWidgets to UIWidgets2 to complete facilitation of both menus working for now.
  • Loading branch information
Malkierian committed Jan 29, 2025
1 parent 0a2d2b7 commit fcfe4e8
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 206 deletions.
43 changes: 40 additions & 3 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "z64.h"
#include "macros.h"
#include "Fonts.h"
#include "window/gui/resource/Font.h"
#include <utils/StringHelper.h>
#include "Enhancements/custom-message/CustomMessageManager.h"
#include "Enhancements/presets.h"
Expand Down Expand Up @@ -400,9 +401,14 @@ OTRGlobals::OTRGlobals() {
hasMasterQuest = hasOriginal = false;

previousImGuiScale = defaultImGuiScale;
defaultFontSmaller = CreateDefaultFontWithSize(10.0f);
defaultFontLarger = CreateDefaultFontWithSize(16.0f);
defaultFontLargest = CreateDefaultFontWithSize(20.0f);

fontMono = CreateFontWithSize(16.0f, "fonts/Inconsolata-Regular.ttf");
fontMonoLarger = CreateFontWithSize(20.0f, "fonts/Inconsolata-Regular.ttf");
fontMonoLargest = CreateFontWithSize(24.0f, "fonts/Inconsolata-Regular.ttf");
fontStandard = CreateFontWithSize(16.0f, "fonts/Montserrat-Regular.ttf");
fontStandardLarger = CreateFontWithSize(20.0f, "fonts/Montserrat-Regular.ttf");
fontStandardLargest = CreateFontWithSize(24.0f, "fonts/Montserrat-Regular.ttf");
ImGui::GetIO().FontDefault = fontMono;
ScaleImGui();

// Move the camera strings from read only memory onto the heap (writable memory)
Expand Down Expand Up @@ -1539,6 +1545,37 @@ extern "C" SoundFontSample* ReadCustomSample(const char* path) {
*/
}

ImFont* OTRGlobals::CreateFontWithSize(float size, std::string fontPath) {
auto mImGuiIo = &ImGui::GetIO();
ImFont* font;
if (fontPath == "") {
ImFontConfig fontCfg = ImFontConfig();
fontCfg.OversampleH = fontCfg.OversampleV = 1;
fontCfg.PixelSnapH = true;
fontCfg.SizePixels = size;
font = mImGuiIo->Fonts->AddFontDefault(&fontCfg);
} else {
auto initData = std::make_shared<Ship::ResourceInitData>();
initData->Format = RESOURCE_FORMAT_BINARY;
initData->Type = static_cast<uint32_t>(RESOURCE_TYPE_FONT);
initData->ResourceVersion = 0;
initData->Path = fontPath;
std::shared_ptr<Ship::Font> fontData = std::static_pointer_cast<Ship::Font>(
Ship::Context::GetInstance()->GetResourceManager()->LoadResource(fontPath, false, initData));
font = mImGuiIo->Fonts->AddFontFromMemoryTTF(fontData->Data, fontData->DataSize, size);
}
// FontAwesome fonts need to have their sizes reduced by 2.0f/3.0f in order to align correctly
float iconFontSize = size * 2.0f / 3.0f;
static const ImWchar sIconsRanges[] = { ICON_MIN_FA, ICON_MAX_16_FA, 0 };
ImFontConfig iconsConfig;
iconsConfig.MergeMode = true;
iconsConfig.PixelSnapH = true;
iconsConfig.GlyphMinAdvanceX = iconFontSize;
mImGuiIo->Fonts->AddFontFromMemoryCompressedBase85TTF(fontawesome_compressed_data_base85, iconFontSize,
&iconsConfig, sIconsRanges);
return font;
}

std::filesystem::path GetSaveFile(std::shared_ptr<Ship::Config> Conf) {
const std::string fileName = Conf->GetString("Game.SaveName", Ship::Context::GetPathRelativeToAppDirectory("oot_save.sav"));
std::filesystem::path saveFile = std::filesystem::absolute(fileName);
Expand Down
8 changes: 8 additions & 0 deletions soh/soh/OTRGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class OTRGlobals {
ImFont* defaultFontLarger;
ImFont* defaultFontLargest;

ImFont* fontStandard;
ImFont* fontStandardLarger;
ImFont* fontStandardLargest;
ImFont* fontMono;
ImFont* fontMonoLarger;
ImFont* fontMonoLargest;

OTRGlobals();
~OTRGlobals();

Expand All @@ -69,6 +76,7 @@ class OTRGlobals {
bool hasMasterQuest;
bool hasOriginal;
ImFont* CreateDefaultFontWithSize(float size);
ImFont* CreateFontWithSize(float size, std::string fontPath);
};
#endif

Expand Down
20 changes: 10 additions & 10 deletions soh/soh/ShipUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C" {

extern float OTRGetAspectRatio();

extern f32 sNESFontWidths[160];
//extern f32 sNESFontWidths[160];
extern const char* fontTbl[156];
//extern TexturePtr gItemIcons[131];
//extern TexturePtr gQuestIcons[14];
Expand Down Expand Up @@ -80,15 +80,15 @@ extern "C" void Ship_CreateQuadVertexGroup(Vtx* vtxList, s32 xStart, s32 yStart,
vtxList[3].v.tc[1] = height << 5;
}

extern "C" f32 Ship_GetCharFontWidthNES(u8 character) {
u8 adjustedChar = character - ' ';

if (adjustedChar >= ARRAY_COUNTU(sNESFontWidths)) {
return 0.0f;
}

return sNESFontWidths[adjustedChar];
}
//extern "C" f32 Ship_GetCharFontWidthNES(u8 character) {
// u8 adjustedChar = character - ' ';
//
// if (adjustedChar >= ARRAY_COUNTU(sNESFontWidths)) {
// return 0.0f;
// }
//
// return sNESFontWidths[adjustedChar];
//}

//extern "C" TexturePtr Ship_GetCharFontTextureNES(u8 character) {
// u8 adjustedChar = character - ' ';
Expand Down
Loading

0 comments on commit fcfe4e8

Please sign in to comment.