From 37862dbf3c26172084660ab38f671eb801540bbb Mon Sep 17 00:00:00 2001 From: Allanis Date: Fri, 8 Mar 2013 14:21:03 +0000 Subject: [PATCH] [Add] Use shift/control modifiers to purchase more outfits at a time. --- src/land.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- src/toolkit.c | 9 ++++++--- src/toolkit.h | 3 ++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/land.c b/src/land.c index c5a1edf..7d66c66 100644 --- a/src/land.c +++ b/src/land.c @@ -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).", @@ -194,8 +200,14 @@ static void outfits_buy(char* str) { toolkit_alert("You can only carry %d of this outfit.", outfit->max); return; } + + 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; + } - pilot_addOutfit(player, outfit, q); + 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; diff --git a/src/toolkit.c b/src/toolkit.c index 072cd61..c2a5dd2 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -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; } } diff --git a/src/toolkit.h b/src/toolkit.h index f5047a5..898145b 100644 --- a/src/toolkit.h +++ b/src/toolkit.h @@ -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, ...);