mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Allow overriding stplyr in Srb2::Draw::Parse
This commit is contained in:
parent
2546fc8351
commit
512eb5ec67
4 changed files with 22 additions and 24 deletions
|
|
@ -1270,7 +1270,7 @@ INT32 G_CheckDoubleUsage(INT32 keynum, INT32 playernum, boolean modify)
|
|||
|
||||
INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
||||
{
|
||||
profile_t *ourProfile = PR_GetLocalPlayerProfile(player);
|
||||
profile_t *ourProfile = PR_GetPlayerProfile(&players[player]);
|
||||
if (ourProfile == NULL)
|
||||
ourProfile = PR_GetLocalPlayerProfile(0);
|
||||
|
||||
|
|
@ -1283,6 +1283,7 @@ INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
|||
|
||||
INT32 bindindex = MAXINPUTMAPPING-1;
|
||||
|
||||
// PASS 1: Binds that are directly in our profile control mapping.
|
||||
while (bindindex >= 0) // Prefer earlier binds
|
||||
{
|
||||
INT32 possiblecontrol = ourProfile->controls[control][bindindex];
|
||||
|
|
@ -1304,12 +1305,12 @@ INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
|||
}
|
||||
}
|
||||
|
||||
// Still no matching device bind? Try defaults...
|
||||
// PASS 2: Binds that are in the default controls.
|
||||
if (bestbind == -1)
|
||||
{
|
||||
bindindex = MAXINPUTMAPPING-1;
|
||||
|
||||
while (bindindex >= 0) // Prefer earlier binds
|
||||
while (bindindex >= 0)
|
||||
{
|
||||
INT32 possiblecontrol = gamecontroldefault[control][bindindex];
|
||||
|
||||
|
|
@ -1318,7 +1319,6 @@ INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
|||
if (possiblecontrol == 0)
|
||||
continue;
|
||||
|
||||
// if (device is gamepad) == (bound control is in gamepad range) - e.g. if bind matches device
|
||||
if ((device != KEYBOARD_MOUSE_DEVICE) == (possiblecontrol >= KEY_JOY1 && possiblecontrol < JOYINPUTEND))
|
||||
{
|
||||
bestbind = possiblecontrol;
|
||||
|
|
@ -1331,12 +1331,12 @@ INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
|||
}
|
||||
}
|
||||
|
||||
// STILL no matching device bind? Try menu reserved!
|
||||
// PASS 3: "Safety" binds that are reserved by the menu system.
|
||||
if (bestbind == -1)
|
||||
{
|
||||
bindindex = MAXINPUTMAPPING-1;
|
||||
|
||||
while (bindindex >= 0) // Prefer earlier binds
|
||||
while (bindindex >= 0)
|
||||
{
|
||||
INT32 possiblecontrol = menucontrolreserved[control][bindindex];
|
||||
|
||||
|
|
@ -1345,7 +1345,6 @@ INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
|||
if (possiblecontrol == 0)
|
||||
continue;
|
||||
|
||||
// if (device is gamepad) == (bound control is in gamepad range) - e.g. if bind matches device
|
||||
if ((device != KEYBOARD_MOUSE_DEVICE) == (possiblecontrol >= KEY_JOY1 && possiblecontrol < JOYINPUTEND))
|
||||
{
|
||||
bestbind = possiblecontrol;
|
||||
|
|
|
|||
|
|
@ -6360,12 +6360,7 @@ void K_AddMessageForPlayer(player_t *player, const char *msg, boolean interrupt,
|
|||
if (interrupt)
|
||||
state->clear();
|
||||
|
||||
// FIXME: SUPER BAD HACK.
|
||||
// Need a way to parse messages as a given player instead.
|
||||
player_t *oldstplyr = stplyr;
|
||||
stplyr = player;
|
||||
std::string parsedmsg = srb2::Draw::TextElement().parse(msg).string();
|
||||
stplyr = oldstplyr;
|
||||
std::string parsedmsg = srb2::Draw::TextElement().as(player - players).parse(msg).string();
|
||||
|
||||
if (persist)
|
||||
state->objective = parsedmsg;
|
||||
|
|
@ -6946,12 +6941,7 @@ INT32 K_DrawGameControl(UINT16 x, UINT16 y, UINT8 player, const char *str, UINT8
|
|||
{
|
||||
using srb2::Draw;
|
||||
|
||||
// FIXME: SUPER BAD HACK.
|
||||
// Need a way to parse messages as a given player instead.
|
||||
player_t *oldstplyr = stplyr;
|
||||
stplyr = &players[player];
|
||||
Draw::TextElement text = Draw::TextElement().parse(str).font(Draw::Font::kMenu);
|
||||
stplyr = oldstplyr;
|
||||
Draw::TextElement text = Draw::TextElement().as(player).parse(str).font(Draw::Font::kMenu);
|
||||
|
||||
INT32 width = text.width();
|
||||
|
||||
|
|
|
|||
|
|
@ -169,22 +169,24 @@ Draw::TextElement& Draw::TextElement::parse(std::string_view raw)
|
|||
if (auto id = inputdefinition.find(it->second & (~0xF0)); id != inputdefinition.end()) // This is a game control, do descriptive input translation!
|
||||
{
|
||||
// Grab our local controls
|
||||
UINT8 localplayer = stplyr - players;
|
||||
UINT8 targetplayer = as_.value_or(stplyr - players); // If not set in the call to parse(), use stplyr's controls
|
||||
if (targetplayer >= MAXPLAYERS)
|
||||
targetplayer = 0;
|
||||
|
||||
INT32 bind = G_FindPlayerBindForGameControl(localplayer, id->second);
|
||||
INT32 bind = G_FindPlayerBindForGameControl(targetplayer, id->second);
|
||||
|
||||
if (auto pretty = prettyinputs.find(bind); pretty != prettyinputs.end()) // Gamepad direction or keyboard arrow, use something nice-looking
|
||||
{
|
||||
string_.push_back((it->second & 0xF0) | pretty->second); // original invocation has the animation bits, but the glyph bits come from the table
|
||||
}
|
||||
else if (auto generic = genericinputs.find(bind); generic != genericinputs.end()) // Gamepad input, display it to the player as they are
|
||||
else if (auto generic = genericinputs.find(bind); generic != genericinputs.end()) // Non-directional gamepad input, display it to the player as they are
|
||||
{
|
||||
string_.push_back(0xEF);
|
||||
string_.push_back(0xEF); // Control code: "switch to descriptive input mode" - Saturn buttons will draw as generic gamepad buttons
|
||||
string_.push_back((it->second & 0xF0) | generic->second); // original invocation has the animation bits, but the glyph bits come from the table
|
||||
}
|
||||
else
|
||||
{
|
||||
string_.push_back('\xEE');
|
||||
string_.push_back('\xEE'); // Control code: "toggle boxed drawing"
|
||||
|
||||
if (bind == -1)
|
||||
string_.append("[NOT BOUND]");
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ public:
|
|||
const std::string& string() const { return string_; }
|
||||
std::optional<Font> font() const { return font_; }
|
||||
std::optional<INT32> flags() const { return flags_; }
|
||||
std::optional<UINT8> as() const { return as_; }
|
||||
|
||||
int width() const;
|
||||
|
||||
|
|
@ -142,10 +143,16 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
TextElement& as(UINT8 as)
|
||||
{
|
||||
as_ = as;
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
std::string string_;
|
||||
std::optional<Font> font_;
|
||||
std::optional<INT32> flags_;
|
||||
std::optional<UINT8> as_;
|
||||
};
|
||||
|
||||
class Chain
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue