Use button macros

This commit is contained in:
Cong
2023-07-09 21:44:40 +10:00
parent 526859a7c6
commit 477e5ffd2a
15 changed files with 84 additions and 83 deletions

View File

@@ -93,7 +93,7 @@ static void AmmoSelect(menu_t *menu, int cmd, void *data)
AmmoMenu *d = data;
d->SelectResult = AMMO_MENU_NONE;
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
const int ammoId = GetSelectedAmmo(d);
if (ammoId < 0)
@@ -121,7 +121,7 @@ static void AmmoSelect(menu_t *menu, int cmd, void *data)
}
}
}
else if (cmd & CMD_BUTTON2)
else if (Button2(cmd))
{
d->SelectResult = AMMO_MENU_CANCEL;
MenuPlaySound(MENU_SOUND_BACK);
@@ -418,15 +418,15 @@ static int HandleInputMenu(int cmd, void *data)
const int numAmmo = (int)d->ammoIds.size;
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
// Do nothing; don't switch away from menu
}
else if (cmd & CMD_BUTTON2)
else if (Button2(cmd))
{
return 1;
}
else if (cmd & CMD_LEFT)
else if (Left(cmd))
{
if ((d->idx % 2) == 1)
{
@@ -434,7 +434,7 @@ static int HandleInputMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_RIGHT)
else if (Right(cmd))
{
if (d->idx < numAmmo * 2 && (d->idx % 2) == 0)
{
@@ -442,7 +442,7 @@ static int HandleInputMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_UP)
else if (Up(cmd))
{
if (d->idx >= 2)
{
@@ -450,7 +450,7 @@ static int HandleInputMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_DOWN)
else if (Down(cmd))
{
if (d->idx + 2 < numAmmo * 2 + 2)
{

View File

@@ -995,10 +995,10 @@ static bool ActorTryChangeDirection(
{
const bool willChangeDirecton =
!actor->petrified && CMD_HAS_DIRECTION(cmd) &&
(!(cmd & CMD_BUTTON2) ||
(!Button2(cmd) ||
ConfigGetEnum(&gConfig, "Game.SwitchMoveStyle") !=
SWITCHMOVE_STRAFE) &&
(!(prevCmd & CMD_BUTTON1) ||
(!Button1(prevCmd) ||
ConfigGetEnum(&gConfig, "Game.FireMoveStyle") != FIREMOVE_STRAFE);
const direction_e dir = CmdToDirection(cmd);
if (willChangeDirecton && dir != actor->direction)
@@ -1015,7 +1015,7 @@ static bool ActorTryChangeDirection(
static bool ActorTryShoot(TActor *actor, const int cmd)
{
const bool willShoot = !actor->petrified && (cmd & CMD_BUTTON1);
const bool willShoot = !actor->petrified && Button1(cmd);
if (willShoot)
{
FireWeapon(actor, ACTOR_GET_GUN(actor));
@@ -1104,10 +1104,10 @@ void CommandActor(TActor *actor, int cmd, int ticks)
}
actor->specialCmdDir = CMD_HAS_DIRECTION(cmd);
if ((cmd & CMD_BUTTON2) && !actor->specialCmdDir)
if (Button2(cmd) && !actor->specialCmdDir)
{
// Special: pick up things that can only be picked up on demand
if (!actor->PickupAll && !(actor->lastCmd & CMD_BUTTON2) &&
if (!actor->PickupAll && !Button2(actor->lastCmd) &&
actor->vehicleUID == -1)
{
GameEvent e = GameEventNew(GAME_EVENT_ACTOR_PICKUP_ALL);
@@ -1126,7 +1126,7 @@ static bool ActorTryMove(TActor *actor, int cmd, int ticks)
!actor->hasShot ||
(ConfigGetEnum(&gConfig, "Game.SwitchMoveStyle") ==
SWITCHMOVE_STRAFE &&
(cmd & CMD_BUTTON2));
Button2(cmd));
const bool willMove =
!actor->petrified && CMD_HAS_DIRECTION(cmd) && canMoveWhenShooting;
actor->MoveVel = svec2_zero();
@@ -1134,13 +1134,13 @@ static bool ActorTryMove(TActor *actor, int cmd, int ticks)
{
const float moveAmount = ActorGetCharacter(actor)->speed * ticks;
struct vec2 moveVel = svec2_zero();
if (cmd & CMD_LEFT)
if (Left(cmd))
moveVel.x--;
else if (cmd & CMD_RIGHT)
else if (Right(cmd))
moveVel.x++;
if (cmd & CMD_UP)
if (Up(cmd))
moveVel.y--;
else if (cmd & CMD_DOWN)
else if (Down(cmd))
moveVel.y++;
if (!svec2_is_zero(moveVel))
{
@@ -1180,13 +1180,13 @@ void SlideActor(TActor *actor, int cmd)
GameEvent e = GameEventNew(GAME_EVENT_ACTOR_SLIDE);
e.u.ActorSlide.UID = actor->uid;
struct vec2 vel = svec2_zero();
if (cmd & CMD_LEFT)
if (Left(cmd))
vel.x = -SLIDE_X;
else if (cmd & CMD_RIGHT)
else if (Right(cmd))
vel.x = SLIDE_X;
if (cmd & CMD_UP)
if (Up(cmd))
vel.y = -SLIDE_Y;
else if (cmd & CMD_DOWN)
else if (Down(cmd))
vel.y = SLIDE_Y;
e.u.ActorSlide.Vel = Vec2ToNet(vel);
GameEventsEnqueue(&gGameEvents, e);

View File

@@ -288,7 +288,7 @@ static bool DidPlayerShoot(void)
continue;
}
const TActor *player = ActorGetByUID(p->ActorUID);
if (player->lastCmd & CMD_BUTTON1)
if (Button1(player->lastCmd))
{
return true;
}

View File

@@ -95,7 +95,7 @@ int AICoopGetCmd(TActor *actor, const int ticks)
break;
}
// Don't slide
if ((cmd & CMD_BUTTON2) && CMD_HAS_DIRECTION(cmd))
if (Button2(cmd) && CMD_HAS_DIRECTION(cmd))
{
cmd &= ~CMD_BUTTON2;
}

View File

@@ -398,19 +398,19 @@ TObject *AIGetObjectRunningInto(TActor *a, int cmd)
// check if there's a (non-dangerous) object in front of it
struct vec2 frontPos = a->Pos;
Thing *item;
if (cmd & CMD_LEFT)
if (Left(cmd))
{
frontPos.x--;
}
else if (cmd & CMD_RIGHT)
else if (Right(cmd))
{
frontPos.x++;
}
if (cmd & CMD_UP)
if (Up(cmd))
{
frontPos.y--;
}
else if (cmd & CMD_DOWN)
else if (Down(cmd))
{
frontPos.y++;
}

View File

@@ -73,10 +73,10 @@ void CameraInput(Camera *camera, const int cmd, const int lastCmd)
{
camera->spectateMode = SPECTATE_FREE;
const int pan = PAN_SPEED;
if (cmd & CMD_LEFT) camera->lastPosition.x -= pan;
else if (cmd & CMD_RIGHT) camera->lastPosition.x += pan;
if (cmd & CMD_UP) camera->lastPosition.y -= pan;
else if (cmd & CMD_DOWN) camera->lastPosition.y += pan;
if (Left(cmd)) camera->lastPosition.x -= pan;
else if (Right(cmd)) camera->lastPosition.x += pan;
if (Up(cmd)) camera->lastPosition.y -= pan;
else if (Down(cmd)) camera->lastPosition.y += pan;
}
else if ((AnyButton(cmd) && !AnyButton(lastCmd)) ||
camera->FollowNextPlayer)
@@ -97,7 +97,7 @@ void CameraInput(Camera *camera, const int cmd, const int lastCmd)
}
CA_FOREACH_END()
// Get the next player by index that has an actor in the game
const int d = (cmd & CMD_BUTTON1) ? 1 : -1;
const int d = Button1(cmd) ? 1 : -1;
for (int i = playerIndex + d;; i += d)
{
i = CLAMP_OPPOSITE(i, 0, (int)gPlayerDatas.size - 1);

View File

@@ -54,14 +54,14 @@
int CmdGetReverse(int cmd)
{
int newCmd = cmd & ~(CMD_LEFT | CMD_RIGHT | CMD_UP | CMD_DOWN);
if (cmd & CMD_LEFT)
int newCmd = cmd & ~CMD_DIRECTIONS;
if (Left(cmd))
newCmd |= CMD_RIGHT;
if (cmd & CMD_RIGHT)
if (Right(cmd))
newCmd |= CMD_LEFT;
if (cmd & CMD_UP)
if (Up(cmd))
newCmd |= CMD_DOWN;
if (cmd & CMD_DOWN)
if (Down(cmd))
newCmd |= CMD_UP;
return newCmd;
}

View File

@@ -75,7 +75,7 @@
#define Down(x) (((x)&CMD_DOWN) != 0)
#define Button1(x) (((x)&CMD_BUTTON1) != 0)
#define Button2(x) (((x)&CMD_BUTTON2) != 0)
#define AnyButton(x) (((x) & (CMD_BUTTON1 | CMD_BUTTON2)) != 0)
#define AnyButton(x) (((x) & (CMD_BUTTON1 | CMD_BUTTON2 | CMD_GRENADE)) != 0)
#define CMD_DIRECTIONS (CMD_LEFT | CMD_RIGHT | CMD_UP | CMD_DOWN)
#define CMD_HAS_DIRECTION(x) ((x)&CMD_DIRECTIONS)

View File

@@ -611,19 +611,19 @@ EventWaitResult EventWaitForAnyKeyOrButton(void)
GetPlayerCmds(&gEventHandlers, &cmds);
for (int i = 0; i < MAX_LOCAL_PLAYERS; i++)
{
if (cmds[i] & (CMD_BUTTON1 | CMD_BUTTON2 | CMD_GRENADE))
if (AnyButton(cmds[i]))
{
// Interpret anything other than CMD_BUTTON1 as cancel
return WaitResult(cmds[i] & CMD_BUTTON1);
return WaitResult(Button1(cmds[i]));
}
}
// Check menu commands
const int menuCmd = GetMenuCmd(&gEventHandlers, true);
if (menuCmd & (CMD_BUTTON1 | CMD_BUTTON2 | CMD_GRENADE))
if (AnyButton(menuCmd))
{
// Interpret anything other than CMD_BUTTON1 as cancel
return WaitResult(menuCmd & CMD_BUTTON1);
return WaitResult(Button1(menuCmd));
}
// Check if anyone pressed escape

View File

@@ -327,12 +327,12 @@ static int HandleInputEquipMenu(int cmd, void *data)
PlayerData *p = PlayerDataGetByUID(d->PlayerUID);
int newSlot = d->slot;
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
MenuPlaySound(MENU_SOUND_ENTER);
return 1;
}
else if (cmd & CMD_BUTTON2)
else if (Button2(cmd))
{
if (d->slot < MAX_WEAPONS)
{
@@ -341,7 +341,7 @@ static int HandleInputEquipMenu(int cmd, void *data)
AnimatedCounterReset(&d->Cash, p->Totals.Score);
}
}
else if (cmd & CMD_LEFT)
else if (Left(cmd))
{
if (d->slot < MAX_WEAPONS && (d->slot & 1) == 1)
{
@@ -360,7 +360,7 @@ static int HandleInputEquipMenu(int cmd, void *data)
}
}
}
else if (cmd & CMD_RIGHT)
else if (Right(cmd))
{
if (d->slot < MAX_WEAPONS && (d->slot & 1) == 0)
{
@@ -379,7 +379,7 @@ static int HandleInputEquipMenu(int cmd, void *data)
}
}
}
else if (cmd & CMD_UP)
else if (Up(cmd))
{
if (d->slot >= MAX_WEAPONS)
{
@@ -410,7 +410,7 @@ static int HandleInputEquipMenu(int cmd, void *data)
}
}
}
else if (cmd & CMD_DOWN)
else if (Down(cmd))
{
if (d->slot < d->endSlot)
{

View File

@@ -76,7 +76,7 @@
static void PlayerSpecialCommands(TActor *actor, const int cmd)
{
if ((cmd & CMD_BUTTON2) && CMD_HAS_DIRECTION(cmd))
if (Button2(cmd) && CMD_HAS_DIRECTION(cmd))
{
if (ConfigGetEnum(&gConfig, "Game.SwitchMoveStyle") ==
SWITCHMOVE_SLIDE &&
@@ -86,7 +86,7 @@ static void PlayerSpecialCommands(TActor *actor, const int cmd)
}
}
else if (
!(actor->lastCmd & CMD_BUTTON2) && (cmd & CMD_BUTTON2) &&
!Button2(actor->lastCmd) && Button2(cmd) &&
!actor->specialCmdDir && !actor->CanPickupSpecial &&
!(ConfigGetEnum(&gConfig, "Game.SwitchMoveStyle") ==
SWITCHMOVE_SLIDE &&

View File

@@ -979,8 +979,8 @@ void MenuProcessCmd(MenuSystem *ms, int cmd)
{
goto bail;
}
if (cmd == CMD_ESC || (cmd & CMD_BUTTON2) ||
((cmd & CMD_LEFT) && menu->u.normal.isSubmenusAlt))
if (cmd == CMD_ESC || Button2(cmd) ||
(Left(cmd) && menu->u.normal.isSubmenusAlt))
{
menuToChange = MenuProcessEscCmd(menu);
if (menuToChange != NULL)
@@ -1066,26 +1066,26 @@ menu_t *MenuProcessButtonCmd(MenuSystem *ms, menu_t *menu, int cmd)
case MENU_TYPE_NORMAL:
case MENU_TYPE_OPTIONS:
case MENU_TYPE_CUSTOM:
if (subMenu->u.normal.isSubmenusAlt ? (cmd & CMD_RIGHT)
: (cmd & CMD_BUTTON1))
if (subMenu->u.normal.isSubmenusAlt ? Right(cmd)
: (Button1(cmd)))
{
return subMenu;
}
break;
case MENU_TYPE_BACK:
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
return menu->parentMenu;
}
break;
case MENU_TYPE_QUIT:
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
return subMenu; // caller will check if subMenu type is QUIT
}
break;
case MENU_TYPE_RETURN:
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
return subMenu;
}

View File

@@ -130,7 +130,7 @@ static int HandleInputNameMenu(int cmd, void *data)
PlayerSelectMenuData *d = data;
PlayerData *p = PlayerDataGetByUID(d->display.PlayerUID);
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
if (d->nameMenuSelection == (int)strlen(letters))
{
@@ -157,7 +157,7 @@ static int HandleInputNameMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_ERROR);
}
}
else if (cmd & CMD_BUTTON2)
else if (Button2(cmd))
{
if (p->name[0])
{
@@ -169,7 +169,7 @@ static int HandleInputNameMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_ERROR);
}
}
else if (cmd & CMD_LEFT)
else if (Left(cmd))
{
if (d->nameMenuSelection > 0)
{
@@ -177,7 +177,7 @@ static int HandleInputNameMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_RIGHT)
else if (Right(cmd))
{
if (d->nameMenuSelection < (int)strlen(letters))
{
@@ -185,7 +185,7 @@ static int HandleInputNameMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_UP)
else if (Up(cmd))
{
if (d->nameMenuSelection >= ENTRY_COLS)
{
@@ -193,7 +193,7 @@ static int HandleInputNameMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_DOWN)
else if (Down(cmd))
{
if (d->nameMenuSelection <= (int)strlen(letters) - ENTRY_COLS)
{
@@ -266,6 +266,7 @@ static void PostInputHeadPartMenu(menu_t *menu, int cmd, void *data)
const HeadPartMenuData *d = data;
// Change player hairstyle based on current menu selection
PlayerData *p = PlayerDataGetByUID(d->PlayerUID);
CASSERT(p != NULL, "cannot find player");
Character *c = &p->Char;
const char *hpName = NULL;
if (menu->u.normal.index > 0)
@@ -429,7 +430,7 @@ static int HandleInputColorMenu(int cmd, void *data)
static void PostInputLoadTemplate(menu_t *menu, int cmd, void *data)
{
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
PlayerSelectMenuData *d = data;
PlayerData *p = PlayerDataGetByUID(d->display.PlayerUID);
@@ -471,7 +472,7 @@ static menu_t *CreateUseTemplateMenu(
static void PostInputSaveTemplate(menu_t *menu, int cmd, void *data)
{
if (!(cmd & CMD_BUTTON1))
if (!Button1(cmd))
{
return;
}
@@ -674,7 +675,7 @@ static void PostInputRotatePlayer(menu_t *menu, int cmd, void *data)
UNUSED(menu);
MenuDisplayPlayerData *d = data;
// Rotate player using left/right keys
const int dx = (cmd & CMD_LEFT) ? 1 : ((cmd & CMD_RIGHT) ? -1 : 0);
const int dx = Left(cmd) ? 1 : (Right(cmd) ? -1 : 0);
if (dx != 0)
{
d->Dir = (direction_e)CLAMP_OPPOSITE(

View File

@@ -104,7 +104,7 @@ static void OnSelect(menu_t *menu, int cmd, void *data)
const PlayerData *pData = PlayerDataGetByUID(d->PlayerUID);
d->SelectResult = UTIL_MENU_NONE;
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
const Option option = GetSelectedOption(d);
const bool buy = (d->idx & 1) == 0;
@@ -152,7 +152,7 @@ static void OnSelect(menu_t *menu, int cmd, void *data)
SoundPlay(&gSoundDevice, StrSound("ammo_none"));
}
}
else if (cmd & CMD_BUTTON2)
else if (Button2(cmd))
{
d->SelectResult = UTIL_MENU_CANCEL;
MenuPlaySound(MENU_SOUND_BACK);
@@ -368,15 +368,15 @@ static int HandleInputMenu(int cmd, void *data)
{
UtilMenu *d = data;
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
// Do nothing; don't switch away from menu
}
else if (cmd & CMD_BUTTON2)
else if (Button2(cmd))
{
return 1;
}
else if (cmd & CMD_LEFT)
else if (Left(cmd))
{
if ((d->idx % 2) == 1)
{
@@ -384,7 +384,7 @@ static int HandleInputMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_RIGHT)
else if (Right(cmd))
{
if (d->idx < OPTION_COUNT * 2 && (d->idx % 2) == 0)
{
@@ -392,7 +392,7 @@ static int HandleInputMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_UP)
else if (Up(cmd))
{
if (d->idx >= 2)
{
@@ -400,7 +400,7 @@ static int HandleInputMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_DOWN)
else if (Down(cmd))
{
if (d->idx + 2 < OPTION_COUNT * 2 + 2)
{

View File

@@ -101,7 +101,7 @@ static void WeaponSelect(menu_t *menu, int cmd, void *data)
UNUSED(menu);
WeaponMenu *d = data;
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
// Add the selected item
const PlayerData *p = PlayerDataGetByUID(d->PlayerUID);
@@ -123,7 +123,7 @@ static void WeaponSelect(menu_t *menu, int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_BUTTON2)
else if (Button2(cmd))
{
d->SelectResult = WEAPON_MENU_CANCEL;
MenuPlaySound(MENU_SOUND_BACK);
@@ -427,7 +427,7 @@ static int HandleInputMenu(int cmd, void *data)
const int numGuns = (int)d->weaponIndices.size;
if (cmd & CMD_BUTTON1)
if (Button1(cmd))
{
if (gCampaign.Setting.BuyAndSell)
{
@@ -440,11 +440,11 @@ static int HandleInputMenu(int cmd, void *data)
}
return 1;
}
else if (cmd & CMD_BUTTON2)
else if (Button2(cmd))
{
return 1;
}
else if (cmd & CMD_LEFT)
else if (Left(cmd))
{
if ((d->idx % d->cols) > 0)
{
@@ -452,7 +452,7 @@ static int HandleInputMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_RIGHT)
else if (Right(cmd))
{
if ((d->idx % d->cols) < d->cols - 1 && numGuns > 0)
{
@@ -464,7 +464,7 @@ static int HandleInputMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_UP)
else if (Up(cmd))
{
if (d->idx >= d->cols)
{
@@ -472,7 +472,7 @@ static int HandleInputMenu(int cmd, void *data)
MenuPlaySound(MENU_SOUND_SWITCH);
}
}
else if (cmd & CMD_DOWN)
else if (Down(cmd))
{
if ((d->idx + d->cols) < DIV_ROUND_UP(numGuns + 1, d->cols) * d->cols)
{