Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "tools/blender/fast64"]
path = tools/blender/fast64
url = https://github.com/Fast-64/fast64.git
[submodule "hmui"]
path = hmui
url = https://github.com/KiritoDv/HMUI
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/assets
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/port
${CMAKE_CURRENT_SOURCE_DIR}/src/port/ui
${CMAKE_CURRENT_SOURCE_DIR}/src/port/hmui
${CMAKE_CURRENT_SOURCE_DIR}/src/port/hmui/os
${CMAKE_CURRENT_SOURCE_DIR}/hmui/src
${CMAKE_CURRENT_SOURCE_DIR}/src/racing
${CMAKE_CURRENT_SOURCE_DIR}/src/ending
${CMAKE_CURRENT_SOURCE_DIR}/src/data
Expand Down Expand Up @@ -283,6 +288,14 @@ file(GLOB_RECURSE ALL_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"src/enhancements/freecam/*.h"
"src/engine/*.cpp"
"src/engine/*.h"
"hmui/src/hmui/HMUI.cpp"
"hmui/src/hmui/Navigator.cpp"
"hmui/src/hmui/MouseEvents.cpp"
"hmui/src/hmui/input/FocusManager.cpp"
"hmui/src/hmui/*.h"
"hmui/src/hmui/graphics/ImGuiGraphicsContext.cpp"
"hmui/src/hmui/graphics/ImGuiGraphicsContext.h"
"hmui/src/hmui/graphics/GraphicsContext.h"
"Resource.rc"
)

Expand Down
1 change: 1 addition & 0 deletions hmui
Submodule hmui added at 05f257
6 changes: 6 additions & 0 deletions include/align_asset_macro.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif
bool GameEngine_OTRSigCheck(const char* imgData);
#ifdef __cplusplus
}
#endif

#if defined(_WIN32)
#define ALIGN_ASSET(x) __declspec(align(x))
Expand Down
2 changes: 1 addition & 1 deletion src/engine/TrackBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@ const char* TrackBrowser_GetMinimapTextureByIdx(size_t trackIndex);
}
#endif // __cplusplus

#endif // TRACKBROWSER_H
#endif // TRACKBROWSER_H
1 change: 1 addition & 0 deletions src/enhancements/freecam/freecam.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void freecam_loop(Camera*);
void freecam_update_controller(void);
void freecam_mouse_manager(Camera*, Vec3f);
void freecam_keyboard_manager(Camera*, Vec3f);
bool FreecamKeyDown(int virtualKey);

extern f32 gFreecamSpeed;
extern f32 gFreecamSpeedMultiplier;
Expand Down
19 changes: 17 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,24 @@ void game_state_handler(void) {
case COURSE_SELECT_MENU_FROM_QUIT:
// Display black
osViBlack(0);
update_menus();
if (CVarGetInteger("gNewMenu", true) == true) {
switch(gMenuSelection) {
case CONTROLLER_PAK_MENU:
case HARBOUR_MASTERS_MENU:
case LOGO_INTRO_MENU:
case START_MENU:
update_menus(); // Tick old menu
break;
}
} else {
update_menus();
}
init_rcp();
func_80094A64(gGfxPool);
if ((CVarGetInteger("gNewMenus", true) == true) && (gMenuSelection == MAIN_MENU)) {
HMUI_SetActive(true);
} else {
func_80094A64(gGfxPool); // Draw old menu
}
#if DVDL
display_dvdl();
#endif
Expand Down
8 changes: 8 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ typedef struct {
u16 numTriangles;
} CollisionGrid;

#ifdef __cplusplus
extern "C" {
#endif

void create_thread(OSThread*, OSId, void (*entry)(void*), void*, void*, OSPri);
void main_func(void);
void thread1_idle(void*);
Expand Down Expand Up @@ -228,4 +232,8 @@ extern f32 gCourseTimer;

// end of definition of main.c variables

#ifdef __cplusplus
}
#endif

#endif
26 changes: 26 additions & 0 deletions src/port/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@

#include <utility>

#include "hmui/HMUI.h"
#include "hmui/graphics/ImGuiGraphicsContext.h"
#include "hmui/graphics/GraphicsContext.h"
#include "port/ui/hmui/os/LUSOSContext.h"
#include "port/ui/hmui/demo/Router.h"

#ifdef __SWITCH__
#include <port/switch/SwitchImpl.h>
#endif
Expand Down Expand Up @@ -64,6 +70,7 @@
}

