Skip to content

Commit

Permalink
Buy/sell sounds (fixes #739)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Feb 8, 2023
1 parent 80e64fb commit 8a9c8bf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Binary file added graphics/hud/button_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 13 additions & 13 deletions src/ammo_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,12 @@ static void AmmoSelect(menu_t *menu, int cmd, void *data)
}
else if (!buy && CanSell(d, ammoId))
{
// TODO: sell sound
SoundPlay(&gSoundDevice, StrSound(ammo->Sound));
d->SelectResult = AMMO_MENU_SELECT;
}
else
{
// TODO: can't buy/sell sound
SoundPlay(&gSoundDevice, StrSound("ammo_none"));
}
}
else if (cmd & CMD_BUTTON2)
Expand Down Expand Up @@ -150,7 +149,7 @@ void AmmoMenuCreate(
const struct vec2i size, EventHandlers *handlers, GraphicsDevice *graphics)
{
menu->PlayerUID = playerUID;
menu->menuBGSprites = PicManagerGetSprites(&gPicManager, "hud/gun_bg");
menu->buttonBG = PicManagerGetPic(&gPicManager, "hud/button_bg");
menu->idx = -1;
AmmoMenuReset(menu);

Expand Down Expand Up @@ -208,7 +207,8 @@ static void DrawMenu(
const Pic *gradient = PicManagerGetPic(&gPicManager, "hud/gradient");
if (d->scroll > 0)
{
const Pic *scrollPic = CArrayGet(&d->menuBGSprites->pics, 0);
// TODO: test scrolling
const Pic *scrollPic = d->buttonBG;
const Rect2i scrollRect =
Rect2iNew(svec2i(pos.x + 3, pos.y + 1 + ammoY), scrollSize);
PicRender(
Expand All @@ -229,7 +229,7 @@ static void DrawMenu(
}
if (scrollDown)
{
const Pic *scrollPic = CArrayGet(&d->menuBGSprites->pics, 0);
const Pic *scrollPic = d->buttonBG;
const Rect2i scrollRect = Rect2iNew(
svec2i(
pos.x + 3,
Expand Down Expand Up @@ -262,8 +262,6 @@ static void DrawAmmoMenuItem(
const PlayerData *pData = PlayerDataGetByUID(data->PlayerUID);
const int ammoId = *(int *)CArrayGet(&data->ammoIds, idx);
const int ammoAmount = PlayerGetAmmoAmount(pData, ammoId);
const int bgSpriteIndex = (int)selected;
const Pic *bg = CArrayGet(&data->menuBGSprites->pics, bgSpriteIndex);
const struct vec2i bgPos =
svec2i(pos.x, pos.y + (idx - data->scroll) * bgSize.y);
// Disallow buy/sell if ammo is free
Expand Down Expand Up @@ -300,26 +298,28 @@ static void DrawAmmoMenuItem(
y = bgPos.y + AMMO_ROW_H;

// Sell/buy buttons
const bool sellSelected = selected && (data->idx & 1) == 1;
const bool sellSelected = selected && data->Active && (data->idx & 1) == 1;
const bool canSell = CanSell(data, ammoId);
const FontOpts foptsSell = {
ALIGN_CENTER, ALIGN_START, svec2i(AMMO_BUTTON_BG_W, FontH()),
svec2i(2, 2), sellSelected ? colorRed : colorGray};
x = bgPos.x + bgSize.x - AMMO_BUTTON_BG_W - 2;
const struct vec2i sellPos = svec2i(x, y);
Draw9Slice(
g, bg, Rect2iNew(sellPos, svec2i(AMMO_BUTTON_BG_W, FontH() + 4)), 3, 3,
3, 3, true, CanSell(data, ammoId) ? colorRed : colorGray, SDL_FLIP_NONE);
g, data->buttonBG, Rect2iNew(sellPos, svec2i(AMMO_BUTTON_BG_W, FontH() + 4)), 3, 3,
3, 3, true, canSell ? (sellSelected ? colorRed : colorMaroon) : colorGray, SDL_FLIP_NONE);
FontStrOpt("Sell", sellPos, foptsSell);

x -= AMMO_BUTTON_BG_W + 3;
const bool buySelected = selected && (data->idx & 1) == 0;
const bool buySelected = selected && data->Active && (data->idx & 1) == 0;
const bool canBuy = CanBuy(data, ammoId);
const FontOpts foptsBuy = {
ALIGN_CENTER, ALIGN_START, svec2i(AMMO_BUTTON_BG_W, FontH()),
svec2i(2, 2), buySelected ? colorGreen : colorGray};
const struct vec2i buyPos = svec2i(x, y);
Draw9Slice(
g, bg, Rect2iNew(buyPos, svec2i(AMMO_BUTTON_BG_W, FontH() + 4)), 3, 3,
3, 3, true, CanBuy(data, ammoId) ? colorGreen : colorGray, SDL_FLIP_NONE);
g, data->buttonBG, Rect2iNew(buyPos, svec2i(AMMO_BUTTON_BG_W, FontH() + 4)), 3, 3,
3, 3, true, canBuy ? (buySelected ? colorGreen : colorOfficeGreen) : colorGray, SDL_FLIP_NONE);
FontStrOpt("Buy", buyPos, foptsBuy);

y = bgPos.y;
Expand Down
2 changes: 1 addition & 1 deletion src/ammo_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct
bool Active;
int PlayerUID;
AmmoMenuResult SelectResult;
const NamedSprites *menuBGSprites;
const Pic *buttonBG;
int idx;
CArray ammoIds; // of int
struct vec2i size;
Expand Down
1 change: 1 addition & 0 deletions src/weapon_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ static void WeaponSelect(menu_t *menu, int cmd, void *data)
WeaponMenuSelectedCostDiff(d) > p->Totals.Score)
{
// Can't afford
SoundPlay(&gSoundDevice, StrSound("ammo_none"));
return;
}
d->SelectResult = WEAPON_MENU_SELECT;
Expand Down

0 comments on commit 8a9c8bf

Please sign in to comment.