mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
This commit is contained in:
parent
38c2574b3c
commit
9fc627f99b
48
newgrf_gui.c
48
newgrf_gui.c
@ -226,31 +226,45 @@ typedef struct newgrf_d {
|
|||||||
} newgrf_d;
|
} newgrf_d;
|
||||||
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(newgrf_d));
|
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(newgrf_d));
|
||||||
|
|
||||||
|
enum ShowNewGRFStateWidgets {
|
||||||
|
SNGRFS_ADD = 3,
|
||||||
|
SNGRFS_REMOVE,
|
||||||
|
SNGRFS_MOVE_UP,
|
||||||
|
SNGRFS_MOVE_DOWN,
|
||||||
|
SNGRFS_FILE_LIST = 7,
|
||||||
|
SNGRFS_NEWGRF_INFO = 9,
|
||||||
|
SNGRFS_SET_PARAMETERS,
|
||||||
|
};
|
||||||
|
|
||||||
static void SetupNewGRFState(Window *w)
|
static void SetupNewGRFState(Window *w)
|
||||||
{
|
{
|
||||||
bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable;
|
bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable;
|
||||||
|
|
||||||
SetWindowWidgetDisabledState(w, 3, !WP(w, newgrf_d).editable);
|
SetWindowWidgetDisabledState(w, 3, !WP(w, newgrf_d).editable);
|
||||||
SetWindowWidgetsDisabledState(w, disable_all, 4, 5, 6, WIDGET_LIST_END);
|
SetWindowWidgetsDisabledState(w, disable_all,
|
||||||
SetWindowWidgetDisabledState(w, 10, !WP(w, newgrf_d).show_params || disable_all);
|
SNGRFS_REMOVE,
|
||||||
|
SNGRFS_MOVE_UP,
|
||||||
|
SNGRFS_MOVE_DOWN,
|
||||||
|
WIDGET_LIST_END
|
||||||
|
);
|
||||||
|
SetWindowWidgetDisabledState(w, SNGRFS_SET_PARAMETERS, !WP(w, newgrf_d).show_params || disable_all);
|
||||||
|
|
||||||
if (!disable_all) {
|
if (!disable_all) {
|
||||||
/* All widgets are now enabled, so disable widgets we can't use */
|
/* All widgets are now enabled, so disable widgets we can't use */
|
||||||
if (WP(w, newgrf_d).sel == *WP(w, newgrf_d).list) DisableWindowWidget(w, 5);
|
if (WP(w, newgrf_d).sel == *WP(w, newgrf_d).list) DisableWindowWidget(w, SNGRFS_MOVE_UP);
|
||||||
if (WP(w, newgrf_d).sel->next == NULL) DisableWindowWidget(w, 6);
|
if (WP(w, newgrf_d).sel->next == NULL) DisableWindowWidget(w, SNGRFS_MOVE_DOWN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void SetupNewGRFWindow(Window *w)
|
static void SetupNewGRFWindow(Window *w)
|
||||||
{
|
{
|
||||||
GRFConfig *c;
|
const GRFConfig *c;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++);
|
for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++);
|
||||||
|
|
||||||
w->vscroll.cap = (w->widget[7].bottom - w->widget[7].top) / 14 + 1;
|
w->vscroll.cap = (w->widget[SNGRFS_FILE_LIST].bottom - w->widget[SNGRFS_FILE_LIST].top) / 14 + 1;
|
||||||
SetVScrollCount(w, i);
|
SetVScrollCount(w, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +273,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
{
|
{
|
||||||
switch (e->event) {
|
switch (e->event) {
|
||||||
case WE_PAINT: {
|
case WE_PAINT: {
|
||||||
GRFConfig *c;
|
const GRFConfig *c;
|
||||||
int i, y;
|
int i, y;
|
||||||
|
|
||||||
SetupNewGRFState(w);
|
SetupNewGRFState(w);
|
||||||
@ -267,7 +281,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
DrawWindowWidgets(w);
|
DrawWindowWidgets(w);
|
||||||
|
|
||||||
/* Draw NewGRF list */
|
/* Draw NewGRF list */
|
||||||
y = w->widget[7].top;
|
y = w->widget[SNGRFS_FILE_LIST].top;
|
||||||
for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++) {
|
for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++) {
|
||||||
if (i >= w->vscroll.pos && i < w->vscroll.pos + w->vscroll.cap) {
|
if (i >= w->vscroll.pos && i < w->vscroll.pos + w->vscroll.cap) {
|
||||||
const char *text = (c->name != NULL && strlen(c->name) != 0) ? c->name : c->filename;
|
const char *text = (c->name != NULL && strlen(c->name) != 0) ? c->name : c->filename;
|
||||||
@ -292,7 +306,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
|
|
||||||
if (WP(w, newgrf_d).sel != NULL) {
|
if (WP(w, newgrf_d).sel != NULL) {
|
||||||
/* Draw NewGRF file info */
|
/* Draw NewGRF file info */
|
||||||
const Widget *wi = &w->widget[9];
|
const Widget *wi = &w->widget[SNGRFS_NEWGRF_INFO];
|
||||||
ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, WP(w, newgrf_d).show_params);
|
ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, WP(w, newgrf_d).show_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,7 +319,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
|
|
||||||
case WE_CLICK:
|
case WE_CLICK:
|
||||||
switch (e->we.click.widget) {
|
switch (e->we.click.widget) {
|
||||||
case 3: { /* Add GRF */
|
case SNGRFS_ADD: { /* Add GRF */
|
||||||
GRFConfig **list = WP(w, newgrf_d).list;
|
GRFConfig **list = WP(w, newgrf_d).list;
|
||||||
Window *w;
|
Window *w;
|
||||||
|
|
||||||
@ -317,7 +331,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 4: { /* Remove GRF */
|
case SNGRFS_REMOVE: { /* Remove GRF */
|
||||||
GRFConfig **pc, *c, *newsel;
|
GRFConfig **pc, *c, *newsel;
|
||||||
|
|
||||||
/* Choose the next GRF file to be the selected file */
|
/* Choose the next GRF file to be the selected file */
|
||||||
@ -341,7 +355,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 5: { /* Move GRF up */
|
case SNGRFS_MOVE_UP: { /* Move GRF up */
|
||||||
GRFConfig **pc, *c;
|
GRFConfig **pc, *c;
|
||||||
if (WP(w, newgrf_d).sel == NULL) break;
|
if (WP(w, newgrf_d).sel == NULL) break;
|
||||||
|
|
||||||
@ -357,7 +371,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 6: { /* Move GRF down */
|
case SNGRFS_MOVE_DOWN: { /* Move GRF down */
|
||||||
GRFConfig **pc, *c;
|
GRFConfig **pc, *c;
|
||||||
if (WP(w, newgrf_d).sel == NULL) break;
|
if (WP(w, newgrf_d).sel == NULL) break;
|
||||||
|
|
||||||
@ -373,9 +387,9 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 7: { /* Select a GRF */
|
case SNGRFS_FILE_LIST: { /* Select a GRF */
|
||||||
GRFConfig *c;
|
GRFConfig *c;
|
||||||
uint i = (e->we.click.pt.y - w->widget[7].top) / 14 + w->vscroll.pos;
|
uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos;
|
||||||
|
|
||||||
for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--);
|
for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--);
|
||||||
WP(w, newgrf_d).sel = c;
|
WP(w, newgrf_d).sel = c;
|
||||||
@ -384,7 +398,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 10: { /* Edit parameters */
|
case SNGRFS_SET_PARAMETERS: { /* Edit parameters */
|
||||||
char buff[512];
|
char buff[512];
|
||||||
if (WP(w, newgrf_d).sel == NULL) break;
|
if (WP(w, newgrf_d).sel == NULL) break;
|
||||||
|
|
||||||
@ -409,7 +423,7 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|||||||
|
|
||||||
case WE_RESIZE:
|
case WE_RESIZE:
|
||||||
w->vscroll.cap += e->we.sizing.diff.y / 14;
|
w->vscroll.cap += e->we.sizing.diff.y / 14;
|
||||||
w->widget[7].data = (w->vscroll.cap << 8) + 1;
|
w->widget[SNGRFS_FILE_LIST].data = (w->vscroll.cap << 8) + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user