[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>
|
<GUIs>
|
||||||
<gui name="simple" gfx="simple">
|
<gui name="simple" gfx="simple">
|
||||||
|
<offset>
|
||||||
|
<x>-75</x>
|
||||||
|
<y>0</y>
|
||||||
|
</offset>
|
||||||
<radar type="rectangle">
|
<radar type="rectangle">
|
||||||
<w>128</w>
|
<w>128</w>
|
||||||
<h>128</h>
|
<h>128</h>
|
||||||
@ -45,4 +49,54 @@
|
|||||||
</health>
|
</health>
|
||||||
</target>
|
</target>
|
||||||
</gui>
|
</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>
|
</GUIs>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<Ships>
|
<Ships>
|
||||||
<ship name="Merchant Ship">
|
<ship name="Merchant Ship">
|
||||||
<GFX>ship</GFX>
|
<GFX>ship</GFX>
|
||||||
<GUI>simple</GUI>
|
<GUI>minimal</GUI>
|
||||||
<class>1</class>
|
<class>1</class>
|
||||||
<movement>
|
<movement>
|
||||||
<thrust>400</thrust>
|
<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 <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
#include "physics.h"
|
#include "physics.h"
|
||||||
|
|
||||||
// ================
|
// ================
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "main.h"
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define VX(v) ((v).x)
|
#define VX(v) ((v).x)
|
||||||
#define VY(v) ((v).y)
|
#define VY(v) ((v).y)
|
||||||
@ -9,7 +10,8 @@
|
|||||||
#define MOD(x,y) (sqrt((x)*(x) + (y)*(y)))
|
#define MOD(x,y) (sqrt((x)*(x) + (y)*(y)))
|
||||||
#define ANGLE(x,y)(((x)==0.) ? 0. : (((x)<0.)?atan((y)/(x))+M_PI:atan((y)/(x))))
|
#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_dist(v,u) MOD((v)->x-(u)->x, (v)->y-(u)->y)
|
||||||
|
#define vect_odist(v) MOD((v)->x, (v)->y)
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
double angle_diff(const double ref, double a);
|
double angle_diff(const double ref, double a);
|
||||||
|
104
src/player.c
104
src/player.c
@ -49,10 +49,6 @@ static unsigned int player_target = PLAYER_ID; // Targetted pilot.
|
|||||||
extern Pilot** pilot_stack;
|
extern Pilot** pilot_stack;
|
||||||
extern int pilots;
|
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.
|
// GUI crap.
|
||||||
// Need these offsets to render properly. -- Used in opengl.c
|
// Need these offsets to render properly. -- Used in opengl.c
|
||||||
// -- Colors.
|
// -- 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 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. };
|
Color cEnergy = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. };
|
||||||
|
|
||||||
typedef enum { RADAR_RECT, RADAR_CIRCLE } RadarShape;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
double w,h; // Dimensions.
|
double w,h; // Dimensions.
|
||||||
RadarShape shape;
|
RadarShape shape;
|
||||||
@ -123,7 +117,9 @@ typedef struct {
|
|||||||
static Msg* msg_stack;
|
static Msg* msg_stack;
|
||||||
|
|
||||||
// External.
|
// 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.
|
// Internal.
|
||||||
static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w, double* h);
|
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);
|
static int gui_parse(const xmlNodePtr parent, const char* name);
|
||||||
@ -180,39 +176,34 @@ void player_render(void) {
|
|||||||
// -- Radar.
|
// -- Radar.
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslated(VX(gui.pos_radar) - gl_screen.w/2. + gui.radar.w/2.,
|
if(gui.radar.shape == RADAR_RECT)
|
||||||
VY(gui.pos_radar) - gl_screen.h/2. - gui.radar.h/2., 0.);
|
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) {
|
// Planets.
|
||||||
case RADAR_RECT:
|
COLOR(cFriend);
|
||||||
// Planets.
|
planets_minimap(gui.radar.res, gui.radar.w, gui.radar.h, gui.radar.shape);
|
||||||
COLOR(cFriend);
|
|
||||||
planets_minimap(gui.radar.res, gui.radar.w, gui.radar.h);
|
|
||||||
|
|
||||||
// Weapons.
|
// Weapons.
|
||||||
glBegin(GL_POINTS);
|
glBegin(GL_POINTS);
|
||||||
COLOR(cRadar_weap);
|
COLOR(cRadar_weap);
|
||||||
weapon_minimap(gui.radar.res, gui.radar.w, gui.radar.h);
|
weapon_minimap(gui.radar.res, gui.radar.w, gui.radar.h, gui.radar.shape);
|
||||||
glEnd(); // Put end to those points.
|
glEnd();
|
||||||
for(j = 0, i = 1; i < pilots; i++) {
|
|
||||||
// Skip the player.
|
// Render the pilots.
|
||||||
if(pilot_stack[i]->id == player_target) j = i;
|
for(j = 0, i = 1; i < pilots; i++) {
|
||||||
else gui_renderPilot(pilot_stack[i]);
|
// Skip the player.
|
||||||
}
|
if(pilot_stack[i]->id == player_target) j = i;
|
||||||
// Render the targetted pilot.
|
else gui_renderPilot(pilot_stack[i]);
|
||||||
if(j != 0) gui_renderPilot(pilot_stack[j]);
|
|
||||||
glBegin(GL_POINTS); // For ze player.
|
|
||||||
break;
|
|
||||||
case RADAR_CIRCLE:
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
// Render the targetted pilot.
|
||||||
|
if(j != 0) gui_renderPilot(pilot_stack[j]);
|
||||||
|
|
||||||
|
// Player.
|
||||||
|
glBegin(GL_POINTS);
|
||||||
// Player. -- Drawn last.
|
// Player. -- Drawn last.
|
||||||
COLOR(cRadar_player);
|
COLOR(cRadar_player);
|
||||||
glVertex2d( 0., 2. ); // We represent the player with a small '+'
|
glVertex2d( 0., 2. ); // We represent the player with a small '+'
|
||||||
@ -271,6 +262,7 @@ void player_render(void) {
|
|||||||
// Renders a pilot.
|
// Renders a pilot.
|
||||||
static void gui_renderPilot(const Pilot* p) {
|
static void gui_renderPilot(const Pilot* p) {
|
||||||
int x, y, sx, sy;
|
int x, y, sx, sy;
|
||||||
|
double w, h;
|
||||||
|
|
||||||
x = (p->solid->pos.x - player->solid->pos.x) / gui.radar.res;
|
x = (p->solid->pos.x - player->solid->pos.x) / gui.radar.res;
|
||||||
y = (p->solid->pos.y - player->solid->pos.y) / 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(sx < 1.) sx = 1.;
|
||||||
if(sy < 1.) sy = 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.
|
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);
|
glBegin(GL_QUADS);
|
||||||
// Colors.
|
// Colors.
|
||||||
if(p->id == player_target) COLOR(cRadar_targ);
|
if(p->id == player_target) COLOR(cRadar_targ);
|
||||||
@ -289,10 +292,10 @@ static void gui_renderPilot(const Pilot* p) {
|
|||||||
else COLOR(cNeutral);
|
else COLOR(cNeutral);
|
||||||
|
|
||||||
// Image.
|
// Image.
|
||||||
glVertex2d(MAX(x-sx, -gui.radar.w/2.), MIN(y+sy, gui.radar.h/2)); // Top left.
|
glVertex2d(MAX(x-sx, -w), MIN(y+sy, h)); // Top left.
|
||||||
glVertex2d(MIN(x+sx, gui.radar.w/2.), MIN(y+sy, gui.radar.h/2)); // Top right.
|
glVertex2d(MIN(x+sx, w), MIN(y+sy, h)); // Top right.
|
||||||
glVertex2d(MIN(x+sx, gui.radar.w/2.), MAX(y-sy, -gui.radar.h/2)); // Bottom right.
|
glVertex2d(MIN(x+sx, w), MAX(y-sy, -h)); // Bottom right.
|
||||||
glVertex2d(MAX(x-sx, -gui.radar.w/2.), MAX(y-sy, -gui.radar.h/2)); // Bottom left.
|
glVertex2d(MAX(x-sx, -w), MAX(y-sy, -h)); // Bottom left.
|
||||||
glEnd();
|
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.w - gui.gfx_frame->w, // x.
|
||||||
gl_screen.h - gui.gfx_frame->h); // h.
|
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.
|
// Let's parse the data now.
|
||||||
node = parent->children;
|
node = parent->children;
|
||||||
do {
|
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");
|
tmp = (char*)xmlGetProp(node, (xmlChar*)"type");
|
||||||
|
|
||||||
// Make sure type is valid.
|
// Make sure type is valid.
|
||||||
@ -476,7 +482,11 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
|
|||||||
}
|
}
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
rect_parse(node, &x, &y, &gui.radar.w, &gui.radar.h);
|
// 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,
|
vect_csetmin(&gui.pos_radar,
|
||||||
VX(gui.pos_frame) + x,
|
VX(gui.pos_frame) + x,
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y);
|
VY(gui.pos_frame) + gui.gfx_frame->h - y);
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include "pilot.h"
|
#include "pilot.h"
|
||||||
|
|
||||||
|
// The pilot.
|
||||||
extern Pilot* 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;
|
typedef enum { KEYBIND_NULL, KEYBIND_KEYBOARD, KEYBIND_JAXIS, KEYBIND_JBUTTON } KeybindType;
|
||||||
|
|
||||||
// Render.
|
// Render.
|
||||||
|
10
src/space.c
10
src/space.c
@ -8,6 +8,7 @@
|
|||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
#include "space.h"
|
#include "space.h"
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
#define XML_NODE_START 1
|
#define XML_NODE_START 1
|
||||||
#define XML_NODE_TEST 3
|
#define XML_NODE_TEST 3
|
||||||
@ -56,12 +57,15 @@ extern void player_message(const char* fmt, ...);
|
|||||||
|
|
||||||
// Draw the planet. Used in planet.c
|
// Draw the planet. Used in planet.c
|
||||||
// Matrix mode is already displaced to center of the minimap.
|
// 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))
|
#define PIXEL(x,y) if((shape == RADAR_RECT && ABS(x)<w/2. && ABS(y)<h/2.) || \
|
||||||
void planets_minimap(double res, double w, double h) {
|
(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 i;
|
||||||
int cx, cy, x, y, r;
|
int cx, cy, x, y, r, rc;
|
||||||
double p;
|
double p;
|
||||||
|
|
||||||
|
if(shape == RADAR_CIRCLE) rc = (int)(w*w);
|
||||||
|
|
||||||
glBegin(GL_POINTS);
|
glBegin(GL_POINTS);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
for(i = 0; i < cur_system->nplanets; i++) {
|
for(i = 0; i < cur_system->nplanets; i++) {
|
||||||
|
18
src/weapon.c
18
src/weapon.c
@ -9,6 +9,7 @@
|
|||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
#include "pilot.h"
|
#include "pilot.h"
|
||||||
#include "collision.h"
|
#include "collision.h"
|
||||||
|
#include "player.h"
|
||||||
#include "weapon.h"
|
#include "weapon.h"
|
||||||
|
|
||||||
// Some stuff from pilot.
|
// Some stuff from pilot.
|
||||||
@ -49,24 +50,27 @@ static void weapon_destroy(Weapon* w, WeaponLayer layer);
|
|||||||
static void weapon_free(Weapon* w);
|
static void weapon_free(Weapon* w);
|
||||||
|
|
||||||
// Draw the minimap weapons (player.c).
|
// Draw the minimap weapons (player.c).
|
||||||
void weapon_minimap(double res, double w, double h) {
|
#define PIXEL(x,y) if((shape == RADAR_RECT && ABS(x) < w/2. && ABS(y)<h/2.) || \
|
||||||
int i;
|
(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;
|
double x, y;
|
||||||
|
|
||||||
|
if(shape == RADAR_CIRCLE) rc = (int)(w*w);
|
||||||
|
|
||||||
for(i = 0; i < nwbackLayer; i++) {
|
for(i = 0; i < nwbackLayer; i++) {
|
||||||
x = (wbackLayer[i]->solid->pos.x - player->solid->pos.x) / res;
|
x = (wbackLayer[i]->solid->pos.x - player->solid->pos.x) / res;
|
||||||
y = (wbackLayer[i]->solid->pos.y - player->solid->pos.y) / res;
|
y = (wbackLayer[i]->solid->pos.y - player->solid->pos.y) / res;
|
||||||
if(ABS(x) < w/2. && ABS(y) < h/2.)
|
PIXEL(x,y);
|
||||||
glVertex2d(x,y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < nwfrontLayer; i++) {
|
for(i = 0; i < nwfrontLayer; i++) {
|
||||||
x = (wfrontLayer[i]->solid->pos.x - player->solid->pos.x) / res;
|
x = (wfrontLayer[i]->solid->pos.x - player->solid->pos.x) / res;
|
||||||
y = (wfrontLayer[i]->solid->pos.y - player->solid->pos.y) / res;
|
y = (wfrontLayer[i]->solid->pos.y - player->solid->pos.y) / res;
|
||||||
if(ABS(x) < w/2. && ABS(y) < h/2.)
|
PIXEL(x,y);
|
||||||
glVertex2d(x,y);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#undef PIXEL
|
||||||
|
|
||||||
// Update all weapons in the layer.
|
// Update all weapons in the layer.
|
||||||
void weapons_update(const double dt, WeaponLayer layer) {
|
void weapons_update(const double dt, WeaponLayer layer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user