Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time Splits v2.1 #43

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions soh/assets/soh_assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ static const ALIGN_ASSET(2) char gArrowDownTex[] = dgArrowDown;
#define dgTriforcePiece "__OTR__textures/parameter_static/gTriforcePiece"
static const ALIGN_ASSET(2) char gTriforcePieceTex[] = dgTriforcePiece;

#define dgWTriforcePiece "__OTR__textures/parameter_static/gWTriforcePiece"
static const ALIGN_ASSET(2) char gWTriforcePieceTex[] = dgWTriforcePiece;

#define dgSplitEntrance "__OTR__textures/parameter_static/gSplitEntrance"
static const ALIGN_ASSET(2) char gSplitEntranceTex[] = dgSplitEntrance;

#define dgBossSoul "__OTR__textures/parameter_static/gBossSoul"
static const ALIGN_ASSET(2) char gBossSoulTex[] = dgBossSoul;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ DEFINE_HOOK(OnActorUpdate, (void* actor));
DEFINE_HOOK(OnActorKill, (void* actor));
DEFINE_HOOK(OnEnemyDefeat, (void* actor));
DEFINE_HOOK(OnBossDefeat, (void* actor));
DEFINE_HOOK(OnTimestamp, (u8 item));
DEFINE_HOOK(OnPlayerBonk, ());
DEFINE_HOOK(OnPlayerHealthChange, (int16_t amount));
DEFINE_HOOK(OnPlayerBottleUpdate, (int16_t contents));
DEFINE_HOOK(OnPlayDestroy, ());
DEFINE_HOOK(OnPlayDrawEnd, ());
DEFINE_HOOK(OnVanillaBehavior, (GIVanillaBehavior flag, bool* result, va_list originalArgs));
Expand Down
12 changes: 12 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,22 @@ void GameInteractor_ExecuteOnBossDefeat(void* actor) {
GameInteractor::Instance->ExecuteHooksForFilter<GameInteractor::OnBossDefeat>(actor);
}

void GameInteractor_ExecuteOnTimestamp (u8 item) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnTimestamp>(item);
}

void GameInteractor_ExecuteOnPlayerBonk() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayerBonk>();
}

void GameInteractor_ExecuteOnPlayerHealthChange(int16_t amount) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayerHealthChange>(amount);
}

void GameInteractor_ExecuteOnPlayerBottleUpdate(int16_t contents) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayerBottleUpdate>(contents);
}

void GameInteractor_ExecuteOnPlayDestroy() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayDestroy>();
}
Expand Down
3 changes: 3 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ void GameInteractor_ExecuteOnActorUpdate(void* actor);
void GameInteractor_ExecuteOnActorKill(void* actor);
void GameInteractor_ExecuteOnEnemyDefeat(void* actor);
void GameInteractor_ExecuteOnBossDefeat(void* actor);
void GameInteractor_ExecuteOnTimestamp (u8 item);
void GameInteractor_ExecuteOnPlayerBonk();
void GameInteractor_ExecuteOnPlayerHealthChange(int16_t amount);
void GameInteractor_ExecuteOnPlayerBottleUpdate(int16_t contents);
void GameInteractor_ExecuteOnOcarinaSongAction();
void GameInteractor_ExecuteOnShopSlotChangeHooks(uint8_t cursorIndex, int16_t price);
void GameInteractor_ExecuteOnPlayDestroy();
Expand Down
995 changes: 995 additions & 0 deletions soh/soh/Enhancements/timesplits/TimeSplits.cpp

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions soh/soh/Enhancements/timesplits/TimeSplits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once
#ifndef TIMESPLITS_H
#define TIMESPLITS_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif // TIMESPLITS_H

#include <libultraship/libultraship.h>

#ifdef __cplusplus
class TimeSplitWindow : public Ship::GuiWindow {
public:
using GuiWindow::GuiWindow;

void InitElement() override;
void Draw() override;
void DrawElement() override;
void UpdateElement() override{};
};

typedef enum {
ACTION_SAVE,
ACTION_LOAD,
ACTION_UPDATE,
ACTION_COLLECT,
ACTION_DELETE
};

typedef enum {
SPLIT_ACTIVE,
SPLIT_INACTIVE,
SPLIT_COLLECTED,
SPLIT_SKIPPED
};

typedef enum {
SPLIT_ITEM,
SPLIT_UPGRADE,
SPLIT_EQUIPMENT,
SPLIT_QUEST,
SPLIT_BOSS,
SPLIT_ENTRANCE,
SPLIT_MISC
};

typedef struct {
uint32_t splitType;
uint32_t splitID;
std::string splitName;
std::string splitImage;
ImVec4 splitTint;
uint32_t splitTimeCurrent;
uint32_t splitTimeBest;
uint32_t splitTimePreviousBest;
uint32_t splitTimeStatus;
uint32_t splitSkullTokenCount;
} SplitObject;

