[Add] Small boarding menu, along with a function to get windows based on name rather than id.
This commit is contained in:
parent
7889035b29
commit
a99544804e
19
src/player.c
19
src/player.c
@ -10,6 +10,7 @@
|
|||||||
#include "space.h"
|
#include "space.h"
|
||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
#include "land.h"
|
#include "land.h"
|
||||||
|
#include "toolkit.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
#define XML_GUI_ID "GUIs" // XML section identifier.
|
#define XML_GUI_ID "GUIs" // XML section identifier.
|
||||||
@ -24,6 +25,9 @@
|
|||||||
|
|
||||||
#define pow2(x) ((x)*(x))
|
#define pow2(x) ((x)*(x))
|
||||||
|
|
||||||
|
#define BOARDING_WIDTH 300
|
||||||
|
#define BOARDING_HEIGHT 200
|
||||||
|
|
||||||
// Player stuff.
|
// Player stuff.
|
||||||
Pilot* player = NULL; // extern in pilot.h
|
Pilot* player = NULL; // extern in pilot.h
|
||||||
unsigned int credits = 0;
|
unsigned int credits = 0;
|
||||||
@ -98,6 +102,7 @@ static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w,
|
|||||||
static int gui_parse(const xmlNodePtr parent, const char* name);
|
static int gui_parse(const xmlNodePtr parent, const char* name);
|
||||||
static void gui_renderPilot(const Pilot* p);
|
static void gui_renderPilot(const Pilot* p);
|
||||||
static void gui_renderBar(const glColour* c, const Rect* r, const double w);
|
static void gui_renderBar(const glColour* c, const Rect* r, const double w);
|
||||||
|
static void player_unboard(char* str);
|
||||||
|
|
||||||
// Create a new player.
|
// Create a new player.
|
||||||
void player_new(void) {
|
void player_new(void) {
|
||||||
@ -777,6 +782,7 @@ void player_setRadarRel(int mod) {
|
|||||||
|
|
||||||
void player_board(void) {
|
void player_board(void) {
|
||||||
Pilot* p;
|
Pilot* p;
|
||||||
|
unsigned int wid;
|
||||||
|
|
||||||
if(player_target == PLAYER_ID) {
|
if(player_target == PLAYER_ID) {
|
||||||
player_message("You need a target to board first!");
|
player_message("You need a target to board first!");
|
||||||
@ -798,8 +804,17 @@ void player_board(void) {
|
|||||||
player_message("You are going too fact to board the ship");
|
player_message("You are going too fact to board the ship");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO:
|
player_message("Boarding ship %s", p->name);
|
||||||
player_message("It's a shame Allanis hasn't added boarding yet, right?!");
|
|
||||||
|
// Create boarding window.
|
||||||
|
wid = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT);
|
||||||
|
|
||||||
|
window_addButton(wid, -20, 20, 50, 30, "btnBoardingClose", "Close", player_unboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void player_unboard(char* str) {
|
||||||
|
if(strcmp(str, "btnBoardingClose")==0)
|
||||||
|
window_destroy(window_get("Boarding"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the next secondary weapon.
|
// Get the next secondary weapon.
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
#include "pause.h"
|
#include "pause.h"
|
||||||
#include "weapon.h"
|
#include "weapon.h"
|
||||||
|
#include "toolkit.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
#define XML_PLANET_ID "Planets"
|
#define XML_PLANET_ID "Planets"
|
||||||
@ -472,7 +473,7 @@ void space_render(double dt) {
|
|||||||
int i;
|
int i;
|
||||||
glBegin(GL_POINTS);
|
glBegin(GL_POINTS);
|
||||||
for(i = 0; i < nstars; i++) {
|
for(i = 0; i < nstars; i++) {
|
||||||
if(!paused) {
|
if(!paused && !toolkit) {
|
||||||
// Update the position.
|
// Update the position.
|
||||||
stars[i].x -= VX(player->solid->vel)/(15.-10.*stars[i].brightness)*dt;
|
stars[i].x -= VX(player->solid->vel)/(15.-10.*stars[i].brightness)*dt;
|
||||||
stars[i].y -= VY(player->solid->vel)/(15.-10.*stars[i].brightness)*dt;
|
stars[i].y -= VY(player->solid->vel)/(15.-10.*stars[i].brightness)*dt;
|
||||||
|
@ -67,7 +67,7 @@ static int mwindows = 0;
|
|||||||
|
|
||||||
static Widget* window_newWidget(Window* w);
|
static Widget* window_newWidget(Window* w);
|
||||||
static void widget_cleanup(Widget* widget);
|
static void widget_cleanup(Widget* widget);
|
||||||
static Window* window_get(const unsigned int wid);
|
static Window* window_wget(const unsigned int wid);
|
||||||
// Render.
|
// Render.
|
||||||
static void window_render(Window* w);
|
static void window_render(Window* w);
|
||||||
static void toolkit_renderButton(Widget* btn, double bx, double by);
|
static void toolkit_renderButton(Widget* btn, double bx, double by);
|
||||||
@ -79,7 +79,7 @@ static void toolkit_renderImage(Widget* img, double bx, double by);
|
|||||||
void window_addButton(const unsigned int wid, const int x, const int y, const int w,
|
void window_addButton(const unsigned int wid, const int x, const int y, const int w,
|
||||||
const int h, char* name, char* display, void (*call)(char*)) {
|
const int h, char* name, char* display, void (*call)(char*)) {
|
||||||
|
|
||||||
Window* wdw = window_get(wid);
|
Window* wdw = window_wget(wid);
|
||||||
Widget* wgt = window_newWidget(wdw);
|
Widget* wgt = window_newWidget(wdw);
|
||||||
|
|
||||||
wgt->type = WIDGET_BUTTON;
|
wgt->type = WIDGET_BUTTON;
|
||||||
@ -101,7 +101,7 @@ void window_addText(const unsigned int wid, const int x, const int y,
|
|||||||
const int w, const int h, const int centered, char* name,
|
const int w, const int h, const int centered, char* name,
|
||||||
glFont* font, glColour* colour, char* string) {
|
glFont* font, glColour* colour, char* string) {
|
||||||
|
|
||||||
Window* wdw = window_get(wid);
|
Window* wdw = window_wget(wid);
|
||||||
Widget* wgt = window_newWidget(wdw);
|
Widget* wgt = window_newWidget(wdw);
|
||||||
|
|
||||||
wgt->type = WIDGET_TEXT;
|
wgt->type = WIDGET_TEXT;
|
||||||
@ -125,7 +125,7 @@ void window_addText(const unsigned int wid, const int x, const int y,
|
|||||||
void window_addImage(const unsigned int wid, const int x, const int y,
|
void window_addImage(const unsigned int wid, const int x, const int y,
|
||||||
char* name, glTexture* image) {
|
char* name, glTexture* image) {
|
||||||
|
|
||||||
Window* wdw = window_get(wid);
|
Window* wdw = window_wget(wid);
|
||||||
Widget* wgt = window_newWidget(wdw);
|
Widget* wgt = window_newWidget(wdw);
|
||||||
|
|
||||||
wgt->type = WIDGET_IMAGE;
|
wgt->type = WIDGET_IMAGE;
|
||||||
@ -154,14 +154,25 @@ static Widget* window_newWidget(Window* w) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the window of id wid.
|
// Return the window of id wid.
|
||||||
static Window* window_get(const unsigned int wid) {
|
static Window* window_wget(const unsigned int wid) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < nwindows; i++)
|
for(i = 0; i < nwindows; i++)
|
||||||
if(windows[i].id == wid)
|
if(windows[i].id == wid)
|
||||||
return &windows[i];
|
return &windows[i];
|
||||||
|
DEBUG("Window '%d' not found in windows stack", wid);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the id of a window.
|
||||||
|
unsigned int window_get(const char* wdwname) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < nwindows; i++)
|
||||||
|
if(strcmp(windows[i].name, wdwname)==0)
|
||||||
|
return windows[i].id;
|
||||||
|
DEBUG("Window '%s' not found in windows stack", wdwname);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a window.
|
// Create a window.
|
||||||
unsigned int window_create(char* name, const int x, const int y, const int w, const int h) {
|
unsigned int window_create(char* name, const int x, const int y, const int w, const int h) {
|
||||||
if(nwindows >= mwindows) {
|
if(nwindows >= mwindows) {
|
||||||
@ -217,7 +228,7 @@ static void widget_cleanup(Widget* widget) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Destroy a window.
|
// Destroy a window.
|
||||||
void window_destroy(unsigned int wid) {
|
void window_destroy(const unsigned int wid) {
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
// Destroy the window.
|
// Destroy the window.
|
||||||
@ -243,7 +254,7 @@ void window_destroy(unsigned int wid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void window_destroyWidget(unsigned int wid, const char* wgtname) {
|
void window_destroyWidget(unsigned int wid, const char* wgtname) {
|
||||||
Window* w = window_get(wid);
|
Window* w = window_wget(wid);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < w->nwidgets; i++)
|
for(i = 0; i < w->nwidgets; i++)
|
||||||
|
@ -19,6 +19,9 @@ void window_addText(const unsigned int wid, const int x, const int y,
|
|||||||
void window_addImage(const unsigned int wid, const int x, const int y,
|
void window_addImage(const unsigned int wid, const int x, const int y,
|
||||||
char* name, glTexture* image);
|
char* name, glTexture* image);
|
||||||
|
|
||||||
|
// Get the window by name.
|
||||||
|
unsigned int window_get(const char* wdwname);
|
||||||
|
|
||||||
// Destroy window.
|
// Destroy window.
|
||||||
void window_destroy(const unsigned int wid);
|
void window_destroy(const unsigned int wid);
|
||||||
void window_destroyWidget(unsigned wid, const char* wgtname);
|
void window_destroyWidget(unsigned wid, const char* wgtname);
|
||||||
|
Loading…
Reference in New Issue
Block a user