Allow overriding stplyr in Srb2::Draw::Parse

This commit is contained in:
Antonio Martinez 2024-09-16 16:32:50 -07:00 committed by AJ Martinez
parent 2546fc8351
commit 512eb5ec67
4 changed files with 22 additions and 24 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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]");

View file

@ -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