diff options
author | rubidium <rubidium@openttd.org> | 2008-05-15 14:12:22 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-05-15 14:12:22 +0000 |
commit | 8fff6e8638b848b129a3609ef22c0d0b611940e8 (patch) | |
tree | 82002bd31d9ce94ced461e9bf3f44976f9e84a90 /src | |
parent | d94bef9d5ce4a2ce83528e1c4346597dec22e843 (diff) | |
download | openttd-8fff6e8638b848b129a3609ef22c0d0b611940e8.tar.xz |
(svn r13103) -Codechange: make a class of the PlayerCompanyWindow.
Diffstat (limited to 'src')
-rw-r--r-- | src/player_gui.cpp | 302 | ||||
-rw-r--r-- | src/window_gui.h | 4 |
2 files changed, 154 insertions, 152 deletions
diff --git a/src/player_gui.cpp b/src/player_gui.cpp index 784c0d78f..ae84535e5 100644 --- a/src/player_gui.cpp +++ b/src/player_gui.cpp @@ -1164,199 +1164,203 @@ static void DrawCompanyOwnerText(const Player *p) * @param w window pointer * @param e event been triggered */ -static void PlayerCompanyWndProc(Window *w, WindowEvent *e) +struct PlayerCompanyWindow : Window { - switch (e->event) { - case WE_PAINT: { - const Player *p = GetPlayer((PlayerID)w->window_number); - bool local = w->window_number == _local_player; - - w->SetWidgetHiddenState(PCW_WIDGET_NEW_FACE, !local); - w->SetWidgetHiddenState(PCW_WIDGET_COLOR_SCHEME, !local); - w->SetWidgetHiddenState(PCW_WIDGET_PRESIDENT_NAME, !local); - w->SetWidgetHiddenState(PCW_WIDGET_COMPANY_NAME, !local); - w->widget[PCW_WIDGET_BUILD_VIEW_HQ].data = (local && p->location_of_house == 0) ? STR_706F_BUILD_HQ : STR_7072_VIEW_HQ; - if (local && p->location_of_house != 0) w->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; //HQ is already built. - w->SetWidgetDisabledState(PCW_WIDGET_BUILD_VIEW_HQ, !local && p->location_of_house == 0); - w->SetWidgetHiddenState(PCW_WIDGET_RELOCATE_HQ, !local || p->location_of_house == 0); - w->SetWidgetHiddenState(PCW_WIDGET_BUY_SHARE, local); - w->SetWidgetHiddenState(PCW_WIDGET_SELL_SHARE, local); - w->SetWidgetHiddenState(PCW_WIDGET_COMPANY_PASSWORD, !local || !_networking); - - if (!local) { - if (_patches.allow_shares) { // Shares are allowed - /* If all shares are owned by someone (none by nobody), disable buy button */ - w->SetWidgetDisabledState(PCW_WIDGET_BUY_SHARE, GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0 || - /* Only 25% left to buy. If the player is human, disable buying it up.. TODO issues! */ - (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) || - /* Spectators cannot do anything of course */ - _local_player == PLAYER_SPECTATOR); - - /* If the player doesn't own any shares, disable sell button */ - w->SetWidgetDisabledState(PCW_WIDGET_SELL_SHARE, (GetAmountOwnedBy(p, _local_player) == 0) || - /* Spectators cannot do anything of course */ - _local_player == PLAYER_SPECTATOR); - } else { // Shares are not allowed, disable buy/sell buttons - w->DisableWidget(PCW_WIDGET_BUY_SHARE); - w->DisableWidget(PCW_WIDGET_SELL_SHARE); - } - } + PlayerCompanyWindowWidgets query_widget; - SetDParam(0, p->index); - SetDParam(1, p->index); + PlayerCompanyWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) + { + this->caption_color = this->window_number; + } - DrawWindowWidgets(w); + ~PlayerCompanyWindow() + { + DeleteWindowById(WC_PLAYER_FACE, this->window_number); + if (this->window_number == _local_player) DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0); + } - /* Player face */ - DrawPlayerFace(p->face, p->player_color, 2, 16); + virtual void OnPaint() + { + const Player *p = GetPlayer((PlayerID)this->window_number); + bool local = this->window_number == _local_player; + + this->SetWidgetHiddenState(PCW_WIDGET_NEW_FACE, !local); + this->SetWidgetHiddenState(PCW_WIDGET_COLOR_SCHEME, !local); + this->SetWidgetHiddenState(PCW_WIDGET_PRESIDENT_NAME, !local); + this->SetWidgetHiddenState(PCW_WIDGET_COMPANY_NAME, !local); + this->widget[PCW_WIDGET_BUILD_VIEW_HQ].data = (local && p->location_of_house == 0) ? STR_706F_BUILD_HQ : STR_7072_VIEW_HQ; + if (local && p->location_of_house != 0) this->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; //HQ is already built. + this->SetWidgetDisabledState(PCW_WIDGET_BUILD_VIEW_HQ, !local && p->location_of_house == 0); + this->SetWidgetHiddenState(PCW_WIDGET_RELOCATE_HQ, !local || p->location_of_house == 0); + this->SetWidgetHiddenState(PCW_WIDGET_BUY_SHARE, local); + this->SetWidgetHiddenState(PCW_WIDGET_SELL_SHARE, local); + this->SetWidgetHiddenState(PCW_WIDGET_COMPANY_PASSWORD, !local || !_networking); + + if (!local) { + if (_patches.allow_shares) { // Shares are allowed + /* If all shares are owned by someone (none by nobody), disable buy button */ + this->SetWidgetDisabledState(PCW_WIDGET_BUY_SHARE, GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0 || + /* Only 25% left to buy. If the player is human, disable buying it up.. TODO issues! */ + (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) || + /* Spectators cannot do anything of course */ + _local_player == PLAYER_SPECTATOR); + + /* If the player doesn't own any shares, disable sell button */ + this->SetWidgetDisabledState(PCW_WIDGET_SELL_SHARE, (GetAmountOwnedBy(p, _local_player) == 0) || + /* Spectators cannot do anything of course */ + _local_player == PLAYER_SPECTATOR); + } else { // Shares are not allowed, disable buy/sell buttons + this->DisableWidget(PCW_WIDGET_BUY_SHARE); + this->DisableWidget(PCW_WIDGET_SELL_SHARE); + } + } - /* "xxx (Manager)" */ - SetDParam(0, p->index); - DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, 94); + SetDParam(0, p->index); + SetDParam(1, p->index); - /* "Inaugurated:" */ - SetDParam(0, p->inaugurated_year); - DrawString(110, 23, STR_7038_INAUGURATED, TC_FROMSTRING); + DrawWindowWidgets(this); - /* "Colour scheme:" */ - DrawString(110, 43, STR_7006_COLOR_SCHEME, TC_FROMSTRING); - /* Draw company-colour bus */ - DrawSprite(SPR_VEH_BUS_SW_VIEW, PLAYER_SPRITE_COLOR(p->index), 215, 44); + /* Player face */ + DrawPlayerFace(p->face, p->player_color, 2, 16); - /* "Vehicles:" */ - DrawPlayerVehiclesAmount((PlayerID)w->window_number); + /* "xxx (Manager)" */ + SetDParam(0, p->index); + DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, 94); - /* "Company value:" */ - SetDParam(0, CalculateCompanyValue(p)); - DrawString(110, 106, STR_7076_COMPANY_VALUE, TC_FROMSTRING); + /* "Inaugurated:" */ + SetDParam(0, p->inaugurated_year); + DrawString(110, 23, STR_7038_INAUGURATED, TC_FROMSTRING); - /* Shares list */ - DrawCompanyOwnerText(p); + /* "Colour scheme:" */ + DrawString(110, 43, STR_7006_COLOR_SCHEME, TC_FROMSTRING); + /* Draw company-colour bus */ + DrawSprite(SPR_VEH_BUS_SW_VIEW, PLAYER_SPRITE_COLOR(p->index), 215, 44); - break; - } + /* "Vehicles:" */ + DrawPlayerVehiclesAmount((PlayerID)this->window_number); - case WE_CLICK: - switch (e->we.click.widget) { - case PCW_WIDGET_NEW_FACE: DoSelectPlayerFace((PlayerID)w->window_number, false); break; + /* "Company value:" */ + SetDParam(0, CalculateCompanyValue(p)); + DrawString(110, 106, STR_7076_COMPANY_VALUE, TC_FROMSTRING); - case PCW_WIDGET_COLOR_SCHEME: - if (BringWindowToFrontById(WC_PLAYER_COLOR, w->window_number)) break; - new SelectPlayerLiveryWindow(&_select_player_livery_desc, (PlayerID)w->window_number); - break; + /* Shares list */ + DrawCompanyOwnerText(p); + } - case PCW_WIDGET_PRESIDENT_NAME: { - const Player *p = GetPlayer((PlayerID)w->window_number); - WP(w, def_d).byte_1 = 0; - SetDParam(0, p->index); - ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, 31, 94, w, CS_ALPHANUMERAL); - break; - } + virtual void OnClick(Point pt, int widget) + { + switch (widget) { + case PCW_WIDGET_NEW_FACE: DoSelectPlayerFace((PlayerID)this->window_number, false); break; - case PCW_WIDGET_COMPANY_NAME: { - Player *p = GetPlayer((PlayerID)w->window_number); - WP(w, def_d).byte_1 = 1; - SetDParam(0, p->index); - ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, 31, 150, w, CS_ALPHANUMERAL); - break; - } + case PCW_WIDGET_COLOR_SCHEME: + if (BringWindowToFrontById(WC_PLAYER_COLOR, this->window_number)) break; + new SelectPlayerLiveryWindow(&_select_player_livery_desc, (PlayerID)this->window_number); + break; + + case PCW_WIDGET_PRESIDENT_NAME: + this->query_widget = PCW_WIDGET_PRESIDENT_NAME; + SetDParam(0, this->window_number); + ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, 31, 94, this, CS_ALPHANUMERAL); + break; + + case PCW_WIDGET_COMPANY_NAME: + this->query_widget = PCW_WIDGET_COMPANY_NAME; + SetDParam(0, this->window_number); + ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, 31, 150, this, CS_ALPHANUMERAL); + break; - case PCW_WIDGET_BUILD_VIEW_HQ: { - TileIndex tile = GetPlayer((PlayerID)w->window_number)->location_of_house; - if (tile == 0) { - if ((byte)w->window_number != _local_player) - return; - SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, w); - SetTileSelectSize(2, 2); - w->LowerWidget(PCW_WIDGET_BUILD_VIEW_HQ); - w->InvalidateWidget(PCW_WIDGET_BUILD_VIEW_HQ); + case PCW_WIDGET_BUILD_VIEW_HQ: { + TileIndex tile = GetPlayer((PlayerID)this->window_number)->location_of_house; + if (tile == 0) { + if ((byte)this->window_number != _local_player) return; + SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, this); + SetTileSelectSize(2, 2); + this->LowerWidget(PCW_WIDGET_BUILD_VIEW_HQ); + this->InvalidateWidget(PCW_WIDGET_BUILD_VIEW_HQ); + } else { + if (_ctrl_pressed) { + ShowExtraViewPortWindow(tile); } else { - if (_ctrl_pressed) { - ShowExtraViewPortWindow(tile); - } else { - ScrollMainWindowToTile(tile); - } + ScrollMainWindowToTile(tile); } - break; } + break; + } - case PCW_WIDGET_RELOCATE_HQ: - SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, w); - SetTileSelectSize(2, 2); - w->LowerWidget(PCW_WIDGET_RELOCATE_HQ); - w->InvalidateWidget(PCW_WIDGET_RELOCATE_HQ); - break; + case PCW_WIDGET_RELOCATE_HQ: + SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, VHM_RECT, this); + SetTileSelectSize(2, 2); + this->LowerWidget(PCW_WIDGET_RELOCATE_HQ); + this->InvalidateWidget(PCW_WIDGET_RELOCATE_HQ); + break; - case PCW_WIDGET_BUY_SHARE: - DoCommandP(0, w->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS)); - break; + case PCW_WIDGET_BUY_SHARE: + DoCommandP(0, this->window_number, 0, NULL, CMD_BUY_SHARE_IN_COMPANY | CMD_MSG(STR_707B_CAN_T_BUY_25_SHARE_IN_THIS)); + break; - case PCW_WIDGET_SELL_SHARE: - DoCommandP(0, w->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN)); - break; + case PCW_WIDGET_SELL_SHARE: + DoCommandP(0, this->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN)); + break; #ifdef ENABLE_NETWORK - case PCW_WIDGET_COMPANY_PASSWORD: - if (w->window_number == _local_player) ShowNetworkCompanyPasswordWindow(); - break; + case PCW_WIDGET_COMPANY_PASSWORD: + if (this->window_number == _local_player) ShowNetworkCompanyPasswordWindow(); + break; #endif /* ENABLE_NETWORK */ - } - break; + } + } - case WE_TICK: - /* redraw the window every now and then */ - if ((++w->vscroll.pos & 0x1F) == 0) w->SetDirty(); - break; + virtual void OnTick() + { + /* redraw the window every now and then */ + if ((++this->vscroll.pos & 0x1F) == 0) this->SetDirty(); + } - case WE_PLACE_OBJ: - if (DoCommandP(e->we.place.tile, 0, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS))) - ResetObjectToPlace(); - w->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; // this button can now behave as a normal push button - w->RaiseButtons(); - break; + virtual void OnPlaceObject(Point pt, TileIndex tile) + { + if (DoCommandP(tile, 0, 0, NULL, CMD_BUILD_COMPANY_HQ | CMD_NO_WATER | CMD_MSG(STR_7071_CAN_T_BUILD_COMPANY_HEADQUARTERS))) + ResetObjectToPlace(); + this->widget[PCW_WIDGET_BUILD_VIEW_HQ].type = WWT_PUSHTXTBTN; // this button can now behave as a normal push button + this->RaiseButtons(); + } - case WE_ABORT_PLACE_OBJ: - w->RaiseButtons(); - break; + virtual void OnPlaceObjectAbort() + { + this->RaiseButtons(); + } - case WE_DESTROY: - DeleteWindowById(WC_PLAYER_FACE, w->window_number); - if (w->window_number == _local_player) DeleteWindowById(WC_COMPANY_PASSWORD_WINDOW, 0); - break; + virtual void OnQueryTextFinished(char *str) + { + if (StrEmpty(str)) return; - case WE_ON_EDIT_TEXT: - if (StrEmpty(e->we.edittext.str)) break; + _cmd_text = str; + switch (this->query_widget) { + default: NOT_REACHED(); - _cmd_text = e->we.edittext.str; - switch (WP(w, def_d).byte_1) { - case 0: /* Change president name */ - DoCommandP(0, 0, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT)); - break; - case 1: /* Change company name */ - DoCommandP(0, 0, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME)); - break; - } - break; - } -} + case PCW_WIDGET_PRESIDENT_NAME: + DoCommandP(0, 0, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT)); + break; + case PCW_WIDGET_COMPANY_NAME: + DoCommandP(0, 0, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME)); + break; + } + } +}; static const WindowDesc _player_company_desc = { WDP_AUTO, WDP_AUTO, 360, 170, 360, 170, WC_COMPANY, WC_NONE, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, _player_company_widgets, - PlayerCompanyWndProc + NULL }; void ShowPlayerCompany(PlayerID player) { - Window *w; - if (!IsValidPlayer(player)) return; - w = AllocateWindowDescFront<Window>(&_player_company_desc, player); - if (w != NULL) w->caption_color = w->window_number; + AllocateWindowDescFront<PlayerCompanyWindow>(&_player_company_desc, player); } diff --git a/src/window_gui.h b/src/window_gui.h index 8102340ae..cc72d2613 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -527,10 +527,8 @@ struct menu_d { assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d)); struct def_d { - int16 data_1, data_2, data_3; - int16 data_4, data_5; bool close; - byte byte_1; + int16 data_1, data_2, data_3; }; assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d)); |