GameEngine* GameEngine::Instance;
std::shared_ptr<HMUI> hmui; // New menu system

bool CreateDirectoryRecursive(std::string const& dirName, std::error_code& err) {
err.clear();
Expand Down Expand Up @@ -348,6 +355,11 @@
InitModsSystem();
instance->gHMAS = new HMAS();
instance->AudioInit();

hmui = std::make_shared<HMUI>();
hmui->initialize(std::make_shared<ImGuiGraphicsContext>(), std::make_shared<LUSOSContext>());
hmui->setRouter(std::make_shared<RouterView>());

Check failure on line 361 in src/port/Engine.cpp

View workflow job for this annotation

GitHub Actions / build (Release)

no member named 'setRouter' in 'HMUI'
hmui->setActive(false);

Check failure on line 362 in src/port/Engine.cpp

View workflow job for this annotation

GitHub Actions / build (Release)

no member named 'setActive' in 'HMUI'
GameUI::SetupGuiElements();
#if defined(__SWITCH__) || defined(__WIIU__)
CVarRegisterInteger("gControlNav", 1); // always enable controller nav on switch/wii u
Expand Down Expand Up @@ -446,6 +458,8 @@

// time_base = fps * original_fps (one second)
int next_original_frame = fps;
float s = fps / (60.0f / 2 /*gVIsPerFrame*/);
hmui->update(s);

// Get matrix replacements for intermediate frames
while (time + original_fps <= next_original_frame) {
Expand All @@ -471,6 +485,14 @@
last_update_rate = 2;
}

void GameEngine::RenderHMUI() {
auto wnd = std::dynamic_pointer_cast<Fast::Fast3dWindow>(Ship::Context::GetInstance()->GetWindow());
if (wnd != nullptr) {
auto ctx = GfxList { (void*) ImGui::GetWindowDrawList() };
hmui->draw(&ctx, wnd->GetWidth(), wnd->GetHeight());
}
}

// Audio
void GameEngine::HandleAudioThread() {
while (audio.running) {
Expand Down Expand Up @@ -617,6 +639,10 @@

// End

extern "C" void HMUI_SetActive(bool state) {
hmui->setActive(state);

Check failure on line 643 in src/port/Engine.cpp

View workflow job for this annotation

GitHub Actions / build (Release)

no member named 'setActive' in 'HMUI'
}

extern "C" uint32_t GameEngine_GetSampleRate() {
auto player = Ship::Context::GetInstance()->GetAudio()->GetAudioPlayer();
if (player == nullptr) {
Expand Down
2 changes: 2 additions & 0 deletions src/port/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class GameEngine {
void ProcessFrame(void (*run_one_game_iter)()) const;
static void Destroy();
static void ProcessGfxCommands(Gfx* pool);
static void RenderHMUI();
static uint8_t GetBankIdByName(const std::string& name);
static int ShowYesNoBox(const char* title, const char* box);
static void ShowMessage(const char* title, const char* message, SDL_MessageBoxFlags type = SDL_MESSAGEBOX_ERROR);
Expand Down Expand Up @@ -110,6 +111,7 @@ struct AudioSequenceData* GameEngine_LoadSequence(uint8_t seqId);
uint32_t GameEngine_GetSequenceCount();
uint8_t GameEngine_IsSequenceLoaded(uint8_t seqId);
void GameEngine_UnloadSequence(uint8_t seqId);
void HMUI_SetActive(bool state);
// bool GameEngine_OTRSigCheck(char* imgData); -> align_asset_macro.h
float OTRGetAspectRatio(void);
float OTRGetDimensionFromLeftEdge(float v);
Expand Down
13 changes: 12 additions & 1 deletion src/port/SpaghettiGui.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <libultraship.h>
#include "SpaghettiGui.h"
#include "Engine.h"
#include <ship/window/gui/Gui.h>
#include <ship/window/Window.h>
#ifdef __SWITCH__
Expand Down Expand Up @@ -158,6 +159,16 @@ namespace Ship {
}

ImGui::End();
ImGui::SetNextWindowPos(viewport->WorkPos);
ImGui::SetNextWindowSize(ImVec2((int)wnd->GetWidth(), (int)wnd->GetHeight()));
// ImGui::SetNextWindowViewport(viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f);
ImGui::Begin("HMUI", nullptr, windowFlags);
ImGui::PopStyleVar(3);
GameEngine::RenderHMUI();
ImGui::End();
}

}
}
104 changes: 104 additions & 0 deletions src/port/ui/hmui/demo/CCView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#pragma once

#include <utility>
#include <iostream>
#include "LayoutSettings.h"

#include "hmui/Navigator.h"

// singleplayer, split-screen, online
class CCViewElements : public Drawable {
public:
// std::vector<Color2D> entries;
std::vector<std::shared_ptr<InternalDrawable>> entries;

void init() override {

std::string modes[] = {"50CC", "100CC", "150CC", "Extra"};

for(int i = 0; i < 4; ++i) {
entries.push_back(GestureDetector(
.focusable = true,
.focusDecorator = FocusDecorator {
.color = Color2D(1.0f, 1.0f, 1.0f, 0.8f),
.thickness = 2.0f
},
.onTap = [i](std::shared_ptr<InternalDrawable> child, float x, float y) {
// Handle tap event
std::shared_ptr<D_Container> c = std::dynamic_pointer_cast<D_Container>(child);
c->properties.color = BUTTON_ON_TAP_COLOUR;
std::cout << "Tapped on child at (" << x << ", " << y << ")\n";

View_SetCC(i);
Navigator::push("/player_select");
},
.onTapRelease = [](std::shared_ptr<InternalDrawable> child, float x, float y) {
// Handle tap event
std::shared_ptr<D_Container> c = std::dynamic_pointer_cast<D_Container>(child);
c->properties.color = MENU_BUTTON_COLOUR;
std::cout << "Tapped on child at (" << x << ", " << y << ")\n";
},
.onHover = [](std::shared_ptr<InternalDrawable> child, float x, float y) {
// Handle hover event
std::cout << "Hovered over child at (" << x << ", " << y << ")\n";
std::shared_ptr<D_Container> c = std::dynamic_pointer_cast<D_Container>(child);
c->properties.color = BUTTON_ON_HOVER_COLOUR;
},
.onHoverEnd = [](std::shared_ptr<InternalDrawable> child, float x, float y) {
std::shared_ptr<D_Container> c = std::dynamic_pointer_cast<D_Container>(child);
c->properties.color = MENU_BUTTON_COLOUR;
},
.child = Container(
.width = MENU_BUTTON_WIDTH,
.height = MENU_BUTTON_HEIGHT,
.alignment = Alignment::Center(),
.color = MENU_BUTTON_COLOUR,
.child = Text(
.text = modes[i],
.scale = MENU_BUTTON_TEXT_SCALE,
.color = MENU_BUTTON_TEXT_COLOUR
),
)
));
}
Drawable::init();
}

std::shared_ptr<InternalDrawable> build() override {

std::vector<std::shared_ptr<InternalDrawable>> stuff = {
Positioned(
.child = BuildMenuBackground(),
.left = 0,
.top = 0,
.right = 0,
.bottom = 0,
),
Positioned(
.child = BuildMenuInfoBar(),
.left = 0,
.bottom = 0
),
Positioned(
.child = BuildMenuContent(entries),
.left = 0,
.top = 0,
.right = 0,
.bottom = 0
),
};
return BuildMenuStack(stuff);
}

~CCViewElements() override = default;
};

class CCView : public Drawable {
public:
std::shared_ptr<InternalDrawable> build() override {
// Render CCView
return std::make_shared<CCViewElements>();
}

~CCView() override = default;
};
Loading
Loading