[Add] More list support. More shipyard features. Allow for NULL text in widget.

This commit is contained in:
Allanis 2013-03-06 21:52:33 +00:00
parent 8b76e4613c
commit c5280cb4b3
4 changed files with 57 additions and 4 deletions

View File

@ -1,3 +1,4 @@
#include "log.h"
#include "toolkit.h" #include "toolkit.h"
#include "player.h" #include "player.h"
#include "rng.h" #include "rng.h"
@ -41,14 +42,20 @@ static int land_wid = 0; // Primary land window.
static int secondary_wid = 0; // For the second opened land window (We can only have 2 max). static int secondary_wid = 0; // For the second opened land window (We can only have 2 max).
static Planet* planet = NULL; static Planet* planet = NULL;
// Commodity excahnge.
static void commodity_exchange(void); static void commodity_exchange(void);
static void commodity_exchange_close(char* str); static void commodity_exchange_close(char* str);
// Outfits.
static void outfits(void); static void outfits(void);
static void outfits_close(char* str); static void outfits_close(char* str);
// Shipyard.
static void shipyard(void); static void shipyard(void);
static void shipyard_close(char* str); static void shipyard_close(char* str);
static void shipyard_update(char* str);
// Spaceport bar.
static void spaceport_bar(void); static void spaceport_bar(void);
static void spaceport_bar_close(char* str); static void spaceport_bar_close(char* str);
// News.
static void news(void); static void news(void);
static void news_close(char* str); static void news_close(char* str);
@ -93,6 +100,9 @@ static void outfits_close(char* str) {
} }
static void shipyard(void) { static void shipyard(void) {
char** ships;
int nships;
secondary_wid = window_create("Shipyard", secondary_wid = window_create("Shipyard",
SHIPYARD_XPOS, SHIPYARD_YPOS, SHIPYARD_XPOS, SHIPYARD_YPOS,
SHIPYARD_WIDTH, SHIPYARD_HEIGHT); SHIPYARD_WIDTH, SHIPYARD_HEIGHT);
@ -100,6 +110,20 @@ static void shipyard(void) {
window_addButton(secondary_wid, -20, 20, window_addButton(secondary_wid, -20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseShipyard", BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseShipyard",
"Close", shipyard_close); "Close", shipyard_close);
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyShip",
"Buy", NULL);
window_addText(secondary_wid, 20+200+20, -160,
SHIPYARD_WIDTH-260, 200, 0, "txtDescription",
&gl_defFont, &cConsole, NULL);
// Setup the ships to buy/sell.
ships = ship_getAll(&nships);
window_addList(secondary_wid, 20, 40,
200, SHIPYARD_HEIGHT-120, "lstShipyard",
ships, nships, 0, shipyard_update);
} }
static void shipyard_close(char* str) { static void shipyard_close(char* str) {
@ -107,6 +131,13 @@ static void shipyard_close(char* str) {
window_destroy(secondary_wid); window_destroy(secondary_wid);
} }
static void shipyard_update(char* str) {
(void)str;
char* tship;
tship = toolkit_getList(secondary_wid, "lstShipyard");
}
// Spaceport bar. // Spaceport bar.
static void spaceport_bar(void) { static void spaceport_bar(void) {
secondary_wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT); secondary_wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT);

View File

@ -46,6 +46,16 @@ static char* ship_classes[] = {
"NULL", "Civialian Light", "Civilian Medium", "Civilian Heavy" "NULL", "Civialian Light", "Civilian Medium", "Civilian Heavy"
}; };
// Return all the ships in text form.
char** ship_getAll(int* n) {
char** shipnames = malloc(sizeof(Ship*) * ships);
for((*n)=0; (*n) < ships; (*n)++)
shipnames[*n] = strdup(ship_stack[*n].name);
return shipnames;
}
static char* ship_class(Ship* s) { static char* ship_class(Ship* s) {
return ship_classes[s->class]; return ship_classes[s->class];
} }

View File

@ -59,6 +59,7 @@ typedef struct Ship_ {
// Get. // Get.
Ship* ship_get(const char* name); Ship* ship_get(const char* name);
char** ship_getAll(int* n);
// Load/quit. // Load/quit.
int ships_load(void); int ships_load(void);

View File

@ -153,7 +153,8 @@ void window_addText(const unsigned int wid, const int x, const int y,
else wgt->y = (double) y; else wgt->y = (double) y;
wgt->dat.txt.colour = colour; wgt->dat.txt.colour = colour;
wgt->dat.txt.centered = centered; wgt->dat.txt.centered = centered;
wgt->dat.txt.text = strdup(string); if(string) wgt->dat.txt.text = strdup(string);
else wgt->dat.txt.text = NULL;
} }
// Add a graphic to the window. // Add a graphic to the window.
@ -315,15 +316,23 @@ unsigned int window_create(char* name, const int x, const int y, const int w, co
// Destroy a widget. // Destroy a widget.
static void widget_cleanup(Widget* widget) { static void widget_cleanup(Widget* widget) {
int i;
if(widget->name) free(widget->name); if(widget->name) free(widget->name);
switch(widget->type) { switch(widget->type) {
case WIDGET_BUTTON: case WIDGET_BUTTON: // Must clear the button display text.
if(widget->dat.btn.display) free(widget->dat.btn.display); if(widget->dat.btn.display) free(widget->dat.btn.display);
break; break;
case WIDGET_TEXT: case WIDGET_TEXT: // Must clear the text.
if(widget->dat.txt.text) free(widget->dat.txt.text); if(widget->dat.txt.text) free(widget->dat.txt.text);
break; break;
case WIDGET_LIST: // Must clear the list.
if(widget->dat.lst.options) {
for(i = 0; i < widget->dat.lst.noptions; i++)
free(widget->dat.lst.options[i]);
free(widget->dat.lst.options);
}
break;
default: default:
break; break;
} }
@ -647,6 +656,8 @@ static void toolkit_renderButton(Widget* btn, double bx, double by) {
} }
static void toolkit_renderText(Widget* txt, double bx, double by) { static void toolkit_renderText(Widget* txt, double bx, double by) {
if(txt->dat.txt.text == NULL) return;
if(txt->dat.txt.centered) if(txt->dat.txt.centered)
gl_printMid(txt->dat.txt.font, txt->w, gl_printMid(txt->dat.txt.font, txt->w,
bx + (double)gl_screen.w/2. + txt->x, bx + (double)gl_screen.w/2. + txt->x,