[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"))
|
||||
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()
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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) {
|
||||
@ -794,28 +819,35 @@ 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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user