From 23cb72bffdb6745fb4d5c622ba3e7b942b6e69a7 Mon Sep 17 00:00:00 2001 From: Allanis Date: Thu, 14 Feb 2013 16:07:19 +0000 Subject: [PATCH] [Add] Utilising all GUI elements. -- Minimal right now. --- dat/gui.xml | 9 +++++-- dat/ship.xml | 2 +- src/opengl.c | 3 ++- src/opengl.h | 1 + src/physics.c | 4 ++-- src/player.c | 65 ++++++++++++++++++++++++++++++++++++--------------- src/player.h | 1 + 7 files changed, 60 insertions(+), 25 deletions(-) diff --git a/dat/gui.xml b/dat/gui.xml index fbe57fb..7861d1c 100644 --- a/dat/gui.xml +++ b/dat/gui.xml @@ -109,6 +109,11 @@ 401 - - + + 40 + 424 + 112 + 100 + + diff --git a/dat/ship.xml b/dat/ship.xml index 0a5fad6..4db4fc6 100644 --- a/dat/ship.xml +++ b/dat/ship.xml @@ -78,7 +78,7 @@ 40 - laser + laser diff --git a/src/opengl.c b/src/opengl.c index 548d821..285d8de 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -18,7 +18,8 @@ #define FONT_DEF "../gfx/fonts/FreeSans.ttf" // Default colors. -glColor cGrey = { .r = .75, .g = 0.75, .b = 0.75, .a = 1 }; +glColor cGrey = { .r = 0.75, .g = 0.75, .b = 0.75, .a = 1 }; +glColor cGreen = { .r = 0.20, .g = 0.80, .b = 0.20, .a = 1 }; // offsets to Adjust the pilot's place onscreen to be in the middle, even with the GUI. extern double gui_xoff; diff --git a/src/opengl.h b/src/opengl.h index edf88af..c234eb0 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -35,6 +35,7 @@ typedef struct { // Default colors. extern glColor cGrey; +extern glColor cGreen; // Spritesheet info. typedef struct { diff --git a/src/physics.c b/src/physics.c index 8ec9e45..4354007 100644 --- a/src/physics.c +++ b/src/physics.c @@ -1,8 +1,8 @@ #include #include -#include #include "main.h" +#include "log.h" #include "physics.h" // ================ @@ -205,7 +205,7 @@ void solid_init(Solid* dest, const double mass, const double dir, const Vec2* po // Create a new solid. Solid* solid_create(const double mass, const double dir, const Vec2* pos, const Vec2* vel) { Solid* dyn = MALLOC_L(Solid); - assert(dyn != NULL); + if(dyn == NULL) ERR("Out of memory"); solid_init(dyn, mass, dir, pos, vel); return dyn; } diff --git a/src/player.c b/src/player.c index 823ef90..8d1e990 100644 --- a/src/player.c +++ b/src/player.c @@ -37,6 +37,7 @@ const char* keybindNames[] = { "accel", "left", "right", "primary", "target", // Player stuff. Pilot* player = NULL; // extern in pilot.h +unsigned int credits = 0; static double player_turn = 0.; // Turn velocity from input. static double player_acc = 0.; // Accel velocity from input. static int player_primary = 0; // Player is shooting primary weapon. @@ -53,6 +54,8 @@ extern int pilots; // -- Colors. // Standard colors. +glColor cConsole = { .r = 0.5, .g = 0.8, .b = 0.5, .a = 1. }; + glColor cInert = { .r = 0.6, .g = 0.6, .b = 0.6, .a = 1. }; glColor cNeutral = { .r = 0.9, .g = 1.0, .b = 0.3, .a = 1. }; glColor cFriend = { .r = 0.0, .g = 1.0, .b = 0.0, .a = 1. }; @@ -91,6 +94,7 @@ typedef struct { Rect nav; Rect shield, armor, energy; Rect weapon; + Rect misc; // Positions. Vec2 pos_frame; @@ -99,6 +103,7 @@ typedef struct { Vec2 pos_shield, pos_armor, pos_energy; Vec2 pos_weapon; Vec2 pos_target, pos_target_health, pos_target_name, pos_target_faction; + Vec2 pos_misc; Vec2 pos_msg; } GUI; @@ -150,6 +155,7 @@ void player_message(const char* fmt, ...) { // Render the player. void player_render(void) { int i, j; + char str[10]; Pilot* p; Vec2 v; glColor* c; @@ -225,23 +231,35 @@ void player_render(void) { glPopMatrix(); // GL_PROJECTION. - // Health. - gui_renderBar(&cShield, &gui.pos_shield, &gui.shield, player->shield / player->shield_max); - gui_renderBar(&cArmor, &gui.pos_armor, &gui.armor, player->armor / player->armor_max); - gui_renderBar(&cEnergy, &gui.pos_energy, &gui.energy, player->energy / player->energy_max); - // Nav. if(planet_target != -1) { } else { - i = gl_printWidth(NULL, "Nav"); + i = gl_printWidth(NULL, "NAV"); vect_csetmin(&v, VX(gui.pos_nav) + (gui.nav.w - i)/2., VY(gui.pos_nav) - 5); - gl_print(NULL, &v, &cGrey, "NAV"); + gl_print(NULL, &v, &cConsole, "NAV"); i = gl_printWidth(&gui.smallFont, "No Target"); vect_csetmin(&v, VX(gui.pos_nav) + (gui.nav.w - i)/2., VY(gui.pos_nav) - 10 - gui.smallFont.h); gl_print(&gui.smallFont, &v, &cGrey, "No Target"); } + // Health + gui_renderBar(&cShield, &gui.pos_shield, &gui.shield, player->shield / player->shield_max); + gui_renderBar(&cArmor, &gui.pos_armor, &gui.armor, player->armor / player->armor_max); + gui_renderBar(&cEnergy, &gui.pos_energy, &gui.energy, player->energy / player->energy_max); + + // Weapon. + if(weapon == -1) { + i = gl_printWidth(NULL, "Secondary"); + vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2., VY(gui.pos_weapon) - 5); + gl_print(NULL, &v, &cConsole, "Secondary"); + i = gl_printWidth(&gui.smallFont, "None"); + vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2., VY(gui.pos_weapon) - 10 - gl_defFont.h); + gl_print(&gui.smallFont, &v, &cGrey, "None"); + } else { + + } + // Target. if(player_target != PLAYER_ID) { p = pilot_get(player_target); @@ -262,21 +280,27 @@ void player_render(void) { else // On armor. gl_print(&gui.smallFont, &gui.pos_target_health, NULL, "%s: %.0f%%", "Armor", p->armor/p->armor_max*100.); - } - // Weapon. - if(weapon == -1) { - i = gl_printWidth(NULL, "Secondary"); - vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2., VY(gui.pos_weapon) - 5); - gl_print(NULL, &v, &cGrey, "Secondary"); - i = gl_printWidth(&gui.smallFont, "None"); - vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2., VY(gui.pos_weapon) - 10 - gl_defFont.h); - gl_print(&gui.smallFont, &v, &cGrey, "None"); } else { - + // No target. + i = gl_printWidth(NULL, "No Target"); + vect_csetmin(&v, VX(gui.pos_target) + (SHIP_TARGET_W - i)/2., VY(gui.pos_target) + + (SHIP_TARGET_H - gl_defFont.h)/2.); + gl_print(NULL, &v, &cGrey, "No Target"); } + + // Misc. + vect_csetmin(&v, VX(gui.pos_misc) + 10, VY(gui.pos_misc) - 10 - gl_defFont.h); + gl_print(NULL, &v, &cConsole, "SCred:"); + if(credits >= 1000000) + snprintf(str, 10, "%.2fM", (double)credits / 1000000.); + else if(credits >= 1000) + snprintf(str, 10, "%d", credits); + i = gl_printWidth(&gui.smallFont, "%s", str); + vect_csetmin(&v, VX(gui.pos_misc) + gui.misc.w - 10 - i, VY(gui.pos_misc) - 10 - gl_defFont.h); + gl_print(&gui.smallFont, &v, NULL, "%s", str); + // Messages. - VX(v) = VX(gui.pos_msg); - VY(v) = VY(gui.pos_msg) + (double)(gl_defFont.h*msg_max)*1.2; + vect_csetmin(&v, VX(gui.pos_msg), VY(gui.pos_msg) + (double)(gl_defFont.h*msg_max)*1.2); for(i = 0; i < msg_max; i++) { VY(v) -= (double)gl_defFont.h*1.2; if(msg_stack[msg_max-i-1].str[0] != '\0') { @@ -598,6 +622,9 @@ static int gui_parse(const xmlNodePtr parent, const char* name) { VY(gui.pos_frame) + gui.gfx_frame->h - y - gui.smallFont.h); } } while((cur = cur->next)); + } else if(xml_isNode(node, "misc")) { + rect_parse(node, &x, &y, &gui.misc.w, &gui.misc.h); + vect_csetmin(&gui.pos_misc, VX(gui.pos_frame) + x, VY(gui.pos_frame) + gui.gfx_frame->h - y); } } while((node = node->next)); diff --git a/src/player.h b/src/player.h index ae1107b..636df4e 100644 --- a/src/player.h +++ b/src/player.h @@ -4,6 +4,7 @@ // The pilot. extern Pilot* pilot; +extern unsigned int credits; typedef enum { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render functions. typedef enum { KEYBIND_NULL, KEYBIND_KEYBOARD, KEYBIND_JAXIS, KEYBIND_JBUTTON } KeybindType;