(svn r13061) -Codechange: make a class of the BuildTreesWindow.

This commit is contained in:
glx 2008-05-12 21:46:08 +00:00
parent 18c33e1569
commit ca4d92e2f2
3 changed files with 155 additions and 160 deletions

View File

@ -52,7 +52,6 @@ void ShowHeightmapLoad();
void PlaceLandBlockInfo(); void PlaceLandBlockInfo();
void ShowAboutWindow(); void ShowAboutWindow();
void ShowBuildTreesToolbar(); void ShowBuildTreesToolbar();
void ShowBuildTreesScenToolbar();
void ShowTownDirectory(); void ShowTownDirectory();
void ShowIndustryDirectory(); void ShowIndustryDirectory();
void ShowSubsidiesList(); void ShowSubsidiesList();

View File

@ -621,7 +621,7 @@ static void ToolbarScenPlantTrees(Window *w)
{ {
w->HandleButtonClick(15); w->HandleButtonClick(15);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
ShowBuildTreesScenToolbar(); ShowBuildTreesToolbar();
} }
static void ToolbarScenPlaceSign(Window *w) static void ToolbarScenPlaceSign(Window *w)

View File

@ -16,16 +16,50 @@
#include "table/strings.h" #include "table/strings.h"
#include "table/tree_land.h" #include "table/tree_land.h"
struct tree_d {
uint16 base;
uint16 count;
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(tree_d));
static int _tree_to_plant;
void PlaceTreesRandomly(); void PlaceTreesRandomly();
static const PalSpriteID _tree_sprites[] = { class BuildTreesWindow : public Window
{
uint16 base;
uint16 count;
int tree_to_plant;
enum BuildTreesWidgets {
BTW_CLOSE,
BTW_CAPTION,
BTW_BACKGROUND,
BTW_TYPE_11,
BTW_TYPE_12,
BTW_TYPE_13,
BTW_TYPE_14,
BTW_TYPE_21,
BTW_TYPE_22,
BTW_TYPE_23,
BTW_TYPE_24,
BTW_TYPE_31,
BTW_TYPE_32,
BTW_TYPE_33,
BTW_TYPE_34,
BTW_TYPE_RANDOM,
BTW_MANY_RANDOM,
};
public:
BuildTreesWindow(const WindowDesc *desc, void *data, WindowNumber window_number) : Window(desc, data, window_number)
{
if (_game_mode != GM_EDITOR) {
this->HideWidget(BTW_MANY_RANDOM);
int offset = this->widget[BTW_MANY_RANDOM].bottom - this->widget[BTW_MANY_RANDOM].top;
this->height -= offset;
this->widget[BTW_BACKGROUND].bottom -= offset;
}
ResetObjectToPlace();
this->FindWindowPlacementAndResize(desc);
}
virtual void OnPaint()
{
static const PalSpriteID tree_sprites[] = {
{ 0x655, PAL_NONE }, { 0x663, PAL_NONE }, { 0x678, PAL_NONE }, { 0x62B, PAL_NONE }, { 0x655, PAL_NONE }, { 0x663, PAL_NONE }, { 0x678, PAL_NONE }, { 0x62B, PAL_NONE },
{ 0x647, PAL_NONE }, { 0x639, PAL_NONE }, { 0x64E, PAL_NONE }, { 0x632, PAL_NONE }, { 0x647, PAL_NONE }, { 0x639, PAL_NONE }, { 0x64E, PAL_NONE }, { 0x632, PAL_NONE },
{ 0x67F, PAL_NONE }, { 0x68D, PAL_NONE }, { 0x69B, PAL_NONE }, { 0x6A9, PAL_NONE }, { 0x67F, PAL_NONE }, { 0x68D, PAL_NONE }, { 0x69B, PAL_NONE }, { 0x6A9, PAL_NONE },
@ -38,156 +72,118 @@ static const PalSpriteID _tree_sprites[] = {
{ 0x7BA, PAL_NONE }, { 0x7C1, PALETTE_TO_RED, }, { 0x7C8, PALETTE_TO_PALE_GREEN }, { 0x7CF, PALETTE_TO_YELLOW }, { 0x7D6, PALETTE_TO_RED } { 0x7BA, PAL_NONE }, { 0x7C1, PALETTE_TO_RED, }, { 0x7C8, PALETTE_TO_PALE_GREEN }, { 0x7CF, PALETTE_TO_YELLOW }, { 0x7D6, PALETTE_TO_RED }
}; };
static void BuildTreesWndProc(Window *w, WindowEvent *e) DrawWindowWidgets(this);
{
switch (e->event) {
case WE_CREATE:
ResetObjectToPlace();
break;
case WE_PAINT: { int i = this->base = _tree_base_by_landscape[_opt.landscape];
DrawWindowWidgets(w); int count = this->count = _tree_count_by_landscape[_opt.landscape];
int i = WP(w, tree_d).base = _tree_base_by_landscape[_opt.landscape];
int count = WP(w, tree_d).count = _tree_count_by_landscape[_opt.landscape];
int x = 18; int x = 18;
int y = 54; int y = 54;
do { do {
DrawSprite(_tree_sprites[i].sprite, _tree_sprites[i].pal, x, y); DrawSprite(tree_sprites[i].sprite, tree_sprites[i].pal, x, y);
x += 35; x += 35;
if (!(++i & 3)) { if (!(++i & 3)) {
x -= 35 * 4; x -= 35 * 4;
y += 47; y += 47;
} }
} while (--count); } while (--count);
} break; }
case WE_CLICK: { virtual void OnClick(Point pt, int widget)
int wid = e->we.click.widget; {
switch (widget) {
switch (wid) { case BTW_CLOSE:
case 0:
ResetObjectToPlace(); ResetObjectToPlace();
break; break;
case 3: case 4: case 5: case 6: case BTW_TYPE_11: case BTW_TYPE_12: case BTW_TYPE_13: case BTW_TYPE_14:
case 7: case 8: case 9: case 10: case BTW_TYPE_21: case BTW_TYPE_22: case BTW_TYPE_23: case BTW_TYPE_24:
case 11:case 12: case 13: case 14: case BTW_TYPE_31: case BTW_TYPE_32: case BTW_TYPE_33: case BTW_TYPE_34:
if (wid - 3 >= WP(w, tree_d).count) break; if (widget - BTW_TYPE_11 >= this->count) break;
if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, VHM_RECT, NULL)) { if (HandlePlacePushButton(this, widget, SPR_CURSOR_TREE, VHM_RECT, NULL)) {
_tree_to_plant = WP(w, tree_d).base + wid - 3; this->tree_to_plant = this->base + widget - BTW_TYPE_11;
} }
break; break;
case 15: // tree of random type. case BTW_TYPE_RANDOM: // tree of random type.
if (HandlePlacePushButton(w, 15, SPR_CURSOR_TREE, VHM_RECT, NULL)) { if (HandlePlacePushButton(this, BTW_TYPE_RANDOM, SPR_CURSOR_TREE, VHM_RECT, NULL)) {
_tree_to_plant = -1; this->tree_to_plant = -1;
} }
break; break;
case 16: // place trees randomly over the landscape case BTW_MANY_RANDOM: // place trees randomly over the landscape
w->LowerWidget(16); this->LowerWidget(BTW_MANY_RANDOM);
w->flags4 |= 5 << WF_TIMEOUT_SHL; this->flags4 |= 5 << WF_TIMEOUT_SHL;
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
PlaceTreesRandomly(); PlaceTreesRandomly();
MarkWholeScreenDirty(); MarkWholeScreenDirty();
break; break;
} }
} break; }
case WE_PLACE_OBJ: virtual void OnPlaceObject(Point pt, TileIndex tile)
VpStartPlaceSizing(e->we.place.tile, VPM_X_AND_Y_LIMITED, DDSP_PLANT_TREES); {
VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_PLANT_TREES);
VpSetPlaceSizingLimit(20); VpSetPlaceSizingLimit(20);
break; }
case WE_PLACE_DRAG: virtual void OnPlaceDrag(ViewportPlaceMethod select_method, byte select_proc, Point pt)
VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); {
return; VpSelectTilesWithMethod(pt.x, pt.y, select_method);
}
case WE_PLACE_MOUSEUP: virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, byte select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
if (e->we.place.pt.x != -1 && e->we.place.select_proc == DDSP_PLANT_TREES) { {
DoCommandP(e->we.place.tile, _tree_to_plant, e->we.place.starttile, NULL, if (pt.x != -1 && select_proc == DDSP_PLANT_TREES) {
DoCommandP(end_tile, this->tree_to_plant, start_tile, NULL,
CMD_PLANT_TREE | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE)); CMD_PLANT_TREE | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE));
} }
break;
case WE_TIMEOUT:
w->RaiseWidget(16);
break;
case WE_ABORT_PLACE_OBJ:
w->RaiseButtons();
break;
} }
virtual void OnTimeout()
{
this->RaiseWidget(BTW_MANY_RANDOM);
this->InvalidateWidget(BTW_MANY_RANDOM);
} }
virtual void OnPlaceObjectAbort()
{
this->RaiseButtons();
}
};
static const Widget _build_trees_widgets[] = { static const Widget _build_trees_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}, // BTW_CLOSE
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, { WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, // BTW_CAPTION
{ WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 170, 0x0, STR_NULL}, { WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 183, 0x0, STR_NULL}, // BTW_BACKGROUND
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_11
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_12
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_13
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_14
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_21
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_22
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_23
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_24
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_31
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_32
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_33
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, { WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, // BTW_TYPE_34
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, // BTW_TYPE_RANDOM
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 170, 181, STR_028A_RANDOM_TREES, STR_028B_PLANT_TREES_RANDOMLY_OVER}, // BTW_MANY_RANDOM
{ WIDGETS_END}, { WIDGETS_END},
}; };
static const WindowDesc _build_trees_desc = { static const WindowDesc _build_trees_desc = {
497, 22, 143, 171, 143, 171,
WC_BUILD_TREES, WC_SCEN_LAND_GEN,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_trees_widgets,
BuildTreesWndProc
};
static const Widget _build_trees_scen_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 183, 0x0, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 170, 181, STR_028A_RANDOM_TREES, STR_028B_PLANT_TREES_RANDOMLY_OVER},
{ WIDGETS_END},
};
static const WindowDesc _build_trees_scen_desc = {
WDP_AUTO, WDP_AUTO, 143, 184, 143, 184, WDP_AUTO, WDP_AUTO, 143, 184, 143, 184,
WC_BUILD_TREES, WC_NONE, WC_BUILD_TREES, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_trees_scen_widgets, _build_trees_widgets,
BuildTreesWndProc NULL
}; };
void ShowBuildTreesToolbar() void ShowBuildTreesToolbar()
{ {
if (!IsValidPlayer(_current_player)) return; if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
AllocateWindowDescFront<Window>(&_build_trees_desc, 0); AllocateWindowDescFront<BuildTreesWindow>(&_build_trees_desc, 0);
}
void ShowBuildTreesScenToolbar()
{
AllocateWindowDescFront<Window>(&_build_trees_scen_desc, 0);
} }