Cash diff next to cash #739

This commit is contained in:
Cong
2022-12-23 20:19:41 +11:00
parent 47c4a6c986
commit 551a3e07c7
3 changed files with 24 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2018-2019 Cong Xu
Copyright (c) 2018-2019, 2022 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -64,17 +64,17 @@ void AnimatedCounterReset(AnimatedCounter *a, const int value)
{
a->max = value;
}
void AnimatedCounterDraw(const AnimatedCounter *a, const struct vec2i pos)
{
struct vec2i AnimatedCounterDraw(const AnimatedCounter *a, const struct vec2i pos)
{
const struct vec2i pos2 = FontStr(a->prefix, pos);
char buf[256];
sprintf(buf, "%d", a->current);
FontStr(buf, pos2);
return FontStr(buf, pos2);
}
void AnimatedCounterTimeDraw(const AnimatedCounter *a, const struct vec2i pos)
struct vec2i AnimatedCounterTimeDraw(const AnimatedCounter *a, const struct vec2i pos)
{
const struct vec2i pos2 = FontStr(a->prefix, pos);
char buf[256];
sprintf(buf, "%d:%02d", a->current / 60, a->current % 60);
FontStr(buf, pos2);
return FontStr(buf, pos2);
}

View File

@@ -41,5 +41,5 @@ void AnimatedCounterTerminate(AnimatedCounter *a);
// Return whether animation has finished
bool AnimatedCounterUpdate(AnimatedCounter *a, const int ticks);
void AnimatedCounterReset(AnimatedCounter *a, const int value);
void AnimatedCounterDraw(const AnimatedCounter *a, const struct vec2i pos);
void AnimatedCounterTimeDraw(const AnimatedCounter *a, const struct vec2i pos);
struct vec2i AnimatedCounterDraw(const AnimatedCounter *a, const struct vec2i pos);
struct vec2i AnimatedCounterTimeDraw(const AnimatedCounter *a, const struct vec2i pos);

View File

@@ -298,8 +298,23 @@ static void DrawEquipMenu(
// Draw player cash
if (gCampaign.Setting.BuyAndSell)
{
AnimatedCounterDraw(
const struct vec2i fpos = AnimatedCounterDraw(
&d->Cash, svec2i_add(pos, svec2i(0, -FontH() - 2)));
const WeaponClass *wc = GetSelectedGun(data);
if (wc)
{
const int costDiff = EquipCostDiff(wc, pData, d->EquipSlot);
if (d->equipping && costDiff != 0)
{
// Draw price diff
const FontOpts foptsD = {
ALIGN_START, ALIGN_START, svec2i_zero(), svec2i_zero(),
costDiff > 0 ? colorRed : colorGreen};
char buf[256];
sprintf(buf, "%s%d", costDiff < 0 ? "+" : "", -costDiff);
FontStrOpt(buf, fpos, foptsD);
}
}
}
DrawEquipSlot(d, g, 0, "I", svec2i(pos.x, pos.y), ALIGN_START);
@@ -783,15 +798,6 @@ static void DrawGun(
char buf[256];
sprintf(buf, "$%d", wc->Price);
FontStrOpt(buf, bgPos, foptsP);
if (enabled && selected && costDiff != wc->Price && costDiff != 0)
{
// Draw price diff
const FontOpts foptsD = {
ALIGN_CENTER, ALIGN_START, bgSize, svec2i(2, 2),
costDiff > 0 ? colorRed : colorGreen};
sprintf(buf, "($%d)", -costDiff);
FontStrOpt(buf, svec2i_add(bgPos, svec2i(0, FontH())), foptsD);
}
}
if (isNew)