Add frame advance toggle (#23)

This commit is contained in:
Garrett Cox
2024-05-22 09:04:57 -05:00
parent 683a108194
commit 76e325feb8
2 changed files with 33 additions and 1 deletions
+23
View File
@@ -484,6 +484,29 @@ void DrawDeveloperToolsMenu() {
UIWidgets::PaddedEnhancementCheckbox("Debug Warp Screen Translation", "gDebugWarpScreenTranslation", true,
false, false, "", UIWidgets::CheckboxGraphics::Cross, true);
UIWidgets::Tooltip("Translate the Debug Warp Screen based on the game language");
if (gPlayState != NULL) {
UIWidgets::PaddedSeparator();
ImGui::Checkbox("Frame Advance##frameAdvance", (bool*)&gPlayState->frameAdvCtx.enabled);
UIWidgets::Tooltip("This allows you to advance through the game one frame at a time on command. "
"To advance a frame, hold Z and tap R on the second controller. Holding Z "
"and R will advance a frame every half second. You can also use the buttons below.");
if (gPlayState->frameAdvCtx.enabled) {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(12.0f, 6.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0,0));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.22f, 0.38f, 0.56f, 1.0f));
if (ImGui::Button("Advance 1", ImVec2(90.0f, 0.0f))) {
CVarSetInteger("gDeveloperTools.FrameAdvanceTick", 1);
}
ImGui::SameLine();
ImGui::Button("Advance (Hold)");
if (ImGui::IsItemActive()) {
CVarSetInteger("gDeveloperTools.FrameAdvanceTick", 1);
}
ImGui::PopStyleVar(3);
ImGui::PopStyleColor(1);
}
}
UIWidgets::PaddedSeparator();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(12.0f, 6.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0, 0));
+10 -1
View File
@@ -23,6 +23,7 @@
#include "libc/stdbool.h"
#include "padutils.h"
#include "macros.h"
#include "libultraship/libultraship.h"
void FrameAdvance_Init(FrameAdvanceContext* frameAdvCtx) {
frameAdvCtx->timer = 0;
@@ -33,9 +34,17 @@ void FrameAdvance_Init(FrameAdvanceContext* frameAdvCtx) {
* Returns true when frame advance is not active (game will run normally)
*/
s32 FrameAdvance_Update(FrameAdvanceContext* frameAdvCtx, Input* input) {
if (!frameAdvCtx->enabled || (CHECK_BTN_ALL(input->cur.button, BTN_Z) &&
if (CVarGetInteger("gDebugEnabled", 0)) {
if (CHECK_BTN_ALL(input->cur.button, BTN_R) && CHECK_BTN_ALL(input->press.button, BTN_DDOWN)) {
frameAdvCtx->enabled = !frameAdvCtx->enabled;
}
}
if (!frameAdvCtx->enabled || CVarGetInteger("gDeveloperTools.FrameAdvanceTick", 0) ||
(CHECK_BTN_ALL(input->cur.button, BTN_Z) &&
(CHECK_BTN_ALL(input->press.button, BTN_R) ||
(CHECK_BTN_ALL(input->cur.button, BTN_R) && (++frameAdvCtx->timer >= 9))))) {
CVarClear("gDeveloperTools.FrameAdvanceTick");
frameAdvCtx->timer = 0;
return true;
}