diff --git a/dat/missions/cargo.lua b/dat/missions/cargo.lua index 19b39b9..9f7671f 100644 --- a/dat/missions/cargo.lua +++ b/dat/missions/cargo.lua @@ -15,8 +15,6 @@ function create() planet, carg_mass, carg_type, "SOMEDAY")) misn_reward = carg_mass * 1000 + rnd.int(0, 5000) misn.setReward(string.format("%d Scred", misn_reward)) - - end function accept() @@ -24,7 +22,7 @@ function accept() toolkit.msg("Mission Accepted", string.format("The workers load the %d tons of %s onto your ship.", carg_mass, carg_type)) - + hook.land("land") end function land() diff --git a/src/land.c b/src/land.c index ff3a7dd..0be240b 100644 --- a/src/land.c +++ b/src/land.c @@ -850,6 +850,8 @@ static void misn_update(char* str) { window_modifyText(secondary_wid, "txtReward", "None"); window_modifyText(secondary_wid, "txtDesc", "There are no missions available here."); + + window_disableButton(secondary_wid, "btnAcceptMission"); return; } for(i = 0; i < mission_ncomputer; i++) @@ -857,6 +859,7 @@ static void misn_update(char* str) { (strcmp(active_misn, mission_computer[i].title)==0)) { window_modifyText(secondary_wid, "txtReward", mission_computer[i].reward); window_modifyText(secondary_wid, "txtDesc", mission_computer[i].desc); + window_enableButton(secondary_wid, "btnAcceptMission"); return; } } diff --git a/src/mission.c b/src/mission.c index 3a13781..6ae8f28 100644 --- a/src/mission.c +++ b/src/mission.c @@ -51,7 +51,7 @@ static int mission_init(Mission* mission, MissionData* misn) { // Sane defaults. mission->title = NULL; - mission->desc = NULL; + //mission->desc = NULL; mission->reward = NULL; // Init lua. diff --git a/src/toolkit.c b/src/toolkit.c index c8fd24d..80c7b7a 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -39,6 +39,7 @@ typedef struct Widget_ { struct { void(*fptr) (char*); // Active callback. char* display; // Stored text. + int disabled; } btn; // Widget text. struct { @@ -162,9 +163,11 @@ void window_addButton(const unsigned int wid, const int x, const int y, Window* wdw = window_wget(wid); Widget* wgt = window_newWidget(wdw); + // Specific. wgt->type = WIDGET_BUTTON; wgt->name = strdup(name); wgt->dat.btn.display = strdup(display); + wgt->dat.btn.disabled = 0; // Initially enabled. // Set the properties. wgt->w = (double) w; @@ -370,7 +373,29 @@ void window_modifyText(const unsigned int wid, char* name, char* newstring) { Widget* wgt = window_getwgt(wid, name); if(wgt->dat.txt.text) free(wgt->dat.txt.text); - //wgt->dat.txt.text = strdup(newstring); + wgt->dat.txt.text = strdup(newstring); +} + +// Disable a button. +void window_disableButton(const unsigned int wid, char* name) { + Widget* wgt = window_getwgt(wid, name); + + if(wgt->type != WIDGET_BUTTON) { + DEBUG("Trying to disable a non-button widget '%s'", name); + return; + } + wgt->dat.btn.disabled = 1; +} + +// Enable a button. +void window_enableButton(const unsigned int wid, char* name) { + Widget* wgt = window_getwgt(wid, name); + + if(wgt->type != WIDGET_BUTTON) { + DEBUG("Trying to enable a non-button widget '%s'", name); + return; + } + wgt->dat.btn.disabled = 0; } void window_modifyImage(const unsigned int wid, char* name, glTexture* image) { @@ -793,29 +818,36 @@ static void toolkit_renderButton(Widget* btn, double bx, double by) { x = bx + btn->x; y = by + btn->y; - - switch(btn->status) { - // Set the color. - case WIDGET_STATUS_NORMAL: - lc = &cGrey80; - c = &cGrey60; - dc = &cGrey40; - oc = &cGrey20; - break; - case WIDGET_STATUS_MOUSEOVER: - lc = &cWhite; - c = &cGrey80; - dc = &cGrey60; - oc = &cGrey40; - break; - case WIDGET_STATUS_MOUSEDOWN: - lc = &cGreen; - c = &cGreen; - dc = &cGrey40; - oc = &cGrey20; - break; - default: - break; + + if(btn->dat.btn.disabled == 1) { + lc = &cGrey50; + c = &cGrey30; + dc = &cGrey30; + oc = &cGrey10; + } else { + switch(btn->status) { + // Set the color. + case WIDGET_STATUS_NORMAL: + lc = &cGrey80; + c = &cGrey60; + dc = &cGrey40; + oc = &cGrey20; + break; + case WIDGET_STATUS_MOUSEOVER: + lc = &cWhite; + c = &cGrey80; + dc = &cGrey60; + oc = &cGrey40; + break; + case WIDGET_STATUS_MOUSEDOWN: + lc = &cGreen; + c = &cGreen; + dc = &cGrey40; + oc = &cGrey20; + break; + default: + break; + } } // Shaded base. @@ -1105,7 +1137,8 @@ static void toolkit_mouseEvent(SDL_Event* event) { break; case SDL_MOUSEBUTTONUP: if(wgt->status == WIDGET_STATUS_MOUSEDOWN) { - if(wgt->type == WIDGET_BUTTON) { + if((wgt->type == WIDGET_BUTTON) && + (wgt->dat.btn.disabled==0)) { if(wgt->dat.btn.fptr == NULL) DEBUG("Toolkit: Button '%s' of Window '%s'" "Does not have a function trigger", @@ -1254,6 +1287,7 @@ static int toolkit_isFocusable(Widget* wgt) { switch(wgt->type) { case WIDGET_BUTTON: + if(wgt->dat.btn.disabled == 1) return 0; case WIDGET_LIST: case WIDGET_INPUT: return 1; diff --git a/src/toolkit.h b/src/toolkit.h index f6d2a46..e095d8a 100644 --- a/src/toolkit.h +++ b/src/toolkit.h @@ -50,7 +50,11 @@ char* dialogue_input(char* title, int min, int max, const char* fmt, ...); // Modification. void window_setFptr(const unsigned int wid, void(*fptr)(char*)); +// Text. void window_modifyText(const unsigned int wid, char* name, char* newstring); +// Button. +void window_disableButton(const unsigned int wid, char* name); +void window_enableButton(const unsigned int wid, char* name); // Image. void window_modifyImage(const unsigned int wid, char* name, glTexture* image); void window_imgColour(const unsigned int wid, char* name, glColour* colour);