Check if buttons txd exsist

This commit is contained in:
Sergeanur 2020-11-07 20:54:38 +02:00
parent 3b81eaa2d7
commit 7f4498e0f0
3 changed files with 44 additions and 29 deletions

View File

@ -2500,10 +2500,11 @@ int32 CControllerConfigManager::GetNumOfSettingsForAction(e_ControllerAction act
nil, /* SHOW_MOUSE_POINTER_TOGGLE */ \ nil, /* SHOW_MOUSE_POINTER_TOGGLE */ \
}} }}
const char *XboxButtons_noIcons[][MAX_CONTROLLERACTIONS] = CONTROLLER_BUTTONS("Y", "B", "A", "X", "LB", "LT", "LS", "RB", "RT", "RS", "BACK");
#ifdef BUTTON_ICONS #ifdef BUTTON_ICONS
const char *XboxButtons[][MAX_CONTROLLERACTIONS] = CONTROLLER_BUTTONS("~T~", "~O~", "~X~", "~Q~", "~K~", "~M~", "~A~", "~J~", "~V~", "~C~", "BACK"); const char *XboxButtons[][MAX_CONTROLLERACTIONS] = CONTROLLER_BUTTONS("~T~", "~O~", "~X~", "~Q~", "~K~", "~M~", "~A~", "~J~", "~V~", "~C~", "BACK");
#else
const char *XboxButtons[][MAX_CONTROLLERACTIONS] = CONTROLLER_BUTTONS("Y", "B", "A", "X", "LB", "LT", "LS", "RB", "RT", "RS", "BACK");
#endif #endif
@ -2524,12 +2525,12 @@ const char *XboxButtons[][MAX_CONTROLLERACTIONS] = CONTROLLER_BUTTONS("Y", "B",
#define PS2_SQUARE "SQUARE" #define PS2_SQUARE "SQUARE"
#endif #endif
const char *PlayStationButtons_noIcons[][MAX_CONTROLLERACTIONS] =
CONTROLLER_BUTTONS(PS2_TRIANGLE, PS2_CIRCLE, PS2_CROSS, PS2_SQUARE, "L1", "L2", "L3", "R1", "R2", "R3", "SELECT");
#ifdef BUTTON_ICONS #ifdef BUTTON_ICONS
const char *PlayStationButtons[][MAX_CONTROLLERACTIONS] = const char *PlayStationButtons[][MAX_CONTROLLERACTIONS] =
CONTROLLER_BUTTONS(PS2_TRIANGLE, PS2_CIRCLE, PS2_CROSS, PS2_SQUARE, "~K~", "~M~", "~A~", "~J~", "~V~", "~C~", "SELECT"); CONTROLLER_BUTTONS(PS2_TRIANGLE, PS2_CIRCLE, PS2_CROSS, PS2_SQUARE, "~K~", "~M~", "~A~", "~J~", "~V~", "~C~", "SELECT");
#else
const char *PlayStationButtons[][MAX_CONTROLLERACTIONS] =
CONTROLLER_BUTTONS(PS2_TRIANGLE, PS2_CIRCLE, PS2_CROSS, PS2_SQUARE, "L1", "L2", "L3", "R1", "R2", "R3", "SELECT");
#endif #endif
#undef PS2_TRIANGLE #undef PS2_TRIANGLE
@ -2547,7 +2548,11 @@ void CControllerConfigManager::GetWideStringOfCommandKeys(uint16 action, wchar *
wchar wstr[16]; wchar wstr[16];
// TODO: INI and/or menu setting for Xbox/PS switch // TODO: INI and/or menu setting for Xbox/PS switch
const char *(*Buttons)[MAX_CONTROLLERACTIONS] = XboxButtons; #ifdef BUTTON_ICONS
const char *(*Buttons)[MAX_CONTROLLERACTIONS] = CFont::ButtonsSlot != -1 ? XboxButtons : XboxButtons_noIcons;
#else
const char *(*Buttons)[MAX_CONTROLLERACTIONS] = XboxButtons_noIcons;
#endif
assert(Buttons[CPad::GetPad(0)->Mode][action] != nil); // we cannot use these assert(Buttons[CPad::GetPad(0)->Mode][action] != nil); // we cannot use these
AsciiToUnicode(Buttons[CPad::GetPad(0)->Mode][action], wstr); AsciiToUnicode(Buttons[CPad::GetPad(0)->Mode][action], wstr);

View File

@ -3,6 +3,9 @@
#include "Sprite2d.h" #include "Sprite2d.h"
#include "TxdStore.h" #include "TxdStore.h"
#include "Font.h" #include "Font.h"
#ifdef BUTTON_ICONS
#include "FileMgr.h"
#endif
void void
AsciiToUnicode(const char *src, wchar *dst) AsciiToUnicode(const char *src, wchar *dst)
@ -227,6 +230,7 @@ wchar foreign_table[128] = {
#ifdef BUTTON_ICONS #ifdef BUTTON_ICONS
CSprite2d CFont::ButtonSprite[MAX_BUTTON_ICONS]; CSprite2d CFont::ButtonSprite[MAX_BUTTON_ICONS];
int CFont::PS2Symbol = BUTTON_NONE; int CFont::PS2Symbol = BUTTON_NONE;
int CFont::ButtonsSlot = -1;
#endif // BUTTON_ICONS #endif // BUTTON_ICONS
void void
@ -288,28 +292,31 @@ CFont::Initialise(void)
CTxdStore::PopCurrentTxd(); CTxdStore::PopCurrentTxd();
#ifdef BUTTON_ICONS #ifdef BUTTON_ICONS
slot = CTxdStore::AddTxdSlot("buttons"); if (int file = CFileMgr::OpenFile("MODELS/X360BTNS.TXD")) {
CTxdStore::LoadTxd(slot, "MODELS/X360BTNS.TXD"); CFileMgr::CloseFile(file);
CTxdStore::AddRef(slot); ButtonsSlot = CTxdStore::AddTxdSlot("buttons");
CTxdStore::PushCurrentTxd(); CTxdStore::LoadTxd(ButtonsSlot, "MODELS/X360BTNS.TXD");
CTxdStore::SetCurrentTxd(slot); CTxdStore::AddRef(ButtonsSlot);
CTxdStore::PushCurrentTxd();
CTxdStore::SetCurrentTxd(ButtonsSlot);
#if 0 // unused #if 0 // unused
ButtonSprite[BUTTON_UP].SetTexture("up"); ButtonSprite[BUTTON_UP].SetTexture("up");
ButtonSprite[BUTTON_DOWN].SetTexture("down"); ButtonSprite[BUTTON_DOWN].SetTexture("down");
ButtonSprite[BUTTON_LEFT].SetTexture("left"); ButtonSprite[BUTTON_LEFT].SetTexture("left");
ButtonSprite[BUTTON_RIGHT].SetTexture("right"); ButtonSprite[BUTTON_RIGHT].SetTexture("right");
#endif #endif
ButtonSprite[BUTTON_CROSS].SetTexture("cross"); ButtonSprite[BUTTON_CROSS].SetTexture("cross");
ButtonSprite[BUTTON_CIRCLE].SetTexture("circle"); ButtonSprite[BUTTON_CIRCLE].SetTexture("circle");
ButtonSprite[BUTTON_SQUARE].SetTexture("square"); ButtonSprite[BUTTON_SQUARE].SetTexture("square");
ButtonSprite[BUTTON_TRIANGLE].SetTexture("triangle"); ButtonSprite[BUTTON_TRIANGLE].SetTexture("triangle");
ButtonSprite[BUTTON_L1].SetTexture("l1"); ButtonSprite[BUTTON_L1].SetTexture("l1");
ButtonSprite[BUTTON_L2].SetTexture("l2"); ButtonSprite[BUTTON_L2].SetTexture("l2");
ButtonSprite[BUTTON_L3].SetTexture("l3"); ButtonSprite[BUTTON_L3].SetTexture("l3");
ButtonSprite[BUTTON_R1].SetTexture("r1"); ButtonSprite[BUTTON_R1].SetTexture("r1");
ButtonSprite[BUTTON_R2].SetTexture("r2"); ButtonSprite[BUTTON_R2].SetTexture("r2");
ButtonSprite[BUTTON_R3].SetTexture("r3"); ButtonSprite[BUTTON_R3].SetTexture("r3");
CTxdStore::PopCurrentTxd(); CTxdStore::PopCurrentTxd();
}
#endif // BUTTON_ICONS #endif // BUTTON_ICONS
} }
@ -360,9 +367,11 @@ void
CFont::Shutdown(void) CFont::Shutdown(void)
{ {
#ifdef BUTTON_ICONS #ifdef BUTTON_ICONS
for (int i = 0; i < MAX_BUTTON_ICONS; i++) if (ButtonsSlot != -1) {
ButtonSprite[i].Delete(); for (int i = 0; i < MAX_BUTTON_ICONS; i++)
CTxdStore::RemoveTxdSlot(CTxdStore::FindTxdSlot("buttons")); ButtonSprite[i].Delete();
CTxdStore::RemoveTxdSlot(ButtonsSlot);
}
#endif #endif
Sprite[0].Delete(); Sprite[0].Delete();
Sprite[1].Delete(); Sprite[1].Delete();

View File

@ -103,6 +103,7 @@ public:
static CFontDetails Details; static CFontDetails Details;
#ifdef BUTTON_ICONS #ifdef BUTTON_ICONS
static int32 ButtonsSlot;
static CSprite2d ButtonSprite[MAX_BUTTON_ICONS]; static CSprite2d ButtonSprite[MAX_BUTTON_ICONS];
static int PS2Symbol; static int PS2Symbol;