[Add] Use image array for shipyard and made toolkit_getList apply to image array.
This commit is contained in:
parent
ea6df25b0c
commit
ca292cf791
58
src/land.c
58
src/land.c
@ -34,7 +34,7 @@
|
||||
#define OUTFITS_HEIGHT 600
|
||||
|
||||
/* Shipyard. */
|
||||
#define SHIPYARD_WIDTH 700
|
||||
#define SHIPYARD_WIDTH 800
|
||||
#define SHIPYARD_HEIGHT 600
|
||||
|
||||
/* News window. */
|
||||
@ -342,8 +342,7 @@ static void outfits_update(char* str) {
|
||||
Outfit* outfit;
|
||||
char buf[128], buf2[16], buf3[16];
|
||||
|
||||
outfitname = toolkit_getImageArray(secondary_wid, "iarOutfits");
|
||||
|
||||
outfitname = toolkit_getList(secondary_wid, "iarOutfits");
|
||||
if(strcmp(outfitname, "None")==0) { /* No outfits. */
|
||||
window_modifyImage(secondary_wid, "imgOutfit", NULL);
|
||||
window_disableButton(secondary_wid, "btnBuyOutfit");
|
||||
@ -454,7 +453,7 @@ static void outfits_buy(char* str) {
|
||||
Outfit* outfit;
|
||||
int q;
|
||||
|
||||
outfitname = toolkit_getImageArray(secondary_wid, "iarOutfits");
|
||||
outfitname = toolkit_getList(secondary_wid, "iarOutfits");
|
||||
outfit = outfit_get(outfitname);
|
||||
|
||||
q = outfits_getMod();
|
||||
@ -495,7 +494,7 @@ static void outfits_sell(char* str) {
|
||||
Outfit* outfit;
|
||||
int q;
|
||||
|
||||
outfitname = toolkit_getImageArray(secondary_wid, "iarOutfits");
|
||||
outfitname = toolkit_getList(secondary_wid, "iarOutfits");
|
||||
outfit = outfit_get(outfitname);
|
||||
|
||||
q = outfits_getMod();
|
||||
@ -536,14 +535,18 @@ static void outfits_renderMod(double bx, double by, double w, double h) {
|
||||
}
|
||||
|
||||
static void shipyard_open(void) {
|
||||
char** ships;
|
||||
int i;
|
||||
Ship** ships;
|
||||
char** sships;
|
||||
glTexture** tships;
|
||||
int nships;
|
||||
char buf[128];
|
||||
|
||||
/* Window creation. */
|
||||
snprintf(buf, 128, "%s - Shipyard", land_planet->name);
|
||||
secondary_wid = window_create(buf,
|
||||
-1, -1, SHIPYARD_WIDTH, SHIPYARD_HEIGHT);
|
||||
|
||||
/* Buttons. */
|
||||
window_addButton(secondary_wid, -20, 20,
|
||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseShipyard",
|
||||
"Close", shipyard_close);
|
||||
@ -560,13 +563,15 @@ static void shipyard_open(void) {
|
||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnInfoShip",
|
||||
"Info", shipyard_info);
|
||||
|
||||
/* Target gfx. */
|
||||
window_addRect(secondary_wid, -40, -50,
|
||||
128, 96, "rctTarget", &cBlack, 0);
|
||||
|
||||
window_addImage(secondary_wid, -40-128, -50-96,
|
||||
"imgTarget", NULL, 1);
|
||||
|
||||
window_addText(secondary_wid, 40+200+40, -55,
|
||||
/* Text. */
|
||||
window_addText(secondary_wid, 40+300+40, -55,
|
||||
80, 96, 0, "txtSDesc", &gl_smallFont, &cDConsole,
|
||||
"Name:\n"
|
||||
"Class:\n"
|
||||
@ -575,11 +580,11 @@ static void shipyard_open(void) {
|
||||
"Price:\n"
|
||||
"Money:\n");
|
||||
|
||||
window_addText(secondary_wid, 40+200+40+80, -55,
|
||||
window_addText(secondary_wid, 40+300+40+80, -55,
|
||||
130, 96, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
|
||||
|
||||
|
||||
window_addText(secondary_wid, 20+200+40, -160,
|
||||
window_addText(secondary_wid, 20+300+40, -160,
|
||||
SHIPYARD_WIDTH-300, 200, 0, "txtDescription",
|
||||
&gl_smallFont, NULL, NULL);
|
||||
|
||||
@ -587,14 +592,23 @@ static void shipyard_open(void) {
|
||||
ships = ship_getTech(&nships, land_planet->tech, PLANET_TECH_MAX);
|
||||
|
||||
if(nships <= 0) {
|
||||
ships = malloc(sizeof(char*));
|
||||
ships[0] = strdup("None");
|
||||
sships = malloc(sizeof(char*));
|
||||
sships[0] = strdup("None");
|
||||
tships = malloc(sizeof(glTexture*));
|
||||
tships[0] = NULL;
|
||||
nships = 1;
|
||||
} else {
|
||||
sships = malloc(sizeof(char*)*nships);
|
||||
tships = malloc(sizeof(glTexture*)*nships);
|
||||
for(i = 0; i < nships; i++) {
|
||||
sships[i] = strdup(ships[i]->name);
|
||||
tships[i] = ships[i]->gfx_target;
|
||||
}
|
||||
|
||||
window_addList(secondary_wid, 20, 40,
|
||||
200, SHIPYARD_HEIGHT-80, "lstShipyard",
|
||||
ships, nships, 0, shipyard_update);
|
||||
free(ships);
|
||||
}
|
||||
window_addImageArray(secondary_wid, 20, 40,
|
||||
310, SHIPYARD_HEIGHT-80, "iarShipyard", 64./96.*128., 64.,
|
||||
tships, sships, nships, shipyard_update);
|
||||
|
||||
/* Write the shipyard stuff. */
|
||||
shipyard_update(NULL);
|
||||
@ -617,7 +631,7 @@ static void shipyard_update(char* str) {
|
||||
Ship* ship;
|
||||
char buf[80], buf2[16], buf3[16];
|
||||
|
||||
shipname = toolkit_getList(secondary_wid, "lstShipyard");
|
||||
shipname = toolkit_getList(secondary_wid, "iarShipyard");
|
||||
|
||||
/* No ships. */
|
||||
if(strcmp(shipname, "None")==0) {
|
||||
@ -670,7 +684,7 @@ static void shipyard_info(char* str) {
|
||||
(void)str;
|
||||
char* shipname;
|
||||
|
||||
shipname = toolkit_getList(secondary_wid, "lstShipyard");
|
||||
shipname = toolkit_getList(secondary_wid, "iarShipyard");
|
||||
ship_view(shipname);
|
||||
}
|
||||
|
||||
@ -679,7 +693,7 @@ static void shipyard_buy(char* str) {
|
||||
char* shipname, buf[16];
|
||||
Ship* ship;
|
||||
|
||||
shipname = toolkit_getList(secondary_wid, "lstShipyard");
|
||||
shipname = toolkit_getList(secondary_wid, "iarShipyard");
|
||||
ship = ship_get(shipname);
|
||||
|
||||
if(pilot_cargoUsed(player) > ship->cap_cargo) {
|
||||
@ -737,7 +751,7 @@ static void shipyard_yours_open(char* str) {
|
||||
"imgTarget", NULL, 1);
|
||||
|
||||
/* Text. */
|
||||
window_addText(terciary_wid, 40+200+40, -55,
|
||||
window_addText(terciary_wid, 40+300+40, -55,
|
||||
100, 96, 0, "txtSDesc", &gl_smallFont, &cDConsole,
|
||||
"Name:\n"
|
||||
"Ship:\n"
|
||||
@ -750,14 +764,14 @@ static void shipyard_yours_open(char* str) {
|
||||
"Transportation\n"
|
||||
"Sell price\n");
|
||||
|
||||
window_addText(terciary_wid, 40+200+40+100, -55,
|
||||
window_addText(terciary_wid, 40+300+40+100, -55,
|
||||
130, 96, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
|
||||
|
||||
window_addText(terciary_wid, 40+200+40, -215,
|
||||
100, 20, 0, "txtSOutfits", &gl_smallFont, &cDConsole,
|
||||
"Outfits:\n");
|
||||
|
||||
window_addText(terciary_wid, 40+200+40, -215-gl_smallFont.h-5,
|
||||
window_addText(terciary_wid, 40+300+40, -215-gl_smallFont.h-5,
|
||||
SHIPYARD_WIDTH-40-200-40-20, 200, 0, "txtDOutfits",
|
||||
&gl_smallFont, &cBlack, NULL);
|
||||
|
||||
|
12
src/ship.c
12
src/ship.c
@ -43,9 +43,9 @@ Ship* ship_get(const char* name) {
|
||||
}
|
||||
|
||||
/* Return all the ships in text form. */
|
||||
char** ship_getTech(int* n, const int* tech, const int techmax) {
|
||||
Ship** ship_getTech(int* n, const int* tech, const int techmax) {
|
||||
int i, j, k, num, price;
|
||||
char** shipnames;
|
||||
Ship** result;
|
||||
Ship** ships;
|
||||
|
||||
/* Get availabble ships for tech. */
|
||||
@ -67,7 +67,7 @@ char** ship_getTech(int* n, const int* tech, const int techmax) {
|
||||
/* Now sort by price. */
|
||||
*n = 0;
|
||||
price = -1;
|
||||
shipnames = malloc(sizeof(char*) * num);
|
||||
result = malloc(sizeof(Ship*) * num);
|
||||
/* Until we fill the new stack. */
|
||||
for(i = 0; i < num; i++) {
|
||||
/* Check for cheapest. */
|
||||
@ -76,7 +76,7 @@ char** ship_getTech(int* n, const int* tech, const int techmax) {
|
||||
if((price == -1) || (ships[price]->price > ships[j]->price)) {
|
||||
/* Check if already in stack. */
|
||||
for(k = 0; k < (*n); k++)
|
||||
if(strcmp(shipnames[k], ships[j]->name)==0)
|
||||
if(strcmp(result[k]->name, ships[j]->name)==0)
|
||||
break;
|
||||
|
||||
/* Not in stack and therefore is cheapest. */
|
||||
@ -85,7 +85,7 @@ char** ship_getTech(int* n, const int* tech, const int techmax) {
|
||||
}
|
||||
}
|
||||
/* Add the current cheapest to stack. */
|
||||
shipnames[i] = strdup(ships[price]->name);
|
||||
result[i] = ships[price];
|
||||
(*n)++;
|
||||
price = -1;
|
||||
}
|
||||
@ -93,7 +93,7 @@ char** ship_getTech(int* n, const int* tech, const int techmax) {
|
||||
/* Cleanup */
|
||||
free(ships);
|
||||
|
||||
return shipnames;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Get the ship's classname. */
|
||||
|
@ -78,7 +78,7 @@ typedef struct Ship_ {
|
||||
|
||||
/* Get. */
|
||||
Ship* ship_get(const char* name);
|
||||
char** ship_getTech(int* n, const int* tech, const int techmax);
|
||||
Ship** ship_getTech(int* n, const int* tech, const int techmax);
|
||||
char* ship_class(Ship* p);
|
||||
int ship_basePrice(Ship* s);
|
||||
|
||||
|
@ -1682,7 +1682,13 @@ static void toolkit_listScroll(Widget* wgt, int direction) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Get what is selected currently in a list. */
|
||||
/**
|
||||
* @fn char* toolkit_getList(const unsigned int wid, char* name)
|
||||
*
|
||||
* @brief Get what is selected currently in a list.
|
||||
*
|
||||
* List included Image Array.
|
||||
*/
|
||||
char* toolkit_getList(const unsigned int wid, char* name) {
|
||||
Widget* wgt = window_getwgt(wid, name);
|
||||
|
||||
@ -1691,10 +1697,20 @@ char* toolkit_getList(const unsigned int wid, char* name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if((wgt->type != WIDGET_LIST) || (wgt->dat.lst.selected == -1))
|
||||
switch(wgt->type) {
|
||||
case WIDGET_LIST:
|
||||
if(wgt->dat.lst.selected == -1)
|
||||
return NULL;
|
||||
|
||||
return wgt->dat.lst.options[wgt->dat.lst.selected];
|
||||
|
||||
case WIDGET_IMAGEARRAY:
|
||||
if(wgt->dat.iar.selected == -1)
|
||||
return NULL;
|
||||
return wgt->dat.iar.captions[wgt->dat.iar.selected];
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the position of current item in the list. */
|
||||
@ -1712,28 +1728,6 @@ int toolkit_getListPos(const unsigned int wid, char* name) {
|
||||
return wgt->dat.lst.selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn char* toolkit_getImageArray(const unsigned int wid, char* name)
|
||||
*
|
||||
* @brief Get what is currently selected in an image array.
|
||||
* @param wid Window to get array data from.
|
||||
* @param name Name of the image array widget.
|
||||
* @return Caption of the currently selected element.
|
||||
*/
|
||||
char* toolkit_getImageArray(const unsigned int wid, char* name) {
|
||||
Widget* wgt = window_getwgt(wid, name);
|
||||
|
||||
if(wgt == NULL) {
|
||||
WARN("Widget '%s' not found", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if((wgt->type != WIDGET_IMAGEARRAY) || (wgt->dat.iar.selected == -1))
|
||||
return NULL;
|
||||
|
||||
return wgt->dat.iar.captions[wgt->dat.iar.selected];
|
||||
}
|
||||
|
||||
/* List mouse even focus. */
|
||||
static void toolkit_listFocus(Widget* lst, double bx, double by) {
|
||||
(void)bx;
|
||||
|
@ -74,7 +74,6 @@ void window_moveWidget(const unsigned int wid,
|
||||
/* Specific. */
|
||||
char* toolkit_getList(const unsigned int wid, char* name);
|
||||
int toolkit_getListPos(const unsigned int wid, char* name);
|
||||
char* toolkit_getImageArray(const unsigned int wid, char* name);
|
||||
glTexture* window_getImage(const unsigned int wid, char* name);
|
||||
|
||||
/* Destroy window. */
|
||||
|
Loading…
Reference in New Issue
Block a user