2019-11-04 22:01:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "tarray.h"
|
|
|
|
#include "name.h"
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
struct FButtonStatus
|
|
|
|
{
|
|
|
|
enum { MAX_KEYS = 6 }; // Maximum number of keys that can press this button
|
|
|
|
|
|
|
|
uint16_t Keys[MAX_KEYS];
|
|
|
|
bool bDown; // Button is down right now
|
|
|
|
bool bWentDown; // Button went down this tic
|
|
|
|
bool bWentUp; // Button went up this tic
|
2020-04-11 22:10:39 +00:00
|
|
|
bool bReleaseLock; // Lock ReleaseKey call in ResetButtonStates
|
|
|
|
void (*PressHandler)(); // for optional game-side customization
|
|
|
|
void (*ReleaseHandler)();
|
2019-11-04 22:01:50 +00:00
|
|
|
|
|
|
|
bool PressKey (int keynum); // Returns true if this key caused the button to be pressed.
|
|
|
|
bool ReleaseKey (int keynum); // Returns true if this key is no longer pressed.
|
|
|
|
void ResetTriggers () { bWentDown = bWentUp = false; }
|
|
|
|
void Reset () { bDown = bWentDown = bWentUp = false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class ButtonMap
|
|
|
|
{
|
2020-04-11 22:10:39 +00:00
|
|
|
|
2020-04-11 22:09:39 +00:00
|
|
|
TArray<FButtonStatus> Buttons;
|
|
|
|
TArray<FString> NumToName; // The internal name of the button
|
2019-11-04 22:01:50 +00:00
|
|
|
TMap<FName, int> NameToNum;
|
2020-04-11 22:10:39 +00:00
|
|
|
|
2019-11-04 22:01:50 +00:00
|
|
|
public:
|
2020-04-11 22:09:39 +00:00
|
|
|
void SetButtons(const char** names, int count);
|
2020-04-11 22:10:39 +00:00
|
|
|
|
|
|
|
int NumButtons() const
|
2019-11-04 22:01:50 +00:00
|
|
|
{
|
2020-04-11 22:09:39 +00:00
|
|
|
return Buttons.Size();
|
2019-11-04 22:01:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 22:10:39 +00:00
|
|
|
int FindButtonIndex(const char* func, int funclen = -1) const;
|
|
|
|
|
|
|
|
FButtonStatus* FindButton(const char* func, int funclen = -1)
|
|
|
|
{
|
|
|
|
int index = FindButtonIndex(func, funclen);
|
|
|
|
return index > -1 ? &Buttons[index] : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
FButtonStatus* GetButton(int index)
|
2019-11-04 22:01:50 +00:00
|
|
|
{
|
2020-04-11 22:10:39 +00:00
|
|
|
return &Buttons[index];
|
2019-11-04 22:01:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 22:10:39 +00:00
|
|
|
void ResetButtonTriggers(); // Call ResetTriggers for all buttons
|
|
|
|
void ResetButtonStates(); // Same as above, but also clear bDown
|
2019-11-04 22:01:50 +00:00
|
|
|
int ListActionCommands(const char* pattern);
|
2020-04-11 22:10:39 +00:00
|
|
|
void AddButtonTabCommands();
|
2019-11-04 22:01:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool ButtonDown(int x) const
|
|
|
|
{
|
|
|
|
return Buttons[x].bDown;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ButtonPressed(int x) const
|
|
|
|
{
|
|
|
|
return Buttons[x].bWentDown;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ButtonReleased(int x) const
|
|
|
|
{
|
|
|
|
return Buttons[x].bWentUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearButton(int x)
|
|
|
|
{
|
|
|
|
Buttons[x].Reset();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern ButtonMap buttonMap;
|