mirror of https://github.com/OpenTTD/OpenTTD
(svn r13042) -Codechange: make a class of CreateScenarioWindow, GenerateLandscapeWindow, NetworkChatWindow, NetworkCompanyPasswordWindow, NetworkGameWindow, NetworkStartServerWindow, QueryStringWindow, SaveLoadWindow. All these classes depended on the 'querystr_d' object which is now put into QueryStringBaseWindow. As a side effect this removes quite a lot of WP macro usages and a few global variables.
parent
e63137f47f
commit
eb2d47b547
|
@ -29,6 +29,7 @@
|
|||
#include "widgets/dropdown_func.h"
|
||||
#include "core/random_func.hpp"
|
||||
#include "landscape_type.h"
|
||||
#include "querystring_gui.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/sprites.h"
|
||||
|
@ -43,14 +44,6 @@ enum glwp_modes {
|
|||
GLWP_END
|
||||
};
|
||||
|
||||
struct generate_d {
|
||||
uint widget_id;
|
||||
uint x;
|
||||
uint y;
|
||||
char name[64];
|
||||
};
|
||||
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(generate_d));
|
||||
|
||||
extern void SwitchMode(int new_mode);
|
||||
|
||||
static inline void SetNewLandscapeType(byte landscape)
|
||||
|
@ -244,72 +237,76 @@ static DropDownList *BuildMapsizeDropDown()
|
|||
return list;
|
||||
}
|
||||
|
||||
static void GenerateLandscapeWndProc(Window *w, WindowEvent *e)
|
||||
{
|
||||
static const StringID elevations[] = {STR_682A_VERY_FLAT, STR_682B_FLAT, STR_682C_HILLY, STR_682D_MOUNTAINOUS, INVALID_STRING_ID};
|
||||
static const StringID sea_lakes[] = {STR_VERY_LOW, STR_6820_LOW, STR_6821_MEDIUM, STR_6822_HIGH, INVALID_STRING_ID};
|
||||
static const StringID smoothness[] = {STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_VERY_ROUGH, INVALID_STRING_ID};
|
||||
static const StringID tree_placer[] = {STR_CONFIG_PATCHES_TREE_PLACER_NONE, STR_CONFIG_PATCHES_TREE_PLACER_ORIGINAL, STR_CONFIG_PATCHES_TREE_PLACER_IMPROVED, INVALID_STRING_ID};
|
||||
static const StringID rotation[] = {STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
|
||||
static const StringID landscape[] = {STR_CONFIG_PATCHES_LAND_GENERATOR_ORIGINAL, STR_CONFIG_PATCHES_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
|
||||
static const StringID num_towns[] = {STR_NUM_VERY_LOW, STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID};
|
||||
static const StringID num_inds[] = {STR_NONE, STR_NUM_VERY_LOW, STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID};
|
||||
static const StringID _elevations[] = {STR_682A_VERY_FLAT, STR_682B_FLAT, STR_682C_HILLY, STR_682D_MOUNTAINOUS, INVALID_STRING_ID};
|
||||
static const StringID _sea_lakes[] = {STR_VERY_LOW, STR_6820_LOW, STR_6821_MEDIUM, STR_6822_HIGH, INVALID_STRING_ID};
|
||||
static const StringID _smoothness[] = {STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_PATCHES_ROUGHNESS_OF_TERRAIN_VERY_ROUGH, INVALID_STRING_ID};
|
||||
static const StringID _tree_placer[] = {STR_CONFIG_PATCHES_TREE_PLACER_NONE, STR_CONFIG_PATCHES_TREE_PLACER_ORIGINAL, STR_CONFIG_PATCHES_TREE_PLACER_IMPROVED, INVALID_STRING_ID};
|
||||
static const StringID _rotation[] = {STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
|
||||
static const StringID _landscape[] = {STR_CONFIG_PATCHES_LAND_GENERATOR_ORIGINAL, STR_CONFIG_PATCHES_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
|
||||
static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID};
|
||||
static const StringID _num_inds[] = {STR_NONE, STR_NUM_VERY_LOW, STR_6816_LOW, STR_6817_NORMAL, STR_6818_HIGH, INVALID_STRING_ID};
|
||||
|
||||
/* Data used for the generate seed edit box */
|
||||
static querystr_d _genseed_query;
|
||||
static char _genseed_buffer[11];
|
||||
struct GenerateLandscapeWindow : public QueryStringBaseWindow {
|
||||
uint widget_id;
|
||||
uint x;
|
||||
uint y;
|
||||
char name[64];
|
||||
glwp_modes mode;
|
||||
|
||||
glwp_modes mode = (glwp_modes)w->window_number;
|
||||
GenerateLandscapeWindow(const WindowDesc *desc, void *data = NULL, WindowNumber number = 0) : QueryStringBaseWindow(desc, NULL, number)
|
||||
{
|
||||
this->LowerWidget(_opt_newgame.landscape + GLAND_TEMPERATE);
|
||||
|
||||
switch (e->event) {
|
||||
case WE_CREATE:
|
||||
w->LowerWidget(_opt_newgame.landscape + GLAND_TEMPERATE);
|
||||
snprintf(this->edit_str_buf, sizeof(this->edit_str_buf), "%u", _patches_newgame.generation_seed);
|
||||
InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 120);
|
||||
this->caption = STR_NULL;
|
||||
this->afilter = CS_NUMERAL;
|
||||
|
||||
snprintf(_genseed_buffer, sizeof(_genseed_buffer), "%u", _patches_newgame.generation_seed);
|
||||
InitializeTextBuffer(&_genseed_query.text, _genseed_buffer, lengthof(_genseed_buffer), 120);
|
||||
_genseed_query.caption = STR_NULL;
|
||||
_genseed_query.afilter = CS_NUMERAL;
|
||||
break;
|
||||
this->mode = (glwp_modes)this->window_number;
|
||||
|
||||
case WE_PAINT:
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
virtual void OnPaint()
|
||||
{
|
||||
/* You can't select smoothness if not terragenesis */
|
||||
if (mode == GLWP_GENERATE) {
|
||||
w->SetWidgetDisabledState(GLAND_SMOOTHNESS_PULLDOWN, _patches_newgame.land_generator == 0);
|
||||
this->SetWidgetDisabledState(GLAND_SMOOTHNESS_PULLDOWN, _patches_newgame.land_generator == 0);
|
||||
}
|
||||
/* Disable snowline if not hilly */
|
||||
w->SetWidgetDisabledState(GLAND_SNOW_LEVEL_TEXT, _opt_newgame.landscape != LT_ARCTIC);
|
||||
this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_TEXT, _opt_newgame.landscape != LT_ARCTIC);
|
||||
/* Disable town, industry and trees in SE */
|
||||
w->SetWidgetDisabledState(GLAND_TOWN_PULLDOWN, _game_mode == GM_EDITOR);
|
||||
w->SetWidgetDisabledState(GLAND_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
|
||||
w->SetWidgetDisabledState(GLAND_TREE_PULLDOWN, _game_mode == GM_EDITOR);
|
||||
this->SetWidgetDisabledState(GLAND_TOWN_PULLDOWN, _game_mode == GM_EDITOR);
|
||||
this->SetWidgetDisabledState(GLAND_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
|
||||
this->SetWidgetDisabledState(GLAND_TREE_PULLDOWN, _game_mode == GM_EDITOR);
|
||||
|
||||
w->SetWidgetDisabledState(GLAND_START_DATE_DOWN, _patches_newgame.starting_year <= MIN_YEAR);
|
||||
w->SetWidgetDisabledState(GLAND_START_DATE_UP, _patches_newgame.starting_year >= MAX_YEAR);
|
||||
w->SetWidgetDisabledState(GLAND_SNOW_LEVEL_DOWN, _patches_newgame.snow_line_height <= 2 || _opt_newgame.landscape != LT_ARCTIC);
|
||||
w->SetWidgetDisabledState(GLAND_SNOW_LEVEL_UP, _patches_newgame.snow_line_height >= MAX_SNOWLINE_HEIGHT || _opt_newgame.landscape != LT_ARCTIC);
|
||||
this->SetWidgetDisabledState(GLAND_START_DATE_DOWN, _patches_newgame.starting_year <= MIN_YEAR);
|
||||
this->SetWidgetDisabledState(GLAND_START_DATE_UP, _patches_newgame.starting_year >= MAX_YEAR);
|
||||
this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_DOWN, _patches_newgame.snow_line_height <= 2 || _opt_newgame.landscape != LT_ARCTIC);
|
||||
this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_UP, _patches_newgame.snow_line_height >= MAX_SNOWLINE_HEIGHT || _opt_newgame.landscape != LT_ARCTIC);
|
||||
|
||||
w->SetWidgetLoweredState(GLAND_TEMPERATE, _opt_newgame.landscape == LT_TEMPERATE);
|
||||
w->SetWidgetLoweredState(GLAND_ARCTIC, _opt_newgame.landscape == LT_ARCTIC);
|
||||
w->SetWidgetLoweredState(GLAND_TROPICAL, _opt_newgame.landscape == LT_TROPIC);
|
||||
w->SetWidgetLoweredState(GLAND_TOYLAND, _opt_newgame.landscape == LT_TOYLAND);
|
||||
this->SetWidgetLoweredState(GLAND_TEMPERATE, _opt_newgame.landscape == LT_TEMPERATE);
|
||||
this->SetWidgetLoweredState(GLAND_ARCTIC, _opt_newgame.landscape == LT_ARCTIC);
|
||||
this->SetWidgetLoweredState(GLAND_TROPICAL, _opt_newgame.landscape == LT_TROPIC);
|
||||
this->SetWidgetLoweredState(GLAND_TOYLAND, _opt_newgame.landscape == LT_TOYLAND);
|
||||
|
||||
if (_game_mode == GM_EDITOR) {
|
||||
w->widget[GLAND_TOWN_PULLDOWN].data = STR_6836_OFF;
|
||||
w->widget[GLAND_INDUSTRY_PULLDOWN].data = STR_6836_OFF;
|
||||
this->widget[GLAND_TOWN_PULLDOWN].data = STR_6836_OFF;
|
||||
this->widget[GLAND_INDUSTRY_PULLDOWN].data = STR_6836_OFF;
|
||||
} else {
|
||||
w->widget[GLAND_TOWN_PULLDOWN].data = num_towns[_opt_newgame.diff.number_towns];
|
||||
w->widget[GLAND_INDUSTRY_PULLDOWN].data = num_inds[_opt_newgame.diff.number_industries];
|
||||
this->widget[GLAND_TOWN_PULLDOWN].data = _num_towns[_opt_newgame.diff.number_towns];
|
||||
this->widget[GLAND_INDUSTRY_PULLDOWN].data = _num_inds[_opt_newgame.diff.number_industries];
|
||||
}
|
||||
|
||||
if (mode == GLWP_GENERATE) {
|
||||
w->widget[GLAND_LANDSCAPE_PULLDOWN].data = landscape[_patches_newgame.land_generator];
|
||||
w->widget[GLAND_TREE_PULLDOWN].data = tree_placer[_patches_newgame.tree_placer];
|
||||
w->widget[GLAND_TERRAIN_PULLDOWN].data = elevations[_opt_newgame.diff.terrain_type];
|
||||
w->widget[GLAND_WATER_PULLDOWN].data = sea_lakes[_opt_newgame.diff.quantity_sea_lakes];
|
||||
w->widget[GLAND_SMOOTHNESS_PULLDOWN].data = smoothness[_patches_newgame.tgen_smoothness];
|
||||
this->widget[GLAND_LANDSCAPE_PULLDOWN].data = _landscape[_patches_newgame.land_generator];
|
||||
this->widget[GLAND_TREE_PULLDOWN].data = _tree_placer[_patches_newgame.tree_placer];
|
||||
this->widget[GLAND_TERRAIN_PULLDOWN].data = _elevations[_opt_newgame.diff.terrain_type];
|
||||
this->widget[GLAND_WATER_PULLDOWN].data = _sea_lakes[_opt_newgame.diff.quantity_sea_lakes];
|
||||
this->widget[GLAND_SMOOTHNESS_PULLDOWN].data = _smoothness[_patches_newgame.tgen_smoothness];
|
||||
} else {
|
||||
w->widget[GLAND_TREE_PULLDOWN].data = tree_placer[_patches_newgame.tree_placer];
|
||||
w->widget[GLAND_HEIGHTMAP_ROTATION_PULLDOWN].data = rotation[_patches_newgame.heightmap_rotation];
|
||||
this->widget[GLAND_TREE_PULLDOWN].data = _tree_placer[_patches_newgame.tree_placer];
|
||||
this->widget[GLAND_HEIGHTMAP_ROTATION_PULLDOWN].data = _rotation[_patches_newgame.heightmap_rotation];
|
||||
}
|
||||
|
||||
/* Set parameters for widget text that requires them. */
|
||||
|
@ -318,66 +315,67 @@ static void GenerateLandscapeWndProc(Window *w, WindowEvent *e)
|
|||
SetDParam(2, 1 << _patches_newgame.map_y); // GLAND_MAPSIZE_Y_PULLDOWN
|
||||
SetDParam(3, _patches_newgame.snow_line_height); // GLAND_SNOW_LEVEL_TEXT
|
||||
|
||||
DrawWindowWidgets(w);
|
||||
DrawWindowWidgets(this);
|
||||
|
||||
DrawEditBox(w, &_genseed_query, GLAND_RANDOM_EDITBOX);
|
||||
this->DrawEditBox(GLAND_RANDOM_EDITBOX);
|
||||
|
||||
if (mode != GLWP_GENERATE) {
|
||||
char buffer[512];
|
||||
|
||||
if (_patches_newgame.heightmap_rotation == HM_CLOCKWISE) {
|
||||
SetDParam(0, WP(w, generate_d).y);
|
||||
SetDParam(1, WP(w, generate_d).x);
|
||||
SetDParam(0, this->y);
|
||||
SetDParam(1, this->x);
|
||||
} else {
|
||||
SetDParam(0, WP(w, generate_d).x);
|
||||
SetDParam(1, WP(w, generate_d).y);
|
||||
SetDParam(0, this->x);
|
||||
SetDParam(1, this->y);
|
||||
}
|
||||
GetString(buffer, STR_HEIGHTMAP_SIZE, lastof(buffer));
|
||||
DrawStringRightAligned(326, 91, STR_HEIGHTMAP_SIZE, TC_BLACK);
|
||||
|
||||
DrawString( 12, 91, STR_HEIGHTMAP_NAME, TC_BLACK);
|
||||
SetDParamStr(0, WP(w, generate_d).name);
|
||||
SetDParamStr(0, this->name);
|
||||
DrawStringTruncated(114, 91, STR_ORANGE, TC_BLACK, 326 - 114 - GetStringBoundingBox(buffer).width - 5);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WE_CLICK:
|
||||
switch (e->we.click.widget) {
|
||||
case 0: delete w; break;
|
||||
virtual void OnClick(Point pt, int widget)
|
||||
{
|
||||
switch (widget) {
|
||||
case 0: delete this; break;
|
||||
|
||||
case GLAND_TEMPERATE:
|
||||
case GLAND_ARCTIC:
|
||||
case GLAND_TROPICAL:
|
||||
case GLAND_TOYLAND:
|
||||
w->RaiseWidget(_opt_newgame.landscape + GLAND_TEMPERATE);
|
||||
SetNewLandscapeType(e->we.click.widget - GLAND_TEMPERATE);
|
||||
this->RaiseWidget(_opt_newgame.landscape + GLAND_TEMPERATE);
|
||||
SetNewLandscapeType(widget - GLAND_TEMPERATE);
|
||||
break;
|
||||
|
||||
case GLAND_MAPSIZE_X_PULLDOWN: // Mapsize X
|
||||
ShowDropDownList(w, BuildMapsizeDropDown(), _patches_newgame.map_x, GLAND_MAPSIZE_X_PULLDOWN);
|
||||
ShowDropDownList(this, BuildMapsizeDropDown(), _patches_newgame.map_x, GLAND_MAPSIZE_X_PULLDOWN);
|
||||
break;
|
||||
|
||||
case GLAND_MAPSIZE_Y_PULLDOWN: // Mapsize Y
|
||||
ShowDropDownList(w, BuildMapsizeDropDown(), _patches_newgame.map_y, GLAND_MAPSIZE_Y_PULLDOWN);
|
||||
ShowDropDownList(this, BuildMapsizeDropDown(), _patches_newgame.map_y, GLAND_MAPSIZE_Y_PULLDOWN);
|
||||
break;
|
||||
|
||||
case GLAND_TOWN_PULLDOWN: // Number of towns
|
||||
ShowDropDownMenu(w, num_towns, _opt_newgame.diff.number_towns, GLAND_TOWN_PULLDOWN, 0, 0);
|
||||
ShowDropDownMenu(this, _num_towns, _opt_newgame.diff.number_towns, GLAND_TOWN_PULLDOWN, 0, 0);
|
||||
break;
|
||||
|
||||
case GLAND_INDUSTRY_PULLDOWN: // Number of industries
|
||||
ShowDropDownMenu(w, num_inds, _opt_newgame.diff.number_industries, GLAND_INDUSTRY_PULLDOWN, 0, 0);
|
||||
ShowDropDownMenu(this, _num_inds, _opt_newgame.diff.number_industries, GLAND_INDUSTRY_PULLDOWN, 0, 0);
|
||||
break;
|
||||
|
||||
case GLAND_RANDOM_BUTTON: // Random seed
|
||||
_patches_newgame.generation_seed = InteractiveRandom();
|
||||
snprintf(_genseed_buffer, lengthof(_genseed_buffer), "%u", _patches_newgame.generation_seed);
|
||||
UpdateTextBufferSize(&_genseed_query.text);
|
||||
w->SetDirty();
|
||||
snprintf(this->edit_str_buf, lengthof(this->edit_str_buf), "%u", _patches_newgame.generation_seed);
|
||||
UpdateTextBufferSize(&this->text);
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case GLAND_RANDOM_EDITBOX: // edit box for random seed
|
||||
ShowOnScreenKeyboard(w, & _genseed_query, GLAND_RANDOM_EDITBOX, 0, 0);
|
||||
ShowOnScreenKeyboard(this, GLAND_RANDOM_EDITBOX, 0, 0);
|
||||
break;
|
||||
|
||||
case GLAND_GENERATE_BUTTON: // Generate
|
||||
|
@ -387,17 +385,17 @@ static void GenerateLandscapeWndProc(Window *w, WindowEvent *e)
|
|||
ShowQuery(
|
||||
STR_TOWN_LAYOUT_WARNING_CAPTION,
|
||||
STR_TOWN_LAYOUT_WARNING_MESSAGE,
|
||||
w,
|
||||
this,
|
||||
LandscapeGenerationCallback);
|
||||
} else if (mode == GLWP_HEIGHTMAP &&
|
||||
(WP(w, generate_d).x * 2 < (1U << _patches_newgame.map_x) ||
|
||||
WP(w, generate_d).x / 2 > (1U << _patches_newgame.map_x) ||
|
||||
WP(w, generate_d).y * 2 < (1U << _patches_newgame.map_y) ||
|
||||
WP(w, generate_d).y / 2 > (1U << _patches_newgame.map_y))) {
|
||||
(this->x * 2 < (1U << _patches_newgame.map_x) ||
|
||||
this->x / 2 > (1U << _patches_newgame.map_x) ||
|
||||
this->y * 2 < (1U << _patches_newgame.map_y) ||
|
||||
this->y / 2 > (1U << _patches_newgame.map_y))) {
|
||||
ShowQuery(
|
||||
STR_HEIGHTMAP_SCALE_WARNING_CAPTION,
|
||||
STR_HEIGHTMAP_SCALE_WARNING_MESSAGE,
|
||||
w,
|
||||
this,
|
||||
LandscapeGenerationCallback);
|
||||
} else {
|
||||
StartGeneratingLandscape(mode);
|
||||
|
@ -407,95 +405,100 @@ static void GenerateLandscapeWndProc(Window *w, WindowEvent *e)
|
|||
case GLAND_START_DATE_DOWN:
|
||||
case GLAND_START_DATE_UP: // Year buttons
|
||||
/* Don't allow too fast scrolling */
|
||||
if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
|
||||
w->HandleButtonClick(e->we.click.widget);
|
||||
w->SetDirty();
|
||||
if ((this->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
|
||||
this->HandleButtonClick(widget);
|
||||
this->SetDirty();
|
||||
|
||||
_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + e->we.click.widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
|
||||
_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
|
||||
}
|
||||
_left_button_clicked = false;
|
||||
break;
|
||||
|
||||
case GLAND_START_DATE_TEXT: // Year text
|
||||
WP(w, generate_d).widget_id = GLAND_START_DATE_TEXT;
|
||||
this->widget_id = GLAND_START_DATE_TEXT;
|
||||
SetDParam(0, _patches_newgame.starting_year);
|
||||
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_START_DATE_QUERY_CAPT, 8, 100, w, CS_NUMERAL);
|
||||
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_START_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL);
|
||||
break;
|
||||
|
||||
case GLAND_SNOW_LEVEL_DOWN:
|
||||
case GLAND_SNOW_LEVEL_UP: // Snow line buttons
|
||||
/* Don't allow too fast scrolling */
|
||||
if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
|
||||
w->HandleButtonClick(e->we.click.widget);
|
||||
w->SetDirty();
|
||||
if ((this->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
|
||||
this->HandleButtonClick(widget);
|
||||
this->SetDirty();
|
||||
|
||||
_patches_newgame.snow_line_height = Clamp(_patches_newgame.snow_line_height + e->we.click.widget - GLAND_SNOW_LEVEL_TEXT, 2, MAX_SNOWLINE_HEIGHT);
|
||||
_patches_newgame.snow_line_height = Clamp(_patches_newgame.snow_line_height + widget - GLAND_SNOW_LEVEL_TEXT, 2, MAX_SNOWLINE_HEIGHT);
|
||||
}
|
||||
_left_button_clicked = false;
|
||||
break;
|
||||
|
||||
case GLAND_SNOW_LEVEL_TEXT: // Snow line text
|
||||
WP(w, generate_d).widget_id = GLAND_SNOW_LEVEL_TEXT;
|
||||
this->widget_id = GLAND_SNOW_LEVEL_TEXT;
|
||||
SetDParam(0, _patches_newgame.snow_line_height);
|
||||
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_SNOW_LINE_QUERY_CAPT, 3, 100, w, CS_NUMERAL);
|
||||
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_SNOW_LINE_QUERY_CAPT, 3, 100, this, CS_NUMERAL);
|
||||
break;
|
||||
|
||||
case GLAND_TREE_PULLDOWN: // Tree placer
|
||||
ShowDropDownMenu(w, tree_placer, _patches_newgame.tree_placer, GLAND_TREE_PULLDOWN, 0, 0);
|
||||
ShowDropDownMenu(this, _tree_placer, _patches_newgame.tree_placer, GLAND_TREE_PULLDOWN, 0, 0);
|
||||
break;
|
||||
|
||||
case GLAND_LANDSCAPE_PULLDOWN: // Landscape generator OR Heightmap rotation
|
||||
/* case GLAND_HEIGHTMAP_ROTATION_TEXT: case GLAND_HEIGHTMAP_ROTATION_PULLDOWN:*/
|
||||
if (mode == GLWP_HEIGHTMAP) {
|
||||
ShowDropDownMenu(w, rotation, _patches_newgame.heightmap_rotation, GLAND_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
|
||||
ShowDropDownMenu(this, _rotation, _patches_newgame.heightmap_rotation, GLAND_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
|
||||
} else {
|
||||
ShowDropDownMenu(w, landscape, _patches_newgame.land_generator, GLAND_LANDSCAPE_PULLDOWN, 0, 0);
|
||||
ShowDropDownMenu(this, _landscape, _patches_newgame.land_generator, GLAND_LANDSCAPE_PULLDOWN, 0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case GLAND_TERRAIN_PULLDOWN: // Terrain type
|
||||
ShowDropDownMenu(w, elevations, _opt_newgame.diff.terrain_type, GLAND_TERRAIN_PULLDOWN, 0, 0);
|
||||
ShowDropDownMenu(this, _elevations, _opt_newgame.diff.terrain_type, GLAND_TERRAIN_PULLDOWN, 0, 0);
|
||||
break;
|
||||
|
||||
case GLAND_WATER_PULLDOWN: // Water quantity
|
||||
ShowDropDownMenu(w, sea_lakes, _opt_newgame.diff.quantity_sea_lakes, GLAND_WATER_PULLDOWN, 0, 0);
|
||||
ShowDropDownMenu(this, _sea_lakes, _opt_newgame.diff.quantity_sea_lakes, GLAND_WATER_PULLDOWN, 0, 0);
|
||||
break;
|
||||
|
||||
case GLAND_SMOOTHNESS_PULLDOWN: // Map smoothness
|
||||
ShowDropDownMenu(w, smoothness, _patches_newgame.tgen_smoothness, GLAND_SMOOTHNESS_PULLDOWN, 0, 0);
|
||||
ShowDropDownMenu(this, _smoothness, _patches_newgame.tgen_smoothness, GLAND_SMOOTHNESS_PULLDOWN, 0, 0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WE_MOUSELOOP:
|
||||
HandleEditBox(w, &_genseed_query, GLAND_RANDOM_EDITBOX);
|
||||
break;
|
||||
virtual void OnMouseLoop()
|
||||
{
|
||||
this->HandleEditBox(GLAND_RANDOM_EDITBOX);
|
||||
}
|
||||
|
||||
case WE_KEYPRESS:
|
||||
HandleEditBoxKey(w, &_genseed_query, GLAND_RANDOM_EDITBOX, e);
|
||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
||||
{
|
||||
bool cont;
|
||||
this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, cont);
|
||||
/* 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(_genseed_buffer, NULL, sizeof(_genseed_buffer) - 1), MAX_UVALUE(uint32) - 1);
|
||||
break;
|
||||
_patches_newgame.generation_seed = minu(strtoul(this->edit_str_buf, NULL, sizeof(this->edit_str_buf) - 1), MAX_UVALUE(uint32) - 1);
|
||||
return cont;
|
||||
}
|
||||
|
||||
case WE_DROPDOWN_SELECT:
|
||||
switch (e->we.dropdown.button) {
|
||||
case GLAND_MAPSIZE_X_PULLDOWN: _patches_newgame.map_x = e->we.dropdown.index; break;
|
||||
case GLAND_MAPSIZE_Y_PULLDOWN: _patches_newgame.map_y = e->we.dropdown.index; break;
|
||||
case GLAND_TREE_PULLDOWN: _patches_newgame.tree_placer = e->we.dropdown.index; break;
|
||||
case GLAND_SMOOTHNESS_PULLDOWN: _patches_newgame.tgen_smoothness = e->we.dropdown.index; break;
|
||||
virtual void OnDropdownSelect(int widget, int index)
|
||||
{
|
||||
switch (widget) {
|
||||
case GLAND_MAPSIZE_X_PULLDOWN: _patches_newgame.map_x = index; break;
|
||||
case GLAND_MAPSIZE_Y_PULLDOWN: _patches_newgame.map_y = index; break;
|
||||
case GLAND_TREE_PULLDOWN: _patches_newgame.tree_placer = index; break;
|
||||
case GLAND_SMOOTHNESS_PULLDOWN: _patches_newgame.tgen_smoothness = index; break;
|
||||
|
||||
case GLAND_TOWN_PULLDOWN:
|
||||
_opt_newgame.diff.number_towns = e->we.dropdown.index;
|
||||
_opt_newgame.diff.number_towns = index;
|
||||
if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
|
||||
DoCommandP(0, 2, _opt_newgame.diff.number_towns, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
|
||||
break;
|
||||
|
||||
case GLAND_INDUSTRY_PULLDOWN:
|
||||
_opt_newgame.diff.number_industries = e->we.dropdown.index;
|
||||
_opt_newgame.diff.number_industries = index;
|
||||
if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
|
||||
DoCommandP(0, 3, _opt_newgame.diff.number_industries, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
|
||||
break;
|
||||
|
@ -503,55 +506,55 @@ static void GenerateLandscapeWndProc(Window *w, WindowEvent *e)
|
|||
case GLAND_LANDSCAPE_PULLDOWN:
|
||||
/* case GLAND_HEIGHTMAP_PULLDOWN: */
|
||||
if (mode == GLWP_HEIGHTMAP) {
|
||||
_patches_newgame.heightmap_rotation = e->we.dropdown.index;
|
||||
_patches_newgame.heightmap_rotation = index;
|
||||
} else {
|
||||
_patches_newgame.land_generator = e->we.dropdown.index;
|
||||
_patches_newgame.land_generator = index;
|
||||
}
|
||||
break;
|
||||
|
||||
case GLAND_TERRAIN_PULLDOWN:
|
||||
_opt_newgame.diff.terrain_type = e->we.dropdown.index;
|
||||
_opt_newgame.diff.terrain_type = index;
|
||||
if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
|
||||
DoCommandP(0, 12, _opt_newgame.diff.terrain_type, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
|
||||
break;
|
||||
|
||||
case GLAND_WATER_PULLDOWN:
|
||||
_opt_newgame.diff.quantity_sea_lakes = e->we.dropdown.index;
|
||||
_opt_newgame.diff.quantity_sea_lakes = index;
|
||||
if (_opt_newgame.diff_level != 3) ShowErrorMessage(INVALID_STRING_ID, STR_DIFFICULTY_TO_CUSTOM, 0, 0);
|
||||
DoCommandP(0, 13, _opt_newgame.diff.quantity_sea_lakes, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
|
||||
break;
|
||||
}
|
||||
w->SetDirty();
|
||||
break;
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
case WE_ON_EDIT_TEXT:
|
||||
if (!StrEmpty(e->we.edittext.str)) {
|
||||
int32 value = atoi(e->we.edittext.str);
|
||||
virtual void OnQueryTextFinished(char *str)
|
||||
{
|
||||
if (!StrEmpty(str)) {
|
||||
int32 value = atoi(str);
|
||||
|
||||
switch (WP(w, generate_d).widget_id) {
|
||||
switch (this->widget_id) {
|
||||
case GLAND_START_DATE_TEXT:
|
||||
w->InvalidateWidget(GLAND_START_DATE_TEXT);
|
||||
this->InvalidateWidget(GLAND_START_DATE_TEXT);
|
||||
_patches_newgame.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
|
||||
break;
|
||||
|
||||
case GLAND_SNOW_LEVEL_TEXT:
|
||||
w->InvalidateWidget(GLAND_SNOW_LEVEL_TEXT);
|
||||
this->InvalidateWidget(GLAND_SNOW_LEVEL_TEXT);
|
||||
_patches_newgame.snow_line_height = Clamp(value, 2, MAX_SNOWLINE_HEIGHT);
|
||||
break;
|
||||
}
|
||||
|
||||
w->SetDirty();
|
||||
this->SetDirty();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const WindowDesc _generate_landscape_desc = {
|
||||
WDP_CENTER, WDP_CENTER, 338, 268, 338, 268,
|
||||
WC_GENERATE_LANDSCAPE, WC_NONE,
|
||||
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
||||
_generate_landscape_widgets,
|
||||
GenerateLandscapeWndProc,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const WindowDesc _heightmap_load_desc = {
|
||||
|
@ -559,7 +562,7 @@ static const WindowDesc _heightmap_load_desc = {
|
|||
WC_GENERATE_LANDSCAPE, WC_NONE,
|
||||
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
|
||||
_heightmap_load_widgets,
|
||||
GenerateLandscapeWndProc,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static void _ShowGenerateLandscape(glwp_modes mode)
|
||||
|
@ -577,14 +580,12 @@ static void _ShowGenerateLandscape(glwp_modes mode)
|
|||
if (!GetHeightmapDimensions(_file_to_saveload.name, &x, &y)) return;
|
||||
}
|
||||
|
||||
Window *w = AllocateWindowDescFront<Window>((mode == GLWP_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode);
|
||||
|
||||
if (w == NULL) return;
|
||||
GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>((mode == GLWP_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode);
|
||||
|
||||
if (mode == GLWP_HEIGHTMAP) {
|
||||
WP(w, generate_d).x = x;
|
||||
WP(w, generate_d).y = y;
|
||||
strecpy(WP(w, generate_d).name, _file_to_saveload.title, lastof(WP(w, generate_d).name));
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
strecpy(w->name, _file_to_saveload.title, lastof(w->name));
|
||||
}
|
||||
|
||||
InvalidateWindow(WC_GENERATE_LANDSCAPE, mode);
|
||||
|
@ -639,23 +640,26 @@ enum CreateScenarioWindowWidgets {
|
|||
};
|
||||
|
||||
|
||||
static void CreateScenarioWndProc(Window *w, WindowEvent *e)
|
||||
struct CreateScenarioWindow : public Window
|
||||
{
|
||||
switch (e->event) {
|
||||
case WE_CREATE:
|
||||
w->LowerWidget(_opt_newgame.landscape + CSCEN_TEMPERATE);
|
||||
break;
|
||||
uint widget_id;
|
||||
|
||||
case WE_PAINT:
|
||||
w->SetWidgetDisabledState(CSCEN_START_DATE_DOWN, _patches_newgame.starting_year <= MIN_YEAR);
|
||||
w->SetWidgetDisabledState(CSCEN_START_DATE_UP, _patches_newgame.starting_year >= MAX_YEAR);
|
||||
w->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_DOWN, _patches_newgame.se_flat_world_height <= 0);
|
||||
w->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_UP, _patches_newgame.se_flat_world_height >= MAX_TILE_HEIGHT);
|
||||
CreateScenarioWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, NULL, window_number)
|
||||
{
|
||||
this->LowerWidget(_opt_newgame.landscape + CSCEN_TEMPERATE);
|
||||
}
|
||||
|
||||
w->SetWidgetLoweredState(CSCEN_TEMPERATE, _opt_newgame.landscape == LT_TEMPERATE);
|
||||
w->SetWidgetLoweredState(CSCEN_ARCTIC, _opt_newgame.landscape == LT_ARCTIC);
|
||||
w->SetWidgetLoweredState(CSCEN_TROPICAL, _opt_newgame.landscape == LT_TROPIC);
|
||||
w->SetWidgetLoweredState(CSCEN_TOYLAND, _opt_newgame.landscape == LT_TOYLAND);
|
||||
virtual void OnPaint()
|
||||
{
|
||||
this->SetWidgetDisabledState(CSCEN_START_DATE_DOWN, _patches_newgame.starting_year <= MIN_YEAR);
|
||||
this->SetWidgetDisabledState(CSCEN_START_DATE_UP, _patches_newgame.starting_year >= MAX_YEAR);
|
||||
this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_DOWN, _patches_newgame.se_flat_world_height <= 0);
|
||||
this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_UP, _patches_newgame.se_flat_world_height >= MAX_TILE_HEIGHT);
|
||||
|
||||
this->SetWidgetLoweredState(CSCEN_TEMPERATE, _opt_newgame.landscape == LT_TEMPERATE);
|
||||
this->SetWidgetLoweredState(CSCEN_ARCTIC, _opt_newgame.landscape == LT_ARCTIC);
|
||||
this->SetWidgetLoweredState(CSCEN_TROPICAL, _opt_newgame.landscape == LT_TROPIC);
|
||||
this->SetWidgetLoweredState(CSCEN_TOYLAND, _opt_newgame.landscape == LT_TOYLAND);
|
||||
|
||||
/* Set parameters for widget text that requires them */
|
||||
SetDParam(0, ConvertYMDToDate(_patches_newgame.starting_year, 0, 1)); // CSCEN_START_DATE_TEXT
|
||||
|
@ -663,26 +667,26 @@ static void CreateScenarioWndProc(Window *w, WindowEvent *e)
|
|||
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(w);
|
||||
DrawWindowWidgets(this);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WE_CLICK:
|
||||
switch (e->we.click.widget) {
|
||||
virtual void OnClick(Point pt, int widget)
|
||||
{
|
||||
switch (widget) {
|
||||
case CSCEN_TEMPERATE:
|
||||
case CSCEN_ARCTIC:
|
||||
case CSCEN_TROPICAL:
|
||||
case CSCEN_TOYLAND:
|
||||
w->RaiseWidget(_opt_newgame.landscape + CSCEN_TEMPERATE);
|
||||
SetNewLandscapeType(e->we.click.widget - CSCEN_TEMPERATE);
|
||||
this->RaiseWidget(_opt_newgame.landscape + CSCEN_TEMPERATE);
|
||||
SetNewLandscapeType(widget - CSCEN_TEMPERATE);
|
||||
break;
|
||||
|
||||
case CSCEN_MAPSIZE_X_PULLDOWN: // Mapsize X
|
||||
ShowDropDownList(w, BuildMapsizeDropDown(), _patches_newgame.map_x, CSCEN_MAPSIZE_X_PULLDOWN);
|
||||
ShowDropDownList(this, BuildMapsizeDropDown(), _patches_newgame.map_x, CSCEN_MAPSIZE_X_PULLDOWN);
|
||||
break;
|
||||
|
||||
case CSCEN_MAPSIZE_Y_PULLDOWN: // Mapsize Y
|
||||
ShowDropDownList(w, BuildMapsizeDropDown(), _patches_newgame.map_y, CSCEN_MAPSIZE_Y_PULLDOWN);
|
||||
ShowDropDownList(this, BuildMapsizeDropDown(), _patches_newgame.map_y, CSCEN_MAPSIZE_Y_PULLDOWN);
|
||||
break;
|
||||
|
||||
case CSCEN_EMPTY_WORLD: // Empty world / flat world
|
||||
|
@ -696,70 +700,71 @@ static void CreateScenarioWndProc(Window *w, WindowEvent *e)
|
|||
case CSCEN_START_DATE_DOWN:
|
||||
case CSCEN_START_DATE_UP: // Year buttons
|
||||
/* Don't allow too fast scrolling */
|
||||
if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
|
||||
w->HandleButtonClick(e->we.click.widget);
|
||||
w->SetDirty();
|
||||
if ((this->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
|
||||
this->HandleButtonClick(widget);
|
||||
this->SetDirty();
|
||||
|
||||
_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + e->we.click.widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
|
||||
_patches_newgame.starting_year = Clamp(_patches_newgame.starting_year + widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
|
||||
}
|
||||
_left_button_clicked = false;
|
||||
break;
|
||||
|
||||
case CSCEN_START_DATE_TEXT: // Year text
|
||||
WP(w, generate_d).widget_id = CSCEN_START_DATE_TEXT;
|
||||
this->widget_id = CSCEN_START_DATE_TEXT;
|
||||
SetDParam(0, _patches_newgame.starting_year);
|
||||
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_START_DATE_QUERY_CAPT, 8, 100, w, CS_NUMERAL);
|
||||
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_START_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL);
|
||||
break;
|
||||
|
||||
case CSCEN_FLAT_LAND_HEIGHT_DOWN:
|
||||
case CSCEN_FLAT_LAND_HEIGHT_UP: // Height level buttons
|
||||
/* Don't allow too fast scrolling */
|
||||
if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
|
||||
w->HandleButtonClick(e->we.click.widget);
|
||||
w->SetDirty();
|
||||
if ((this->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
|
||||
this->HandleButtonClick(widget);
|
||||
this->SetDirty();
|
||||
|
||||
_patches_newgame.se_flat_world_height = Clamp(_patches_newgame.se_flat_world_height + e->we.click.widget - CSCEN_FLAT_LAND_HEIGHT_TEXT, 0, MAX_TILE_HEIGHT);
|
||||
_patches_newgame.se_flat_world_height = Clamp(_patches_newgame.se_flat_world_height + widget - CSCEN_FLAT_LAND_HEIGHT_TEXT, 0, MAX_TILE_HEIGHT);
|
||||
}
|
||||
_left_button_clicked = false;
|
||||
break;
|
||||
|
||||
case CSCEN_FLAT_LAND_HEIGHT_TEXT: // Height level text
|
||||
WP(w, generate_d).widget_id = CSCEN_FLAT_LAND_HEIGHT_TEXT;
|
||||
this->widget_id = CSCEN_FLAT_LAND_HEIGHT_TEXT;
|
||||
SetDParam(0, _patches_newgame.se_flat_world_height);
|
||||
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_FLAT_WORLD_HEIGHT_QUERY_CAPT, 3, 100, w, CS_NUMERAL);
|
||||
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_FLAT_WORLD_HEIGHT_QUERY_CAPT, 3, 100, this, CS_NUMERAL);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_DROPDOWN_SELECT:
|
||||
switch (e->we.dropdown.button) {
|
||||
case CSCEN_MAPSIZE_X_PULLDOWN: _patches_newgame.map_x = e->we.dropdown.index; break;
|
||||
case CSCEN_MAPSIZE_Y_PULLDOWN: _patches_newgame.map_y = e->we.dropdown.index; break;
|
||||
}
|
||||
w->SetDirty();
|
||||
break;
|
||||
|
||||
case WE_ON_EDIT_TEXT:
|
||||
if (!StrEmpty(e->we.edittext.str)) {
|
||||
int32 value = atoi(e->we.edittext.str);
|
||||
virtual void OnDropdownSelect(int widget, int index)
|
||||
{
|
||||
switch (widget) {
|
||||
case CSCEN_MAPSIZE_X_PULLDOWN: _patches_newgame.map_x = index; break;
|
||||
case CSCEN_MAPSIZE_Y_PULLDOWN: _patches_newgame.map_y = index; break;
|
||||
}
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
switch (WP(w, generate_d).widget_id) {
|
||||
virtual void OnQueryTextFinished(char *str)
|
||||
{
|
||||
if (!StrEmpty(str)) {
|
||||
int32 value = atoi(str);
|
||||
|
||||
switch (this->widget_id) {
|
||||
case CSCEN_START_DATE_TEXT:
|
||||
w->InvalidateWidget(CSCEN_START_DATE_TEXT);
|
||||
this->InvalidateWidget(CSCEN_START_DATE_TEXT);
|
||||
_patches_newgame.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
|
||||
break;
|
||||
|
||||
case CSCEN_FLAT_LAND_HEIGHT_TEXT:
|
||||
w->InvalidateWidget(CSCEN_FLAT_LAND_HEIGHT_TEXT);
|
||||
this->InvalidateWidget(CSCEN_FLAT_LAND_HEIGHT_TEXT);
|
||||
_patches_newgame.se_flat_world_height = Clamp(value, 0, MAX_TILE_HEIGHT);
|
||||
break;
|
||||
}
|
||||
|
||||
w->SetDirty();
|
||||
this->SetDirty();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const Widget _create_scenario_widgets[] = {
|
||||
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
||||
|
@ -796,13 +801,13 @@ static const WindowDesc _create_scenario_desc = {
|
|||
WC_GENERATE_LANDSCAPE, WC_NONE,
|
||||
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
|
||||
_create_scenario_widgets,
|
||||
CreateScenarioWndProc,
|
||||
NULL,
|
||||
};
|
||||
|
||||
void ShowCreateScenario()
|
||||
{
|
||||
DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
|
||||
AllocateWindowDescFront<Window>(&_create_scenario_desc, GLWP_SCENARIO);
|
||||
new CreateScenarioWindow(&_create_scenario_desc, GLWP_SCENARIO);
|
||||
}
|
||||
|
||||
|
||||
|
|
482
src/misc_gui.cpp
482
src/misc_gui.cpp
|
@ -44,6 +44,7 @@
|
|||
#include "newgrf_cargo.h"
|
||||
#include "rail_gui.h"
|
||||
#include "tilehighlight_func.h"
|
||||
#include "querystring_gui.h"
|
||||
|
||||
#include "table/sprites.h"
|
||||
#include "table/strings.h"
|
||||
|
@ -878,43 +879,6 @@ void UpdateTextBufferSize(Textbuf *tb)
|
|||
tb->caretxoffs = tb->width;
|
||||
}
|
||||
|
||||
int HandleEditBoxKey(Window *w, querystr_d *string, int wid, WindowEvent *e)
|
||||
{
|
||||
e->we.keypress.cont = false;
|
||||
|
||||
switch (e->we.keypress.keycode) {
|
||||
case WKC_ESC: return 2;
|
||||
|
||||
case WKC_RETURN: case WKC_NUM_ENTER: return 1;
|
||||
|
||||
case (WKC_CTRL | 'V'):
|
||||
if (InsertTextBufferClipboard(&string->text)) w->InvalidateWidget(wid);
|
||||
break;
|
||||
|
||||
case (WKC_CTRL | 'U'):
|
||||
DeleteTextBufferAll(&string->text);
|
||||
w->InvalidateWidget(wid);
|
||||
break;
|
||||
|
||||
case WKC_BACKSPACE: case WKC_DELETE:
|
||||
if (DeleteTextBufferChar(&string->text, e->we.keypress.keycode)) w->InvalidateWidget(wid);
|
||||
break;
|
||||
|
||||
case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
|
||||
if (MoveTextBufferPos(&string->text, e->we.keypress.keycode)) w->InvalidateWidget(wid);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (IsValidChar(e->we.keypress.key, string->afilter)) {
|
||||
if (InsertTextBufferChar(&string->text, e->we.keypress.key)) w->InvalidateWidget(wid);
|
||||
} else { // key wasn't caught. Continue only if standard entry specified
|
||||
e->we.keypress.cont = (string->afilter == CS_ALPHANUMERAL);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool HandleCaret(Textbuf *tb)
|
||||
{
|
||||
/* caret changed? */
|
||||
|
@ -927,12 +891,49 @@ bool HandleCaret(Textbuf *tb)
|
|||
return false;
|
||||
}
|
||||
|
||||
void HandleEditBox(Window *w, querystr_d *string, int wid)
|
||||
int QueryString::HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, bool &cont)
|
||||
{
|
||||
if (HandleCaret(&string->text)) w->InvalidateWidget(wid);
|
||||
cont = false;
|
||||
|
||||
switch (keycode) {
|
||||
case WKC_ESC: return 2;
|
||||
|
||||
case WKC_RETURN: case WKC_NUM_ENTER: return 1;
|
||||
|
||||
case (WKC_CTRL | 'V'):
|
||||
if (InsertTextBufferClipboard(&this->text)) w->InvalidateWidget(wid);
|
||||
break;
|
||||
|
||||
case (WKC_CTRL | 'U'):
|
||||
DeleteTextBufferAll(&this->text);
|
||||
w->InvalidateWidget(wid);
|
||||
break;
|
||||
|
||||
case WKC_BACKSPACE: case WKC_DELETE:
|
||||
if (DeleteTextBufferChar(&this->text, keycode)) w->InvalidateWidget(wid);
|
||||
break;
|
||||
|
||||
case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
|
||||
if (MoveTextBufferPos(&this->text, keycode)) w->InvalidateWidget(wid);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (IsValidChar(key, this->afilter)) {
|
||||
if (InsertTextBufferChar(&this->text, key)) w->InvalidateWidget(wid);
|
||||
} else { // key wasn't caught. Continue only if standard entry specified
|
||||
cont = (this->afilter == CS_ALPHANUMERAL);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DrawEditBox(Window *w, querystr_d *string, int wid)
|
||||
void QueryString::HandleEditBox(Window *w, int wid)
|
||||
{
|
||||
if (HandleCaret(&this->text)) w->InvalidateWidget(wid);
|
||||
}
|
||||
|
||||
void QueryString::DrawEditBox(Window *w, int wid)
|
||||
{
|
||||
const Widget *wi = &w->widget[wid];
|
||||
|
||||
|
@ -957,7 +958,7 @@ void DrawEditBox(Window *w, querystr_d *string, int wid)
|
|||
|
||||
/* We will take the current widget length as maximum width, with a small
|
||||
* space reserved at the end for the caret to show */
|
||||
const Textbuf *tb = &string->text;
|
||||
const Textbuf *tb = &this->text;
|
||||
|
||||
delta = (wi->right - wi->left) - tb->width - 10;
|
||||
if (delta > 0) delta = 0;
|
||||
|
@ -970,6 +971,21 @@ void DrawEditBox(Window *w, querystr_d *string, int wid)
|
|||
_cur_dpi = old_dpi;
|
||||
}
|
||||
|
||||
int QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode, bool &cont)
|
||||
{
|
||||
return this->QueryString::HandleEditBoxKey(this, wid, key, keycode, cont);
|
||||
}
|
||||
|
||||
void QueryStringBaseWindow::HandleEditBox(int wid)
|
||||
{
|
||||
this->QueryString::HandleEditBox(this, wid);
|
||||
}
|
||||
|
||||
void QueryStringBaseWindow::DrawEditBox(int wid)
|
||||
{
|
||||
this->QueryString::DrawEditBox(this, wid);
|
||||
}
|
||||
|
||||
enum QueryStringWidgets {
|
||||
QUERY_STR_WIDGET_TEXT = 3,
|
||||
QUERY_STR_WIDGET_CANCEL,
|
||||
|
@ -977,69 +993,79 @@ enum QueryStringWidgets {
|
|||
};
|
||||
|
||||
|
||||
static void QueryStringWndProc(Window *w, WindowEvent *e)
|
||||
struct QueryStringWindow : public QueryStringBaseWindow
|
||||
{
|
||||
querystr_d *qs = &WP(w, querystr_d);
|
||||
Window *parent;
|
||||
|
||||
switch (e->event) {
|
||||
case WE_CREATE:
|
||||
QueryStringWindow(const WindowDesc *desc, Window *parent) : QueryStringBaseWindow(desc), parent(parent)
|
||||
{
|
||||
SetBit(_no_scroll, SCROLL_EDIT);
|
||||
break;
|
||||
|
||||
case WE_PAINT:
|
||||
SetDParam(0, qs->caption);
|
||||
DrawWindowWidgets(w);
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
DrawEditBox(w, qs, QUERY_STR_WIDGET_TEXT);
|
||||
break;
|
||||
virtual void OnPaint()
|
||||
{
|
||||
SetDParam(0, this->caption);
|
||||
DrawWindowWidgets(this);
|
||||
|
||||
case WE_CLICK:
|
||||
switch (e->we.click.widget) {
|
||||
this->DrawEditBox(QUERY_STR_WIDGET_TEXT);
|
||||
}
|
||||
|
||||
void OnOk()
|
||||
{
|
||||
if (this->orig == NULL || strcmp(this->text.buf, this->orig) != 0) {
|
||||
/* If the parent is NULL, the editbox is handled by general function
|
||||
* HandleOnEditText */
|
||||
if (this->parent != NULL) {
|
||||
this->parent->OnQueryTextFinished(this->text.buf);
|
||||
} else {
|
||||
HandleOnEditText(this->text.buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget)
|
||||
{
|
||||
switch (widget) {
|
||||
case QUERY_STR_WIDGET_TEXT:
|
||||
ShowOnScreenKeyboard(w, &WP(w, querystr_d), QUERY_STR_WIDGET_TEXT, QUERY_STR_WIDGET_CANCEL, QUERY_STR_WIDGET_OK);
|
||||
ShowOnScreenKeyboard(this, QUERY_STR_WIDGET_TEXT, QUERY_STR_WIDGET_CANCEL, QUERY_STR_WIDGET_OK);
|
||||
break;
|
||||
|
||||
case QUERY_STR_WIDGET_OK:
|
||||
press_ok:;
|
||||
if (qs->orig == NULL || strcmp(qs->text.buf, qs->orig) != 0) {
|
||||
Window *parent = w->parent;
|
||||
qs->handled = true;
|
||||
|
||||
/* If the parent is NULL, the editbox is handled by general function
|
||||
* HandleOnEditText */
|
||||
if (parent != NULL) {
|
||||
parent->OnQueryTextFinished(qs->text.buf);
|
||||
} else {
|
||||
HandleOnEditText(qs->text.buf);
|
||||
}
|
||||
}
|
||||
this->OnOk();
|
||||
/* Fallthrough */
|
||||
case QUERY_STR_WIDGET_CANCEL:
|
||||
delete w;
|
||||
delete this;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_MOUSELOOP:
|
||||
HandleEditBox(w, qs, QUERY_STR_WIDGET_TEXT);
|
||||
break;
|
||||
|
||||
case WE_KEYPRESS:
|
||||
switch (HandleEditBoxKey(w, qs, QUERY_STR_WIDGET_TEXT, e)) {
|
||||
case 1: goto press_ok; // Enter pressed, confirms change
|
||||
case 2: delete w; break; // ESC pressed, closes window, abandons changes
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_DESTROY: // Call cancellation of query, if we have not handled it before
|
||||
if (!qs->handled && w->parent != NULL) {
|
||||
qs->handled = true;
|
||||
w->parent->OnQueryTextFinished(NULL);
|
||||
virtual void OnMouseLoop()
|
||||
{
|
||||
this->HandleEditBox(QUERY_STR_WIDGET_TEXT);
|
||||
}
|
||||
|
||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
||||
{
|
||||
bool cont;
|
||||
switch (this->HandleEditBoxKey(QUERY_STR_WIDGET_TEXT, key, keycode, cont)) {
|
||||
case 1: this->OnOk(); // Enter pressed, confirms change
|
||||
/* FALL THROUGH */
|
||||
case 2: delete this; break; // ESC pressed, closes window, abandons changes
|
||||
}
|
||||
return cont;
|
||||
}
|
||||
|
||||
~QueryStringWindow()
|
||||
{
|
||||
if (!this->handled && this->parent != NULL) {
|
||||
this->handled = true;
|
||||
this->parent->OnQueryTextFinished(NULL);
|
||||
}
|
||||
ClrBit(_no_scroll, SCROLL_EDIT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const Widget _query_string_widgets[] = {
|
||||
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
||||
|
@ -1056,12 +1082,9 @@ static const WindowDesc _query_string_desc = {
|
|||
WC_QUERY_STRING, WC_NONE,
|
||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
||||
_query_string_widgets,
|
||||
QueryStringWndProc
|
||||
NULL
|
||||
};
|
||||
|
||||
char _edit_str_buf[64];
|
||||
char _orig_str_buf[lengthof(_edit_str_buf)];
|
||||
|
||||
/** Show a query popup window with a textbox in it.
|
||||
* @param str StringID for the text shown in the textbox
|
||||
* @param caption StringID of text shown in caption of querywindow
|
||||
|
@ -1075,28 +1098,27 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth,
|
|||
{
|
||||
uint realmaxlen = maxlen & ~0x1000;
|
||||
|
||||
assert(realmaxlen < lengthof(_edit_str_buf));
|
||||
|
||||
DeleteWindowById(WC_QUERY_STRING, 0);
|
||||
DeleteWindowById(WC_SAVELOAD, 0);
|
||||
|
||||
Window *w = new Window(&_query_string_desc);
|
||||
w->parent = parent;
|
||||
QueryStringWindow *w = new QueryStringWindow(&_query_string_desc, parent);
|
||||
|
||||
GetString(_edit_str_buf, str, lastof(_edit_str_buf));
|
||||
_edit_str_buf[realmaxlen - 1] = '\0';
|
||||
assert(realmaxlen < lengthof(w->edit_str_buf));
|
||||
|
||||
GetString(w->edit_str_buf, str, lastof(w->edit_str_buf));
|
||||
w->edit_str_buf[realmaxlen - 1] = '\0';
|
||||
|
||||
if (maxlen & 0x1000) {
|
||||
WP(w, querystr_d).orig = NULL;
|
||||
w->orig = NULL;
|
||||
} else {
|
||||
strecpy(_orig_str_buf, _edit_str_buf, lastof(_orig_str_buf));
|
||||
WP(w, querystr_d).orig = _orig_str_buf;
|
||||
strecpy(w->orig_str_buf, w->edit_str_buf, lastof(w->orig_str_buf));
|
||||
w->orig = w->orig_str_buf;
|
||||
}
|
||||
|
||||
w->LowerWidget(QUERY_STR_WIDGET_TEXT);
|
||||
WP(w, querystr_d).caption = caption;
|
||||
WP(w, querystr_d).afilter = afilter;
|
||||
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, realmaxlen, maxwidth);
|
||||
w->caption = caption;
|
||||
w->afilter = afilter;
|
||||
InitializeTextBuffer(&w->text, w->edit_str_buf, realmaxlen, maxwidth);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1306,29 +1328,61 @@ static void MakeSortedSaveGameList()
|
|||
}
|
||||
}
|
||||
|
||||
static void GenerateFileName()
|
||||
{
|
||||
extern void StartupEngines();
|
||||
|
||||
struct SaveLoadWindow : public QueryStringBaseWindow {
|
||||
FiosItem o_dir;
|
||||
|
||||
void GenerateFileName()
|
||||
{
|
||||
/* Check if we are not a spectator who wants to generate a name..
|
||||
Let's use the name of player #0 for now. */
|
||||
const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
|
||||
|
||||
SetDParam(0, p->index);
|
||||
SetDParam(1, _date);
|
||||
GetString(_edit_str_buf, STR_4004, lastof(_edit_str_buf));
|
||||
SanitizeFilename(_edit_str_buf);
|
||||
}
|
||||
GetString(this->edit_str_buf, STR_4004, lastof(this->edit_str_buf));
|
||||
SanitizeFilename(this->edit_str_buf);
|
||||
}
|
||||
|
||||
extern void StartupEngines();
|
||||
SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(desc)
|
||||
{
|
||||
static const StringID saveload_captions[] = {
|
||||
STR_4001_LOAD_GAME,
|
||||
STR_0298_LOAD_SCENARIO,
|
||||
STR_4000_SAVE_GAME,
|
||||
STR_0299_SAVE_SCENARIO,
|
||||
STR_LOAD_HEIGHTMAP,
|
||||
};
|
||||
|
||||
static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
|
||||
{
|
||||
static FiosItem o_dir;
|
||||
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
|
||||
SetBit(_no_scroll, SCROLL_SAVE);
|
||||
|
||||
switch (e->event) {
|
||||
case WE_CREATE: // Set up OPENTTD button
|
||||
w->vscroll.cap = 10;
|
||||
w->resize.step_width = 2;
|
||||
w->resize.step_height = 10;
|
||||
/* Use an array to define what will be the current file type being handled
|
||||
* by current file mode */
|
||||
switch (mode) {
|
||||
case SLD_SAVE_GAME: this->GenerateFileName(); break;
|
||||
case SLD_SAVE_SCENARIO: strcpy(this->edit_str_buf, "UNNAMED"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
assert((uint)mode < lengthof(saveload_captions));
|
||||
|
||||
this->widget[1].data = saveload_captions[mode];
|
||||
this->LowerWidget(7);
|
||||
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 240);
|
||||
|
||||
/* pause is only used in single-player, non-editor mode, non-menu mode. It
|
||||
* will be unpaused in the WE_DESTROY event handler. */
|
||||
if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) {
|
||||
if (_pause_game >= 0) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
|
||||
}
|
||||
|
||||
BuildFileList();
|
||||
|
||||
ResetObjectToPlace();
|
||||
|
||||
o_dir.type = FIOS_TYPE_DIRECT;
|
||||
switch (_saveload_mode) {
|
||||
|
@ -1349,67 +1403,84 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
|
|||
default:
|
||||
ttd_strlcpy(o_dir.name, _personal_dir, lengthof(o_dir.name));
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_PAINT: {
|
||||
this->vscroll.cap = 10;
|
||||
this->resize.step_width = 2;
|
||||
this->resize.step_height = 10;
|
||||
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
virtual ~SaveLoadWindow()
|
||||
{
|
||||
/* pause is only used in single-player, non-editor mode, non menu mode */
|
||||
if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
|
||||
if (_pause_game >= 0) DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
|
||||
}
|
||||
FiosFreeSavegameList();
|
||||
ClrBit(_no_scroll, SCROLL_SAVE);
|
||||
}
|
||||
|
||||
virtual void OnPaint()
|
||||
{
|
||||
int pos;
|
||||
int y;
|
||||
|
||||
SetVScrollCount(w, _fios_num);
|
||||
DrawWindowWidgets(w);
|
||||
DrawFiosTexts(w->width);
|
||||
SetVScrollCount(this, _fios_num);
|
||||
DrawWindowWidgets(this);
|
||||
DrawFiosTexts(this->width);
|
||||
|
||||
if (_savegame_sort_dirty) {
|
||||
_savegame_sort_dirty = false;
|
||||
MakeSortedSaveGameList();
|
||||
}
|
||||
|
||||
GfxFillRect(w->widget[7].left + 1, w->widget[7].top + 1, w->widget[7].right, w->widget[7].bottom, 0xD7);
|
||||
DrawSortButtonState(w, _savegame_sort_order & SORT_BY_NAME ? 2 : 3, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP);
|
||||
GfxFillRect(this->widget[7].left + 1, this->widget[7].top + 1, this->widget[7].right, this->widget[7].bottom, 0xD7);
|
||||
DrawSortButtonState(this, _savegame_sort_order & SORT_BY_NAME ? 2 : 3, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP);
|
||||
|
||||
y = w->widget[7].top + 1;
|
||||
for (pos = w->vscroll.pos; pos < _fios_num; pos++) {
|
||||
y = this->widget[7].top + 1;
|
||||
for (pos = this->vscroll.pos; pos < _fios_num; pos++) {
|
||||
const FiosItem *item = _fios_list + pos;
|
||||
|
||||
DoDrawStringTruncated(item->title, 4, y, _fios_colors[item->type], w->width - 18);
|
||||
DoDrawStringTruncated(item->title, 4, y, _fios_colors[item->type], this->width - 18);
|
||||
y += 10;
|
||||
if (y >= w->vscroll.cap * 10 + w->widget[7].top + 1) break;
|
||||
if (y >= this->vscroll.cap * 10 + this->widget[7].top + 1) break;
|
||||
}
|
||||
|
||||
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
|
||||
DrawEditBox(w, &WP(w, querystr_d), 10);
|
||||
this->DrawEditBox(10);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WE_CLICK:
|
||||
switch (e->we.click.widget) {
|
||||
virtual void OnClick(Point pt, int widget)
|
||||
{
|
||||
switch (widget) {
|
||||
case 2: // Sort save names by name
|
||||
_savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
|
||||
SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
|
||||
_savegame_sort_dirty = true;
|
||||
w->SetDirty();
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case 3: // Sort save names by date
|
||||
_savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
|
||||
SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
|
||||
_savegame_sort_dirty = true;
|
||||
w->SetDirty();
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case 6: // OpenTTD 'button', jumps to OpenTTD directory
|
||||
FiosBrowseTo(&o_dir);
|
||||
w->SetDirty();
|
||||
this->SetDirty();
|
||||
BuildFileList();
|
||||
break;
|
||||
|
||||
case 7: { // Click the listbox
|
||||
int y = (e->we.click.pt.y - w->widget[e->we.click.widget].top - 1) / 10;
|
||||
int y = (pt.y - this->widget[widget].top - 1) / 10;
|
||||
char *name;
|
||||
const FiosItem *file;
|
||||
|
||||
if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count) return;
|
||||
if (y < 0 || (y += this->vscroll.pos) >= this->vscroll.count) return;
|
||||
|
||||
file = _fios_list + y;
|
||||
|
||||
|
@ -1422,62 +1493,68 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
|
|||
ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
|
||||
ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title));
|
||||
|
||||
delete w;
|
||||
delete this;
|
||||
} else if (_saveload_mode == SLD_LOAD_HEIGHTMAP) {
|
||||
SetFiosType(file->type);
|
||||
ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
|
||||
ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title));
|
||||
|
||||
delete w;
|
||||
delete this;
|
||||
ShowHeightmapLoad();
|
||||
} else {
|
||||
/* SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox */
|
||||
ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength);
|
||||
UpdateTextBufferSize(&WP(w, querystr_d).text);
|
||||
w->InvalidateWidget(10);
|
||||
ttd_strlcpy(this->text.buf, file->title, this->text.maxlength);
|
||||
UpdateTextBufferSize(&this->text);
|
||||
this->InvalidateWidget(10);
|
||||
}
|
||||
} else {
|
||||
/* Changed directory, need repaint. */
|
||||
w->SetDirty();
|
||||
this->SetDirty();
|
||||
BuildFileList();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 10: // edit box
|
||||
ShowOnScreenKeyboard(w, &WP(w, querystr_d), e->we.click.widget, 0, 0);
|
||||
ShowOnScreenKeyboard(this, widget, 0, 0);
|
||||
break;
|
||||
|
||||
case 11: case 12: // Delete, Save game
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WE_MOUSELOOP:
|
||||
virtual void OnMouseLoop()
|
||||
{
|
||||
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
|
||||
HandleEditBox(w, &WP(w, querystr_d), 10);
|
||||
this->HandleEditBox(10);
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_KEYPRESS:
|
||||
if (e->we.keypress.keycode == WKC_ESC) {
|
||||
delete w;
|
||||
return;
|
||||
}
|
||||
|
||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
||||
{
|
||||
if (keycode == WKC_ESC) {
|
||||
delete this;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cont = true;
|
||||
if ((_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) &&
|
||||
HandleEditBoxKey(w, &WP(w, querystr_d), 10, e) == 1) { // Press Enter
|
||||
w->HandleButtonClick(12);
|
||||
this->HandleEditBoxKey(10, key, keycode, cont) == 1) { // Press Enter
|
||||
this->HandleButtonClick(12);
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_TIMEOUT:
|
||||
return cont;
|
||||
}
|
||||
|
||||
virtual void OnTimeout()
|
||||
{
|
||||
/* This test protects against using widgets 11 and 12 which are only available
|
||||
* in those two saveload mode */
|
||||
if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) break;
|
||||
if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) return;
|
||||
|
||||
if (w->IsWidgetLowered(11)) { // Delete button clicked
|
||||
if (!FiosDelete(WP(w, querystr_d).text.buf)) {
|
||||
if (this->IsWidgetLowered(11)) { // Delete button clicked
|
||||
if (!FiosDelete(this->text.buf)) {
|
||||
ShowErrorMessage(INVALID_STRING_ID, STR_4008_UNABLE_TO_DELETE_FILE, 0, 0);
|
||||
} else {
|
||||
BuildFileList();
|
||||
|
@ -1485,51 +1562,42 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
|
|||
if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
|
||||
}
|
||||
|
||||
UpdateTextBufferSize(&WP(w, querystr_d).text);
|
||||
w->SetDirty();
|
||||
} else if (w->IsWidgetLowered(12)) { // Save button clicked
|
||||
UpdateTextBufferSize(&this->text);
|
||||
this->SetDirty();
|
||||
} else if (this->IsWidgetLowered(12)) { // Save button clicked
|
||||
_switch_mode = SM_SAVE;
|
||||
FiosMakeSavegameName(_file_to_saveload.name, WP(w, querystr_d).text.buf, sizeof(_file_to_saveload.name));
|
||||
FiosMakeSavegameName(_file_to_saveload.name, this->text.buf, sizeof(_file_to_saveload.name));
|
||||
|
||||
/* In the editor set up the vehicle engines correctly (date might have changed) */
|
||||
if (_game_mode == GM_EDITOR) StartupEngines();
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
/* pause is only used in single-player, non-editor mode, non menu mode */
|
||||
if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
|
||||
if (_pause_game >= 0) DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
|
||||
}
|
||||
FiosFreeSavegameList();
|
||||
ClrBit(_no_scroll, SCROLL_SAVE);
|
||||
break;
|
||||
|
||||
case WE_RESIZE: {
|
||||
virtual void OnResize(Point new_size, Point delta)
|
||||
{
|
||||
/* Widget 2 and 3 have to go with halve speed, make it so obiwan */
|
||||
uint diff = e->we.sizing.diff.x / 2;
|
||||
w->widget[2].right += diff;
|
||||
w->widget[3].left += diff;
|
||||
w->widget[3].right += e->we.sizing.diff.x;
|
||||
uint diff = delta.x / 2;
|
||||
this->widget[2].right += diff;
|
||||
this->widget[3].left += diff;
|
||||
this->widget[3].right += delta.x;
|
||||
|
||||
/* Same for widget 11 and 12 in save-dialog */
|
||||
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
|
||||
w->widget[11].right += diff;
|
||||
w->widget[12].left += diff;
|
||||
w->widget[12].right += e->we.sizing.diff.x;
|
||||
this->widget[11].right += diff;
|
||||
this->widget[12].left += diff;
|
||||
this->widget[12].right += delta.x;
|
||||
}
|
||||
|
||||
w->vscroll.cap += e->we.sizing.diff.y / 10;
|
||||
} break;
|
||||
this->vscroll.cap += delta.y / 10;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const WindowDesc _load_dialog_desc = {
|
||||
WDP_CENTER, WDP_CENTER, 257, 154, 257, 294,
|
||||
WC_SAVELOAD, WC_NONE,
|
||||
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
||||
_load_dialog_widgets,
|
||||
SaveLoadDlgWndProc,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const WindowDesc _save_dialog_desc = {
|
||||
|
@ -1537,7 +1605,7 @@ static const WindowDesc _save_dialog_desc = {
|
|||
WC_SAVELOAD, WC_NONE,
|
||||
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
||||
_save_dialog_widgets,
|
||||
SaveLoadDlgWndProc,
|
||||
NULL,
|
||||
};
|
||||
|
||||
/** These values are used to convert the file/operations mode into a corresponding file type.
|
||||
|
@ -1553,50 +1621,22 @@ static const FileType _file_modetotype[] = {
|
|||
|
||||
void ShowSaveLoadDialog(SaveLoadDialogMode mode)
|
||||
{
|
||||
static const StringID saveload_captions[] = {
|
||||
STR_4001_LOAD_GAME,
|
||||
STR_0298_LOAD_SCENARIO,
|
||||
STR_4000_SAVE_GAME,
|
||||
STR_0299_SAVE_SCENARIO,
|
||||
STR_LOAD_HEIGHTMAP,
|
||||
};
|
||||
|
||||
const WindowDesc *sld = &_save_dialog_desc;
|
||||
|
||||
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
|
||||
DeleteWindowById(WC_QUERY_STRING, 0);
|
||||
DeleteWindowById(WC_SAVELOAD, 0);
|
||||
|
||||
_saveload_mode = mode;
|
||||
SetBit(_no_scroll, SCROLL_SAVE);
|
||||
|
||||
/* Use an array to define what will be the current file type being handled
|
||||
* by current file mode */
|
||||
_file_to_saveload.filetype = _file_modetotype[mode];
|
||||
const WindowDesc *sld;
|
||||
switch (mode) {
|
||||
case SLD_SAVE_GAME: GenerateFileName(); break;
|
||||
case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break;
|
||||
default: sld = &_load_dialog_desc; break;
|
||||
case SLD_SAVE_GAME:
|
||||
case SLD_SAVE_SCENARIO:
|
||||
sld = &_save_dialog_desc; break;
|
||||
default:
|
||||
sld = &_load_dialog_desc; break;
|
||||
}
|
||||
|
||||
assert((uint)mode < lengthof(saveload_captions));
|
||||
_saveload_mode = mode;
|
||||
_file_to_saveload.filetype = _file_modetotype[mode];
|
||||
|
||||
Window *w = new Window(sld);
|
||||
w->widget[1].data = saveload_captions[mode];
|
||||
w->LowerWidget(7);
|
||||
|
||||
WP(w, querystr_d).afilter = CS_ALPHANUMERAL;
|
||||
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 240);
|
||||
|
||||
/* pause is only used in single-player, non-editor mode, non-menu mode. It
|
||||
* will be unpaused in the WE_DESTROY event handler. */
|
||||
if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) {
|
||||
if (_pause_game >= 0) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
|
||||
}
|
||||
|
||||
BuildFileList();
|
||||
|
||||
ResetObjectToPlace();
|
||||
new SaveLoadWindow(sld, mode);
|
||||
}
|
||||
|
||||
void RedrawAutosave()
|
||||
|
|
File diff suppressed because it is too large
Load Diff
177
src/osk_gui.cpp
177
src/osk_gui.cpp
|
@ -12,20 +12,11 @@
|
|||
#include "debug.h"
|
||||
#include "window_func.h"
|
||||
#include "gfx_func.h"
|
||||
#include "querystring_gui.h"
|
||||
|
||||
#include "table/sprites.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
struct osk_d {
|
||||
querystr_d *qs; // text-input
|
||||
int text_btn; // widget number of parent's text field
|
||||
int ok_btn; // widget number of parent's ok button (=0 when ok shouldn't be passed on)
|
||||
int cancel_btn; // widget number of parent's cancel button (=0 when cancel shouldn't be passed on; text will be reverted to original)
|
||||
Textbuf *text; // pointer to parent's textbuffer (to update caret position)
|
||||
char *orig; // the original text, in case we cancel
|
||||
};
|
||||
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(osk_d));
|
||||
|
||||
enum OskWidgets {
|
||||
OSK_WIDGET_TEXT = 3,
|
||||
OSK_WIDGET_CANCEL = 5,
|
||||
|
@ -50,77 +41,97 @@ enum {
|
|||
};
|
||||
static byte _keystate = KEYS_NONE;
|
||||
|
||||
/*
|
||||
struct OskWindow : public Window {
|
||||
QueryString *qs; ///< text-input
|
||||
int text_btn; ///< widget number of parent's text field
|
||||
int ok_btn; ///< widget number of parent's ok button (=0 when ok shouldn't be passed on)
|
||||
int cancel_btn; ///< widget number of parent's cancel button (=0 when cancel shouldn't be passed on; text will be reverted to original)
|
||||
Textbuf *text; ///< pointer to parent's textbuffer (to update caret position)
|
||||
char orig_str_buf[64]; ///< Original string.
|
||||
|
||||
OskWindow(const WindowDesc *desc, QueryStringBaseWindow *parent, int button, int cancel, int ok) : Window(desc)
|
||||
{
|
||||
this->parent = parent;
|
||||
assert(parent != NULL);
|
||||
|
||||
if (parent->widget[button].data != 0) parent->caption = parent->widget[button].data;
|
||||
|
||||
this->qs = parent;
|
||||
this->text_btn = button;
|
||||
this->cancel_btn = cancel;
|
||||
this->ok_btn = ok;
|
||||
this->text = &parent->text;
|
||||
|
||||
/* make a copy in case we need to reset later */
|
||||
strcpy(this->orig_str_buf, this->qs->text.buf);
|
||||
|
||||
SetBit(_no_scroll, SCROLL_EDIT);
|
||||
/* Not needed by default. */
|
||||
this->DisableWidget(OSK_WIDGET_SPECIAL);
|
||||
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only show valid characters; do not show characters that would
|
||||
* only insert a space when we have a spacebar to do that or
|
||||
* characters that are not allowed to be entered.
|
||||
*/
|
||||
static void ChangeOskDiabledState(Window *w, const querystr_d *qs, bool shift)
|
||||
{
|
||||
void ChangeOskDiabledState(bool shift)
|
||||
{
|
||||
for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
|
||||
w->SetWidgetDisabledState(OSK_WIDGET_LETTERS + i,
|
||||
!IsValidChar(_keyboard[shift][i], qs->afilter) || _keyboard[shift][i] == ' ');
|
||||
this->SetWidgetDisabledState(OSK_WIDGET_LETTERS + i,
|
||||
!IsValidChar(_keyboard[shift][i], this->qs->afilter) || _keyboard[shift][i] == ' ');
|
||||
}
|
||||
this->SetWidgetDisabledState(OSK_WIDGET_SPACE, !IsValidChar(' ', this->qs->afilter));
|
||||
}
|
||||
w->SetWidgetDisabledState(OSK_WIDGET_SPACE, !IsValidChar(' ', qs->afilter));
|
||||
}
|
||||
|
||||
/* on screen keyboard */
|
||||
static void OskWndProc(Window *w, WindowEvent *e)
|
||||
{
|
||||
querystr_d *qs = WP(w, osk_d).qs;
|
||||
|
||||
switch (e->event) {
|
||||
case WE_CREATE:
|
||||
SetBit(_no_scroll, SCROLL_EDIT);
|
||||
/* Not needed by default. */
|
||||
w->DisableWidget(OSK_WIDGET_SPECIAL);
|
||||
break;
|
||||
|
||||
case WE_PAINT: {
|
||||
virtual void OnPaint()
|
||||
{
|
||||
bool shift = HasBit(_keystate, KEYS_CAPS) ^ HasBit(_keystate, KEYS_SHIFT);
|
||||
|
||||
w->LowerWidget(OSK_WIDGET_TEXT);
|
||||
w->SetWidgetLoweredState(OSK_WIDGET_SHIFT, HasBit(_keystate, KEYS_SHIFT));
|
||||
w->SetWidgetLoweredState(OSK_WIDGET_CAPS, HasBit(_keystate, KEYS_CAPS));
|
||||
this->LowerWidget(OSK_WIDGET_TEXT);
|
||||
this->SetWidgetLoweredState(OSK_WIDGET_SHIFT, HasBit(_keystate, KEYS_SHIFT));
|
||||
this->SetWidgetLoweredState(OSK_WIDGET_CAPS, HasBit(_keystate, KEYS_CAPS));
|
||||
|
||||
ChangeOskDiabledState(w, qs, shift);
|
||||
this->ChangeOskDiabledState(shift);
|
||||
|
||||
SetDParam(0, qs->caption);
|
||||
DrawWindowWidgets(w);
|
||||
SetDParam(0, this->qs->caption);
|
||||
DrawWindowWidgets(this);
|
||||
|
||||
for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
|
||||
DrawCharCentered(_keyboard[shift][i],
|
||||
w->widget[OSK_WIDGET_LETTERS + i].left + 8,
|
||||
w->widget[OSK_WIDGET_LETTERS + i].top + 3,
|
||||
this->widget[OSK_WIDGET_LETTERS + i].left + 8,
|
||||
this->widget[OSK_WIDGET_LETTERS + i].top + 3,
|
||||
TC_BLACK);
|
||||
}
|
||||
|
||||
DrawEditBox(w, qs, OSK_WIDGET_TEXT);
|
||||
break;
|
||||
this->qs->DrawEditBox(this, OSK_WIDGET_TEXT);
|
||||
}
|
||||
|
||||
case WE_CLICK:
|
||||
virtual void OnClick(Point pt, int widget)
|
||||
{
|
||||
/* clicked a letter */
|
||||
if (e->we.click.widget >= OSK_WIDGET_LETTERS) {
|
||||
if (widget >= OSK_WIDGET_LETTERS) {
|
||||
bool shift = HasBit(_keystate, KEYS_CAPS) ^ HasBit(_keystate, KEYS_SHIFT);
|
||||
|
||||
WChar c = _keyboard[shift][e->we.click.widget - OSK_WIDGET_LETTERS];
|
||||
WChar c = _keyboard[shift][widget - OSK_WIDGET_LETTERS];
|
||||
|
||||
if (!IsValidChar(c, qs->afilter)) break;
|
||||
if (!IsValidChar(c, this->qs->afilter)) return;
|
||||
|
||||
if (InsertTextBufferChar(&qs->text, c)) w->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
if (InsertTextBufferChar(&this->qs->text, c)) this->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
|
||||
if (HasBit(_keystate, KEYS_SHIFT)) {
|
||||
ToggleBit(_keystate, KEYS_SHIFT);
|
||||
w->widget[OSK_WIDGET_SHIFT].color = HasBit(_keystate, KEYS_SHIFT) ? 15 : 14;
|
||||
w->SetDirty();
|
||||
this->widget[OSK_WIDGET_SHIFT].color = HasBit(_keystate, KEYS_SHIFT) ? 15 : 14;
|
||||
this->SetDirty();
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e->we.click.widget) {
|
||||
switch (widget) {
|
||||
case OSK_WIDGET_BACKSPACE:
|
||||
if (DeleteTextBufferChar(&qs->text, WKC_BACKSPACE)) w->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
if (DeleteTextBufferChar(&this->qs->text, WKC_BACKSPACE)) this->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
break;
|
||||
|
||||
case OSK_WIDGET_SPECIAL:
|
||||
|
@ -133,59 +144,59 @@ static void OskWndProc(Window *w, WindowEvent *e)
|
|||
|
||||
case OSK_WIDGET_CAPS:
|
||||
ToggleBit(_keystate, KEYS_CAPS);
|
||||
w->SetDirty();
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case OSK_WIDGET_SHIFT:
|
||||
ToggleBit(_keystate, KEYS_SHIFT);
|
||||
w->SetDirty();
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case OSK_WIDGET_SPACE:
|
||||
if (InsertTextBufferChar(&qs->text, ' ')) w->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
if (InsertTextBufferChar(&this->qs->text, ' ')) this->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
break;
|
||||
|
||||
case OSK_WIDGET_LEFT:
|
||||
if (MoveTextBufferPos(&qs->text, WKC_LEFT)) w->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
if (MoveTextBufferPos(&this->qs->text, WKC_LEFT)) this->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
break;
|
||||
|
||||
case OSK_WIDGET_RIGHT:
|
||||
if (MoveTextBufferPos(&qs->text, WKC_RIGHT)) w->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
if (MoveTextBufferPos(&this->qs->text, WKC_RIGHT)) this->InvalidateWidget(OSK_WIDGET_TEXT);
|
||||
break;
|
||||
|
||||
case OSK_WIDGET_OK:
|
||||
if (qs->orig == NULL || strcmp(qs->text.buf, qs->orig) != 0) {
|
||||
if (this->qs->orig == NULL || strcmp(this->qs->text.buf, this->qs->orig) != 0) {
|
||||
/* pass information by simulating a button press on parent window */
|
||||
if (WP(w, osk_d).ok_btn != 0) {
|
||||
w->parent->OnClick(e->we.click.pt, WP(w, osk_d).ok_btn);
|
||||
if (this->ok_btn != 0) {
|
||||
this->parent->OnClick(pt, this->ok_btn);
|
||||
}
|
||||
}
|
||||
delete w;
|
||||
delete this;
|
||||
break;
|
||||
|
||||
case OSK_WIDGET_CANCEL:
|
||||
if (WP(w, osk_d).cancel_btn != 0) { // pass a cancel event to the parent window
|
||||
w->parent->OnClick(e->we.click.pt, WP(w, osk_d).cancel_btn);
|
||||
if (this->cancel_btn != 0) { // pass a cancel event to the parent window
|
||||
this->parent->OnClick(pt, this->cancel_btn);
|
||||
/* Window gets deleted when the parent window removes itself. */
|
||||
} else { // or reset to original string
|
||||
strcpy(qs->text.buf, WP(w, osk_d).orig);
|
||||
strcpy(qs->text.buf, this->orig_str_buf);
|
||||
UpdateTextBufferSize(&qs->text);
|
||||
MoveTextBufferPos(&qs->text, WKC_END);
|
||||
delete w;
|
||||
delete this;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* make sure that the parent window's textbox also gets updated */
|
||||
if (w->parent != NULL) w->parent->InvalidateWidget(WP(w, osk_d).text_btn);
|
||||
break;
|
||||
|
||||
case WE_MOUSELOOP:
|
||||
HandleEditBox(w, qs, OSK_WIDGET_TEXT);
|
||||
/* make the caret of the parent window also blink */
|
||||
w->parent->InvalidateWidget(WP(w, osk_d).text_btn);
|
||||
break;
|
||||
if (this->parent != NULL) this->parent->InvalidateWidget(this->text_btn);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnMouseLoop()
|
||||
{
|
||||
this->qs->HandleEditBox(this, OSK_WIDGET_TEXT);
|
||||
/* make the caret of the parent window also blink */
|
||||
this->parent->InvalidateWidget(this->text_btn);
|
||||
}
|
||||
};
|
||||
|
||||
static const Widget _osk_widgets[] = {
|
||||
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL},
|
||||
|
@ -270,7 +281,7 @@ WindowDesc _osk_desc = {
|
|||
WC_OSK, WC_NONE,
|
||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
||||
_osk_widgets,
|
||||
OskWndProc
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -338,26 +349,10 @@ void GetKeyboardLayout()
|
|||
* @param ok widget number of parent's ok button (0 if ok events should not
|
||||
* be passed)
|
||||
*/
|
||||
void ShowOnScreenKeyboard(Window *parent, querystr_d *q, int button, int cancel, int ok)
|
||||
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok)
|
||||
{
|
||||
DeleteWindowById(WC_OSK, 0);
|
||||
|
||||
Window *w = new Window(&_osk_desc);
|
||||
|
||||
w->parent = parent;
|
||||
assert(parent != NULL);
|
||||
|
||||
if (parent->widget[button].data != 0) q->caption = parent->widget[button].data;
|
||||
|
||||
WP(w, osk_d).qs = q;
|
||||
WP(w, osk_d).text_btn = button;
|
||||
WP(w, osk_d).cancel_btn = cancel;
|
||||
WP(w, osk_d).ok_btn = ok;
|
||||
WP(w, osk_d).text = &q->text;
|
||||
|
||||
GetKeyboardLayout();
|
||||
|
||||
/* make a copy in case we need to reset later */
|
||||
strcpy(_orig_str_buf, WP(w, osk_d).qs->text.buf);
|
||||
WP(w, osk_d).orig = _orig_str_buf;
|
||||
new OskWindow(&_osk_desc, parent, button, cancel, ok);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/* $Id$ */
|
||||
|
||||
/** @file querystring_gui.h Base for the GUIs that have an edit box in them. */
|
||||
|
||||
#ifndef QUERYSTRING_GUI_H
|
||||
#define QUERYSTRING_GUI_H
|
||||
|
||||
#include "textbuf_gui.h"
|
||||
#include "window_gui.h"
|
||||
|
||||
struct QueryString {
|
||||
StringID caption;
|
||||
Textbuf text;
|
||||
const char *orig;
|
||||
CharSetFilter afilter;
|
||||
bool handled;
|
||||
|
||||
void DrawEditBox(Window *w, int wid);
|
||||
void HandleEditBox(Window *w, int wid);
|
||||
int HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, bool &cont);
|
||||
};
|
||||
|
||||
struct QueryStringBaseWindow : public Window, public QueryString {
|
||||
char edit_str_buf[64];
|
||||
char orig_str_buf[64];
|
||||
|
||||
QueryStringBaseWindow(const WindowDesc *desc, void *data = NULL, WindowNumber window_number = 0) : Window(desc, data, window_number)
|
||||
{
|
||||
}
|
||||
|
||||
void DrawEditBox(int wid);
|
||||
void HandleEditBox(int wid);
|
||||
int HandleEditBoxKey(int wid, uint16 key, uint16 keycode, bool &cont);
|
||||
};
|
||||
|
||||
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
|
||||
|
||||
#endif /* QUERYSTRING_GUI_H */
|
|
@ -19,6 +19,7 @@
|
|||
#include "map_func.h"
|
||||
#include "gfx_func.h"
|
||||
#include "viewport_func.h"
|
||||
#include "querystring_gui.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/sprites.h"
|
||||
|
@ -143,11 +144,11 @@ void ShowSignList()
|
|||
}
|
||||
}
|
||||
|
||||
/** Edit sign window stuff */
|
||||
struct editsign_d : querystr_d {
|
||||
SignID cur_sign;
|
||||
};
|
||||
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(editsign_d));
|
||||
static void RenameSign(SignID index, const char *text)
|
||||
{
|
||||
_cmd_text = text;
|
||||
DoCommandP(0, index, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
|
||||
}
|
||||
|
||||
enum QueryEditSignWidgets {
|
||||
QUERY_EDIT_SIGN_WIDGET_TEXT = 3,
|
||||
|
@ -158,120 +159,122 @@ enum QueryEditSignWidgets {
|
|||
QUERY_EDIT_SIGN_WIDGET_NEXT,
|
||||
};
|
||||
|
||||
static void UpdateSignEditWindow(Window *w, const Sign *si)
|
||||
{
|
||||
struct SignWindow : QueryStringBaseWindow {
|
||||
SignID cur_sign;
|
||||
|
||||
SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(desc)
|
||||
{
|
||||
SetBit(_no_scroll, SCROLL_EDIT);
|
||||
this->caption = STR_280B_EDIT_SIGN_TEXT;
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
this->LowerWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||
|
||||
UpdateSignEditWindow(si);
|
||||
}
|
||||
|
||||
~SignWindow()
|
||||
{
|
||||
ClrBit(_no_scroll, SCROLL_EDIT);
|
||||
}
|
||||
|
||||
void UpdateSignEditWindow(const Sign *si)
|
||||
{
|
||||
/* Display an empty string when the sign hasnt been edited yet */
|
||||
if (si->name != NULL) {
|
||||
SetDParam(0, si->index);
|
||||
GetString(_edit_str_buf, STR_SIGN_NAME, lastof(_edit_str_buf));
|
||||
GetString(this->edit_str_buf, STR_SIGN_NAME, lastof(this->edit_str_buf));
|
||||
} else {
|
||||
GetString(_edit_str_buf, STR_EMPTY, lastof(_edit_str_buf));
|
||||
GetString(this->edit_str_buf, STR_EMPTY, lastof(this->edit_str_buf));
|
||||
}
|
||||
_edit_str_buf[lengthof(_edit_str_buf) - 1] = '\0';
|
||||
this->edit_str_buf[lengthof(this->edit_str_buf) - 1] = '\0';
|
||||
|
||||
WP(w, editsign_d).cur_sign = si->index;
|
||||
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, 31, 255); // Allow 31 characters (including \0)
|
||||
this->cur_sign = si->index;
|
||||
InitializeTextBuffer(&this->text, this->edit_str_buf, 31, 255); // Allow 31 characters (including \0)
|
||||
|
||||
w->InvalidateWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||
}
|
||||
this->InvalidateWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||
}
|
||||
|
||||
static void RenameSign(SignID index, const char *text)
|
||||
{
|
||||
_cmd_text = text;
|
||||
DoCommandP(0, index, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
|
||||
}
|
||||
virtual void OnPaint()
|
||||
{
|
||||
SetDParam(0, this->caption);
|
||||
DrawWindowWidgets(this);
|
||||
this->DrawEditBox(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||
}
|
||||
|
||||
static void QuerySignEditWndProc(Window *w, WindowEvent *e)
|
||||
{
|
||||
editsign_d *qs = &WP(w, editsign_d);
|
||||
Sign *si;
|
||||
uint sign_index = 0;
|
||||
|
||||
switch (e->event) {
|
||||
case WE_CREATE:
|
||||
SetBit(_no_scroll, SCROLL_EDIT);
|
||||
break;
|
||||
|
||||
case WE_PAINT:
|
||||
SetDParam(0, qs->caption);
|
||||
DrawWindowWidgets(w);
|
||||
DrawEditBox(w, qs, QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||
break;
|
||||
|
||||
case WE_CLICK:
|
||||
switch (e->we.click.widget) {
|
||||
case QUERY_EDIT_SIGN_WIDGET_PREVIOUS:
|
||||
virtual void OnClick(Point pt, int widget)
|
||||
{
|
||||
switch (widget) {
|
||||
case QUERY_EDIT_SIGN_WIDGET_PREVIOUS: {
|
||||
if (_sign_sort_dirty) GlobalSortSignList();
|
||||
sign_index = _sign_sort[_num_sign_sort - 1]->index;
|
||||
SignID sign_index = _sign_sort[_num_sign_sort - 1]->index;
|
||||
for (uint i = 1; i < _num_sign_sort; i++) {
|
||||
if (qs->cur_sign == _sign_sort[i]->index) {
|
||||
if (this->cur_sign == _sign_sort[i]->index) {
|
||||
sign_index = _sign_sort[i - 1]->index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
si = GetSign(sign_index);
|
||||
const Sign *si = GetSign(sign_index);
|
||||
|
||||
/* Scroll to sign and reopen window */
|
||||
ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
|
||||
UpdateSignEditWindow(w, si);
|
||||
break;
|
||||
UpdateSignEditWindow(si);
|
||||
} break;
|
||||
|
||||
case QUERY_EDIT_SIGN_WIDGET_NEXT:
|
||||
case QUERY_EDIT_SIGN_WIDGET_NEXT: {
|
||||
if (_sign_sort_dirty) GlobalSortSignList();
|
||||
sign_index = _sign_sort[0]->index;
|
||||
SignID sign_index = _sign_sort[0]->index;
|
||||
for (uint i = 0; i < _num_sign_sort - 1; i++) {
|
||||
if (qs->cur_sign == _sign_sort[i]->index) {
|
||||
if (this->cur_sign == _sign_sort[i]->index) {
|
||||
sign_index = _sign_sort[i + 1]->index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
si = GetSign(sign_index);
|
||||
const Sign *si = GetSign(sign_index);
|
||||
|
||||
/* Scroll to sign and reopen window */
|
||||
ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
|
||||
UpdateSignEditWindow(w, si);
|
||||
break;
|
||||
UpdateSignEditWindow(si);
|
||||
} break;
|
||||
|
||||
case QUERY_EDIT_SIGN_WIDGET_TEXT:
|
||||
ShowOnScreenKeyboard(w, qs, e->we.click.widget, QUERY_EDIT_SIGN_WIDGET_CANCEL, QUERY_EDIT_SIGN_WIDGET_OK);
|
||||
ShowOnScreenKeyboard(this, widget, QUERY_EDIT_SIGN_WIDGET_CANCEL, QUERY_EDIT_SIGN_WIDGET_OK);
|
||||
break;
|
||||
|
||||
case QUERY_EDIT_SIGN_WIDGET_DELETE:
|
||||
/* Only need to set the buffer to null, the rest is handled as the OK button */
|
||||
DeleteTextBufferAll(&qs->text);
|
||||
DeleteTextBufferAll(&this->text);
|
||||
/* FALL THROUGH */
|
||||
|
||||
case QUERY_EDIT_SIGN_WIDGET_OK:
|
||||
RenameSign(qs->cur_sign, qs->text.buf);
|
||||
RenameSign(this->cur_sign, this->text.buf);
|
||||
/* FALL THROUGH */
|
||||
|
||||
case QUERY_EDIT_SIGN_WIDGET_CANCEL:
|
||||
delete w;
|
||||
delete this;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WE_KEYPRESS:
|
||||
switch (HandleEditBoxKey(w, qs, QUERY_EDIT_SIGN_WIDGET_TEXT, e)) {
|
||||
virtual bool OnKeyPress(uint16 key, uint16 keycode)
|
||||
{
|
||||
bool cont = true;
|
||||
switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, cont)) {
|
||||
case 1: // Enter pressed, confirms change
|
||||
RenameSign(qs->cur_sign, qs->text.buf);
|
||||
RenameSign(this->cur_sign, this->text.buf);
|
||||
/* FALL THROUGH */
|
||||
|
||||
case 2: // ESC pressed, closes window, abandons changes
|
||||
delete w;
|
||||
delete this;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_MOUSELOOP:
|
||||
HandleEditBox(w, qs, QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
ClrBit(_no_scroll, SCROLL_EDIT);
|
||||
break;
|
||||
return cont;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnMouseLoop()
|
||||
{
|
||||
this->HandleEditBox(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||
}
|
||||
};
|
||||
|
||||
static const Widget _query_sign_edit_widgets[] = {
|
||||
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
||||
|
@ -292,7 +295,7 @@ static const WindowDesc _query_sign_edit_desc = {
|
|||
WC_QUERY_STRING, WC_NONE,
|
||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
||||
_query_sign_edit_widgets,
|
||||
QuerySignEditWndProc
|
||||
NULL
|
||||
};
|
||||
|
||||
void ShowRenameSignWindow(const Sign *si)
|
||||
|
@ -301,11 +304,5 @@ void ShowRenameSignWindow(const Sign *si)
|
|||
DeleteWindowById(WC_QUERY_STRING, 0);
|
||||
DeleteWindowById(WC_SAVELOAD, 0);
|
||||
|
||||
Window *w = new Window(&_query_sign_edit_desc);
|
||||
|
||||
WP(w, editsign_d).caption = STR_280B_EDIT_SIGN_TEXT;
|
||||
WP(w, editsign_d).afilter = CS_ALPHANUMERAL;
|
||||
w->LowerWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
|
||||
|
||||
UpdateSignEditWindow(w, si);
|
||||
new SignWindow(&_query_sign_edit_desc, si);
|
||||
}
|
||||
|
|
|
@ -18,21 +18,6 @@ struct Textbuf {
|
|||
uint16 caretxoffs; ///< the current position of the caret in pixels
|
||||
};
|
||||
|
||||
struct querystr_d {
|
||||
StringID caption;
|
||||
Textbuf text;
|
||||
const char *orig;
|
||||
CharSetFilter afilter;
|
||||
bool handled;
|
||||
};
|
||||
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(querystr_d));
|
||||
|
||||
extern char _edit_str_buf[64];
|
||||
extern char _orig_str_buf[lengthof(_edit_str_buf)];
|
||||
|
||||
void DrawEditBox(Window *w, querystr_d *string, int wid);
|
||||
void HandleEditBox(Window *w, querystr_d *string, int wid);
|
||||
int HandleEditBoxKey(Window *w, querystr_d *string, int wid, WindowEvent *we);
|
||||
bool HandleCaret(Textbuf *tb);
|
||||
|
||||
void DeleteTextBufferAll(Textbuf *tb);
|
||||
|
@ -56,6 +41,4 @@ static const uint OSK_KEYBOARD_ENTRIES = 50;
|
|||
*/
|
||||
extern char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES * 4 + 1];
|
||||
|
||||
void ShowOnScreenKeyboard(Window *parent, querystr_d *q, int button, int cancel, int ok);
|
||||
|
||||
#endif /* TEXTBUF_GUI_H */
|
||||
|
|
Loading…
Reference in New Issue