Skip to content

Commit

Permalink
Merge pull request #44 from Malkierian/modern-menu
Browse files Browse the repository at this point in the history
Modern menu
  • Loading branch information
aMannus authored Jan 30, 2025
2 parents 1744f1f + fcfe4e8 commit 00a31c8
Show file tree
Hide file tree
Showing 14 changed files with 3,390 additions and 7 deletions.
Binary file added soh/assets/custom/fonts/Inconsolata-Regular.ttf
Binary file not shown.
Binary file added soh/assets/custom/fonts/Montserrat-Regular.ttf
Binary file not shown.
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
116 changes: 116 additions & 0 deletions soh/soh/ShipUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "ShipUtils.h"
#include <libultraship/libultraship.h>
//#include "assets/2s2h_assets.h"

extern "C" {
#include "z64.h"
#include "functions.h"
#include "macros.h"

extern float OTRGetAspectRatio();

//extern f32 sNESFontWidths[160];
extern const char* fontTbl[156];
//extern TexturePtr gItemIcons[131];
//extern TexturePtr gQuestIcons[14];
//extern TexturePtr gBombersNotebookPhotos[24];
}

constexpr f32 fourByThree = 4.0f / 3.0f;

// Gets the additional ratio of the screen compared to the original 4:3 ratio, clamping to 1 if smaller
extern "C" f32 Ship_GetExtendedAspectRatioMultiplier() {
f32 currentRatio = OTRGetAspectRatio();
return MAX(currentRatio / fourByThree, 1.0f);
}

// Enables Extended Culling options on specific actors by applying an inverse ratio of the draw distance slider
// to the projected Z value of the actor. This tricks distance checks without having to replace hardcoded values.
// Requires that Ship_ExtendedCullingActorRestoreProjectedPos is called within the same function scope.
extern "C" void Ship_ExtendedCullingActorAdjustProjectedZ(Actor* actor) {
s32 multiplier = CVarGetInteger("gEnhancements.Graphics.IncreaseActorDrawDistance", 1);
multiplier = MAX(multiplier, 1);
if (multiplier > 1) {
actor->projectedPos.z /= multiplier;
}
}

// Enables Extended Culling options on specific actors by applying an inverse ratio of the widescreen aspect ratio
// to the projected X value of the actor. This tricks distance checks without having to replace hardcoded values.
// Requires that Ship_ExtendedCullingActorRestoreProjectedPos is called within the same function scope.
extern "C" void Ship_ExtendedCullingActorAdjustProjectedX(Actor* actor) {
if (CVarGetInteger("gEnhancements.Graphics.ActorCullingAccountsForWidescreen", 0)) {
f32 ratioAdjusted = Ship_GetExtendedAspectRatioMultiplier();
actor->projectedPos.x /= ratioAdjusted;
}
}

// Restores the projectedPos values on the actor after modifications from the Extended Culling hacks
//extern "C" void Ship_ExtendedCullingActorRestoreProjectedPos(PlayState* play, Actor* actor) {
// f32 invW = 0.0f;
// Actor_GetProjectedPos(play, &actor->world.pos, &actor->projectedPos, &invW);
//}

extern "C" bool Ship_IsCStringEmpty(const char* str) {
return str == NULL || str[0] == '\0';
}

// Build vertex coordinates for a quad command
// In order of top left, top right, bottom left, then bottom right
// Supports flipping the texture horizontally
extern "C" void Ship_CreateQuadVertexGroup(Vtx* vtxList, s32 xStart, s32 yStart, s32 width, s32 height, u8 flippedH) {
vtxList[0].v.ob[0] = xStart;
vtxList[0].v.ob[1] = yStart;
vtxList[0].v.tc[0] = (flippedH ? width : 0) << 5;
vtxList[0].v.tc[1] = 0 << 5;

vtxList[1].v.ob[0] = xStart + width;
vtxList[1].v.ob[1] = yStart;
vtxList[1].v.tc[0] = (flippedH ? width * 2 : width) << 5;
vtxList[1].v.tc[1] = 0 << 5;

vtxList[2].v.ob[0] = xStart;
vtxList[2].v.ob[1] = yStart + height;
vtxList[2].v.tc[0] = (flippedH ? width : 0) << 5;
vtxList[2].v.tc[1] = height << 5;

vtxList[3].v.ob[0] = xStart + width;
vtxList[3].v.ob[1] = yStart + height;
vtxList[3].v.tc[0] = (flippedH ? width * 2 : width) << 5;
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" TexturePtr Ship_GetCharFontTextureNES(u8 character) {
// u8 adjustedChar = character - ' ';
//
// if (adjustedChar >= ARRAY_COUNTU(sNESFontWidths)) {
// return (TexturePtr)gEmptyTexture;
// }
//
// return (TexturePtr)fontTbl[adjustedChar];
//}

//void LoadGuiTextures() {
// for (TexturePtr entry : gItemIcons) {
// const char* path = static_cast<const char*>(entry);
// Ship::Context::GetInstance()->GetWindow()->GetGui()->LoadGuiTexture(path, path, ImVec4(1, 1, 1, 1));
// }
// for (TexturePtr entry : gQuestIcons) {
// const char* path = static_cast<const char*>(entry);
// Ship::Context::GetInstance()->GetWindow()->GetGui()->LoadGuiTexture(path, path, ImVec4(1, 1, 1, 1));
// }
// for (TexturePtr entry : gBombersNotebookPhotos) {
// const char* path = static_cast<const char*>(entry);
// Ship::Context::GetInstance()->GetWindow()->GetGui()->LoadGuiTexture(path, path, ImVec4(1, 1, 1, 1));
// }
//}
31 changes: 31 additions & 0 deletions soh/soh/ShipUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef SHIP_UTILS_H
#define SHIP_UTILS_H

#include <libultraship/libultraship.h>
//#include "PR/ultratypes.h"

#ifdef __cplusplus

void LoadGuiTextures();

extern "C" {
#endif

struct PlayState;
struct Actor;

f32 Ship_GetExtendedAspectRatioMultiplier();
void Ship_ExtendedCullingActorAdjustProjectedZ(Actor* actor);
void Ship_ExtendedCullingActorAdjustProjectedX(Actor* actor);
void Ship_ExtendedCullingActorRestoreProjectedPos(PlayState* play, Actor* actor);

bool Ship_IsCStringEmpty(const char* str);
void Ship_CreateQuadVertexGroup(Vtx* vtxList, s32 xStart, s32 yStart, s32 width, s32 height, u8 flippedH);
f32 Ship_GetCharFontWidthNES(u8 character);
//TexturePtr Ship_GetCharFontTextureNES(u8 character);

#ifdef __cplusplus
}
#endif

#endif // SHIP_UTILS_H
Loading

0 comments on commit 00a31c8

Please sign in to comment.