[Add] Refuel button should appear more often now.

This commit is contained in:
Allanis 2014-03-10 15:24:15 +00:00
parent 0817a156b9
commit e10e6d4bcb
3 changed files with 83 additions and 0 deletions

View File

@ -108,6 +108,7 @@ static void misn_accept(unsigned int wid, char* str);
static void misn_genList(unsigned int wid, int first); static void misn_genList(unsigned int wid, int first);
static void misn_update(unsigned int wid, char* str); static void misn_update(unsigned int wid, char* str);
/* Refuel. */ /* Refuel. */
static void land_checkAddRefuel(void);
static unsigned int refuel_price(void); static unsigned int refuel_price(void);
static void spaceport_refuel(unsigned int wid, char* str); static void spaceport_refuel(unsigned int wid, char* str);
@ -224,6 +225,7 @@ static void commodity_sell(unsigned int wid, char* str) {
q = pilot_rmCargo(player, com, q); q = pilot_rmCargo(player, com, q);
player->credits += q * com->medium; player->credits += q * com->medium;
land_checkAddRefuel();
commodity_update(wid, NULL); commodity_update(wid, NULL);
} }
@ -487,6 +489,7 @@ static void outfits_sell(unsigned int wid, char* str) {
if(outfit_canSell(outfit, q, 1) == 0) return; if(outfit_canSell(outfit, q, 1) == 0) return;
player->credits += outfit->price * pilot_rmOutfit(player, outfit, q); player->credits += outfit->price * pilot_rmOutfit(player, outfit, q);
land_checkAddRefuel();
outfits_update(wid, NULL); outfits_update(wid, NULL);
} }
@ -893,6 +896,7 @@ static void shipyard_yoursSell(unsigned int wid, char* str) {
/* Sold. */ /* Sold. */
player->credits += price; player->credits += price;
land_checkAddRefuel();
player_rmShip(shipname); player_rmShip(shipname);
dialogue_msg("Ship Sold", "You have sold your ship %s for %s SCred.", dialogue_msg("Ship Sold", "You have sold your ship %s for %s SCred.",
shipname, buf); shipname, buf);
@ -1119,6 +1123,36 @@ static void spaceport_refuel(unsigned int wid, char* str) {
window_destroyWidget(wid, "btnRefuel"); window_destroyWidget(wid, "btnRefuel");
} }
/**
* @brief Check if should add the refuel button and does if needed.
*/
static void land_checkAddRefuel(void) {
char buf[32], cred[16];
/* Check to see if fuel conditions are met. */
if(!planet_hasService(land_planet, PLANET_SERVICE_BASIC))
return;
/* Full fuel. */
if(player->fuel >= player->fuel_max)
return;
/* Just enable button if it exists. */
if(widget_exists(land_wid, "btnRefuel")) {
window_enableButton(land_wid, "btnRefuel");
} else { /* Create it. */
credits2str(cred, refuel_price(), 2);
snprintf(buf, 32, "Refuel %s", cred);
window_addButton(land_wid, -20, 20+2*(BUTTON_HEIGHT+20),
BUTTON_WIDTH, BUTTON_HEIGHT, "btnRefuel",
buf, spaceport_refuel);
}
/* Make sure player can click it. */
if(player->credits < refuel_price())
window_disableButton(land_wid, "btnRefuel");
}
/* Land the player. */ /* Land the player. */
void land(Planet* p) { void land(Planet* p) {
char buf[32], cred[16]; char buf[32], cred[16];

View File

@ -729,6 +729,31 @@ void window_destroy(const unsigned int wid) {
toolkit_clearKey(); toolkit_clearKey();
} }
/**
* @brief Check to see if a widget exists.
* @param wid Window to check widget in
* @param wgtname Name of the widget to check.
*/
int widget_exists(const unsigned int wid, const char* wgtname) {
Window* w = window_wget(wid);
int i;
/* Get window. */
if(w == NULL) {
if(w == NULL) {
WARN("Window '%d' does not exist", wid);
return -1;
}
/* Check for widget. */
for(i = 0; i < w->nwidgets; i++)
if(strcmp(wgtname, w->widgets[i].name)==0)
return 1;
return 0;
}
}
/** /**
* @brief wid Window to destroy widget in. * @brief wid Window to destroy widget in.
* @param wid Window to destroy widget in. * @param wid Window to destroy widget in.
@ -1369,6 +1394,29 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) {
if(inp->type != WIDGET_INPUT) return 0; if(inp->type != WIDGET_INPUT) return 0;
/*
* Handle arrow keys.
* @todo Finish implementin, no cursor makes it complicated
* to see where you are.
*/
#if 0
if((type == SDL_KEYDOWN) &&
((key == SDLK_LEFT) || (key == SDLK_RETURN))) {
/* Move pointer. */
if(key == SDLK_LEFT) {
if(inp->dat.inp.pos > 0)
inp->dat.inp.pos -= 1;
}
else if(key == SDLK_RIGHT) {
if((inp->dat.inp.pos < inp->dat.inp.max-1) &&
(inp->dat.inp.input[inp->dat.inp.pos+1] != '\0'))
inp->dat.inp.pos += 1;
}
return 1;
}
#endif
mods = SDL_GetModState(); mods = SDL_GetModState();
if(inp->dat.inp.oneline && isascii(key)) { if(inp->dat.inp.oneline && isascii(key)) {
/* Backspace -> delete text. */ /* Backspace -> delete text. */

View File

@ -65,6 +65,7 @@ void window_imgColour(const unsigned int wid, char* name, glColour* colour);
/* Get. */ /* Get. */
/* Generic. */ /* Generic. */
int window_exists(const char* wdwname); int window_exists(const char* wdwname);
int widget_exists(const unsigned int wid, const char* wgtname);
unsigned int window_get(const char* wdwname); unsigned int window_get(const char* wdwname);
char* window_getInput(const unsigned int wid, char* name); char* window_getInput(const unsigned int wid, char* name);
void window_posWidget(const unsigned int wid, void window_posWidget(const unsigned int wid,