diff --git a/src/player.c b/src/player.c index 8ccf3c6..a526f5e 100644 --- a/src/player.c +++ b/src/player.c @@ -10,6 +10,7 @@ #include "space.h" #include "rng.h" #include "land.h" +#include "toolkit.h" #include "player.h" #define XML_GUI_ID "GUIs" // XML section identifier. @@ -24,6 +25,9 @@ #define pow2(x) ((x)*(x)) +#define BOARDING_WIDTH 300 +#define BOARDING_HEIGHT 200 + // Player stuff. Pilot* player = NULL; // extern in pilot.h 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 void gui_renderPilot(const Pilot* p); static void gui_renderBar(const glColour* c, const Rect* r, const double w); +static void player_unboard(char* str); // Create a new player. void player_new(void) { @@ -777,6 +782,7 @@ void player_setRadarRel(int mod) { void player_board(void) { Pilot* p; + unsigned int wid; if(player_target == PLAYER_ID) { 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"); return; } - // TODO: - player_message("It's a shame Allanis hasn't added boarding yet, right?!"); + player_message("Boarding ship %s", p->name); + + // 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. diff --git a/src/space.c b/src/space.c index 53ed8b1..58ce2c6 100644 --- a/src/space.c +++ b/src/space.c @@ -10,6 +10,7 @@ #include "xml.h" #include "pause.h" #include "weapon.h" +#include "toolkit.h" #include "player.h" #define XML_PLANET_ID "Planets" @@ -472,7 +473,7 @@ void space_render(double dt) { int i; glBegin(GL_POINTS); for(i = 0; i < nstars; i++) { - if(!paused) { + if(!paused && !toolkit) { // Update the position. 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; diff --git a/src/toolkit.c b/src/toolkit.c index 58ee140..dc88def 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -67,7 +67,7 @@ static int mwindows = 0; static Widget* window_newWidget(Window* w); static void widget_cleanup(Widget* widget); -static Window* window_get(const unsigned int wid); +static Window* window_wget(const unsigned int wid); // Render. static void window_render(Window* w); 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, 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); 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, glFont* font, glColour* colour, char* string) { - Window* wdw = window_get(wid); + Window* wdw = window_wget(wid); Widget* wgt = window_newWidget(wdw); 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, char* name, glTexture* image) { - Window* wdw = window_get(wid); + Window* wdw = window_wget(wid); Widget* wgt = window_newWidget(wdw); wgt->type = WIDGET_IMAGE; @@ -154,14 +154,25 @@ static Widget* window_newWidget(Window* w) { } // Return the window of id wid. -static Window* window_get(const unsigned int wid) { +static Window* window_wget(const unsigned int wid) { int i; for(i = 0; i < nwindows; i++) if(windows[i].id == wid) return &windows[i]; + DEBUG("Window '%d' not found in windows stack", wid); 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. unsigned int window_create(char* name, const int x, const int y, const int w, const int h) { if(nwindows >= mwindows) { @@ -217,7 +228,7 @@ static void widget_cleanup(Widget* widget) { } // Destroy a window. -void window_destroy(unsigned int wid) { +void window_destroy(const unsigned int wid) { int i, j; // Destroy the window. @@ -243,7 +254,7 @@ void window_destroy(unsigned int wid) { } void window_destroyWidget(unsigned int wid, const char* wgtname) { - Window* w = window_get(wid); + Window* w = window_wget(wid); int i; for(i = 0; i < w->nwidgets; i++) diff --git a/src/toolkit.h b/src/toolkit.h index eea5dfd..b4976b8 100644 --- a/src/toolkit.h +++ b/src/toolkit.h @@ -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, char* name, glTexture* image); +// Get the window by name. +unsigned int window_get(const char* wdwname); + // Destroy window. void window_destroy(const unsigned int wid); void window_destroyWidget(unsigned wid, const char* wgtname);