--- a/src/genworld_gui.cpp Mon May 19 14:14:33 2008 +0000
+++ b/src/genworld_gui.cpp Mon May 19 15:13:58 2008 +0000
@@ -253,7 +253,7 @@
char name[64];
glwp_modes mode;
- GenerateLandscapeWindow(const WindowDesc *desc, void *data = NULL, WindowNumber number = 0) : QueryStringBaseWindow(desc, NULL, number)
+ GenerateLandscapeWindow(const WindowDesc *desc, WindowNumber number = 0) : QueryStringBaseWindow(desc, number)
{
this->LowerWidget(_opt_newgame.landscape + GLAND_TEMPERATE);
@@ -315,7 +315,7 @@
SetDParam(2, 1 << _patches_newgame.map_y); // GLAND_MAPSIZE_Y_PULLDOWN
SetDParam(3, _patches_newgame.snow_line_height); // GLAND_SNOW_LEVEL_TEXT
- DrawWindowWidgets(this);
+ this->DrawWidgets();
this->DrawEditBox(GLAND_RANDOM_EDITBOX);
@@ -470,17 +470,17 @@
this->HandleEditBox(GLAND_RANDOM_EDITBOX);
}
- virtual bool OnKeyPress(uint16 key, uint16 keycode)
+ virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
- bool cont;
- this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, cont);
+ EventState state;
+ this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, state);
/* the seed is unsigned, therefore atoi cannot be used.
* As 2^32 - 1 (MAX_UVALUE(uint32)) is a 'magic' value
* (use random seed) it should not be possible to be
* entered into the input field; the generate seed
* button can be used instead. */
_patches_newgame.generation_seed = minu(strtoul(this->edit_str_buf, NULL, sizeof(this->edit_str_buf) - 1), MAX_UVALUE(uint32) - 1);
- return cont;
+ return state;
}
virtual void OnDropdownSelect(int widget, int index)
@@ -554,7 +554,6 @@
WC_GENERATE_LANDSCAPE, WC_NONE,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_generate_landscape_widgets,
- NULL,
};
static const WindowDesc _heightmap_load_desc = {
@@ -562,7 +561,6 @@
WC_GENERATE_LANDSCAPE, WC_NONE,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
_heightmap_load_widgets,
- NULL,
};
static void _ShowGenerateLandscape(glwp_modes mode)
@@ -644,7 +642,7 @@
{
uint widget_id;
- CreateScenarioWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, NULL, window_number)
+ CreateScenarioWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
{
this->LowerWidget(_opt_newgame.landscape + CSCEN_TEMPERATE);
}
@@ -667,7 +665,7 @@
SetDParam(2, 1 << _patches_newgame.map_y); // CSCEN_MAPSIZE_Y_PULLDOWN
SetDParam(3, _patches_newgame.se_flat_world_height); // CSCEN_FLAT_LAND_HEIGHT_TEXT
- DrawWindowWidgets(this);
+ this->DrawWidgets();
}
virtual void OnClick(Point pt, int widget)
@@ -801,7 +799,6 @@
WC_GENERATE_LANDSCAPE, WC_NONE,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
_create_scenario_widgets,
- NULL,
};
void ShowCreateScenario()
@@ -811,13 +808,20 @@
}
-static const Widget _show_terrain_progress_widgets[] = {
-{ WWT_CAPTION, RESIZE_NONE, 14, 0, 180, 0, 13, STR_GENERATION_WORLD, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_PANEL, RESIZE_NONE, 14, 0, 180, 14, 96, 0x0, STR_NULL},
-{ WWT_TEXTBTN, RESIZE_NONE, 15, 20, 161, 74, 85, STR_GENERATION_ABORT, STR_NULL}, // Abort button
+static const Widget _generate_progress_widgets[] = {
+{ WWT_CAPTION, RESIZE_NONE, 14, 0, 180, 0, 13, STR_GENERATION_WORLD, STR_018C_WINDOW_TITLE_DRAG_THIS}, // GPWW_CAPTION
+{ WWT_PANEL, RESIZE_NONE, 14, 0, 180, 14, 96, 0x0, STR_NULL}, // GPWW_BACKGROUND
+{ WWT_TEXTBTN, RESIZE_NONE, 15, 20, 161, 74, 85, STR_GENERATION_ABORT, STR_NULL}, // GPWW_ABORT
{ WIDGETS_END},
};
+static const WindowDesc _generate_progress_desc = {
+ WDP_CENTER, WDP_CENTER, 181, 97, 181, 97,
+ WC_GENERATE_PROGRESS_WINDOW, WC_NONE,
+ WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
+ _generate_progress_widgets,
+};
+
struct tp_info {
uint percent;
StringID cls;
@@ -837,51 +841,52 @@
}
}
-static void ShowTerrainProgressProc(Window* w, WindowEvent* e)
-{
- switch (e->event) {
- case WE_CLICK:
- switch (e->we.click.widget) {
- case 2:
- if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
- ShowQuery(
- STR_GENERATION_ABORT_CAPTION,
- STR_GENERATION_ABORT_MESSAGE,
- w,
- AbortGeneratingWorldCallback
- );
- break;
- }
- break;
-
- case WE_PAINT:
- DrawWindowWidgets(w);
+struct GenerateProgressWindow : public Window {
+private:
+ enum GenerationProgressWindowWidgets {
+ GPWW_CAPTION,
+ GPWW_BACKGROUND,
+ GPWW_ABORT,
+ };
- /* Draw the % complete with a bar and a text */
- DrawFrameRect(19, 20, (w->width - 18), 37, 14, FR_BORDERONLY);
- DrawFrameRect(20, 21, (int)((w->width - 40) * _tp.percent / 100) + 20, 36, 10, FR_NONE);
- SetDParam(0, _tp.percent);
- DrawStringCentered(90, 25, STR_PROGRESS, TC_FROMSTRING);
-
- /* Tell which class we are generating */
- DrawStringCentered(90, 46, _tp.cls, TC_FROMSTRING);
+public:
+ GenerateProgressWindow() : Window(&_generate_progress_desc) {};
- /* And say where we are in that class */
- SetDParam(0, _tp.current);
- SetDParam(1, _tp.total);
- DrawStringCentered(90, 58, STR_GENERATION_PROGRESS, TC_FROMSTRING);
-
- w->SetDirty();
- break;
+ virtual void OnClick(Point pt, int widget)
+ {
+ switch (widget) {
+ case GPWW_ABORT:
+ if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
+ ShowQuery(
+ STR_GENERATION_ABORT_CAPTION,
+ STR_GENERATION_ABORT_MESSAGE,
+ this,
+ AbortGeneratingWorldCallback
+ );
+ break;
+ }
}
-}
-static const WindowDesc _show_terrain_progress_desc = {
- WDP_CENTER, WDP_CENTER, 181, 97, 181, 97,
- WC_GENERATE_PROGRESS_WINDOW, WC_NONE,
- WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
- _show_terrain_progress_widgets,
- ShowTerrainProgressProc
+ virtual void OnPaint()
+ {
+ this->DrawWidgets();
+
+ /* Draw the % complete with a bar and a text */
+ DrawFrameRect(19, 20, (this->width - 18), 37, 14, FR_BORDERONLY);
+ DrawFrameRect(20, 21, (int)((this->width - 40) * _tp.percent / 100) + 20, 36, 10, FR_NONE);
+ SetDParam(0, _tp.percent);
+ DrawStringCentered(90, 25, STR_PROGRESS, TC_FROMSTRING);
+
+ /* Tell which class we are generating */
+ DrawStringCentered(90, 46, _tp.cls, TC_FROMSTRING);
+
+ /* And say where we are in that class */
+ SetDParam(0, _tp.current);
+ SetDParam(1, _tp.total);
+ DrawStringCentered(90, 58, STR_GENERATION_PROGRESS, TC_FROMSTRING);
+
+ this->SetDirty();
+ }
};
/**
@@ -901,7 +906,8 @@
*/
void ShowGenerateWorldProgress()
{
- AllocateWindowDescFront<Window>(&_show_terrain_progress_desc, 0);
+ if (BringWindowToFrontById(WC_GENERATE_PROGRESS_WINDOW, 0)) return;
+ new GenerateProgressWindow();
}
static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total)