(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.

This commit is contained in:
peter1138
2006-12-04 14:27:54 +00:00
parent 9a87e1e0ea
commit c7d3d996bf
8 changed files with 502 additions and 150 deletions

View File

@@ -916,146 +916,6 @@ void ShowPatchesSelection(void)
AllocateWindowDesc(&_patches_selection_desc);
}
enum {
NEWGRF_WND_PROC_OFFSET_TOP_WIDGET = 14,
NEWGRF_WND_PROC_ROWSIZE = 14
};
static void NewgrfWndProc(Window *w, WindowEvent *e)
{
static GRFFile *_sel_grffile;
switch (e->event) {
case WE_PAINT: {
int x, y = NEWGRF_WND_PROC_OFFSET_TOP_WIDGET;
uint16 i = 0;
GRFFile *c = _first_grffile;
DrawWindowWidgets(w);
if (_first_grffile == NULL) { // no grf sets installed
DrawStringMultiCenter(140, 210, STR_NEWGRF_NO_FILES_INSTALLED, 250);
break;
}
// draw list of all grf files
while (c != NULL) {
if (i >= w->vscroll.pos) { // draw files according to scrollbar position
bool h = (_sel_grffile == c);
// show highlighted item with a different background and highlighted text
if (h) GfxFillRect(1, y + 1, 267, y + 12, 156);
// XXX - will be grf name later
DoDrawString(c->filename, 25, y + 2, h ? 0xC : 0x10);
DrawSprite(SPRITE_PALETTE(SPR_SQUARE | PALETTE_TO_RED), 5, y + 2);
y += NEWGRF_WND_PROC_ROWSIZE;
}
c = c->next;
if (++i == w->vscroll.cap + w->vscroll.pos) break; // stop after displaying 12 items
}
// DoDrawString(_sel_grffile->setname, 120, 200, 0x01); // draw grf name
if (_sel_grffile == NULL) { // no grf file selected yet
DrawStringMultiCenter(140, 210, STR_NEWGRF_TIP, 250);
} else {
// draw filename
x = DrawString(5, 199, STR_NEWGRF_FILENAME, 0);
DoDrawString(_sel_grffile->filename, x + 2, 199, 0x01);
// draw grf id
x = DrawString(5, 209, STR_NEWGRF_GRF_ID, 0);
snprintf(_userstring, lengthof(_userstring), "%08X", (uint32)BSWAP32(_sel_grffile->grfid));
DrawString(x + 2, 209, STR_SPEC_USERSTRING, 0x01);
}
} break;
case WE_CLICK:
switch (e->we.click.widget) {
case 3: { // select a grf file
int y = (e->we.click.pt.y - NEWGRF_WND_PROC_OFFSET_TOP_WIDGET) / NEWGRF_WND_PROC_ROWSIZE;
if (y >= w->vscroll.cap) return; // click out of bounds
y += w->vscroll.pos;
if (y >= w->vscroll.count) return;
_sel_grffile = _first_grffile;
// get selected grf-file
while (y-- != 0) _sel_grffile = _sel_grffile->next;
SetWindowDirty(w);
} break;
case 9: /* Cancel button */
DeleteWindowById(WC_GAME_OPTIONS, 0);
break;
} break;
#if 0 /* Parameter edit box not used yet */
case WE_TIMEOUT:
WP(w,def_d).data_2 = 0;
SetWindowDirty(w);
break;
case WE_ON_EDIT_TEXT: {
if (*e->edittext.str) {
SetWindowDirty(w);
}
break;
}
#endif
case WE_DESTROY:
_sel_grffile = NULL;
DeleteWindowById(WC_QUERY_STRING, 0);
break;
}
}
static const Widget _newgrf_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 279, 0, 13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 14, 0, 279, 183, 276, 0x0, STR_NULL},
{ WWT_MATRIX, RESIZE_NONE, 14, 0, 267, 14, 182, 0xC01, /*small rows*/ STR_NEWGRF_TIP},
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 268, 279, 14, 182, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 147, 158, 244, 255, STR_0188, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 159, 170, 244, 255, STR_0189, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 175, 274, 244, 255, STR_NEWGRF_SET_PARAMETERS, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 5, 138, 261, 272, STR_NEWGRF_APPLY_CHANGES, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 142, 274, 261, 272, STR_012E_CANCEL, STR_NULL},
{ WIDGETS_END},
};
static const WindowDesc _newgrf_desc = {
WDP_CENTER, WDP_CENTER, 280, 277,
WC_GAME_OPTIONS,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_newgrf_widgets,
NewgrfWndProc,
};
void ShowNewgrf(void)
{
const GRFFile* c;
Window *w;
uint count;
DeleteWindowById(WC_GAME_OPTIONS, 0);
w = AllocateWindowDesc(&_newgrf_desc);
count = 0;
for (c = _first_grffile; c != NULL; c = c->next) count++;
w->vscroll.cap = 12;
w->vscroll.count = count;
w->vscroll.pos = 0;
DisableWindowWidget(w, 5); // Small up arrow
DisableWindowWidget(w, 6); // Small sown arrow
DisableWindowWidget(w, 7); // Set parameter button
}
/**
* Draw [<][>] boxes.