[Change] Fetched part of land.c stuff inline with new toolkit changes.

This commit is contained in:
Allanis 2014-01-15 01:11:10 +00:00
parent 4503785b1a
commit 597091c929

View File

@ -61,6 +61,7 @@ static unsigned int land_visited = 0;
/* Land variables. */ /* Land variables. */
int landed = 0; int landed = 0;
static unsigned int land_wid = 0; /**< Land window ID. */
Planet* land_planet = NULL; Planet* land_planet = NULL;
static glTexture* gfx_exterior = NULL; static glTexture* gfx_exterior = NULL;
@ -71,101 +72,90 @@ static int mission_ncomputer = 0;
/* Player stuff. */ /* Player stuff. */
extern int hyperspace_target; extern int hyperspace_target;
/* Window stuff. */
static int land_wid = 0; /* Primary land window. */
/* For the second opened land window */
static int secondary_wid = 0;
static int terciary_wid = 0; /* For fancy things like news, your ship etc.. */
/* Commodity excahnge. */ /* Commodity excahnge. */
static void commodity_exchange_open(void); static void commodity_exchange_open(void);
static void commodity_exchange_close(char* str); static void commodity_update(unsigned int wid, char* str);
static void commodity_update(char* str); static void commodity_buy(unsigned int wid, char* str);
static void commodity_buy(char* str); static void commodity_sell(unsigned int wid, char* str);
static void commodity_sell(char* str);
/* Outfits. */ /* Outfits. */
static void outfits_open(void); static void outfits_open(void);
static void outfits_close(char* str); static void outfits_update(unsigned int wid, char* str);
static void outfits_update(char* str);
static int outfit_canBuy(Outfit* outfit, int q, int errmsg); static int outfit_canBuy(Outfit* outfit, int q, int errmsg);
static void outfits_buy(char* str); static void outfits_buy(unsigned int wid, char* str);
static int outfit_canSell(Outfit* outfit, int q, int errmsg); static int outfit_canSell(Outfit* outfit, int q, int errmsg);
static void outfits_sell(char* str); static void outfits_sell(unsigned int wid, char* str);
static int outfits_getMod(void); static int outfits_getMod(void);
static void outfits_renderMod(double bx, double by, double w, double h); static void outfits_renderMod(double bx, double by, double w, double h);
/* Shipyard. */ /* Shipyard. */
static void shipyard_open(void); static void shipyard_open(void);
static void shipyard_close(char* str); static void shipyard_update(unsigned int wid, char* str);
static void shipyard_update(char* str); static void shipyard_info(unsigned int wid, char* str);
static void shipyard_info(char* str); static void shipyard_buy(unsigned int wid, char* str);
static void shipyard_buy(char* str);
/* Your ship. */ /* Your ship. */
static void shipyard_yours_open(char* str); static void shipyard_yours_open(unsigned int wid, char* str);
static void shipyard_yours_close(char* str); static void shipyard_yoursUpdate(unsigned int wid, char* str);
static void shipyard_yoursUpdate(char* str); static void shipyard_yoursChange(unsigned int wid, char* str);
static void shipyard_yoursChange(char* str); static void shipyard_yoursSell(unsigned int wid, char* str);
static void shipyard_yoursSell(char* str); static void shipyard_yoursTransport(unsigned int wid, char* str);
static void shipyard_yoursTransport(char* str);
static int shipyard_yoursTransportPrice(char* shipname); static int shipyard_yoursTransportPrice(char* shipname);
/* Spaceport bar. */ /* Spaceport bar. */
static void spaceport_bar_open(void); static void spaceport_bar_open(void);
static void spaceport_bar_close(char* str);
/* News. */ /* News. */
static void news_open(void); static void news_open(unsigned int parent, char* str);
static void news_close(char* str);
/* Mission computer. */ /* Mission computer. */
static void misn_open(void); static void misn_open(void);
static void misn_close(char* str); static void misn_accept(unsigned int wid, char* str);
static void misn_accept(char* str); static void misn_genList(unsigned int wid, int first);
static void misn_genList(int first); static void misn_update(unsigned int wid, char* str);
static void misn_update(char* str);
/* Refuel. */ /* Refuel. */
static int refuel_price(void); static int refuel_price(void);
static void spaceport_refuel(char* str); static void spaceport_refuel(unsigned int wid, char* str);
/* The local market. */ /* The local market. */
static void commodity_exchange_open(void) { static void commodity_exchange_open(void) {
int i; int i;
char** goods; char** goods;
secondary_wid = window_create("Commodity Exchange", -1, -1, unsigned int wid;
wid = window_create("Commodity Exchange", -1, -1,
COMMODITY_WIDTH, COMMODITY_HEIGHT); COMMODITY_WIDTH, COMMODITY_HEIGHT);
window_addButton(secondary_wid, -20, 20, window_addButton(wid, -20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose", BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose",
"Close", commodity_exchange_close); "Close", commodity_exchange_close);
window_addButton(secondary_wid, -40-((BUTTON_WIDTH-20)/2), 20*2+BUTTON_HEIGHT, window_addButton(wid, -40-((BUTTON_WIDTH-20)/2), 20*2+BUTTON_HEIGHT,
(BUTTON_WIDTH-20)/2, BUTTON_HEIGHT, "btnCommodityBuy", (BUTTON_WIDTH-20)/2, BUTTON_HEIGHT, "btnCommodityBuy",
"Buy", commodity_buy); "Buy", commodity_buy);
window_addButton(secondary_wid, -20, 20*2+BUTTON_HEIGHT, window_addButton(wid, -20, 20*2+BUTTON_HEIGHT,
(BUTTON_WIDTH-20)/2, BUTTON_HEIGHT, "btnCommoditySell", (BUTTON_WIDTH-20)/2, BUTTON_HEIGHT, "btnCommoditySell",
"Sell", commodity_sell); "Sell", commodity_sell);
window_addText(secondary_wid, -20, -40, BUTTON_WIDTH, 60, 0, window_addText(wid, -20, -40, BUTTON_WIDTH, 60, 0,
"txtSInfo", &gl_smallFont, &cDConsole, "txtSInfo", &gl_smallFont, &cDConsole,
"You have:\n" "You have:\n"
"Market price:\n" "Market price:\n"
"\n" "\n"
"Free Space:\n"); "Free Space:\n");
window_addText(secondary_wid, -20, -40, BUTTON_WIDTH/2, 60, 0, window_addText(wid, -20, -40, BUTTON_WIDTH/2, 60, 0,
"txtDInfo", &gl_smallFont, &cBlack, NULL); "txtDInfo", &gl_smallFont, &cBlack, NULL);
window_addText(secondary_wid, -40, -120, BUTTON_WIDTH-20, window_addText(wid, -40, -120, BUTTON_WIDTH-20,
BUTTON_WIDTH, 0, "txtDesc", &gl_smallFont, &cBlack, NULL); BUTTON_WIDTH, 0, "txtDesc", &gl_smallFont, &cBlack, NULL);
goods = malloc(sizeof(char*)*land_planet->ncommodities); goods = malloc(sizeof(char*)*land_planet->ncommodities);
for(i = 0; i < land_planet->ncommodities; i++) for(i = 0; i < land_planet->ncommodities; i++)
goods[i] = strdup(land_planet->commodities[i]->name); goods[i] = strdup(land_planet->commodities[i]->name);
window_addList(secondary_wid, 20, -40, window_addList(wid, 20, -40,
COMMODITY_WIDTH-BUTTON_WIDTH-60, COMMODITY_WIDTH-BUTTON_WIDTH-60,
COMMODITY_HEIGHT-80-BUTTON_HEIGHT, "lstGoods", COMMODITY_HEIGHT-80-BUTTON_HEIGHT, "lstGoods",
goods, land_planet->ncommodities, 0, commodity_update); goods, land_planet->ncommodities, 0, commodity_update);
/* Update. */ /* Update. */
commodity_update(NULL); commodity_update(wid, NULL);
/* Check commodity exchange missions. */ /* Check commodity exchange missions. */
if(!has_visited(VISITED_COMMODITY)) { if(!has_visited(VISITED_COMMODITY)) {
@ -175,19 +165,13 @@ static void commodity_exchange_open(void) {
} }
} }
static void commodity_exchange_close(char* str) { static void commodity_update(unsigned int wid, char* str) {
if(strcmp(str, "btnCommodityClose")==0)
window_destroy(secondary_wid);
secondary_wid = 0;
}
static void commodity_update(char* str) {
(void)str; (void)str;
char buf[128]; char buf[128];
char* comname; char* comname;
Commodity* com; Commodity* com;
comname = toolkit_getList(secondary_wid, "lstGoods"); comname = toolkit_getList(wid, "lstGoods");
com = commodity_get(comname); com = commodity_get(comname);
snprintf(buf, 128, snprintf(buf, 128,
@ -199,11 +183,11 @@ static void commodity_update(char* str) {
com->medium, com->medium,
pilot_cargoFree(player)); pilot_cargoFree(player));
window_modifyText(secondary_wid, "txtDInfo", buf); window_modifyText(wid, "txtDInfo", buf);
window_modifyText(secondary_wid, "txtDesc", com->description); window_modifyText(wid, "txtDesc", com->description);
} }
static void commodity_buy(char* str) { static void commodity_buy(unsigned int wid, char* str) {
(void)str; (void)str;
char* comname; char* comname;
Commodity* com; Commodity* com;
@ -211,7 +195,7 @@ static void commodity_buy(char* str) {
q = 10; q = 10;
comname = toolkit_getList(secondary_wid, "lstGoods"); comname = toolkit_getList(wid, "lstGoods");
com = commodity_get(comname); com = commodity_get(comname);
if(player->credits <= q * com->medium) { if(player->credits <= q * com->medium) {
@ -225,22 +209,22 @@ static void commodity_buy(char* str) {
q = pilot_addCargo(player, com, q); q = pilot_addCargo(player, com, q);
player->credits -= q * com->medium; player->credits -= q * com->medium;
commodity_update(NULL); commodity_update(wid, NULL);
} }
static void commodity_sell(char* str) { static void commodity_sell(unsigned int wid, char* str) {
(void)str; (void)str;
char* comname; char* comname;
Commodity* com; Commodity* com;
int q; int q;
q = 10; q = 10;
comname = toolkit_getList(secondary_wid, "lstGoods"); comname = toolkit_getList(wid, "lstGoods");
com = commodity_get(comname); com = commodity_get(comname);
q = pilot_rmCargo(player, com, q); q = pilot_rmCargo(player, com, q);
player->credits += q * com->medium; player->credits += q * com->medium;
commodity_update(NULL); commodity_update(wid, NULL);
} }
static void outfits_open(void) { static void outfits_open(void) {
@ -250,38 +234,39 @@ static void outfits_open(void) {
glTexture** toutfits; glTexture** toutfits;
int noutfits; int noutfits;
char buf[128]; char buf[128];
unsigned int wid;
/* Create window. */ /* Create window. */
snprintf(buf, 128, "%s - Outfits", land_planet->name); snprintf(buf, 128, "%s - Outfits", land_planet->name);
secondary_wid = window_create(buf, -1, -1, wid = window_create(buf, -1, -1,
OUTFITS_WIDTH, OUTFITS_HEIGHT); OUTFITS_WIDTH, OUTFITS_HEIGHT);
/* Will allow buying from keyboard. */ /* Will allow buying from keyboard. */
window_setAccept(secondary_wid, outfits_buy); window_setAccept(wid, outfits_buy);
/* Buttons. */ /* Buttons. */
window_addButton(secondary_wid, -20, 20, window_addButton(wid, -20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseOutfits", BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseOutfits",
"Close", outfits_close); "Close", outfits_close);
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 40+BUTTON_HEIGHT, window_addButton(wid, -40-BUTTON_WIDTH, 40+BUTTON_HEIGHT,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyOutfit", BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyOutfit",
"Buy", outfits_buy); "Buy", outfits_buy);
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 20, window_addButton(wid, -40-BUTTON_WIDTH, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnSellOutfit", BUTTON_WIDTH, BUTTON_HEIGHT, "btnSellOutfit",
"Sell", outfits_sell); "Sell", outfits_sell);
/* Fancy 128x128 image. */ /* Fancy 128x128 image. */
window_addRect(secondary_wid, -20, -50, 128, 128, "rctImage", &cBlack, 0); window_addRect(wid, -20, -50, 128, 128, "rctImage", &cBlack, 0);
window_addImage(secondary_wid, -20-128, -50-128, "imgOutfit", NULL, 1); window_addImage(wid, -20-128, -50-128, "imgOutfit", NULL, 1);
window_addCust(secondary_wid, -40-BUTTON_WIDTH, 60+2*BUTTON_HEIGHT, window_addCust(wid, -40-BUTTON_WIDTH, 60+2*BUTTON_HEIGHT,
BUTTON_WIDTH, BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT,
"cstMod", 0, outfits_renderMod, NULL); "cstMod", 0, outfits_renderMod, NULL);
/* The descriptive text. */ /* The descriptive text. */
window_addText(secondary_wid, 40+300+20, -60, window_addText(wid, 40+300+20, -60,
80, 96, 0, "txtSDesc", &gl_smallFont, &cDConsole, 80, 96, 0, "txtSDesc", &gl_smallFont, &cDConsole,
"Name:\n" "Name:\n"
"Type:\n" "Type:\n"
@ -293,10 +278,10 @@ static void outfits_open(void) {
"Price:\n" "Price:\n"
"Money:\n"); "Money:\n");
window_addText(secondary_wid, 40+300+40+60, -60, window_addText(wid, 40+300+40+60, -60,
250, 96, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL); 250, 96, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
window_addText(secondary_wid, 20+300+40, -220, window_addText(wid, 20+300+40, -220,
OUTFITS_WIDTH-400, 180, 0, "txtDescription", OUTFITS_WIDTH-400, 180, 0, "txtDescription",
&gl_smallFont, NULL, NULL); &gl_smallFont, NULL, NULL);
@ -320,12 +305,12 @@ static void outfits_open(void) {
free(outfits); free(outfits);
} }
window_addImageArray(secondary_wid, 20, 40, window_addImageArray(wid, 20, 40,
310, OUTFITS_HEIGHT-80, "iarOutfits", 64, 64, 310, OUTFITS_HEIGHT-80, "iarOutfits", 64, 64,
toutfits, soutfits, noutfits, outfits_update); toutfits, soutfits, noutfits, outfits_update);
/* Write the outfits stuff. */ /* Write the outfits stuff. */
outfits_update(NULL); outfits_update(wid, NULL);
if(!has_visited(VISITED_OUTFITS)) { if(!has_visited(VISITED_OUTFITS)) {
/* @todo mission check. */ /* @todo mission check. */
@ -333,23 +318,17 @@ static void outfits_open(void) {
} }
} }
static void outfits_close(char* str) { static void outfits_update(unsigned int wid, char* str) {
if(strcmp(str, "btnCloseOutfits")==0)
window_destroy(secondary_wid);
secondary_wid = 0;
}
static void outfits_update(char* str) {
(void)str; (void)str;
char* outfitname; char* outfitname;
Outfit* outfit; Outfit* outfit;
char buf[128], buf2[16], buf3[16]; char buf[128], buf2[16], buf3[16];
outfitname = toolkit_getList(secondary_wid, "iarOutfits"); outfitname = toolkit_getList(wid, "iarOutfits");
if(strcmp(outfitname, "None")==0) { /* No outfits. */ if(strcmp(outfitname, "None")==0) { /* No outfits. */
window_modifyImage(secondary_wid, "imgOutfit", NULL); window_modifyImage(wid, "imgOutfit", NULL);
window_disableButton(secondary_wid, "btnBuyOutfit"); window_disableButton(wid, "btnBuyOutfit");
window_disableButton(secondary_wid, "btnSellOutfit"); window_disableButton(wid, "btnSellOutfit");
snprintf(buf, 128, snprintf(buf, 128,
"None\n" "None\n"
"NA\n" "NA\n"
@ -361,27 +340,27 @@ static void outfits_update(char* str) {
"NA\n" "NA\n"
"NA\n", "NA\n",
pilot_freeSpace(player)); pilot_freeSpace(player));
window_modifyText(secondary_wid, "txtDDesc", buf); window_modifyText(wid, "txtDDesc", buf);
return; return;
} }
outfit = outfit_get(outfitname); outfit = outfit_get(outfitname);
window_modifyImage(secondary_wid, "imgOutfit", outfit->gfx_store); window_modifyImage(wid, "imgOutfit", outfit->gfx_store);
if(outfit_canBuy(outfit, 1, 0) > 0) if(outfit_canBuy(outfit, 1, 0) > 0)
window_enableButton(secondary_wid, "btnBuyOutfit"); window_enableButton(wid, "btnBuyOutfit");
else else
window_disableButton(secondary_wid, "btnBuyOutfit"); window_disableButton(wid, "btnBuyOutfit");
/* Gray out sell button. */ /* Gray out sell button. */
if(outfit_canSell(outfit, 1, 0) > 0) if(outfit_canSell(outfit, 1, 0) > 0)
window_enableButton(secondary_wid, "btnSellOutfit"); window_enableButton(wid, "btnSellOutfit");
else else
window_disableButton(secondary_wid, "btnSellOutfit"); window_disableButton(wid, "btnSellOutfit");
/* New text. */ /* New text. */
window_modifyText(secondary_wid, "txtDescription", outfit->description); window_modifyText(wid, "txtDescription", outfit->description);
credits2str(buf2, outfit->price, 2); credits2str(buf2, outfit->price, 2);
credits2str(buf3, player->credits, 2); credits2str(buf3, player->credits, 2);
snprintf(buf, 128, snprintf(buf, 128,
@ -402,7 +381,7 @@ static void outfits_update(char* str) {
buf2, buf2,
buf3); buf3);
window_modifyText(secondary_wid, "txtDDesc", buf); window_modifyText(wid, "txtDDesc", buf);
} }
static int outfit_canBuy(Outfit* outfit, int q, int errmsg) { static int outfit_canBuy(Outfit* outfit, int q, int errmsg) {