engine-c: richer snapshot/live HUD (scrap/power/minimap/command strip)
This commit is contained in:
parent
57acaa430f
commit
d983fbb0d7
2 changed files with 325 additions and 25 deletions
|
|
@ -650,16 +650,79 @@ void render_build_menu(Game *g) {
|
|||
}
|
||||
|
||||
void render_hud(Game *g) {
|
||||
/* top resource bar */
|
||||
SDL_SetRenderDrawColor(g->ren, 16, 16, 20, 220);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){0, 0, VIEW_W, 28});
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof buf, "%s - Scrap: %d", faction_name(g->human),
|
||||
g->scrap[g->human]);
|
||||
render_text(&g->spr, g->ren, g->spr.font_med, buf, 10, 4,
|
||||
(SDL_Color){230,230,230,255});
|
||||
/* KKND2-like chrome: top scrap/power bars + bottom command strip */
|
||||
Faction hf = g->human;
|
||||
SDL_Color hc = faction_color(hf);
|
||||
SDL_Color ec = faction_color(enemy_of(hf));
|
||||
|
||||
/* selection summary */
|
||||
int scrap_h = g->scrap[hf];
|
||||
if (scrap_h < 0) scrap_h = 0;
|
||||
int scrap_cap = 8000;
|
||||
if (scrap_h > scrap_cap) scrap_cap = scrap_h + 500;
|
||||
float scrap_frac = (float)scrap_h / (float)scrap_cap;
|
||||
if (scrap_frac > 1.0f) scrap_frac = 1.0f;
|
||||
|
||||
int pwr_gen = 0, pwr_use = 0;
|
||||
for (int i = 0; i < g->bld_count; i++) {
|
||||
Building *b = &g->buildings[i];
|
||||
if (b->dead || b->faction != hf || b->build < 1.0f) continue;
|
||||
if (b->type == BT_POWER) pwr_gen += 100;
|
||||
else if (b->type == BT_BASE) pwr_use += 20;
|
||||
else if (b->type == BT_WARFACTORY || b->type == BT_REFINERY) pwr_use += 40;
|
||||
else if (b->type == BT_RESEARCH || b->type == BT_REPAIR) pwr_use += 30;
|
||||
else if (b->type == BT_TURRET) pwr_use += 15;
|
||||
else pwr_use += 5;
|
||||
}
|
||||
if (pwr_gen < 1) pwr_gen = 1;
|
||||
float pwr_frac = (float)pwr_gen / (float)(pwr_gen + pwr_use);
|
||||
if (pwr_frac > 1.0f) pwr_frac = 1.0f;
|
||||
int pwr_ok = (pwr_gen >= pwr_use);
|
||||
|
||||
int bar_h = 28;
|
||||
SDL_SetRenderDrawColor(g->ren, 22, 26, 32, 230);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){0, 0, VIEW_W, bar_h});
|
||||
SDL_SetRenderDrawColor(g->ren, 55, 62, 70, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){0, 0, VIEW_W, 2});
|
||||
SDL_SetRenderDrawColor(g->ren, 90, 110, 70, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){0, bar_h - 1, VIEW_W, 1});
|
||||
|
||||
/* faction badge */
|
||||
SDL_SetRenderDrawColor(g->ren, 12, 14, 16, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){4, 4, 20, 20});
|
||||
SDL_SetRenderDrawColor(g->ren, hc.r, hc.g, hc.b, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){6, 6, 16, 16});
|
||||
|
||||
/* scrap bar */
|
||||
int scrap_x = 48, scrap_w = (int)(VIEW_W * 0.22f);
|
||||
if (scrap_w < 80) scrap_w = 80;
|
||||
SDL_SetRenderDrawColor(g->ren, 28, 26, 18, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){scrap_x, 8, scrap_w, 12});
|
||||
SDL_SetRenderDrawColor(g->ren, 230, 200, 70, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){scrap_x, 8, (int)(scrap_w * scrap_frac), 12});
|
||||
for (int s = 1; s < 8; s++) {
|
||||
int sx = scrap_x + (scrap_w * s) / 8;
|
||||
SDL_SetRenderDrawColor(g->ren, 18, 16, 12, 255);
|
||||
SDL_RenderDrawLine(g->ren, sx, 8, sx, 19);
|
||||
}
|
||||
|
||||
/* power bar */
|
||||
int pwr_bx = scrap_x + scrap_w + 16, pwr_bw = (int)(VIEW_W * 0.14f);
|
||||
if (pwr_bw < 50) pwr_bw = 50;
|
||||
SDL_SetRenderDrawColor(g->ren, 24, 28, 24, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){pwr_bx, 8, pwr_bw, 12});
|
||||
if (pwr_ok) SDL_SetRenderDrawColor(g->ren, 70, 210, 90, 255);
|
||||
else SDL_SetRenderDrawColor(g->ren, 220, 70, 60, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){pwr_bx, 8, (int)(pwr_bw * pwr_frac), 12});
|
||||
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof buf, "Scrap %d", scrap_h);
|
||||
render_text(&g->spr, g->ren, g->spr.font_small, buf, scrap_x + 4, 8,
|
||||
(SDL_Color){255,245,200,255});
|
||||
snprintf(buf, sizeof buf, "Pwr %d/%d", pwr_gen, pwr_use);
|
||||
render_text(&g->spr, g->ren, g->spr.font_small, buf, pwr_bx + 4, 8,
|
||||
(SDL_Color){220,255,220,255});
|
||||
|
||||
/* selection summary + threat pip */
|
||||
int n_units = 0, n_bld = 0;
|
||||
for (int i = 0; i < g->sel_count; i++) {
|
||||
int id = g->selection[i];
|
||||
|
|
@ -667,16 +730,69 @@ void render_hud(Game *g) {
|
|||
else if (bld_by_id(g, id)) n_bld++;
|
||||
}
|
||||
if (n_units > 0 || n_bld > 0) {
|
||||
snprintf(buf, sizeof buf, "Selected: %d units, %d buildings",
|
||||
n_units, n_bld);
|
||||
snprintf(buf, sizeof buf, "Sel %dU/%dB", n_units, n_bld);
|
||||
render_text(&g->spr, g->ren, g->spr.font_small, buf,
|
||||
VIEW_W - 260, 6, (SDL_Color){200,220,200,255});
|
||||
VIEW_W - 280, 6, (SDL_Color){200,220,200,255});
|
||||
}
|
||||
{
|
||||
int eth = 0;
|
||||
for (int i = 0; i < g->unit_count; i++)
|
||||
if (!g->units[i].dead && g->units[i].faction != hf) eth++;
|
||||
if (eth > 36) eth = 36;
|
||||
SDL_SetRenderDrawColor(g->ren, 36, 22, 28, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){VIEW_W - 56, 5, 48, 18});
|
||||
SDL_SetRenderDrawColor(g->ren, ec.r, ec.g, ec.b, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){VIEW_W - 52, 8, 8, 12});
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){VIEW_W - 40, 10, eth, 8});
|
||||
}
|
||||
|
||||
/* hints */
|
||||
/* bottom command strip */
|
||||
int bot_h = 36, bot_y = VIEW_H - bot_h;
|
||||
SDL_SetRenderDrawColor(g->ren, 18, 20, 24, 230);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){0, bot_y, VIEW_W, bot_h});
|
||||
SDL_SetRenderDrawColor(g->ren, 70, 90, 70, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){0, bot_y, VIEW_W, 1});
|
||||
SDL_SetRenderDrawColor(g->ren, 12, 14, 16, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){6, bot_y + 4, 28, 28});
|
||||
SDL_SetRenderDrawColor(g->ren, hc.r, hc.g, hc.b, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){8, bot_y + 6, 24, 24});
|
||||
int slots = (n_units > 0 || n_bld > 0) ? (n_units + n_bld) : 6;
|
||||
if (slots > 10) slots = 10;
|
||||
for (int s = 0; s < slots; s++) {
|
||||
int sx = 42 + s * 28;
|
||||
SDL_SetRenderDrawColor(g->ren, 28, 32, 28, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){sx, bot_y + 4, 24, 28});
|
||||
if (s < n_units || (n_units == 0 && n_bld == 0 && s < 4)) {
|
||||
SDL_SetRenderDrawColor(g->ren, hc.r, hc.g, hc.b, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){sx + 5, bot_y + 9, 14, 16});
|
||||
} else if (s < n_units + n_bld) {
|
||||
SDL_SetRenderDrawColor(g->ren, hc.r, hc.g, hc.b, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){sx + 4, bot_y + 8, 16, 16});
|
||||
}
|
||||
}
|
||||
for (int s = 0; s < 4; s++) {
|
||||
int sx = VIEW_W - 120 + s * 28;
|
||||
SDL_SetRenderDrawColor(g->ren, 32, 28, 22, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){sx, bot_y + 4, 24, 28});
|
||||
if (s == 0) {
|
||||
SDL_SetRenderDrawColor(g->ren, 200, 180, 60, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){sx + 8, bot_y + 12, 8, 10});
|
||||
} else if (s == 1) {
|
||||
SDL_SetRenderDrawColor(g->ren, 255, 80, 40, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){sx + 8, bot_y + 12, 8, 8});
|
||||
} else if (s == 2) {
|
||||
SDL_SetRenderDrawColor(g->ren, 80, 180, 255, 255);
|
||||
SDL_RenderFillRect(g->ren, &(SDL_Rect){sx + 6, bot_y + 14, 12, 6});
|
||||
} else {
|
||||
SDL_SetRenderDrawColor(g->ren, 180, 255, 120, 255);
|
||||
SDL_RenderDrawRect(g->ren, &(SDL_Rect){sx + 6, bot_y + 10, 12, 12});
|
||||
}
|
||||
}
|
||||
|
||||
/* hints above command strip */
|
||||
render_text(&g->spr, g->ren, g->spr.font_small,
|
||||
"LMB select/drag RMB move/attack A select-all [B] build Space pause F5 save",
|
||||
10, VIEW_H - 90, (SDL_Color){150,150,150,255});
|
||||
10, bot_y - 18, (SDL_Color){150,150,150,255});
|
||||
|
||||
/* objective */
|
||||
const Mission *m = mission_get(g->mission_id);
|
||||
|
|
@ -693,7 +809,7 @@ void render_hud(Game *g) {
|
|||
else
|
||||
snprintf(obuf, sizeof obuf, "Objective: %s", obj);
|
||||
render_text(&g->spr, g->ren, g->spr.font_small, obuf,
|
||||
VIEW_W/2 - 90, 6, (SDL_Color){230,230,160,255});
|
||||
pwr_bx + pwr_bw + 16, 6, (SDL_Color){230,230,160,255});
|
||||
|
||||
if (g->state == GAME_PAUSED)
|
||||
render_text(&g->spr, g->ren, g->spr.font_big, "PAUSED",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue