[Add] Use shift/control modifiers to purchase more outfits at a time.

This commit is contained in:
Allanis 2013-03-08 14:21:03 +00:00
parent eeb09fdf05
commit 37862dbf3c
3 changed files with 52 additions and 7 deletions

View File

@ -50,6 +50,8 @@ static void outfits_close(char* str);
static void outfits_update(char* str);
static void outfits_buy(char* str);
static void outfits_sell(char* str);
static int outfits_getMod(void);
static void outfits_renderMod(double bx, double by, double w, double h);
// Shipyard.
static void shipyard(void);
static void shipyard_close(char* str);
@ -108,6 +110,9 @@ static void outfits(void) {
BUTTON_WIDTH, BUTTON_HEIGHT, "btnSellOutfit",
"Sell", outfits_sell);
window_addCust(secondary_wid, -40-BUTTON_WIDTH, 60+2*BUTTON_HEIGHT,
BUTTON_WIDTH, BUTTON_HEIGHT, "cstMod", outfits_renderMod);
window_addText(secondary_wid, 40+200+20, -60,
80, 96, 0, "txtSDesc", &gl_smallFont, &cDConsole,
"Name:\n"
@ -178,11 +183,12 @@ static void outfits_buy(char* str) {
char* outfitname;
Outfit* outfit;
int q;
char buf[16];
outfitname = toolkit_getList(secondary_wid, "lstOutfits");
outfit = outfit_get(outfitname);
q = 1; // Q should be dependant on MOD keys. TODO
q = outfits_getMod();
if((player_freeSpace() - outfit->mass) < 0) {
toolkit_alert("No enough free space (you need %d more slots).",
@ -195,7 +201,13 @@ static void outfits_buy(char* str) {
return;
}
pilot_addOutfit(player, outfit, q);
else if(1*(int)outfit->price >= player_credits) {
credits2str(buf, q*outfit->price - player_credits, 2);
toolkit_alert("You need %s more SCred.", buf);
return;
}
player_credits -= outfit->price * pilot_addOutfit(player, outfit, q);
outfits_update(NULL);
}
@ -207,7 +219,8 @@ static void outfits_sell(char* str) {
outfitname = toolkit_getList(secondary_wid, "lstOutfits");
outfit = outfit_get(outfitname);
q = 1;
q = outfits_getMod();
if(player_outfitOwned(outfitname) <= 0) {
// No outfits to sell.
@ -219,6 +232,34 @@ static void outfits_sell(char* str) {
outfits_update(NULL);
}
// Return the current modifier status.
static int outfits_getMod(void) {
SDLMod mods;
int q;
mods = SDL_GetModState();
q = 1;
if(mods & (KMOD_LCTRL | KMOD_RCTRL)) q *= 5;
if(mods & (KMOD_LSHIFT | KMOD_RSHIFT)) q *= 10;
return q;
}
static void outfits_renderMod(double bx, double by, double w, double h) {
(void) h;
int q;
char buf[8];
q = outfits_getMod();
if(q == 1) return;
snprintf(buf, 8, "%dx", q);
gl_printMid(&gl_smallFont, w,
bx + (double)gl_screen.w/2.,
by + (double)gl_screen.h/2.,
&cBlack, buf);
}
static void shipyard(void) {
char** ships;
int nships;

View File

@ -64,7 +64,7 @@ typedef struct Widget_ {
} rct;
// Widget cust.
struct {
void(*render) (double bx, double by);
void(*render) (double bx, double by, double bw, double bh);
} cst;
} dat;
} Widget;
@ -240,7 +240,8 @@ void window_addRect(const unsigned int wid, const int x, const int y, const int
}
void window_addCust(const unsigned int wid, const int x, const int y,
const int w, const int h, char* name, void(*render) (double x, double y)) {
const int w, const int h, char* name,
void(*render) (double x, double y, double w, double h)) {
Window* wdw = window_wget(wid);
Widget* wgt = window_newWidget(wdw);
@ -658,7 +659,9 @@ static void window_render(Window* w) {
toolkit_renderRect(&w->widgets[i], x, y);
break;
case WIDGET_CUST:
(*w->widgets[i].dat.cst.render)(x, y);
(*w->widgets[i].dat.cst.render)
(x+w->widgets[i].x, y+w->widgets[i].y,
w->widgets[i].w, w->widgets[i].h);
break;
}
}

View File

@ -33,7 +33,8 @@ void window_addRect(const unsigned int wid,
void window_addCust(const unsigned int wid,
const int x, const int y, // Position.
const int w, const int h, // Size.
char* name, void(*render) (double x, double y));
char* name,
void(*render) (double x, double y, double w, double h));
// Popups and alerts.
void toolkit_alert(const char* fmt, ...);