[Add] Utilising all GUI elements.
-- Minimal right now.
This commit is contained in:
parent
9fae81c389
commit
23cb72bffd
@ -109,6 +109,11 @@
|
||||
<y>401</y>
|
||||
</health>
|
||||
</target>
|
||||
</gui>
|
||||
|
||||
<misc>
|
||||
<x>40</x>
|
||||
<y>424</y>
|
||||
<w>112</w>
|
||||
<h>100</h>
|
||||
</misc>
|
||||
</gui>
|
||||
</GUIs>
|
||||
|
@ -78,7 +78,7 @@
|
||||
<cap_cargo>40</cap_cargo>
|
||||
</characteristics>
|
||||
<outfits>
|
||||
<outfit quantity='1'>laser</outfit>
|
||||
<outfit quantity='4'>laser</outfit>
|
||||
</outfits>
|
||||
</ship>
|
||||
</Ships>
|
||||
|
@ -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;
|
||||
|
@ -35,6 +35,7 @@ typedef struct {
|
||||
|
||||
// Default colors.
|
||||
extern glColor cGrey;
|
||||
extern glColor cGreen;
|
||||
|
||||
// Spritesheet info.
|
||||
typedef struct {
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
65
src/player.c
65
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));
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user