[Add] New GUI.
[Fix] Circular radar.
This commit is contained in:
parent
d288a2db9f
commit
74ed3e094b
54
dat/gui.xml
54
dat/gui.xml
@ -1,5 +1,9 @@
|
||||
<GUIs>
|
||||
<gui name="simple" gfx="simple">
|
||||
<offset>
|
||||
<x>-75</x>
|
||||
<y>0</y>
|
||||
</offset>
|
||||
<radar type="rectangle">
|
||||
<w>128</w>
|
||||
<h>128</h>
|
||||
@ -45,4 +49,54 @@
|
||||
</health>
|
||||
</target>
|
||||
</gui>
|
||||
<gui name="minimal" gfx="minimal">
|
||||
<offset>
|
||||
<x>-65</x>
|
||||
<y>0</y>
|
||||
</offset>
|
||||
<radar type="circle">
|
||||
<w>70</w>
|
||||
<x>72</x>
|
||||
<y>72</y>
|
||||
</radar>
|
||||
<health>
|
||||
<shield>
|
||||
<w>98</w>
|
||||
<h>8</h>
|
||||
<x>52</x>
|
||||
<y>186</y>
|
||||
</shield>
|
||||
<armor>
|
||||
<w>98</w>
|
||||
<h>8</h>
|
||||
<x>52</x>
|
||||
<y>197</y>
|
||||
</armor>
|
||||
<energy>
|
||||
<w>98</w>
|
||||
<h>8</h>
|
||||
<x>52</x>
|
||||
<y>207</y>
|
||||
</energy>
|
||||
</health>
|
||||
<target>
|
||||
<gfx>
|
||||
<x>34</x>
|
||||
<y>273</y>
|
||||
</gfx>
|
||||
<name>
|
||||
<x>40</x>
|
||||
<y>260</y>
|
||||
</name>
|
||||
<faction>
|
||||
<x>40</x>
|
||||
<y>273</y>
|
||||
</faction>
|
||||
<health>
|
||||
<x>40</x>
|
||||
<y>370</y>
|
||||
</health>
|
||||
</target>
|
||||
</gui>
|
||||
|
||||
</GUIs>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<Ships>
|
||||
<ship name="Merchant Ship">
|
||||
<GFX>ship</GFX>
|
||||
<GUI>simple</GUI>
|
||||
<GUI>minimal</GUI>
|
||||
<class>1</class>
|
||||
<movement>
|
||||
<thrust>400</thrust>
|
||||
|
BIN
gfx/gui/minimal.png
Normal file
BIN
gfx/gui/minimal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
BIN
gfx/gui/minimal_pilot.png
Normal file
BIN
gfx/gui/minimal_pilot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 371 B |
BIN
gfx/gui/minimal_planet.png
Normal file
BIN
gfx/gui/minimal_planet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 326 B |
Binary file not shown.
@ -2,6 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "physics.h"
|
||||
|
||||
// ================
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define VX(v) ((v).x)
|
||||
#define VY(v) ((v).y)
|
||||
@ -10,6 +11,7 @@
|
||||
#define ANGLE(x,y)(((x)==0.) ? 0. : (((x)<0.)?atan((y)/(x))+M_PI:atan((y)/(x))))
|
||||
|
||||
#define vect_dist(v,u) MOD((v)->x-(u)->x, (v)->y-(u)->y)
|
||||
#define vect_odist(v) MOD((v)->x, (v)->y)
|
||||
|
||||
// Misc
|
||||
double angle_diff(const double ref, double a);
|
||||
|
74
src/player.c
74
src/player.c
@ -49,10 +49,6 @@ static unsigned int player_target = PLAYER_ID; // Targetted pilot.
|
||||
extern Pilot** pilot_stack;
|
||||
extern int pilots;
|
||||
|
||||
// Weapon stuff for GUI.
|
||||
extern void weapon_minimap(double res, double w, double h);
|
||||
extern void planets_minimap(double res, double w, double h);
|
||||
|
||||
// GUI crap.
|
||||
// Need these offsets to render properly. -- Used in opengl.c
|
||||
// -- Colors.
|
||||
@ -74,8 +70,6 @@ Color cShield = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. };
|
||||
Color cArmor = { .r = 0.5, .g = 0.5, .b = 0.5, .a = 1. };
|
||||
Color cEnergy = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. };
|
||||
|
||||
typedef enum { RADAR_RECT, RADAR_CIRCLE } RadarShape;
|
||||
|
||||
typedef struct {
|
||||
double w,h; // Dimensions.
|
||||
RadarShape shape;
|
||||
@ -123,7 +117,9 @@ typedef struct {
|
||||
static Msg* msg_stack;
|
||||
|
||||
// External.
|
||||
extern void pilot_render(Pilot* pilot); // Extern is in Pilot.*
|
||||
extern void pilot_render(const Pilot* pilot); // Extern is in Pilot.*
|
||||
extern void weapon_minimap(const double res, const double w, const double h, const RadarShape shape); // weapon.c
|
||||
extern void planets_minimap(const double res, const double w, const double h, const RadarShape shape); // space.c
|
||||
// Internal.
|
||||
static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w, double* h);
|
||||
static int gui_parse(const xmlNodePtr parent, const char* name);
|
||||
@ -180,20 +176,24 @@ void player_render(void) {
|
||||
// -- Radar.
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
if(gui.radar.shape == RADAR_RECT)
|
||||
glTranslated(VX(gui.pos_radar) - gl_screen.w/2. + gui.radar.w/2.,
|
||||
VY(gui.pos_radar) - gl_screen.h/2. - gui.radar.h/2., 0.);
|
||||
else if(gui.radar.shape == RADAR_CIRCLE)
|
||||
glTranslated(VX(gui.pos_radar) - gl_screen.w/2.,
|
||||
VY(gui.pos_radar) - gl_screen.h/2., 0.);
|
||||
|
||||
switch(gui.radar.shape) {
|
||||
case RADAR_RECT:
|
||||
// Planets.
|
||||
COLOR(cFriend);
|
||||
planets_minimap(gui.radar.res, gui.radar.w, gui.radar.h);
|
||||
planets_minimap(gui.radar.res, gui.radar.w, gui.radar.h, gui.radar.shape);
|
||||
|
||||
// Weapons.
|
||||
glBegin(GL_POINTS);
|
||||
COLOR(cRadar_weap);
|
||||
weapon_minimap(gui.radar.res, gui.radar.w, gui.radar.h);
|
||||
glEnd(); // Put end to those points.
|
||||
weapon_minimap(gui.radar.res, gui.radar.w, gui.radar.h, gui.radar.shape);
|
||||
glEnd();
|
||||
|
||||
// Render the pilots.
|
||||
for(j = 0, i = 1; i < pilots; i++) {
|
||||
// Skip the player.
|
||||
if(pilot_stack[i]->id == player_target) j = i;
|
||||
@ -201,18 +201,9 @@ void player_render(void) {
|
||||
}
|
||||
// Render the targetted pilot.
|
||||
if(j != 0) gui_renderPilot(pilot_stack[j]);
|
||||
glBegin(GL_POINTS); // For ze player.
|
||||
break;
|
||||
case RADAR_CIRCLE:
|
||||
|
||||
// Player.
|
||||
glBegin(GL_POINTS);
|
||||
for(i = 1; i < pilots; i++) {
|
||||
p = pilot_stack[i];
|
||||
COLOR(cNeutral);
|
||||
glVertex2d((p->solid->pos.x - player->solid->pos.x) / gui.radar.res,
|
||||
(p->solid->pos.y - player->solid->pos.y) / gui.radar.res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Player. -- Drawn last.
|
||||
COLOR(cRadar_player);
|
||||
glVertex2d( 0., 2. ); // We represent the player with a small '+'
|
||||
@ -271,6 +262,7 @@ void player_render(void) {
|
||||
// Renders a pilot.
|
||||
static void gui_renderPilot(const Pilot* p) {
|
||||
int x, y, sx, sy;
|
||||
double w, h;
|
||||
|
||||
x = (p->solid->pos.x - player->solid->pos.x) / gui.radar.res;
|
||||
y = (p->solid->pos.y - player->solid->pos.y) / gui.radar.res;
|
||||
@ -279,9 +271,20 @@ static void gui_renderPilot(const Pilot* p) {
|
||||
if(sx < 1.) sx = 1.;
|
||||
if(sy < 1.) sy = 1.;
|
||||
|
||||
if((ABS(x) > gui.radar.w/2+sx) || (ABS(y) > gui.radar.h/2.+sy))
|
||||
if(((gui.radar.shape == RADAR_RECT) && ((ABS(x) > gui.radar.w/2.+sx)
|
||||
|| (ABS(y) > gui.radar.h/2.+sy))) || ((gui.radar.shape == RADAR_CIRCLE) &&
|
||||
((x*x + y*y) > (int)(gui.radar.w*gui.radar.w))))
|
||||
return; // Pilot isn't in range.
|
||||
|
||||
if(gui.radar.shape == RADAR_RECT) {
|
||||
w = gui.radar.w/2.;
|
||||
h = gui.radar.h/2.;
|
||||
}
|
||||
else if(gui.radar.shape == RADAR_CIRCLE) {
|
||||
w = gui.radar.w;
|
||||
h = gui.radar.w;
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
// Colors.
|
||||
if(p->id == player_target) COLOR(cRadar_targ);
|
||||
@ -289,10 +292,10 @@ static void gui_renderPilot(const Pilot* p) {
|
||||
else COLOR(cNeutral);
|
||||
|
||||
// Image.
|
||||
glVertex2d(MAX(x-sx, -gui.radar.w/2.), MIN(y+sy, gui.radar.h/2)); // Top left.
|
||||
glVertex2d(MIN(x+sx, gui.radar.w/2.), MIN(y+sy, gui.radar.h/2)); // Top right.
|
||||
glVertex2d(MIN(x+sx, gui.radar.w/2.), MAX(y-sy, -gui.radar.h/2)); // Bottom right.
|
||||
glVertex2d(MAX(x-sx, -gui.radar.w/2.), MAX(y-sy, -gui.radar.h/2)); // Bottom left.
|
||||
glVertex2d(MAX(x-sx, -w), MIN(y+sy, h)); // Top left.
|
||||
glVertex2d(MIN(x+sx, w), MIN(y+sy, h)); // Top right.
|
||||
glVertex2d(MIN(x+sx, w), MAX(y-sy, -h)); // Bottom right.
|
||||
glVertex2d(MAX(x-sx, -w), MAX(y-sy, -h)); // Bottom left.
|
||||
glEnd();
|
||||
}
|
||||
|
||||
@ -458,13 +461,16 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
|
||||
gl_screen.w - gui.gfx_frame->w, // x.
|
||||
gl_screen.h - gui.gfx_frame->h); // h.
|
||||
|
||||
// For rendering the player. Displaces it a little so it's centered onscreen.
|
||||
gui_xoff = - gui.gfx_frame->w/2.;
|
||||
|
||||
// Let's parse the data now.
|
||||
node = parent->children;
|
||||
do {
|
||||
if(strcmp((char*)node->name, "radar")==0) {
|
||||
// Offset.
|
||||
if(strcmp((char*)node->name, "offset")==0) {
|
||||
rect_parse(node, &x, &y, NULL, NULL);
|
||||
gui_xoff = x;
|
||||
gui_yoff = y;
|
||||
}
|
||||
else if(strcmp((char*)node->name, "radar")==0) {
|
||||
tmp = (char*)xmlGetProp(node, (xmlChar*)"type");
|
||||
|
||||
// Make sure type is valid.
|
||||
@ -476,7 +482,11 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
|
||||
}
|
||||
free(tmp);
|
||||
|
||||
// Load the appropriate measurements.
|
||||
if(gui.radar.shape == RADAR_RECT)
|
||||
rect_parse(node, &x, &y, &gui.radar.w, &gui.radar.h);
|
||||
else if(gui.radar.shape == RADAR_CIRCLE)
|
||||
rect_parse(node, &x, &y, &gui.radar.w, NULL);
|
||||
vect_csetmin(&gui.pos_radar,
|
||||
VX(gui.pos_frame) + x,
|
||||
VY(gui.pos_frame) + gui.gfx_frame->h - y);
|
||||
|
@ -2,8 +2,10 @@
|
||||
#include <SDL.h>
|
||||
#include "pilot.h"
|
||||
|
||||
// The pilot.
|
||||
extern Pilot* pilot;
|
||||
|
||||
typedef enum { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render functions.
|
||||
typedef enum { KEYBIND_NULL, KEYBIND_KEYBOARD, KEYBIND_JAXIS, KEYBIND_JBUTTON } KeybindType;
|
||||
|
||||
// Render.
|
||||
|
10
src/space.c
10
src/space.c
@ -8,6 +8,7 @@
|
||||
#include "pack.h"
|
||||
#include "space.h"
|
||||
#include "faction.h"
|
||||
#include "player.h"
|
||||
|
||||
#define XML_NODE_START 1
|
||||
#define XML_NODE_TEST 3
|
||||
@ -56,12 +57,15 @@ extern void player_message(const char* fmt, ...);
|
||||
|
||||
// Draw the planet. Used in planet.c
|
||||
// Matrix mode is already displaced to center of the minimap.
|
||||
#define PIXEL(x,y) if(ABS(x)<w/2. && ABS(y)<h/2.) glVertex2i((x),(y))
|
||||
void planets_minimap(double res, double w, double h) {
|
||||
#define PIXEL(x,y) if((shape == RADAR_RECT && ABS(x)<w/2. && ABS(y)<h/2.) || \
|
||||
(shape == RADAR_CIRCLE && (((x)*(x)+(y)*(y)) < rc))) glVertex2i((x),(y))
|
||||
void planets_minimap(const double res, const double w, const double h, const RadarShape shape) {
|
||||
int i;
|
||||
int cx, cy, x, y, r;
|
||||
int cx, cy, x, y, r, rc;
|
||||
double p;
|
||||
|
||||
if(shape == RADAR_CIRCLE) rc = (int)(w*w);
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
for(i = 0; i < cur_system->nplanets; i++) {
|
||||
|
18
src/weapon.c
18
src/weapon.c
@ -9,6 +9,7 @@
|
||||
#include "rng.h"
|
||||
#include "pilot.h"
|
||||
#include "collision.h"
|
||||
#include "player.h"
|
||||
#include "weapon.h"
|
||||
|
||||
// Some stuff from pilot.
|
||||
@ -49,24 +50,27 @@ static void weapon_destroy(Weapon* w, WeaponLayer layer);
|
||||
static void weapon_free(Weapon* w);
|
||||
|
||||
// Draw the minimap weapons (player.c).
|
||||
void weapon_minimap(double res, double w, double h) {
|
||||
int i;
|
||||
#define PIXEL(x,y) if((shape == RADAR_RECT && ABS(x) < w/2. && ABS(y)<h/2.) || \
|
||||
(shape == RADAR_CIRCLE && (((x)*(x)+(y)*(y))<rc))) glVertex2i((x),(y))
|
||||
void weapon_minimap(const double res, const double w, const double h, const RadarShape shape) {
|
||||
int i, rc;
|
||||
double x, y;
|
||||
|
||||
if(shape == RADAR_CIRCLE) rc = (int)(w*w);
|
||||
|
||||
for(i = 0; i < nwbackLayer; i++) {
|
||||
x = (wbackLayer[i]->solid->pos.x - player->solid->pos.x) / res;
|
||||
y = (wbackLayer[i]->solid->pos.y - player->solid->pos.y) / res;
|
||||
if(ABS(x) < w/2. && ABS(y) < h/2.)
|
||||
glVertex2d(x,y);
|
||||
PIXEL(x,y);
|
||||
}
|
||||
|
||||
for(i = 0; i < nwfrontLayer; i++) {
|
||||
x = (wfrontLayer[i]->solid->pos.x - player->solid->pos.x) / res;
|
||||
y = (wfrontLayer[i]->solid->pos.y - player->solid->pos.y) / res;
|
||||
if(ABS(x) < w/2. && ABS(y) < h/2.)
|
||||
glVertex2d(x,y);
|
||||
|
||||
PIXEL(x,y);
|
||||
}
|
||||
}
|
||||
#undef PIXEL
|
||||
|
||||
// Update all weapons in the layer.
|
||||
void weapons_update(const double dt, WeaponLayer layer) {
|
||||
|
Loading…
Reference in New Issue
Block a user