#endif
4 changes: 4 additions & 0 deletions soh/soh/SohGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ namespace SohGui {
std::shared_ptr<EntranceTrackerWindow> mEntranceTrackerWindow;
std::shared_ptr<ItemTrackerSettingsWindow> mItemTrackerSettingsWindow;
std::shared_ptr<ItemTrackerWindow> mItemTrackerWindow;
std::shared_ptr<TimeSplitWindow> mTimeSplitWindow;
std::shared_ptr<RandomizerSettingsWindow> mRandomizerSettingsWindow;
std::shared_ptr<AdvancedResolutionSettings::AdvancedResolutionSettingsWindow> mAdvancedResolutionSettingsWindow;
std::shared_ptr<SohModalWindow> mModalWindow;
Expand Down Expand Up @@ -210,6 +211,8 @@ namespace SohGui {
gui->AddGuiWindow(mItemTrackerSettingsWindow);
mRandomizerSettingsWindow = std::make_shared<RandomizerSettingsWindow>(CVAR_WINDOW("RandomizerSettings"), "Randomizer Settings", ImVec2(920, 600));
gui->AddGuiWindow(mRandomizerSettingsWindow);
mTimeSplitWindow = std::make_shared<TimeSplitWindow>(CVAR_WINDOW("TimeSplitEnabled"), "Time Splits", ImVec2(450, 660));
gui->AddGuiWindow(mTimeSplitWindow);
mAdvancedResolutionSettingsWindow = std::make_shared<AdvancedResolutionSettings::AdvancedResolutionSettingsWindow>(CVAR_WINDOW("AdvancedResolutionEditor"), "Advanced Resolution Settings", ImVec2(497, 599));
gui->AddGuiWindow(mAdvancedResolutionSettingsWindow);
mModalWindow = std::make_shared<SohModalWindow>(CVAR_WINDOW("ModalWindow"), "Modal Window");
Expand Down Expand Up @@ -247,6 +250,7 @@ namespace SohGui {
mSohMenuBar = nullptr;
mInputViewer = nullptr;
mInputViewerSettings = nullptr;
mTimeSplitWindow = nullptr;
}

void RegisterPopup(std::string title, std::string message, std::string button1, std::string button2, std::function<void()> button1callback, std::function<void()> button2callback) {
Expand Down
1 change: 1 addition & 0 deletions soh/soh/SohGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Enhancements/randomizer/randomizer_entrance_tracker.h"
#include "Enhancements/randomizer/randomizer_item_tracker.h"
#include "Enhancements/randomizer/randomizer_settings_window.h"
#include "Enhancements/timesplits/TimeSplits.h"
#include "SohModals.h"

#ifdef __cplusplus
Expand Down
8 changes: 8 additions & 0 deletions soh/soh/SohMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "Enhancements/randomizer/randomizer_settings_window.h"
#include "Enhancements/resolution-editor/ResolutionEditor.h"
#include "Enhancements/enemyrandomizer.h"
#include "Enhancements/timesplits/TimeSplits.h"

// FA icons are kind of wonky, if they worked how I expected them to the "+ 2.0f" wouldn't be needed, but
// they don't work how I expect them to so I added that because it looked good when I eyeballed it
Expand Down Expand Up @@ -571,6 +572,7 @@ void DrawSettingsMenu() {
extern std::shared_ptr<AudioEditor> mAudioEditorWindow;
extern std::shared_ptr<CosmeticsEditorWindow> mCosmeticsEditorWindow;
extern std::shared_ptr<GameplayStatsWindow> mGameplayStatsWindow;
extern std::shared_ptr<TimeSplitWindow> mTimeSplitWindow;

void DrawEnhancementsMenu() {
if (ImGui::BeginMenu("Enhancements"))
Expand Down Expand Up @@ -1650,6 +1652,12 @@ void DrawEnhancementsMenu() {
mGameplayStatsWindow->ToggleVisibility();
}
}

if (mTimeSplitWindow) {
if (ImGui::Button(GetWindowButtonText("Time Splits", CVarGetInteger(CVAR_WINDOW("TimeSplitEnabled"), 0)).c_str(), ImVec2(-1.0f, 0.0f))) {
mTimeSplitWindow->ToggleVisibility();
}
}
ImGui::PopStyleVar(3);
ImGui::PopStyleColor(1);

Expand Down
3 changes: 3 additions & 0 deletions soh/src/code/z_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@ void GameplayStats_SetTimestamp(PlayState* play, u8 item) {
}

gSaveContext.sohStats.itemTimestamp[item] = time;
GameInteractor_ExecuteOnTimestamp(item);
}

// Gameplay stat tracking: Update time the item was acquired
Expand Down Expand Up @@ -3321,6 +3322,8 @@ s32 Health_ChangeBy(PlayState* play, s16 healthChange) {
// "Life=%d *** %d ******"
osSyncPrintf(" ライフ=%d *** %d ******\n", gSaveContext.health, healthLevel);

GameInteractor_ExecuteOnPlayerHealthChange(healthChange);

if (gSaveContext.health <= 0) {
gSaveContext.health = 0;
return 0;
Expand Down
1 change: 1 addition & 0 deletions soh/src/overlays/actors/ovl_player_actor/z_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -14686,6 +14686,7 @@ void Player_Action_SwingBottle(Player* this, PlayState* play) {
Message_StartTextbox(play, sBottleCatchInfo[this->av1.bottleCatchType - 1].textId, &this->actor);
}
Audio_PlayFanfare(NA_BGM_ITEM_GET | 0x900);
GameInteractor_ExecuteOnPlayerBottleUpdate((sBottleCatchInfo[this->av1.bottleCatchType - 1].itemId));
this->av2.startedTextbox = true;
} else if (Message_GetState(&play->msgCtx) == TEXT_STATE_CLOSING) {
this->av1.bottleCatchType = BOTTLE_CATCH_NONE;
Expand Down
Loading