[Add] Option to enable/disable buttons.
This commit is contained in:
parent
2233635cdc
commit
1a994d60ad
@ -15,8 +15,6 @@ function create()
|
|||||||
planet, carg_mass, carg_type, "SOMEDAY"))
|
planet, carg_mass, carg_type, "SOMEDAY"))
|
||||||
misn_reward = carg_mass * 1000 + rnd.int(0, 5000)
|
misn_reward = carg_mass * 1000 + rnd.int(0, 5000)
|
||||||
misn.setReward(string.format("%d Scred", misn_reward))
|
misn.setReward(string.format("%d Scred", misn_reward))
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function accept()
|
function accept()
|
||||||
@ -24,7 +22,7 @@ function accept()
|
|||||||
toolkit.msg("Mission Accepted",
|
toolkit.msg("Mission Accepted",
|
||||||
string.format("The workers load the %d tons of %s onto your ship.",
|
string.format("The workers load the %d tons of %s onto your ship.",
|
||||||
carg_mass, carg_type))
|
carg_mass, carg_type))
|
||||||
|
hook.land("land")
|
||||||
end
|
end
|
||||||
|
|
||||||
function land()
|
function land()
|
||||||
|
@ -850,6 +850,8 @@ static void misn_update(char* str) {
|
|||||||
window_modifyText(secondary_wid, "txtReward", "None");
|
window_modifyText(secondary_wid, "txtReward", "None");
|
||||||
window_modifyText(secondary_wid, "txtDesc",
|
window_modifyText(secondary_wid, "txtDesc",
|
||||||
"There are no missions available here.");
|
"There are no missions available here.");
|
||||||
|
|
||||||
|
window_disableButton(secondary_wid, "btnAcceptMission");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(i = 0; i < mission_ncomputer; i++)
|
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)) {
|
(strcmp(active_misn, mission_computer[i].title)==0)) {
|
||||||
window_modifyText(secondary_wid, "txtReward", mission_computer[i].reward);
|
window_modifyText(secondary_wid, "txtReward", mission_computer[i].reward);
|
||||||
window_modifyText(secondary_wid, "txtDesc", mission_computer[i].desc);
|
window_modifyText(secondary_wid, "txtDesc", mission_computer[i].desc);
|
||||||
|
window_enableButton(secondary_wid, "btnAcceptMission");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ static int mission_init(Mission* mission, MissionData* misn) {
|
|||||||
|
|
||||||
// Sane defaults.
|
// Sane defaults.
|
||||||
mission->title = NULL;
|
mission->title = NULL;
|
||||||
mission->desc = NULL;
|
//mission->desc = NULL;
|
||||||
mission->reward = NULL;
|
mission->reward = NULL;
|
||||||
|
|
||||||
// Init lua.
|
// Init lua.
|
||||||
|
@ -39,6 +39,7 @@ typedef struct Widget_ {
|
|||||||
struct {
|
struct {
|
||||||
void(*fptr) (char*); // Active callback.
|
void(*fptr) (char*); // Active callback.
|
||||||
char* display; // Stored text.
|
char* display; // Stored text.
|
||||||
|
int disabled;
|
||||||
} btn;
|
} btn;
|
||||||
// Widget text.
|
// Widget text.
|
||||||
struct {
|
struct {
|
||||||
@ -162,9 +163,11 @@ void window_addButton(const unsigned int wid, const int x, const int y,
|
|||||||
Window* wdw = window_wget(wid);
|
Window* wdw = window_wget(wid);
|
||||||
Widget* wgt = window_newWidget(wdw);
|
Widget* wgt = window_newWidget(wdw);
|
||||||
|
|
||||||
|
// Specific.
|
||||||
wgt->type = WIDGET_BUTTON;
|
wgt->type = WIDGET_BUTTON;
|
||||||
wgt->name = strdup(name);
|
wgt->name = strdup(name);
|
||||||
wgt->dat.btn.display = strdup(display);
|
wgt->dat.btn.display = strdup(display);
|
||||||
|
wgt->dat.btn.disabled = 0; // Initially enabled.
|
||||||
|
|
||||||
// Set the properties.
|
// Set the properties.
|
||||||
wgt->w = (double) w;
|
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);
|
Widget* wgt = window_getwgt(wid, name);
|
||||||
|
|
||||||
if(wgt->dat.txt.text) free(wgt->dat.txt.text);
|
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) {
|
void window_modifyImage(const unsigned int wid, char* name, glTexture* image) {
|
||||||
@ -794,28 +819,35 @@ static void toolkit_renderButton(Widget* btn, double bx, double by) {
|
|||||||
x = bx + btn->x;
|
x = bx + btn->x;
|
||||||
y = by + btn->y;
|
y = by + btn->y;
|
||||||
|
|
||||||
switch(btn->status) {
|
if(btn->dat.btn.disabled == 1) {
|
||||||
// Set the color.
|
lc = &cGrey50;
|
||||||
case WIDGET_STATUS_NORMAL:
|
c = &cGrey30;
|
||||||
lc = &cGrey80;
|
dc = &cGrey30;
|
||||||
c = &cGrey60;
|
oc = &cGrey10;
|
||||||
dc = &cGrey40;
|
} else {
|
||||||
oc = &cGrey20;
|
switch(btn->status) {
|
||||||
break;
|
// Set the color.
|
||||||
case WIDGET_STATUS_MOUSEOVER:
|
case WIDGET_STATUS_NORMAL:
|
||||||
lc = &cWhite;
|
lc = &cGrey80;
|
||||||
c = &cGrey80;
|
c = &cGrey60;
|
||||||
dc = &cGrey60;
|
dc = &cGrey40;
|
||||||
oc = &cGrey40;
|
oc = &cGrey20;
|
||||||
break;
|
break;
|
||||||
case WIDGET_STATUS_MOUSEDOWN:
|
case WIDGET_STATUS_MOUSEOVER:
|
||||||
lc = &cGreen;
|
lc = &cWhite;
|
||||||
c = &cGreen;
|
c = &cGrey80;
|
||||||
dc = &cGrey40;
|
dc = &cGrey60;
|
||||||
oc = &cGrey20;
|
oc = &cGrey40;
|
||||||
break;
|
break;
|
||||||
default:
|
case WIDGET_STATUS_MOUSEDOWN:
|
||||||
break;
|
lc = &cGreen;
|
||||||
|
c = &cGreen;
|
||||||
|
dc = &cGrey40;
|
||||||
|
oc = &cGrey20;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shaded base.
|
// Shaded base.
|
||||||
@ -1105,7 +1137,8 @@ static void toolkit_mouseEvent(SDL_Event* event) {
|
|||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
if(wgt->status == WIDGET_STATUS_MOUSEDOWN) {
|
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)
|
if(wgt->dat.btn.fptr == NULL)
|
||||||
DEBUG("Toolkit: Button '%s' of Window '%s'"
|
DEBUG("Toolkit: Button '%s' of Window '%s'"
|
||||||
"Does not have a function trigger",
|
"Does not have a function trigger",
|
||||||
@ -1254,6 +1287,7 @@ static int toolkit_isFocusable(Widget* wgt) {
|
|||||||
|
|
||||||
switch(wgt->type) {
|
switch(wgt->type) {
|
||||||
case WIDGET_BUTTON:
|
case WIDGET_BUTTON:
|
||||||
|
if(wgt->dat.btn.disabled == 1) return 0;
|
||||||
case WIDGET_LIST:
|
case WIDGET_LIST:
|
||||||
case WIDGET_INPUT:
|
case WIDGET_INPUT:
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -50,7 +50,11 @@ char* dialogue_input(char* title, int min, int max, const char* fmt, ...);
|
|||||||
|
|
||||||
// Modification.
|
// Modification.
|
||||||
void window_setFptr(const unsigned int wid, void(*fptr)(char*));
|
void window_setFptr(const unsigned int wid, void(*fptr)(char*));
|
||||||
|
// Text.
|
||||||
void window_modifyText(const unsigned int wid, char* name, char* newstring);
|
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.
|
// Image.
|
||||||
void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
|
void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
|
||||||
void window_imgColour(const unsigned int wid, char* name, glColour* colour);
|
void window_imgColour(const unsigned int wid, char* name, glColour* colour);
|
||||||
|
Loading…
Reference in New Issue
Block a user