aboutsummaryrefslogtreecommitdiff
path: root/hud
diff options
context:
space:
mode:
authorjacopo grandi <jak.sk8@hotmail.it>2021-02-18 14:14:23 +0100
committerjacopo grandi <jak.sk8@hotmail.it>2021-02-18 14:14:23 +0100
commit5f0fce4191309e9526b7109a0d87c092ce6a4193 (patch)
tree105257f876551814aa74a0760ec116bd1bf307a5 /hud
parentead78d51e662057467b79d3a65b20c4ba83cbf07 (diff)
main
Diffstat (limited to 'hud')
-rw-r--r--hud/hud.c788
-rw-r--r--hud/hud.h74
-rw-r--r--hud/hud_views.c380
-rw-r--r--hud/hud_views.h47
4 files changed, 1289 insertions, 0 deletions
diff --git a/hud/hud.c b/hud/hud.c
new file mode 100644
index 0000000..383cb01
--- /dev/null
+++ b/hud/hud.c
@@ -0,0 +1,788 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <hud.h>
+#include <hud_views.h>
+
+#include <intersect.h>
+
+// TODO: make sound module mabye?
+#define SOUND_MOUSE_OVER 0
+#define SOUND_MOUSE_CLICK_0 1
+#define SOUND_MOUSE_WHEEL 2
+#define SOUND_SUCCESS 3
+
+
+// INIT
+void init_sel_chassis (graphic_settings *gs, hud_sel *sc, txtd *t,
+ SDL_Rect back, float start)
+{
+ sc->start = start;
+ sc->nav = 0;
+ sc->rect_back = back;
+}
+
+void init_form_new_unit (graphic_settings *gs, form_new_unit *fnu, txtd *t) {
+ int w = 290+200+300+20*2+10*4 + 30*3 + 200, h = 145+300+20*2+10*1 + 30*2;
+ int x = gs->resx/2-w/2, y = gs->resy/2-h/2;
+ fnu->rect_back = { x, y, w, h };
+
+ fnu->rect_chassis = { x+20, y+20+145+10+30, 300, 300 };
+ fnu->rect_brain = { x+20, y+20+30, 145, 145 };
+ fnu->rect_battery = { x+150+25, y+20+30, 145, 145 };
+ for (int i=0; i<8; i++) {
+ fnu->rect_weapons[i] = { x+20+300+10+30, y+20+120*i +30, 200, 110 };
+ }
+ for (int i=0; i<8; i++) {
+ fnu->rect_armor[i] = { x+20+500+20+30*2, y+20+60*i +30, 150, 50 };
+ }
+ for (int i=0; i<8; i++) {
+ fnu->rect_augs[i] = { x+20+500+20+160+30*2, y+20+60*i +30, 150, 50 };
+ }
+
+ fnu->rect_stats = { x+w-20-200, y+20, 200, h-70 };
+
+ int width = get_text_width("save", t);
+ button bdone = { "save", 4, { x+w-4*2-width-20, y+h-4*2-11-20 } };
+ fnu->done = bdone;
+}
+
+void init_overlay_game (graphic_settings *gs, overlay_game *og, txtd *t) {
+ int w = 250, h = gs->resy-20;
+ og->rect_templates = { 10, gs->resy-10-h, w, h };
+
+ float wnu = get_text_width("new template", t);
+ button b = { "new template", 4, { w-wnu-4*2, 20 } };
+ og->new_template = b;
+
+ float wst = get_text_width("save templates", t);
+ button b2 = { "save templates", 4, { w-wst-4*2, gs->resy-20-4*2-10 } };
+ og->save_templates = b2;
+
+ int warmy = 250, harmy = gs->resy-20;
+ og->rect_army = { gs->resx-warmy-10, gs->resy-harmy-10, warmy, harmy };
+ button b3 = { "save army", 4, { gs->resx-warmy, gs->resy-20-4*2-10 } };
+ og->save_army = b3;
+
+ int wbattle = 400, hbattle = 100;
+ og->rect_battle = { gs->resx/2-wbattle/2, 10, wbattle, hbattle };
+
+ float wsb = get_text_width("start battle", t);
+ button b1 = { "start battle", 4,
+ { og->rect_battle.x+wbattle-wsb-4*2-5, hbattle-4*2-5 } };
+ og->start_battle = b1;
+
+ button b4 = { "host game", 4,
+ { og->rect_battle.x+5, hbattle-4*2-5 } };
+ og->host_game = b4;
+
+ button b5 = { "join game", 4,
+ { og->rect_battle.x+5, hbattle-4*2-5-25 } };
+ og->join_game = b5;
+}
+
+void hud_reset (graphic_settings *gs, hud *h, txtd *t) {
+ init_form_new_unit(gs, &h->fnu, t);
+ init_overlay_game(gs, &h->og, t);
+ SDL_Rect clip = { h->fnu.rect_back.x, h->sc.ref->y,
+ h->fnu.rect_back.w, 300 };
+ float start = h->sc.ref->x - h->fnu.rect_back.x;
+ init_sel_chassis(gs, &h->sc, t, clip, start);
+}
+
+void hud_init (graphic_settings *gs, hud *h, txtd *t) {
+ h->fnu.sel = 0; h->fnu.ind = 0;
+ h->sc.ref = &h->fnu.rect_chassis;
+ h->og.temp_place = -1;
+ info_unit_init(&h->fnu.uinfo);
+ strcpy(h->og.army_listcur, "army");
+ strcpy(h->og.playername, "");
+ h->nameedit = NULL;
+ h->og.battle_state = 0;
+ h->og.edit_playername = 0;
+ hud_reset(gs, h, t);
+}
+
+void hud_resize (graphic_settings *gs, hud *h, txtd *t) {
+ hud_reset(gs, h, t);
+}
+
+
+// PROCESS
+int hud_fnu_check (info_unit *u, infos *info) {
+ if (u->chassis == -1) return 1;
+ if (u->battery == -1) return 2;
+ if (u->brain == -1) return 3;
+ float curweight = info_unit_get_weight(info, u);
+ float maxweight = info->chassis[u->chassis].weight_max;
+ if (curweight > maxweight) { return 4; }
+ return 0;
+}
+
+void hud_map_sel (info_unit *u, infos *info, int sel, int ind,
+ int8_t **n, int *bound, int size[])
+{
+ if (sel == 0) {
+ *n = &u->chassis;
+ *bound = info->chassislen;
+ size[0] = 300; size[1] = 300;
+ }
+ if (sel == 1) {
+ *n = &u->battery;
+ *bound = info->batterieslen;
+ size[0] = 145; size[1] = 145;
+ }
+ if (sel == 2) {
+ *n = &u->armor[ind];
+ *bound = info->armorslen;
+ size[0] = 150; size[1] = 250;
+ }
+ if (sel == 3) {
+ *n = &u->weapons[ind];
+ *bound = info->weaponslen;
+ size[0] = 200; size[1] = 110;
+ }
+ if (sel == 4) {
+ *n = &u->augs[ind];
+ *bound = info->augslen;
+ size[0] = 150; size[1] = 200;
+ }
+ if (sel == 5) {
+ *n = &u->brain;
+ *bound = info->brainslen;
+ size[0] = 145; size[1] = 145;
+ }
+}
+
+void hud_process_sel (graphic_settings *gs, hud *h, MKb *mkb,
+ infos *info, army *ar, map *m, txtd *t, Mix_Chunk *sounds[])
+{
+ if (mkb->mwheeldelta != 0) {
+ Mix_PlayChannel( -1, sounds[SOUND_MOUSE_WHEEL], 0 );
+ }
+ int8_t *n = NULL; int bound = 0; int size[2];
+ hud_map_sel(&h->fnu.uinfo, info, h->fnu.sel, h->fnu.ind, &n, &bound, size);
+ h->sc.nav += mkb->mwheeldelta*size[0];
+ if (h->sc.nav > (*n+1)*size[0]) {
+ h->sc.nav = (*n+1)*size[0];
+ }
+ if (h->sc.nav < (*n-bound+1)*size[0]) {
+ h->sc.nav = (*n-bound+1)*size[0];
+ }
+ float mousepos[2] = { mkb->mx, mkb->my };
+ if (mkb->mheld[0] == 1) {
+ float possc[2] = { h->sc.rect_back.x, h->sc.rect_back.y };
+ float sizesc[2] = { h->sc.rect_back.w, h->sc.rect_back.h };
+ if (!pt_rect(mousepos, possc, sizesc)) {
+ h->state = 1;
+ } else {
+ int i, inav = (int)h->sc.nav/size[0];
+ for (int j=-7;j<h->sc.rect_back.w/size[0]+1; j++) {
+ i = *n+j-inav;
+ if (i<-1) continue;
+ if (i>=bound) break;
+ float x = h->sc.rect_back.x+size[0]*j
+ +(int)h->sc.nav%size[0]+h->sc.start;
+ float y = h->sc.rect_back.y;
+ float pos[2] = {x, y}, s[2] = { size[0], size[1] };
+ if (pt_rect(mousepos, pos, s)) {
+ *n = i;
+ h->state = 1;
+ Mix_PlayChannel( -1, sounds[SOUND_MOUSE_CLICK_0], 0 );
+ break;
+ }
+ }
+ }
+ }
+}
+
+
+void hud_edit_close(hud *h) {
+ h->nameedit = NULL;
+ h->og.edit_playername = 0;
+}
+
+void hud_open_fnu (hud *h, info_unit *u, int i) {
+ h->state = 1;
+ h->fnu.uinfo = *u;
+ h->og.temp_modify = i;
+ hud_edit_close(h);
+}
+
+void hud_close_fnu (hud *h, infos *info) {
+ if (hud_fnu_check(&h->fnu.uinfo, info) > 0) return;
+ if (h->og.temp_modify == -1) {
+ info_template_add(info, &h->fnu.uinfo);
+ } else {
+ info->templates[h->og.temp_modify] = h->fnu.uinfo;
+ }
+ h->state = 0;
+}
+
+
+void hud_og_place(hud *h, int i) {
+ h->og.temp_place = i;
+}
+
+
+void hud_open_sel (graphic_settings *gs, hud *h,
+ txtd *t, infos *info, SDL_Rect *ref)
+{
+ int8_t *n = NULL; int bound = 0; int size[2];
+ hud_map_sel(&h->fnu.uinfo, info, h->fnu.sel,
+ h->fnu.ind, &n, &bound, size);
+ h->sc.nav = 0; if (*n == -1) h->sc.nav -= size[0];
+ h->sc.ref = ref;
+ hud_resize(gs, h, t);
+ h->sc.rect_back.h = size[1];
+}
+
+void hud_process_form_new_unit (graphic_settings *gs, hud *h, MKb *mkb,
+ infos *info, army *ar, map *m, txtd *t, Mix_Chunk *sounds[])
+{
+ float mousepos[2] = { mkb->mx, mkb->my };
+ if (mkb->mheld[0] == 1) {
+ if (mouse_in_button(mousepos, t, &h->fnu.done)) {
+ hud_close_fnu(h, info);
+ Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
+ /*
+ for (int i=0; i<ar->uslen; i++) {
+ unit *u = ar->us+i;
+ unit_init(info, ar, m, u->gridpos[0], u->gridpos[1],
+ &u->info, 0, u);
+ }*/
+ }
+ float possc[2] = { h->fnu.rect_chassis.x, h->fnu.rect_chassis.y };
+ float sizesc[2] = { h->fnu.rect_chassis.w, h->fnu.rect_chassis.h };
+ if (pt_rect(mousepos, possc, sizesc)) {
+ h->fnu.sel = 0; h->state = 2;
+ hud_open_sel(gs, h, t, info, &h->fnu.rect_chassis);
+ }
+ float possb[2] = { h->fnu.rect_battery.x, h->fnu.rect_battery.y };
+ float sizesb[2] = { h->fnu.rect_battery.w, h->fnu.rect_battery.h };
+ if (pt_rect(mousepos, possb, sizesb)) {
+ h->fnu.sel = 1; h->state = 2;
+ hud_open_sel(gs, h, t, info, &h->fnu.rect_battery);
+ }
+ float possbr[2] = { h->fnu.rect_brain.x, h->fnu.rect_brain.y };
+ float sizesbr[2] = { h->fnu.rect_brain.w, h->fnu.rect_brain.h };
+ if (pt_rect(mousepos, possbr, sizesbr)) {
+ h->fnu.sel = 5; h->state = 2;
+ hud_open_sel(gs, h, t, info, &h->fnu.rect_brain);
+ }
+ if (h->fnu.uinfo.chassis != -1) {
+ for (int i=0;
+ i<info->chassis[h->fnu.uinfo.chassis].slot_armor; i++)
+ {
+ float possa[2] = {
+ h->fnu.rect_armor[i].x, h->fnu.rect_armor[i].y };
+ float sizesa[2] = {
+ h->fnu.rect_armor[i].w, h->fnu.rect_armor[i].h };
+ if (pt_rect(mousepos, possa, sizesa)) {
+ h->fnu.sel = 2; h->fnu.ind = i; h->state = 2;
+ hud_open_sel(gs, h, t, info, &h->fnu.rect_armor[i]);
+ }
+ }
+ for (int i=0;
+ i<info->chassis[h->fnu.uinfo.chassis].slot_weapon; i++)
+ {
+ float possa[2] = {
+ h->fnu.rect_weapons[i].x, h->fnu.rect_weapons[i].y };
+ float sizesa[2] = {
+ h->fnu.rect_weapons[i].w, h->fnu.rect_weapons[i].h };
+ if (pt_rect(mousepos, possa, sizesa)) {
+ h->fnu.sel = 3; h->fnu.ind = i; h->state = 2;
+ hud_open_sel(gs, h, t, info, &h->fnu.rect_weapons[i]);
+ }
+ }
+ for (int i=0;
+ i<info->chassis[h->fnu.uinfo.chassis].slot_aug; i++)
+ {
+ float possa[2] = {
+ h->fnu.rect_augs[i].x, h->fnu.rect_augs[i].y };
+ float sizesa[2] = {
+ h->fnu.rect_augs[i].w, h->fnu.rect_augs[i].h };
+ if (pt_rect(mousepos, possa, sizesa)) {
+ h->fnu.sel = 4; h->fnu.ind = i; h->state = 2;
+ hud_open_sel(gs, h, t, info, &h->fnu.rect_augs[i]);
+ }
+ }
+ }
+ }
+}
+
+void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
+ infos *info, army *ar, map *m, txtd *t, gamestate *gst,
+ net_client *netc, net_server *nets, Mix_Chunk *sounds[])
+{
+ if (h->og.battle_state == 1) {
+ if (nets->sock_client == NULL) {
+ net_server_accept(nets);
+ } else {
+ char buffer[1024*64];
+ int len = net_server_recv(nets, buffer);
+ if (len != -1) {
+ h->og.battle_state = 3;
+
+ int armysize = sizeof(unit)*gst->army_bp[0].uslen;
+ char data[armysize];
+ memcpy(data, gst->army_bp[0].us, armysize);
+ net_server_send(nets, data, armysize);
+ printf("send (%d)\n", armysize);
+
+ memcpy(gst->army_bp[1].us, buffer, len);
+ gst->army_bp[1].uslen = len/sizeof(unit);
+ gst->playernum = 2;
+ gst_tobattle(gst);
+ gst->cam[0] = -gs->resx/2+gst->map_battle.sx*gst->map_battle.ts/2;
+ gst->cam[1] = -gs->resy/2+gst->map_battle.sy*gst->map_battle.ts/2;
+ h->state = 4;
+ }
+ }
+ }
+ if (h->og.battle_state == 2) {
+ char buffer[1024*64];
+ int len = net_client_recv(netc, buffer);
+ if (len != -1) {
+ h->og.battle_state = 3;
+
+ memcpy(gst->army_bp[1].us, buffer, len);
+ gst->army_bp[1].uslen = len/sizeof(unit);
+ gst->playernum = 2;
+ gst_tobattle(gst);
+ gst->cam[0] = -gs->resx/2+gst->map_battle.sx*gst->map_battle.ts/2;
+ gst->cam[1] = -gs->resy/2+gst->map_battle.sy*gst->map_battle.ts/2;
+ h->state = 4;
+ }
+ }
+
+ float mousepos[2] = { mkb->mx, mkb->my };
+ if (mkb->mheld[0] == 1) {
+ if (mouse_in_button(mousepos, t, &h->og.new_template)) {
+ info_unit u; info_unit_init(&u);
+ hud_open_fnu(h, &u, -1);
+ h->og.temp_place = -1;
+ }
+
+ if (mouse_in_button(mousepos, t, &h->og.save_templates)) {
+ info_save_templates(info, "default");
+ Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
+ }
+
+ if (mouse_in_button(mousepos, t, &h->og.start_battle)) {
+ /*
+ army_move(info, ar, m);
+ army_fire(info, ar, m);*/
+ gst_tobattle(gst);
+ gst->cam[0] = -gs->resx/2+gst->map_battle.sx*gst->map_battle.ts/2;
+ gst->cam[1] = -gs->resy/2+gst->map_battle.sy*gst->map_battle.ts/2;
+ h->og.battle_state = 3;
+ h->state = 4;
+ Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
+ }
+
+ if (mouse_in_button(mousepos, t, &h->og.join_game)) {
+ printf("open client\n");
+ net_client_open(netc);
+ int conn = net_client_connect(netc, "127.0.0.1", SERVER_PORT);
+ if (conn == 0) {
+ int armysize = sizeof(unit)*gst->army_bp[0].uslen;
+ char data[armysize];
+ memcpy(data, gst->army_bp[0].us, armysize);
+ net_client_send(netc, data, armysize);
+ printf("send (%d)\n", armysize);
+ }
+ h->og.battle_state = 2;
+ }
+
+ if (mouse_in_button(mousepos, t, &h->og.host_game)) {
+ printf("open server\n");
+ net_server_open(nets, SERVER_PORT);
+ h->og.battle_state = 1;
+ }
+
+ if (mouse_in_button(mousepos, t, &h->og.save_army)) {
+ info_save_army(gst->army_bp+0, h->og.army_listcur);
+ h->og.army_listlen = info_army_get_list(h->og.army_list);
+ }
+
+ if (h->og.temp_place != -1) {
+ int x = (int)((mkb->mx+gst->cam[0])/32);
+ int y = (int)((mkb->my+gst->cam[1])/32);
+ if (x >= 0 && y >= 0 && x < m->sx && y < m->sy) {
+ if (ar->grid[xytoi(m,x,y)] == NULL) {
+ unit u;
+ unit_init(info, ar, m, x, y,
+ info->templates+h->og.temp_place, 0, &u);
+ army_spawn(ar, m, u);
+ }
+ } else {
+ h->og.temp_place = -1;
+ }
+ }
+
+ for (int i=0; i<info->templateslen; i++) {
+ float x = h->og.rect_templates.x+5;
+ float y = h->og.rect_templates.y+5 + i*20 + 30;
+ float wedit = get_text_width("edit", t);
+ float possa[2] = { x, y };
+ float sizesa[2] = { wedit+4*2, 11+4*2 };
+ if (pt_rect(mousepos, possa, sizesa)) {
+ hud_open_fnu(h, info->templates+i, i);
+ h->og.temp_place = -1;
+ }
+ float wplace = get_text_width("place", t);
+ float posp[2] = { x+wedit+4*2+5, y };
+ float sizep[2] = { wplace+4*2, 11+4*2 };
+ if (pt_rect(mousepos, posp, sizep)) {
+ hud_og_place(h, i);
+ }
+ }
+
+ for (int i=0; i<h->og.army_listlen; i++) {
+ float x = h->og.rect_army.x+5;
+ float y = h->og.rect_army.y+5 + i*20 + 30;
+ float wload = get_text_width("load", t);
+ float posp[2] = { x, y };
+ float sizep[2] = { wload+4*2, 11+4*2 };
+ if (pt_rect(mousepos, posp, sizep)) {
+ strcpy(h->og.army_listcur, h->og.army_list[i]);
+ info_load_army(gst->army_bp+0, h->og.army_listcur);
+ Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
+ }
+ }
+
+ if (h->nameedit == NULL) {
+ float pn[2] = { h->og.rect_battle.x+5, h->og.rect_battle.y+5 };
+ char sn[64]; sprintf(sn, "PLAYER NAME: %s", h->og.playername);
+ float sizen[2] = { get_text_width(sn, t), 10 };
+ if (pt_rect(mousepos, pn, sizen)) {
+ h->nameedit = h->og.playername;
+ printf("editing this %s\n", h->nameedit);
+ h->og.edit_playername = 1;
+ }
+ } else {
+ Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
+ hud_edit_close(h);
+ }
+ }
+
+ // rm unit
+ if (mkb->mheld[2] == 1) {
+ Mix_PlayChannel( -1, sounds[SOUND_MOUSE_CLICK_0], 0 );
+ int x = (int)((mkb->mx+gst->cam[0])/32);
+ int y = (int)((mkb->my+gst->cam[1])/32);
+ if (x >= 0 && y >= 0 && x < m->sx && y < m->sy) {
+ if (ar->grid[xytoi(m,x,y)] != NULL) {
+ unit_remove(ar, m, ar->grid[xytoi(m,x,y)]);
+ }
+ }
+ }
+}
+
+void hud_edit_name(hud *h, MKb *mkb, Mix_Chunk *sounds[]) {
+ for (int i=0; i<mkb->kbnum; i++) {
+ if (mkb->kb[i] >= SDL_SCANCODE_A
+ && mkb->kb[i] <= SDL_SCANCODE_Z) {
+ if (strlen(h->nameedit) < 31) {
+ char c = mkb->kb[i]-SDL_SCANCODE_A+'a';
+ if (SDL_GetModState() & KMOD_SHIFT) {
+ c = mkb->kb[i]-SDL_SCANCODE_A+'A';
+ }
+ sprintf(h->nameedit, "%s%c", h->nameedit, c);
+ }
+ }
+ }
+ if (mkb_search(mkb, SDL_SCANCODE_SPACE)) {
+ Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
+ if (strlen(h->nameedit) < 31) {
+ sprintf(h->nameedit, "%s ", h->nameedit);
+ }
+ }
+ if (mkb_search(mkb, SDL_SCANCODE_BACKSPACE)) {
+ if (strlen(h->nameedit) > 0)
+ h->nameedit[strlen(h->nameedit)-1] = '\0';
+ }
+ if (mkb_search(mkb, SDL_SCANCODE_ESCAPE)) {
+ Mix_PlayChannel( -1, sounds[SOUND_SUCCESS], 0 );
+ hud_edit_close(h); return;
+ }
+}
+
+void hud_process (graphic_settings *gs, hud *h, MKb *mkb,
+ infos *info, army *ar, map *m, txtd *t, gamestate *gst,
+ net_client *netc, net_server *nets, Mix_Chunk *sounds[])
+{
+ if (h->nameedit != NULL) { hud_edit_name(h, mkb, sounds); }
+ switch (h->state) {
+ case 0:
+ hud_process_overlay_game(gs, h, mkb, info, ar, m, t, gst,
+ netc, nets, sounds);
+ break;
+ case 1: hud_process_form_new_unit(gs, h, mkb, info, ar, m, t,
+ sounds); break;
+ case 2: hud_process_sel(gs, h, mkb, info, ar, m, t, sounds); break;
+ }
+}
+
+
+
+// RENDER
+void hud_render_sel (hud_sel *sc, MKb *mkb, info_unit *u,
+ SDL_Renderer* rend, SDL_Texture *sprites, txtd *t, infos *info,
+ int sel, int ind)
+{
+ int8_t *n = NULL; int bound = 0; int size[2];
+ hud_map_sel(u, info, sel, ind, &n, &bound, size);
+ SDL_SetRenderDrawColor(rend, 150, 200, 0, 255);
+ SDL_RenderFillRect(rend, &sc->rect_back);
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, &sc->rect_back);
+ SDL_RenderSetClipRect(rend, &sc->rect_back);
+ int i;
+ for (int j=-7;j<sc->rect_back.w/size[0]+1; j++) {
+ i = *n+j - (int)sc->nav/size[0];
+ if (i<-1) continue;
+ if (i>=bound) break;
+ float x = sc->rect_back.x+size[0]*j+(int)sc->nav%size[0]+sc->start;
+ float y = sc->rect_back.y;
+ SDL_Rect r = { x, y, size[0]+1, size[1] };
+ SDL_SetRenderDrawColor(rend, 150, 200, 120, 255);
+ SDL_RenderFillRect(rend, &r);
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, &r);
+ if (sel==0) render_view_chassis(rend, t, x, y, info, i, sprites);
+ if (sel==1) render_view_battery(rend, t, x, y, info, i);
+ if (sel==2) render_view_armor_detail(rend, t, x, y, info, i);
+ if (sel==3) render_view_weapon_detail(rend, t, x, y, info, i);
+ if (sel==4) render_view_aug_detail(rend, t, x, y, info, i);
+ if (sel==5) render_view_brain(rend, t, x, y, info, i);
+ }
+ SDL_RenderSetClipRect(rend, NULL);
+}
+
+void hud_render_form_new_unit (form_new_unit *fnu, MKb *mkb,
+ SDL_Renderer* rend, txtd *t, infos *info, SDL_Texture *sprites)
+{
+ SDL_SetRenderDrawColor(rend, 150, 200, 255, 255);
+ SDL_RenderFillRect(rend, &fnu->rect_back);
+
+ SDL_SetRenderDrawColor(rend, 200, 0, 255, 255);
+ SDL_RenderFillRect(rend, &fnu->rect_chassis);
+ SDL_RenderFillRect(rend, &fnu->rect_brain);
+ SDL_RenderFillRect(rend, &fnu->rect_battery);
+
+ SDL_SetRenderDrawColor(rend, 255, 150, 50, 255);
+ SDL_RenderFillRect(rend, &fnu->rect_stats);
+
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, &fnu->rect_back);
+ SDL_RenderDrawRect(rend, &fnu->rect_chassis);
+ SDL_RenderDrawRect(rend, &fnu->rect_brain);
+ SDL_RenderDrawRect(rend, &fnu->rect_battery);
+ SDL_RenderDrawRect(rend, &fnu->rect_stats);
+
+ render_view_stats(rend, t, fnu->rect_stats.x, fnu->rect_stats.y,
+ info, &fnu->uinfo);
+
+ if (fnu->uinfo.chassis != -1) {
+ for (int i=0; i<info->chassis[fnu->uinfo.chassis].slot_weapon; i++) {
+ SDL_SetRenderDrawColor(rend, 200, 100, 255, 255);
+ SDL_RenderFillRect(rend, fnu->rect_weapons+i);
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, fnu->rect_weapons+i);
+ render_view_weapon(rend, t,
+ fnu->rect_weapons[i].x,
+ fnu->rect_weapons[i].y, info, fnu->uinfo.weapons[i]);
+ }
+ for (int i=0; i<info->chassis[fnu->uinfo.chassis].slot_armor; i++) {
+ SDL_SetRenderDrawColor(rend, 200, 200, 255, 255);
+ SDL_RenderFillRect(rend, fnu->rect_armor+i);
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, fnu->rect_armor+i);
+ render_view_armor(rend, t,
+ fnu->rect_armor[i].x,
+ fnu->rect_armor[i].y, info, fnu->uinfo.armor[i]);
+ }
+ for (int i=0; i<info->chassis[fnu->uinfo.chassis].slot_aug; i++) {
+ SDL_SetRenderDrawColor(rend, 200, 200, 255, 255);
+ SDL_RenderFillRect(rend, fnu->rect_augs+i);
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, fnu->rect_augs+i);
+ render_view_aug(rend, t,
+ fnu->rect_augs[i].x,
+ fnu->rect_augs[i].y, info, fnu->uinfo.augs[i]);
+ }
+ }
+
+ char schassis[32] = "CHASSIS";
+ float wchassis = get_text_width(schassis, t)*2;
+ float pchassis[2] = {
+ fnu->rect_chassis.x+fnu->rect_chassis.w/2 - wchassis / 2,
+ fnu->rect_chassis.y+fnu->rect_chassis.h + 7
+ };
+ render_text_scaled(rend, schassis, pchassis, t, 2);
+
+ char sbrain[32] = "CONTROLLER";
+ float wbrain = get_text_width(sbrain, t)*2;
+ float pbrain[2] = {
+ fnu->rect_brain.x+fnu->rect_brain.w/2 - wbrain / 2,
+ fnu->rect_brain.y - 16-7
+ };
+ render_text_scaled(rend, sbrain, pbrain, t, 2);
+
+ char sbattery[32] = "BATTERY";
+ float wbattery = get_text_width(sbattery, t)*2;
+ float pbattery[2] = {
+ fnu->rect_battery.x+fnu->rect_battery.w/2 - wbattery / 2,
+ fnu->rect_battery.y - 16-7
+ };
+ render_text_scaled(rend, sbattery, pbattery, t, 2);
+
+ char sweapons[32] = "WEAPONS";
+ float wweapons = get_text_width(sweapons, t)*2;
+ float pweapons[2] = {
+ fnu->rect_weapons[0].x+fnu->rect_weapons[0].w/2 - wweapons / 2,
+ fnu->rect_weapons[0].y - 16-7
+ };
+ render_text_scaled(rend, sweapons, pweapons, t, 2);
+
+ char sarmor[32] = "ARMOR";
+ float warmor = get_text_width(sarmor, t)*2;
+ float parmor[2] = {
+ fnu->rect_armor[0].x+fnu->rect_armor[0].w/2 - warmor / 2,
+ fnu->rect_armor[0].y - 16-7
+ };
+ render_text_scaled(rend, sarmor, parmor, t, 2);
+
+ char saugs[32] = "AUGMENTS";
+ float waugs = get_text_width(saugs, t)*2;
+ float pagus[2] = {
+ fnu->rect_augs[0].x+fnu->rect_augs[0].w/2 - waugs / 2,
+ fnu->rect_augs[0].y - 16-7
+ };
+ render_text_scaled(rend, saugs, pagus, t, 2);
+
+ render_button(rend, t, &fnu->done);
+
+ int err = hud_fnu_check(&fnu->uinfo, info);
+ char serr[32] = "ok";
+ if (err==1) strcpy(serr, "select a chassis");
+ if (err==2) strcpy(serr, "select a battery");
+ if (err==3) strcpy(serr, "select a controller");
+ if (err==4) strcpy(serr, "overburdened, remove weight");
+ float werr = get_text_width(serr, t);
+ float perr[2] = {
+ fnu->done.pos[0]-werr-10,
+ fnu->done.pos[1]+fnu->done.pad
+ };
+ render_text_scaled(rend, serr, perr, t, 1);
+
+ render_view_chassis(rend, t,
+ fnu->rect_chassis.x, fnu->rect_chassis.y,
+ info, fnu->uinfo.chassis, sprites);
+ render_view_battery(rend, t,
+ fnu->rect_battery.x, fnu->rect_battery.y, info, fnu->uinfo.battery);
+ render_view_brain(rend, t,
+ fnu->rect_brain.x, fnu->rect_brain.y, info, fnu->uinfo.brain);
+}
+
+void hud_render_overlay_game (overlay_game *og, MKb *mkb,
+ SDL_Renderer* rend, txtd *t, infos *info, SDL_Texture *sprites)
+{
+ SDL_SetRenderDrawColor(rend, 40, 150, 200, 255);
+ SDL_RenderFillRect(rend, &og->rect_templates);
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, &og->rect_templates);
+ char stemp[32] = "TEMPLATES";
+ float ptemp[2] = {
+ og->rect_templates.x+10,
+ og->rect_templates.y+10
+ };
+ render_text_scaled(rend, stemp, ptemp, t, 2);
+
+ render_button(rend, t, &og->new_template);
+ render_button(rend, t, &og->save_templates);
+
+ for (int i=0; i<info->templateslen; i++) {
+ float x = og->rect_templates.x+5;
+ float y = og->rect_templates.y+5 + i*20 + 30;
+ render_view_template(rend, t, x, y, info, i);
+ }
+
+ SDL_SetRenderDrawColor(rend, 0, 200, 120, 255);
+ SDL_RenderFillRect(rend, &og->rect_army);
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, &og->rect_army);
+ char sarmy[32] = "ARMY";
+ float parmy[2] = {
+ og->rect_army.x+10,
+ og->rect_army.y+10
+ };
+ render_text_scaled(rend, sarmy, parmy, t, 2);
+
+ render_button(rend, t, &og->save_army);
+
+ button b = { "load", 4, { 0, 0 } };
+ for (int i=0; i<og->army_listlen; i++) {
+ float x = og->rect_army.x+5;
+ float y = og->rect_army.y+5 + i*20 + 30;
+ float bw = get_text_width("load", t)+4*2;
+ b.pos[0] = x; b.pos[1] = y;
+ render_button(rend, t, &b);
+ float pa[2] = { x+bw+5, y+4 };
+ render_text_scaled(rend, og->army_list[i], pa, t, 1);
+ if (strcmp(og->army_listcur, og->army_list[i]) == 0) {
+ float w = get_text_width(og->army_list[i], t);
+ float pe[2] = { x+bw+5+w+5, y+4 };
+ render_text_scaled(rend, "<- editing", pe, t, 1);
+ }
+ }
+
+ SDL_SetRenderDrawColor(rend, 250, 60, 60, 255);
+ SDL_RenderFillRect(rend, &og->rect_battle);
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, &og->rect_battle);
+
+ float pn[2] = { og->rect_battle.x+5, og->rect_battle.y+5 };
+ char sn[64];
+ if (og->edit_playername == 1) {
+ sprintf(sn, "PLAYER NAME: %s_", og->playername);
+ printf("looool\n");
+ } else {
+ sprintf(sn, "PLAYER NAME: %s", og->playername);
+ }
+ render_text_scaled(rend, sn, pn, t, 1);
+
+ render_button(rend, t, &og->host_game);
+ render_button(rend, t, &og->join_game);
+ render_button(rend, t, &og->start_battle);
+
+ if (og->temp_place != -1) {
+ SDL_Rect srcRect = {
+ info->templates[og->temp_place].chassis*32, 32, 32, 32 };
+ SDL_Rect dstRect = { mkb->mx - 16, mkb->my - 16, 32, 32 };
+ SDL_RenderCopy(rend, sprites, &srcRect, &dstRect);
+ }
+}
+
+void hud_render (hud *h, SDL_Renderer* rend, txtd *t, MKb *mkb, infos *info,
+ SDL_Texture *sprites)
+{
+ switch (h->state) {
+ case 0:
+ hud_render_overlay_game(&h->og, mkb, rend, t, info, sprites);
+ break;
+ case 1:
+ hud_render_overlay_game(&h->og, mkb, rend, t, info, sprites);
+ hud_render_form_new_unit(&h->fnu, mkb, rend, t, info, sprites);
+ break;
+ case 2:
+ hud_render_overlay_game(&h->og, mkb, rend, t, info, sprites);
+ hud_render_form_new_unit(&h->fnu, mkb, rend, t, info, sprites);
+ hud_render_sel(&h->sc, mkb, &h->fnu.uinfo,
+ rend, sprites, t, info, h->fnu.sel, h->fnu.ind);
+ break;
+ }
+} \ No newline at end of file
diff --git a/hud/hud.h b/hud/hud.h
new file mode 100644
index 0000000..2728bb2
--- /dev/null
+++ b/hud/hud.h
@@ -0,0 +1,74 @@
+#ifndef HUD_H
+#define HUD_H
+
+#include <SDL.h>
+#include <SDL_mixer.h>
+
+#include <render_text.h>
+#include <button.h>
+#include <graphicsettings.h>
+#include <mkb.h>
+#include <info.h>
+#include <units.h>
+#include <map.h>
+#include <gst.h>
+#include <net.h>
+
+typedef struct {
+ float start;
+ float nav;
+ SDL_Rect rect_back;
+ SDL_Rect *ref;
+} hud_sel;
+
+typedef struct {
+ button new_template;
+ button save_templates;
+ button save_army;
+ button start_battle;
+ button host_game;
+ button join_game;
+ SDL_Rect rect_battle;
+ SDL_Rect rect_templates;
+ int temp_modify;
+ int temp_place;
+ SDL_Rect rect_army;
+ char army_list[64][32];
+ int army_listlen;
+ char army_listcur[32];
+ char playername[32];
+ int battle_state;
+ int edit_playername;
+} overlay_game;
+
+typedef struct {
+ SDL_Rect rect_back;
+ SDL_Rect rect_chassis;
+ SDL_Rect rect_brain;
+ SDL_Rect rect_battery;
+ SDL_Rect rect_weapons[8];
+ SDL_Rect rect_armor[8];
+ SDL_Rect rect_augs[8];
+ SDL_Rect rect_stats;
+ button done;
+ info_unit uinfo;
+ int sel, ind;
+} form_new_unit;
+
+typedef struct {
+ hud_sel sc;
+ overlay_game og;
+ form_new_unit fnu;
+ int state;
+ char *nameedit;
+} hud;
+
+void hud_init(graphic_settings *gs, hud *h, txtd *t);
+void hud_resize (graphic_settings *gs, hud *h, txtd *t);
+void hud_process (graphic_settings *gs, hud *h, MKb *mkb,
+ infos *info, army *ar, map *m, txtd *t, gamestate *gst,
+ net_client *netc, net_server *nets, Mix_Chunk *sounds[]);
+void hud_render (hud *h, SDL_Renderer* rend, txtd *t, MKb *mkb, infos *info,
+ SDL_Texture *sprites);
+
+#endif \ No newline at end of file
diff --git a/hud/hud_views.c b/hud/hud_views.c
new file mode 100644
index 0000000..557ff1f
--- /dev/null
+++ b/hud/hud_views.c
@@ -0,0 +1,380 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include <hud_views.h>
+
+void render_view_stats (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, info_unit *tm)
+{
+ float h = 10;
+ float pname[2] = { px+10, py+h };
+ char sname[64]; sprintf(sname, "STATS");
+ render_text_scaled(rend, sname, pname, t, 2);
+ h += 35;
+
+ float calcweight = info_unit_get_weight(info, tm);
+ float maxweight = info->chassis[tm->chassis].weight_max;
+ float pw[2] = { px+10, py+h };
+ char sw[64]; sprintf(sw, "WEIGHT: %.0f/%.0f",
+ calcweight, maxweight);
+ render_text_scaled(rend, sw, pw, t, 1);
+ h += 15;
+
+ float hp = info_unit_get_health(info, tm);
+ float php[2] = { px+10, py+h };
+ char shp[64]; sprintf(shp, "HP: %.2f", hp);
+ render_text_scaled(rend, shp, php, t, 1);
+ h += 15;
+
+ float speed = info_unit_get_speed(info, tm);
+ float pspeed[2] = { px+10, py+h };
+ char sspeed[64]; sprintf(sspeed, "SPEED: %.2f", speed);
+ render_text_scaled(rend, sspeed, pspeed, t, 1);
+ h += 15;
+
+ float dps = info_unit_get_dps(info, tm);
+ float pdps[2] = { px+10, py+h };
+ char sdps[64]; sprintf(sdps, "DAMAGE PER TURN: %.2f", dps);
+ render_text_scaled(rend, sdps, pdps, t, 1);
+ h += 20;
+
+ float part[2] = { px+10, py+h };
+ render_text_scaled(rend, "ARMOR:", part, t, 1);
+ h += 15;
+
+ for (int i=0; i<7; i++) {
+ float ar = info_unit_get_armor(info, tm, i);
+ float par[2] = { px+10, py+h };
+ char sar[64]; sprintf(sar, "%s: %.1f%", info->damage_types[i], ar);
+ render_text_scaled(rend, sar, par, t, 1);
+ h += 15;
+ }
+ h += 5;
+}
+
+void render_view_chassis (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int chassis, SDL_Texture *sprites)
+{
+ if (chassis != -1) {
+ float pname[2] = { px+10, py+10 };
+ char sname[64]; sprintf(sname, "%s",
+ info->chassis[chassis].name);
+ render_text_scaled(rend, sname, pname, t, 2);
+ float pweight[2] = { px+10, py+40 };
+ char sweight[64]; sprintf(sweight, "MAX WEIGHT: %0.0f",
+ info->chassis[chassis].weight_max);
+ render_text_scaled(rend, sweight, pweight, t, 1);
+ float php[2] = { px+10, py+55 };
+ char shp[64]; sprintf(shp, "HP: %0.1f",
+ info->chassis[chassis].hp);
+ render_text_scaled(rend, shp, php, t, 1);
+ float pspeed[2] = { px+10, py+70 };
+ char sspeed[64]; sprintf(sspeed, "SPEED: %0.2f tiles/turn",
+ info->chassis[chassis].speed);
+ render_text_scaled(rend, sspeed, pspeed, t, 1);
+
+ SDL_Rect srcRect = { chassis*32, 32, 32, 32 };
+ SDL_Rect dstRect = { px+300-32-10, py+10, 32, 32 };
+ SDL_RenderCopy(rend, sprites, &srcRect, &dstRect);
+ } else {
+ float pname[2] = { px+10, py+10 };
+ render_text_scaled(rend, "select a chassis...", pname, t, 1);
+ }
+}
+
+void render_view_battery (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int batt)
+{
+ if (batt != -1) {
+ float pname[2] = { px+10, py+10 };
+ char sname[64]; sprintf(sname, "%s",
+ info->batteries[batt].name);
+ render_text_scaled(rend, sname, pname, t, 1);
+ float pweight[2] = { px+10, py+40 };
+ char sweight[64]; sprintf(sweight, "WEIGHT: %0.0f",
+ info->batteries[batt].weight);
+ render_text_scaled(rend, sweight, pweight, t, 1);
+ float pcapacity[2] = { px+10, py+55 };
+ char scapacity[64]; sprintf(scapacity, "CAPACITY: %0.1f",
+ info->batteries[batt].capacity);
+ render_text_scaled(rend, scapacity, pcapacity, t, 1);
+ float prech[2] = { px+10, py+70 };
+ char srech[64];
+ if (info->batteries[batt].recharge == 0) {
+ strcpy(srech, "NOT RECHARGEABLE");
+ } else {
+ strcpy(srech, "RECHARGEABLE");
+ }
+ render_text_scaled(rend, srech, prech, t, 1);
+ } else {
+ float pname[2] = { px+10, py+10 };
+ render_text_scaled(rend, "select a battery...", pname, t, 1);
+ }
+}
+
+
+void render_view_armor (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int armor)
+{
+ if (armor != -1) {
+ float pname[2] = { px+10, py+10 };
+ char sname[64]; sprintf(sname, "%s", info->armors[armor].name);
+ render_text_scaled(rend, sname, pname, t, 1);
+ char sa[64]; int j=0;
+ char temp[16] = "red: ";
+ strcpy(sa+j, temp);
+ j += strlen(temp);
+ for (int i=0; i<7; i++) {
+ if (i<7-1) {
+ sprintf(temp, "%.0f, ", info->armors[armor].armor[i]);
+ } else {
+ sprintf(temp, "%.0f", info->armors[armor].armor[i]);
+ }
+ strcpy(sa+j, temp);
+ j += strlen(temp);
+ }
+ sa[j] = '\0';
+ float pa[2] = { px+10, py+25 };
+ render_text_scaled(rend, sa, pa, t, 1);
+ } else {
+ float pname[2] = { px+10, py+10 };
+ render_text_scaled(rend, "select an armor...", pname, t, 1);
+ }
+}
+
+void render_view_armor_detail (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int armor)
+{
+ if (armor != -1) {
+ float pname[2] = { px+10, py+10 };
+ char sname[64]; sprintf(sname, "%s", info->armors[armor].name);
+ render_text_scaled(rend, sname, pname, t, 1);
+ float pweight[2] = { px+10, py+40 };
+ char sweight[64]; sprintf(sweight, "WEIGHT: %0.0f",
+ info->armors[armor].weight);
+ render_text_scaled(rend, sweight, pweight, t, 1);
+
+ float pred[2] = { px+10, py+60 };
+ render_text_scaled(rend, "DAMAGE REDUCTION", pred, t, 1);
+
+ int h=0;
+ for (int i=0; i<7; i++) {
+ if (info->armors[armor].armor[i] < 0.001) continue;
+ float pa[2] = { px+10, py+75+h*15 };
+ char sa[64]; sprintf(sa, "%s: %.1f%",
+ info->damage_types[i], info->armors[armor].armor[i]);
+ render_text_scaled(rend, sa, pa, t, 1);
+ h++;
+ }
+ } else {
+ render_view_weapon(rend, t, px, py, info, armor);
+ }
+}
+
+
+void render_view_weapon (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int weapon)
+{
+ if (weapon != -1) {
+ float pname[2] = { px+10, py+10 };
+ char sname[64]; sprintf(sname, "%s",
+ info->weapons[weapon].name);
+ render_text_scaled(rend, sname, pname, t, 1);
+ float pweight[2] = { px+10, py+30 };
+ char sweight[64]; sprintf(sweight, "WEIGHT: %.0f",
+ info->weapons[weapon].weight);
+ render_text_scaled(rend, sweight, pweight, t, 1);
+ float ptype[2] = { px+10, py+45 };
+ char stype[64]; sprintf(stype, "DAMAGE TYPE: %s",
+ info->damage_types[info->weapons[weapon].damage_type]);
+ render_text_scaled(rend, stype, ptype, t, 1);
+ float pdamage[2] = { px+10, py+60 };
+ char sdamage[64]; sprintf(sdamage, "DAMAGE: %.0f",
+ info->weapons[weapon].damage);
+ render_text_scaled(rend, sdamage, pdamage, t, 1);
+ float prange[2] = { px+10, py+75 };
+ char srange[64]; sprintf(srange, "RANGE: %.0f",
+ info->weapons[weapon].range);
+ render_text_scaled(rend, srange, prange, t, 1);
+ float pcool[2] = { px+10, py+90 };
+ char scool[64]; sprintf(scool, "COOLDOWN: %.0f",
+ info->weapons[weapon].cooldown);
+ render_text_scaled(rend, scool, pcool, t, 1);
+ } else {
+ float pname[2] = { px+10, py+10 };
+ render_text_scaled(rend, "select a weapon...", pname, t, 1);
+ }
+}
+
+void render_view_weapon_detail (SDL_Renderer* rend, txtd *t,
+ int px, int py, infos *info, int weapon)
+{
+ if (weapon != -1) {
+ float pname[2] = { px+10, py+10 };
+ char sname[64]; sprintf(sname, "%s",
+ info->weapons[weapon].name);
+ render_text_scaled(rend, sname, pname, t, 1);
+ float pweight[2] = { px+10, py+30 };
+ char sweight[64]; sprintf(sweight, "WEIGHT: %.0f",
+ info->weapons[weapon].weight);
+ render_text_scaled(rend, sweight, pweight, t, 1);
+ float ptype[2] = { px+10, py+45 };
+ char stype[64]; sprintf(stype, "DAMAGE TYPE: %s",
+ info->damage_types[info->weapons[weapon].damage_type]);
+ render_text_scaled(rend, stype, ptype, t, 1);
+ float pdamage[2] = { px+10, py+60 };
+ char sdamage[64]; sprintf(sdamage, "DAMAGE: %.0f",
+ info->weapons[weapon].damage);
+ render_text_scaled(rend, sdamage, pdamage, t, 1);
+ float prange[2] = { px+10, py+75 };
+ char srange[64]; sprintf(srange, "RANGE: %.0f",
+ info->weapons[weapon].range);
+ render_text_scaled(rend, srange, prange, t, 1);
+ float pcool[2] = { px+10, py+90 };
+ char scool[64]; sprintf(scool, "COOLDOWN: %.0f",
+ info->weapons[weapon].cooldown);
+ render_text_scaled(rend, scool, pcool, t, 1);
+ } else {
+ render_view_weapon(rend, t, px, py, info, weapon);
+ }
+}
+
+
+void render_view_aug (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int aug)
+{
+ if (aug != -1) {
+ float pname[2] = { px+10, py+10 };
+ char sname[64]; sprintf(sname, "%s",
+ info->augs[aug].name);
+ render_text_scaled(rend, sname, pname, t, 1);
+ float pweight[2] = { px+10, py+30 };
+ char sweight[64]; sprintf(sweight, "WEIGHT: %.0f",
+ info->augs[aug].weight);
+ render_text_scaled(rend, sweight, pweight, t, 1);
+ } else {
+ float pname[2] = { px+10, py+10 };
+ render_text_scaled(rend, "select an augment...", pname, t, 1);
+ }
+}
+
+void render_view_aug_detail (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int aug)
+{
+ if (aug != -1) {
+ float h = 10;
+ float pname[2] = { px+10, py+h };
+ char sname[64]; sprintf(sname, "%s",
+ info->augs[aug].name);
+ render_text_scaled(rend, sname, pname, t, 1);
+ h += 20;
+
+ float pweight[2] = { px+10, py+h };
+ char sweight[64]; sprintf(sweight, "WEIGHT: %.0f",
+ info->augs[aug].weight);
+ render_text_scaled(rend, sweight, pweight, t, 1);
+ h += 15;
+
+ float range = info->augs[aug].add_range;
+ if (range != 0) {
+ float p[2] = { px+10, py+h };
+ char s[64]; sprintf(s, "RANGE: %.1f", range);
+ render_text_scaled(rend, s, p, t, 1);
+ h += 15;
+ }
+
+ float cooldown = info->augs[aug].add_cooldown;
+ if (cooldown != 0) {
+ float p[2] = { px+10, py+h };
+ char s[64]; sprintf(s, "COOLDOWN: %.2f", cooldown);
+ render_text_scaled(rend, s, p, t, 1);
+ h += 15;
+ }
+
+ float speed = info->augs[aug].add_speed;
+ if (speed != 0) {
+ float p[2] = { px+10, py+h };
+ char s[64]; sprintf(s, "SPEED: %.2f", speed);
+ render_text_scaled(rend, s, p, t, 1);
+ h += 15;
+ }
+
+ float hp = info->augs[aug].add_hp;
+ if (hp != 0) {
+ float p[2] = { px+10, py+h };
+ char s[64]; sprintf(s, "HP: %.1f", hp);
+ render_text_scaled(rend, s, p, t, 1);
+ h += 15;
+ }
+
+ h += 5;
+
+ float sum = 0;
+ for (int i=0; i<7; i++) sum += fabs(info->augs[aug].add_armor[i]);
+ if (sum != 0) {
+ float p[2] = { px+10, py+h };
+ render_text_scaled(rend, "ARMOR: ", p, t, 1);
+ h += 15;
+ for (int i=0; i<7; i++) {
+ if (info->augs[aug].add_armor[i] == 0) continue;
+ float pa[2] = { px+10, py+h };
+ char sa[64]; sprintf(sa, "%s: %.1f%",
+ info->damage_types[i], info->augs[aug].add_armor[i]);
+ render_text_scaled(rend, sa, pa, t, 1);
+ h += 15;
+ }
+ }
+
+ sum = 0;
+ for (int i=0; i<7; i++) sum += fabs(info->augs[aug].add_damage[i]);
+ if (sum != 0) {
+ float p[2] = { px+10, py+h };
+ render_text_scaled(rend, "DAMAGE: ", p, t, 1);
+ h += 15;
+ for (int i=0; i<7; i++) {
+ if (info->augs[aug].add_damage[i] == 0) continue;
+ float pa[2] = { px+10, py+h };
+ char sa[64]; sprintf(sa, "%s: %.1f%",
+ info->damage_types[i], info->augs[aug].add_damage[i]);
+ render_text_scaled(rend, sa, pa, t, 1);
+ h += 15;
+ }
+ }
+ } else {
+ render_view_aug(rend, t, px, py, info, aug);
+ }
+}
+
+
+void render_view_brain (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int brain)
+{
+ if (brain != -1) {
+ float pname[2] = { px+10, py+10 };
+ char sname[64]; sprintf(sname, "%s",
+ info->brains[brain].name);
+ render_text_scaled(rend, sname, pname, t, 1);
+ } else {
+ float pname[2] = { px+10, py+10 };
+ render_text_scaled(rend, "select a controller...", pname, t, 1);
+ }
+}
+
+
+void render_view_template (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int temp)
+{
+ button b = { "edit", 4, { px, py } };
+ render_button(rend, t, &b);
+ float wedit = get_text_width("edit", t);
+
+ button b1 = { "place", 4, { px+wedit+2*4+5, py } };
+ render_button(rend, t, &b1);
+ float wplace = get_text_width("place", t);
+
+ float pname[2] = { wplace+wedit+4*4+10+px, py+4 };
+ char *sname = info->chassis[info->templates[temp].chassis].name;
+ render_text_scaled(rend, sname, pname, t, 1);
+} \ No newline at end of file
diff --git a/hud/hud_views.h b/hud/hud_views.h
new file mode 100644
index 0000000..ceced23
--- /dev/null
+++ b/hud/hud_views.h
@@ -0,0 +1,47 @@
+#ifndef HUD_VIEWS_H
+#define HUD_VIEWS_H
+
+#include <SDL.h>
+
+#include <render_text.h>
+#include <button.h>
+#include <graphicsettings.h>
+#include <mkb.h>
+#include <info.h>
+#include <units.h>
+#include <hud.h>
+
+void render_view_stats (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, info_unit *tm);
+
+
+void render_view_chassis (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int chassis, SDL_Texture *sprites);
+
+void render_view_battery (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int batt);
+
+void render_view_armor (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int armor);
+void render_view_armor_detail (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int armor);
+
+void render_view_weapon (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int weapon);
+void render_view_weapon_detail (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int weapon);
+
+void render_view_aug (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int aug);
+void render_view_aug_detail (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int aug);
+
+void render_view_brain (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int brain);
+
+
+void render_view_template (SDL_Renderer* rend, txtd *t, int px, int py,
+ infos *info, int temp);
+
+
+#endif \ No newline at end of file