Files
PDModdingCommunity_PD-Loader/source-code/source/plugins/TLAC/Components/Pause.h
T
somewhatlurker 32b110efa9 pause: better input filtering
buttons now need to be pressed again after leaving pause to trigger (instead of instantly hitting when unpaused)
2019-10-23 04:52:39 +11:00

105 lines
3.3 KiB
C++

#pragma once
#include "../Constants.h"
#include "EmulatorComponent.h"
#include "PlayerData.h"
#include "Input/InputState.h"
#include <string>
#include <vector>
#include <chrono>
namespace TLAC::Components
{
class Pause : public EmulatorComponent
{
public:
Pause();
~Pause();
virtual const char* GetDisplayName() override;
virtual void Initialize(ComponentsManager*) override;
virtual void Update() override;
virtual void UpdatePostInput() override;
virtual void UpdateDraw2D() override;
static bool pause; // set pause to change pause state
static bool giveUp; // set give up to end current song
private:
// this is a mess of static so that menuItems can work
static bool isPauseKeyTapped();
static std::vector<bool> streamPlayStates;
static void InjectCode(void* address, const std::vector<uint8_t> data);
static bool isPaused; // tracks internal state
static void saveOldPatchOps();
static std::vector<uint8_t> origAetMovOp;
static uint8_t* aetMovPatchAddress;
static std::vector<uint8_t> origFramespeedOp;
static uint8_t* framespeedPatchAddress;
static bool hookedGiveUpFunc(void* cls);
static void setSEVolume(int amount);
static PlayerData* playerData;
static InputState* inputState;
static const JvsButtons allButtons = (JvsButtons)(JVS_START | JVS_TRIANGLE | JVS_SQUARE | JVS_CROSS | JVS_CIRCLE | JVS_L | JVS_R); // deliberately only has control panel buttons
static JvsButtons filteredButtons;
static const int menuX = 640;
static const int menuY = 360;
static const int menuItemHeight = 36;
static const int menuTextSize = 24;
static const uint32_t bgLayer = 0x18;
static const uint32_t contentLayer = 0x19; // same as startup screen
static bool showUI;
static unsigned int menuPos;
static unsigned int mainMenuPos; // syncs to menuPos when menuSet == menuset_main (used for restoring on back)
static unsigned int menuSet;
int triangleAet;
int squareAet;
int crossAet;
int circleAet;
static std::chrono::time_point<std::chrono::high_resolution_clock> menuItemSelectTime;
enum menusets
{
MENUSET_MAIN = 0,
MENUSET_SEVOL = 1,
};
static void mainmenu() { menuSet = MENUSET_MAIN; menuPos = mainMenuPos; menuItemSelectTime = std::chrono::high_resolution_clock::now(); };
static void unpause() { pause = false; };
//static void restart() { *(uint8_t*)0x140d0b538 = 1; unpause(); }
static void giveup() { giveUp = true; };
static void sevolmenu() { menuSet = MENUSET_SEVOL; menuPos = 1; menuItemSelectTime = std::chrono::high_resolution_clock::now(); };
static void sevolplus() { setSEVolume(10); };
static void sevolminus() { setSEVolume(-10); };
// defined as an array now so submenus could be added
std::vector<std::pair<std::string, void(*)()>> menuItems[2] = {
{
std::pair<std::string, void(*)()>(std::string("RESUME"), &unpause),
//std::pair<std::string, void(*)()>(std::string("RESTART"), &restart),
std::pair<std::string, void(*)()>(std::string("SE VOLUME"), &sevolmenu),
std::pair<std::string, void(*)()>(std::string("GIVE UP"), &giveup),
},
{
std::pair<std::string, void(*)()>(std::string("+"), &sevolplus),
std::pair<std::string, void(*)()>(std::string("XX"), &mainmenu),
std::pair<std::string, void(*)()>(std::string("-"), &sevolminus),
}
};
};
}