1
0
Fork 0

(svn r13172) -Codechange: make a window class of the terraform toolbars.

release/0.7
rubidium 2008-05-18 21:53:45 +00:00
parent ade538828d
commit 9fc630422d
1 changed files with 164 additions and 148 deletions

View File

@ -229,57 +229,67 @@ static OnButtonClick * const _terraform_button_proc[] = {
TerraformClick_PlaceSign, TerraformClick_PlaceSign,
}; };
static void TerraformToolbWndProc(Window *w, WindowEvent *e) struct TerraformToolbarWindow : Window {
{ TerraformToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
switch (e->event) { {
case WE_PAINT: this->FindWindowPlacementAndResize(desc);
w->DrawWidgets();
break;
case WE_CLICK:
if (e->we.click.widget >= 4) _terraform_button_proc[e->we.click.widget - 4](w);
break;
case WE_KEYPRESS: {
uint i;
for (i = 0; i != lengthof(_terraform_keycodes); i++) {
if (e->we.keypress.keycode == _terraform_keycodes[i]) {
e->we.keypress.cont = false;
_terraform_button_proc[i](w);
break;
}
}
break;
} }
case WE_PLACE_OBJ: ~TerraformToolbarWindow()
_place_proc(e->we.place.tile); {
return; }
case WE_PLACE_DRAG: virtual void OnPaint()
VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); {
break; this->DrawWidgets();
}
case WE_PLACE_MOUSEUP: virtual void OnClick(Point pt, int widget)
if (e->we.place.pt.x != -1) { {
switch (e->we.place.select_proc) { if (widget >= 4) _terraform_button_proc[widget - 4](this);
}
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
for (uint i = 0; i != lengthof(_terraform_keycodes); i++) {
if (keycode == _terraform_keycodes[i]) {
_terraform_button_proc[i](this);
return ES_HANDLED;
}
}
return ES_NOT_HANDLED;
}
virtual void OnPlaceObject(Point pt, TileIndex tile)
{
_place_proc(tile);
}
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
{
VpSelectTilesWithMethod(pt.x, pt.y, select_method);
}
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
{
if (pt.x != -1) {
switch (select_proc) {
default: NOT_REACHED(); default: NOT_REACHED();
case DDSP_DEMOLISH_AREA: case DDSP_DEMOLISH_AREA:
case DDSP_RAISE_AND_LEVEL_AREA: case DDSP_RAISE_AND_LEVEL_AREA:
case DDSP_LOWER_AND_LEVEL_AREA: case DDSP_LOWER_AND_LEVEL_AREA:
case DDSP_LEVEL_AREA: case DDSP_LEVEL_AREA:
GUIPlaceProcDragXY(e->we.place.select_proc, e->we.place.starttile, e->we.place.tile); GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
break; break;
} }
} }
break; }
case WE_ABORT_PLACE_OBJ: virtual void OnPlaceObjectAbort()
w->RaiseButtons(); {
break; this->RaiseButtons();
} }
} };
static const Widget _terraform_widgets[] = { static const Widget _terraform_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
@ -303,13 +313,13 @@ static const WindowDesc _terraform_desc = {
WC_SCEN_LAND_GEN, WC_NONE, WC_SCEN_LAND_GEN, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_terraform_widgets, _terraform_widgets,
TerraformToolbWndProc NULL
}; };
void ShowTerraformToolbar(Window *link) void ShowTerraformToolbar(Window *link)
{ {
if (!IsValidPlayer(_current_player)) return; if (!IsValidPlayer(_current_player)) return;
Window *w = AllocateWindowDescFront<Window>(&_terraform_desc, 0); Window *w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
if (w != NULL && link != NULL) { if (w != NULL && link != NULL) {
/* Align the terraform toolbar under the main toolbar and put the linked /* Align the terraform toolbar under the main toolbar and put the linked
* toolbar to left of it * toolbar to left of it
@ -567,16 +577,16 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
} }
} }
static void ScenEditLandGenWndProc(Window *w, WindowEvent *e) struct ScenarioEditorLandscapeGenerationWindow : Window {
{ ScenarioEditorLandscapeGenerationWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
switch (e->event) { {
case WE_CREATE:
/* XXX - lighthouse button is widget 11!! Don't forget when changing */ /* XXX - lighthouse button is widget 11!! Don't forget when changing */
w->widget[11].tooltips = (_opt.landscape == LT_TROPIC) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE; this->widget[11].tooltips = (_opt.landscape == LT_TROPIC) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE;
break; this->FindWindowPlacementAndResize(desc);
}
case WE_PAINT: { virtual void OnPaint() {
w->DrawWidgets(); this->DrawWidgets();
int n = _terraform_size * _terraform_size; int n = _terraform_size * _terraform_size;
const int8 *coords = &_multi_terraform_coords[0][0]; const int8 *coords = &_multi_terraform_coords[0][0];
@ -587,39 +597,41 @@ static void ScenEditLandGenWndProc(Window *w, WindowEvent *e)
coords += 2; coords += 2;
} while (--n); } while (--n);
if (w->IsWidgetLowered(5) || w->IsWidgetLowered(6)) // change area-size if raise/lower corner is selected if (this->IsWidgetLowered(5) || this->IsWidgetLowered(6)) { // change area-size if raise/lower corner is selected
SetTileSelectSize(_terraform_size, _terraform_size); SetTileSelectSize(_terraform_size, _terraform_size);
}
}
} break; virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
case WE_KEYPRESS:
for (uint i = 0; i != lengthof(_editor_terraform_keycodes); i++) { for (uint i = 0; i != lengthof(_editor_terraform_keycodes); i++) {
if (e->we.keypress.keycode == _editor_terraform_keycodes[i]) { if (keycode == _editor_terraform_keycodes[i]) {
e->we.keypress.cont = false; _editor_terraform_button_proc[i](this);
_editor_terraform_button_proc[i](w); return ES_HANDLED;
break;
} }
} }
break; return ES_NOT_HANDLED;
}
case WE_CLICK: virtual void OnClick(Point pt, int widget)
switch (e->we.click.widget) { {
switch (widget) {
case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12:
_editor_terraform_button_proc[e->we.click.widget - 4](w); _editor_terraform_button_proc[widget - 4](this);
break; break;
case 13: case 14: { // Increase/Decrease terraform size case 13: case 14: { // Increase/Decrease terraform size
int size = (e->we.click.widget == 13) ? 1 : -1; int size = (widget == 13) ? 1 : -1;
w->HandleButtonClick(e->we.click.widget); this->HandleButtonClick(widget);
size += _terraform_size; size += _terraform_size;
if (!IsInsideMM(size, 1, 8 + 1)) return; if (!IsInsideMM(size, 1, 8 + 1)) return;
_terraform_size = size; _terraform_size = size;
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
w->SetDirty(); this->SetDirty();
} break; } break;
case 15: // gen random land case 15: // gen random land
w->HandleButtonClick(15); this->HandleButtonClick(15);
ShowCreateScenario(); ShowCreateScenario();
break; break;
case 16: // Reset landscape case 16: // Reset landscape
@ -630,29 +642,33 @@ static void ScenEditLandGenWndProc(Window *w, WindowEvent *e)
ResetLandscapeConfirmationCallback); ResetLandscapeConfirmationCallback);
break; break;
} }
break; }
case WE_TIMEOUT: virtual void OnTimeout()
for (uint i = 0; i < w->widget_count; i++) { {
if (w->IsWidgetLowered(i)) { for (uint i = 0; i < this->widget_count; i++) {
w->RaiseWidget(i); if (this->IsWidgetLowered(i)) {
w->InvalidateWidget(i); this->RaiseWidget(i);
this->InvalidateWidget(i);
} }
if (i == 3) i = 12; if (i == 3) i = 12;
} }
break; }
case WE_PLACE_OBJ: virtual void OnPlaceObject(Point pt, TileIndex tile)
_place_proc(e->we.place.tile); {
break; _place_proc(tile);
}
case WE_PLACE_DRAG: virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); {
break; VpSelectTilesWithMethod(pt.x, pt.y, select_method);
}
case WE_PLACE_MOUSEUP: virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
if (e->we.place.pt.x != -1) { {
switch (e->we.place.select_proc) { if (pt.x != -1) {
switch (select_proc) {
default: NOT_REACHED(); default: NOT_REACHED();
case DDSP_CREATE_ROCKS: case DDSP_CREATE_ROCKS:
case DDSP_CREATE_DESERT: case DDSP_CREATE_DESERT:
@ -662,28 +678,28 @@ static void ScenEditLandGenWndProc(Window *w, WindowEvent *e)
case DDSP_LOWER_AND_LEVEL_AREA: case DDSP_LOWER_AND_LEVEL_AREA:
case DDSP_LEVEL_AREA: case DDSP_LEVEL_AREA:
case DDSP_DEMOLISH_AREA: case DDSP_DEMOLISH_AREA:
GUIPlaceProcDragXY(e->we.place.select_proc, e->we.place.starttile, e->we.place.tile); GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
break; break;
} }
} }
break; }
case WE_ABORT_PLACE_OBJ: virtual void OnPlaceObjectAbort()
w->RaiseButtons(); {
w->SetDirty(); this->RaiseButtons();
break; this->SetDirty();
} }
} };
static const WindowDesc _scen_edit_land_gen_desc = { static const WindowDesc _scen_edit_land_gen_desc = {
WDP_AUTO, WDP_AUTO, 204, 103, 204, 103, WDP_AUTO, WDP_AUTO, 204, 103, 204, 103,
WC_SCEN_LAND_GEN, WC_NONE, WC_SCEN_LAND_GEN, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_scen_edit_land_gen_widgets, _scen_edit_land_gen_widgets,
ScenEditLandGenWndProc, NULL,
}; };
void ShowEditorTerraformToolbar() void ShowEditorTerraformToolbar()
{ {
AllocateWindowDescFront<Window>(&_scen_edit_land_gen_desc, 0); AllocateWindowDescFront<ScenarioEditorLandscapeGenerationWindow>(&_scen_edit_land_gen_desc, 0);
} }