truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" tron@507: #include "table/strings.h" tron@679: #include "map.h" truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "viewport.h" truelight@0: #include "gfx.h" truelight@0: #include "player.h" truelight@0: #include "command.h" truelight@0: #include "news.h" truelight@0: #include "town.h" dominik@130: #include "vehicle.h" dominik@126: #include "console.h" tron@337: #include "sound.h" truelight@543: #include "network.h" truelight@988: #include "signs.h" truelight@543: truelight@543: #ifdef ENABLE_NETWORK truelight@543: #include "network_data.h" truelight@543: #include "network_client.h" truelight@543: #include "network_server.h" truelight@543: #endif /* ENABLE_NETWORK */ truelight@0: truelight@0: #include "table/animcursors.h" truelight@0: truelight@0: tron@349: /* Min/Max date for scenario editor */ darkvater@970: static const uint MinDate = 0; // 1920-01-01 (MAX_YEAR_BEGIN_REAL) tron@349: static const uint MaxDate = 29220; // 2000-01-01 tron@349: tron@1093: extern void DoTestSave(void); tron@1093: extern void DoTestLoad(void); truelight@0: truelight@0: extern bool disable_computer; truelight@0: truelight@0: static int _rename_id; truelight@0: static int _rename_what; truelight@0: truelight@0: static byte _terraform_size = 1; truelight@0: static byte _last_built_railtype; truelight@0: extern void GenerateWorld(int mode); truelight@0: tron@1093: extern void GenerateIndustries(void); tron@1093: extern void GenerateTowns(void); truelight@0: tron@1093: extern uint GetCurrentCurrencyRate(void); truelight@543: truelight@545: extern void CcTerraform(bool success, uint tile, uint32 p1, uint32 p2); truelight@545: tron@1093: void HandleOnEditTextCancel(void) tron@1093: { truelight@543: switch(_rename_what) { truelight@543: #ifdef ENABLE_NETWORK truelight@543: case 4: truelight@543: NetworkDisconnect(); dominik@611: ShowNetworkGameWindow(); truelight@543: break; truelight@543: #endif /* ENABLE_NETWORK */ truelight@543: } truelight@543: } truelight@543: truelight@543: void HandleOnEditText(WindowEvent *e) { truelight@0: byte *b = e->edittext.str; truelight@0: int id; truelight@0: memcpy(_decode_parameters, b, 32); truelight@0: truelight@0: id = _rename_id; truelight@193: truelight@0: switch(_rename_what) { truelight@0: case 0: truelight@0: // for empty string send "remove sign" parameter truelight@0: DoCommandP(0, id, (*b==0)?1:0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME)); truelight@0: break; truelight@0: case 1: truelight@0: if(*b == 0) truelight@0: return; darkvater@395: DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME)); truelight@0: break; truelight@543: #ifdef ENABLE_NETWORK truelight@543: case 2: truelight@543: // Speak to.. truelight@543: if (!_network_server) truelight@543: SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str); truelight@543: else truelight@543: NetworkServer_HandleChat(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str, NETWORK_SERVER_INDEX); truelight@543: break; truelight@543: case 3: { truelight@543: // Give money truelight@543: int32 money = atoi(e->edittext.str) / GetCurrentCurrencyRate(); truelight@543: char msg[100]; truelight@813: truelight@815: money = clamp(money, 0, 0xFFFFFF); // Clamp between 16 million and 0 truelight@813: truelight@543: // Give 'id' the money, and substract it from ourself truelight@543: if (!DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY)) break; truelight@543: truelight@543: // Inform the player of this action truelight@722: snprintf(msg, 100, "%d", money); truelight@543: truelight@543: if (!_network_server) truelight@543: SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg); truelight@543: else truelight@543: NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg, NETWORK_SERVER_INDEX); truelight@543: break; truelight@543: } truelight@543: case 4: {// Game-Password and Company-Password truelight@543: SEND_COMMAND(PACKET_CLIENT_PASSWORD)(id, e->edittext.str); truelight@543: break; truelight@543: } truelight@543: #endif /* ENABLE_NETWORK */ truelight@0: } truelight@0: } truelight@0: dominik@1070: /** dominik@1070: * This code is shared for the majority of the pushbuttons. dominik@1070: * Handles e.g. the pressing of a button (to build things), playing of click sound and sets certain parameters dominik@1070: * dominik@1070: * @param w Window which called the function dominik@1070: * @param widget ID of the widget (=button) that called this function dominik@1070: * @param cursor How should the cursor image change? E.g. cursor with depot image in it dominik@1070: * @param mode Tile highlighting mode, e.g. drawing a rectangle or a dot on the ground dominik@1070: * @param placeproc Procedure which will be called when someone clicks on the map tron@1109: dominik@1070: * @return true if the button is clicked, false if it's unclicked dominik@1070: */ dominik@1070: truelight@0: bool HandlePlacePushButton(Window *w, int widget, uint32 cursor, int mode, PlaceProc *placeproc) truelight@0: { truelight@0: uint32 mask = 1 << widget; truelight@0: truelight@0: if (w->disabled_state & mask) truelight@0: return false; truelight@0: tron@541: if (!_no_button_sound) SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: truelight@0: if (w->click_state & mask) { truelight@0: ResetObjectToPlace(); truelight@0: return false; truelight@0: } truelight@0: truelight@0: SetObjectToPlace(cursor, mode, w->window_class, w->window_number); truelight@0: w->click_state |= mask; truelight@0: _place_proc = placeproc; truelight@0: return true; truelight@0: } truelight@0: truelight@0: truelight@0: void CcPlaySound10(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { tron@541: if (success) SndPlayTileFx(SND_12_EXPLOSION, tile); truelight@0: } truelight@0: truelight@0: truelight@0: typedef void ToolbarButtonProc(Window *w); truelight@0: truelight@0: static void ToolbarPauseClick(Window *w) truelight@0: { truelight@543: if (_networking && !_network_server) { return;} // only server can pause the game darkvater@213: truelight@543: if (DoCommandP(0, _pause?0:1, 0, NULL, CMD_PAUSE)) tron@541: SndPlayFx(SND_15_BEEP); truelight@0: } truelight@0: truelight@0: static void ToolbarFastForwardClick(Window *w) truelight@0: { truelight@0: _fast_forward ^= true; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: } truelight@0: truelight@0: typedef void MenuClickedProc(int index); truelight@0: truelight@0: tron@410: static void MenuClickSettings(int index) truelight@0: { truelight@0: switch(index) { truelight@0: case 0: ShowGameOptions(); return; truelight@0: case 1: ShowGameDifficulty(); return; truelight@0: case 2: ShowPatchesSelection(); return; dominik@478: case 3: ShowNewgrf(); return; truelight@543: darkvater@1015: case 5: _display_opt ^= DO_SHOW_TOWN_NAMES; MarkWholeScreenDirty(); return; darkvater@1015: case 6: _display_opt ^= DO_SHOW_STATION_NAMES; MarkWholeScreenDirty(); return; darkvater@1015: case 7: _display_opt ^= DO_SHOW_SIGNS; MarkWholeScreenDirty(); return; darkvater@1015: case 8: _display_opt ^= DO_WAYPOINTS; MarkWholeScreenDirty(); return; darkvater@1015: case 9: _display_opt ^= DO_FULL_ANIMATION; MarkWholeScreenDirty(); return; darkvater@1015: case 10: _display_opt ^= DO_FULL_DETAIL; MarkWholeScreenDirty(); return; darkvater@1015: case 11: _display_opt ^= DO_TRANS_BUILDINGS; MarkWholeScreenDirty(); return; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickSaveLoad(int index) truelight@0: { truelight@0: if (_game_mode == GM_EDITOR) { truelight@0: switch(index) { truelight@0: case 0: truelight@0: ShowSaveLoadDialog(SLD_SAVE_SCENARIO); truelight@0: break; truelight@0: case 1: truelight@0: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); truelight@0: break; truelight@0: case 2: truelight@0: AskExitToGameMenu(); truelight@0: break; truelight@0: case 4: truelight@0: AskExitGame(); truelight@0: break; truelight@0: } truelight@0: } else { truelight@0: switch(index) { truelight@0: case 0: truelight@0: ShowSaveLoadDialog(SLD_SAVE_GAME); truelight@0: break; truelight@0: case 1: truelight@0: ShowSaveLoadDialog(SLD_LOAD_GAME); truelight@0: break; truelight@0: case 2: truelight@0: AskExitToGameMenu(); truelight@0: break; truelight@0: case 3: truelight@0: AskExitGame(); truelight@0: break; truelight@0: } truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickMap(int index) truelight@0: { truelight@0: switch(index) { truelight@0: case 0: ShowSmallMap(); break; darkvater@152: case 1: ShowExtraViewPortWindow(); break; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickTown(int index) truelight@0: { truelight@0: ShowTownDirectory(); truelight@0: } truelight@0: tron@410: static void MenuClickScenMap(int index) truelight@0: { truelight@0: switch(index) { truelight@0: case 0: ShowSmallMap(); break; tron@355: case 1: ShowExtraViewPortWindow(); break; tron@355: case 2: ShowTownDirectory(); break; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickSubsidies(int index) truelight@0: { truelight@0: ShowSubsidiesList(); truelight@0: } truelight@0: tron@410: static void MenuClickStations(int index) truelight@0: { truelight@0: ShowPlayerStations(index); truelight@0: } truelight@0: tron@410: static void MenuClickFinances(int index) truelight@0: { truelight@0: ShowPlayerFinances(index); truelight@0: } truelight@0: truelight@543: #ifdef ENABLE_NETWORK darkvater@1003: extern void ShowClientList(void); truelight@543: #endif /* ENABLE_NETWORK */ truelight@543: tron@410: static void MenuClickCompany(int index) truelight@0: { truelight@543: if (_networking && index == 0) { truelight@543: #ifdef ENABLE_NETWORK truelight@543: ShowClientList(); truelight@543: #endif /* ENABLE_NETWORK */ truelight@543: } else { truelight@543: if (_networking) index--; truelight@543: ShowPlayerCompany(index); truelight@543: } truelight@0: } truelight@193: truelight@0: tron@410: static void MenuClickGraphs(int index) truelight@0: { truelight@0: switch(index) { truelight@0: case 0: ShowOperatingProfitGraph(); return; truelight@0: case 1: ShowIncomeGraph(); return; truelight@0: case 2: ShowDeliveredCargoGraph(); return; truelight@0: case 3: ShowPerformanceHistoryGraph(); return; truelight@0: case 4: ShowCompanyValueGraph(); return; truelight@0: case 5: ShowCargoPaymentRates(); return; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickLeague(int index) truelight@0: { dominik@116: switch(index) { dominik@116: case 0: ShowCompanyLeagueTable(); return; dominik@116: case 1: ShowPerformanceRatingDetail(); return; dominik@116: } truelight@0: } truelight@0: tron@410: static void MenuClickIndustry(int index) truelight@0: { truelight@0: switch(index) { darkvater@197: case 0: ShowIndustryDirectory(); break; darkvater@197: case 1: ShowBuildIndustryWindow(); break; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickShowTrains(int index) truelight@0: { tron@588: ShowPlayerTrains(index, -1); truelight@0: } truelight@0: tron@410: static void MenuClickShowRoad(int index) truelight@0: { tron@588: ShowPlayerRoadVehicles(index, -1); truelight@0: } truelight@0: tron@410: static void MenuClickShowShips(int index) truelight@0: { tron@588: ShowPlayerShips(index, -1); truelight@0: } truelight@0: tron@410: static void MenuClickShowAir(int index) truelight@0: { tron@588: ShowPlayerAircraft(index, -1); truelight@0: } truelight@0: tron@410: static void MenuClickBuildRail(int index) truelight@0: { truelight@0: Player *p = DEREF_PLAYER(_local_player); truelight@0: _last_built_railtype = min(index, p->max_railtype-1); truelight@0: ShowBuildRailToolbar(_last_built_railtype, -1); truelight@0: } truelight@0: tron@410: static void MenuClickBuildRoad(int index) truelight@0: { truelight@0: ShowBuildRoadToolbar(); truelight@0: } truelight@0: tron@410: static void MenuClickBuildWater(int index) truelight@0: { truelight@0: ShowBuildDocksToolbar(); truelight@0: } truelight@0: tron@410: static void MenuClickBuildAir(int index) truelight@0: { truelight@0: ShowBuildAirToolbar(); truelight@0: } truelight@0: truelight@543: #ifdef ENABLE_NETWORK dominik@649: truelight@543: void ShowNetworkChatQueryWindow(byte desttype, byte dest) truelight@543: { truelight@543: _rename_id = desttype + (dest << 8); truelight@543: _rename_what = 2; truelight@793: ShowChatWindow(STR_EMPTY, STR_NETWORK_CHAT_QUERY_CAPTION, 150, 338, 1, 0); truelight@543: } truelight@543: truelight@543: void ShowNetworkGiveMoneyWindow(byte player) truelight@543: { truelight@543: _rename_id = player; truelight@543: _rename_what = 3; truelight@543: ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, 1, 0); truelight@543: } truelight@543: tron@1093: void ShowNetworkNeedGamePassword(void) truelight@543: { truelight@543: _rename_id = NETWORK_GAME_PASSWORD; truelight@543: _rename_what = 4; truelight@543: ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_GAME_PASSWORD_CAPTION, 20, 180, WC_SELECT_GAME, 0); truelight@543: } truelight@543: tron@1093: void ShowNetworkNeedCompanyPassword(void) truelight@543: { truelight@543: _rename_id = NETWORK_COMPANY_PASSWORD; truelight@543: _rename_what = 4; truelight@543: ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, 20, 180, WC_SELECT_GAME, 0); truelight@543: } truelight@543: truelight@543: #endif /* ENABLE_NETWORK */ truelight@543: truelight@0: void ShowRenameSignWindow(SignStruct *ss) truelight@0: { truelight@988: _rename_id = ss->index; truelight@0: _rename_what = 0; truelight@0: ShowQueryString(ss->str, STR_280B_EDIT_SIGN_TEXT, 30, 180, 1, 0); truelight@0: } truelight@0: darkvater@395: void ShowRenameWaypointWindow(Waypoint *cp) truelight@0: { darkvater@395: int id = cp - _waypoints; truelight@697: truelight@697: /* Are we allowed to change the name of the waypoint? */ truelight@697: if (!CheckTileOwnership(cp->xy)) { tron@926: ShowErrorMessage(_error_message, STR_CANT_CHANGE_WAYPOINT_NAME, tron@926: TileX(cp->xy) * 16, TileY(cp->xy) * 16); truelight@697: return; truelight@697: } truelight@697: truelight@0: _rename_id = id; truelight@0: _rename_what = 1; tron@534: SetDParam(0, id); darkvater@395: ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, 30, 180, 1, 0); truelight@0: } truelight@0: tron@1093: static void SelectSignTool(void) truelight@0: { truelight@0: if (_cursor.sprite == 0x2D2) truelight@0: ResetObjectToPlace(); truelight@0: else { truelight@0: SetObjectToPlace(0x2D2, 1, 1, 0); truelight@0: _place_proc = PlaceProc_Sign; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickForest(int index) truelight@0: { truelight@0: switch(index) { truelight@0: case 0: ShowTerraformToolbar(); break; truelight@0: case 1: ShowBuildTreesToolbar(); break; truelight@0: case 2: SelectSignTool(); break; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickMusicWindow(int index) truelight@0: { truelight@0: ShowMusicWindow(); truelight@0: } truelight@0: tron@410: static void MenuClickNewspaper(int index) truelight@0: { truelight@0: switch(index) { truelight@0: case 0: ShowLastNewsMessage(); break; truelight@0: case 1: ShowMessageOptions(); break; truelight@0: case 2: ShowMessageHistory(); break; truelight@0: case 3: ; /* XXX: chat not done */ truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickHelp(int index) truelight@0: { truelight@0: switch(index) { truelight@0: case 0: PlaceLandBlockInfo(); break; truelight@0: case 2: _make_screenshot = 1; break; truelight@0: case 3: _make_screenshot = 2; break; truelight@0: case 4: ShowAboutWindow(); break; truelight@0: } truelight@0: } truelight@0: truelight@0: static MenuClickedProc * const _menu_clicked_procs[] = { truelight@0: NULL, /* 0 */ truelight@0: NULL, /* 1 */ truelight@0: MenuClickSettings, /* 2 */ truelight@0: MenuClickSaveLoad, /* 3 */ truelight@0: MenuClickMap, /* 4 */ truelight@0: MenuClickTown, /* 5 */ truelight@0: MenuClickSubsidies, /* 6 */ truelight@0: MenuClickStations, /* 7 */ truelight@0: MenuClickFinances, /* 8 */ truelight@0: MenuClickCompany, /* 9 */ truelight@0: MenuClickGraphs, /* 10 */ truelight@0: MenuClickLeague, /* 11 */ truelight@0: MenuClickIndustry, /* 12 */ truelight@0: MenuClickShowTrains, /* 13 */ truelight@0: MenuClickShowRoad, /* 14 */ truelight@0: MenuClickShowShips, /* 15 */ truelight@0: MenuClickShowAir, /* 16 */ truelight@0: MenuClickScenMap, /* 17 */ truelight@0: NULL, /* 18 */ truelight@0: MenuClickBuildRail, /* 19 */ truelight@0: MenuClickBuildRoad, /* 20 */ truelight@0: MenuClickBuildWater, /* 21 */ truelight@0: MenuClickBuildAir, /* 22 */ truelight@0: MenuClickForest, /* 23 */ truelight@0: MenuClickMusicWindow, /* 24 */ truelight@0: MenuClickNewspaper, /* 25 */ truelight@0: MenuClickHelp, /* 26 */ truelight@0: }; truelight@0: truelight@0: static void MenuWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: int count,sel; truelight@0: int x,y; truelight@0: uint16 chk; truelight@0: StringID string; truelight@0: int eo; truelight@0: int inc; truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: count = WP(w,menu_d).item_count; truelight@0: sel = WP(w,menu_d).sel_index; truelight@0: chk = WP(w,menu_d).checked_items; truelight@0: string = WP(w,menu_d).string_id; truelight@0: truelight@0: x = 1; truelight@0: y = 1; truelight@0: truelight@0: eo = 157; truelight@0: truelight@0: inc = (chk != 0) ? 2 : 1; truelight@0: truelight@0: do { truelight@0: if (sel== 0) GfxFillRect(x, y, x + eo, y+9, 0); truelight@0: DrawString(x + 2, y, (StringID)(string + (chk&1)), (byte)(sel==0?(byte)0xC:(byte)0x10)); truelight@0: y += 10; truelight@0: string += inc; truelight@0: chk >>= 1; truelight@0: } while (--sel,--count); truelight@0: } break; truelight@0: truelight@0: case WE_DESTROY: { truelight@0: Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0); truelight@0: v->click_state &= ~(1 << WP(w,menu_d).main_button); truelight@0: SetWindowDirty(v); truelight@0: return; truelight@0: } truelight@193: truelight@0: case WE_POPUPMENU_SELECT: { truelight@0: int index = GetMenuItemIndex(w, e->popupmenu.pt.x, e->popupmenu.pt.y); truelight@0: int action_id; truelight@193: truelight@0: truelight@0: if (index < 0) { truelight@0: Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0); truelight@0: if (GetWidgetFromPos(w2, e->popupmenu.pt.x - w2->left, e->popupmenu.pt.y - w2->top) == WP(w,menu_d).main_button) truelight@0: index = WP(w,menu_d).sel_index; truelight@0: } truelight@0: truelight@0: action_id = WP(w,menu_d).action_id; truelight@0: DeleteWindow(w); truelight@193: truelight@0: if (index >= 0) truelight@0: _menu_clicked_procs[action_id](index); truelight@193: truelight@0: break; truelight@0: } truelight@0: case WE_POPUPMENU_OVER: { truelight@0: int index = GetMenuItemIndex(w, e->popupmenu.pt.x, e->popupmenu.pt.y); truelight@0: truelight@0: if (index == -1 || index == WP(w,menu_d).sel_index) truelight@0: return; truelight@0: truelight@0: WP(w,menu_d).sel_index = index; truelight@0: SetWindowDirty(w); truelight@0: return; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@867: static const Widget _menu_widgets[] = { truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 0, 159, 0, 65535, 0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: truelight@867: static const Widget _player_menu_widgets[] = { truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 0, 240, 0, 81, 0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: truelight@0: static int GetPlayerIndexFromMenu(int index) truelight@0: { truelight@0: Player *p; truelight@0: truelight@0: if (index >= 0) { truelight@0: FOR_ALL_PLAYERS(p) { truelight@0: if (p->is_active) { truelight@0: if (--index < 0) truelight@0: return p->index; truelight@0: } truelight@193: } truelight@0: } truelight@0: return -1; truelight@0: } truelight@0: truelight@0: static void UpdatePlayerMenuHeight(Window *w) truelight@0: { truelight@0: int num = 0; truelight@0: Player *p; truelight@0: truelight@0: FOR_ALL_PLAYERS(p) { truelight@0: if (p->is_active) truelight@0: num++; truelight@0: } truelight@193: truelight@543: // Increase one to fit in PlayerList in the menu when truelight@543: // in network truelight@543: if (_networking && WP(w,menu_d).main_button == 9) { truelight@543: num++; truelight@543: } truelight@543: truelight@0: if (WP(w,menu_d).item_count != num) { truelight@0: WP(w,menu_d).item_count = num; truelight@0: SetWindowDirty(w); truelight@0: num = num * 10 + 2; truelight@0: w->height = num; truelight@867: w->widget[0].bottom = w->widget[0].top + num - 1; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } truelight@0: truelight@543: extern void DrawPlayerIcon(int p, int x, int y); truelight@543: truelight@0: static void PlayerMenuWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: int x,y; truelight@0: byte sel, color; truelight@0: Player *p; truelight@0: uint16 chk; truelight@0: truelight@0: UpdatePlayerMenuHeight(w); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: x = 1; truelight@0: y = 1; truelight@0: sel = WP(w,menu_d).sel_index; truelight@0: chk = WP(w,menu_d).checked_items; // let this mean gray items. truelight@193: truelight@543: // 9 = playerlist truelight@543: if (_networking && WP(w,menu_d).main_button == 9) { truelight@543: if (sel == 0) { truelight@543: GfxFillRect(x, y, x + 238, y + 9, 0); truelight@543: } truelight@543: DrawString(x + 19, y, STR_NETWORK_CLIENT_LIST, 0x0); truelight@543: y += 10; truelight@543: sel--; truelight@543: } truelight@543: truelight@0: FOR_ALL_PLAYERS(p) { truelight@0: if (p->is_active) { truelight@0: if (p->index == sel) { truelight@543: GfxFillRect(x, y, x + 238, y + 9, 0); truelight@0: } truelight@543: truelight@543: DrawPlayerIcon(p->index, x + 2, y + 1); truelight@193: tron@534: SetDParam(0, p->name_1); tron@534: SetDParam(1, p->name_2); tron@534: SetDParam(2, GetPlayerNameString(p->index, 3)); truelight@193: truelight@0: color = (byte)((p->index==sel) ? 0xC : 0x10); truelight@0: if (chk&1) color = 14; truelight@543: DrawString(x + 19, y, STR_7021, color); truelight@193: truelight@0: y += 10; truelight@193: } truelight@193: chk >>= 1; truelight@0: } truelight@543: truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_DESTROY: { truelight@0: Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0); truelight@0: v->click_state &= ~(1 << WP(w,menu_d).main_button); truelight@0: SetWindowDirty(v); truelight@0: return; truelight@0: } truelight@193: truelight@0: case WE_POPUPMENU_SELECT: { truelight@543: int index = GetMenuItemIndex(w, e->popupmenu.pt.x, e->popupmenu.pt.y); truelight@0: int action_id = WP(w,menu_d).action_id; truelight@0: truelight@543: // We have a new entry at the top of the list of menu 9 when networking truelight@543: // so keep that in count truelight@724: if (_networking && WP(w,menu_d).main_button == 9) { truelight@724: if (index > 0) truelight@724: index = GetPlayerIndexFromMenu(index - 1) + 1; truelight@724: } else truelight@724: index = GetPlayerIndexFromMenu(index); truelight@543: truelight@0: if (index < 0) { truelight@0: Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0); truelight@0: if (GetWidgetFromPos(w2, e->popupmenu.pt.x - w2->left, e->popupmenu.pt.y - w2->top) == WP(w,menu_d).main_button) truelight@0: index = WP(w,menu_d).sel_index; truelight@0: } truelight@0: truelight@0: DeleteWindow(w); truelight@193: truelight@0: if (index >= 0) { truelight@0: assert(index >= 0 && index < 30); truelight@0: _menu_clicked_procs[action_id](index); truelight@0: } truelight@0: break; truelight@0: } truelight@0: case WE_POPUPMENU_OVER: { truelight@0: int index; truelight@0: UpdatePlayerMenuHeight(w); truelight@543: index = GetMenuItemIndex(w, e->popupmenu.pt.x, e->popupmenu.pt.y); truelight@543: truelight@543: // We have a new entry at the top of the list of menu 9 when networking truelight@543: // so keep that in count truelight@724: if (_networking && WP(w,menu_d).main_button == 9) { truelight@724: if (index > 0) truelight@724: index = GetPlayerIndexFromMenu(index - 1) + 1; truelight@724: } else truelight@724: index = GetPlayerIndexFromMenu(index); truelight@0: truelight@0: if (index == -1 || index == WP(w,menu_d).sel_index) truelight@0: return; truelight@0: truelight@0: WP(w,menu_d).sel_index = index; truelight@0: SetWindowDirty(w); truelight@0: return; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: static Window *PopupMainToolbMenu(Window *w, int x, int main_button, StringID base_string, int item_count) truelight@0: { truelight@0: x += w->left; truelight@0: truelight@0: SETBIT(w->click_state, (byte)main_button); truelight@0: InvalidateWidget(w, (byte)main_button); truelight@0: truelight@0: DeleteWindowById(WC_TOOLBAR_MENU, 0); truelight@0: truelight@867: w = AllocateWindow(x, 0x16, 0xA0, item_count * 10 + 2, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets); truelight@867: w->widget[0].bottom = item_count * 10 + 1; truelight@0: w->flags4 &= ~WF_WHITE_BORDER_MASK; truelight@193: truelight@0: WP(w,menu_d).item_count = item_count; truelight@0: WP(w,menu_d).sel_index = 0; truelight@0: WP(w,menu_d).main_button = main_button; truelight@0: WP(w,menu_d).action_id = (main_button >> 8) ? (main_button >> 8) : main_button; truelight@0: WP(w,menu_d).string_id = base_string; truelight@0: WP(w,menu_d).checked_items = 0; truelight@0: truelight@0: _popup_menu_active = true; truelight@193: tron@541: SndPlayFx(SND_15_BEEP); truelight@0: truelight@0: return w; truelight@0: } truelight@0: truelight@0: static Window *PopupMainPlayerToolbMenu(Window *w, int x, int main_button, int gray) truelight@0: { truelight@0: x += w->left; truelight@193: truelight@0: SETBIT(w->click_state, main_button); truelight@0: InvalidateWidget(w, main_button); truelight@0: truelight@0: DeleteWindowById(WC_TOOLBAR_MENU, 0); truelight@0: w = AllocateWindow(x, 0x16, 0xF1, 0x52, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets); truelight@0: w->flags4 &= ~WF_WHITE_BORDER_MASK; truelight@0: WP(w,menu_d).item_count = 0; truelight@724: WP(w,menu_d).sel_index = (_local_player != OWNER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0); truelight@724: if (_networking && main_button == 9) { truelight@724: if (_local_player != OWNER_SPECTATOR) truelight@724: WP(w,menu_d).sel_index++; truelight@724: else truelight@724: /* Select client list by default for spectators */ truelight@724: WP(w,menu_d).sel_index = 0; truelight@543: } truelight@0: WP(w,menu_d).action_id = main_button; truelight@0: WP(w,menu_d).main_button = main_button; truelight@0: WP(w,menu_d).checked_items = gray; truelight@0: _popup_menu_active = true; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: return w; truelight@0: } truelight@0: truelight@0: static void ToolbarSaveClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 66, 3, STR_015C_SAVE_GAME, 4); truelight@0: } truelight@0: truelight@0: static void ToolbarMapClick(Window *w) truelight@0: { darkvater@152: PopupMainToolbMenu(w, 96, 4, STR_02DE_MAP_OF_WORLD, 2); truelight@0: } truelight@0: truelight@0: static void ToolbarTownClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 118, 5, STR_02BB_TOWN_DIRECTORY, 1); truelight@0: } truelight@0: truelight@0: static void ToolbarSubsidiesClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 140, 6, STR_02DD_SUBSIDIES, 1); truelight@0: } truelight@0: truelight@0: static void ToolbarStationsClick(Window *w) truelight@0: { truelight@0: PopupMainPlayerToolbMenu(w, 162, 7, 0); truelight@0: } truelight@0: truelight@0: static void ToolbarMoneyClick(Window *w) truelight@0: { truelight@0: PopupMainPlayerToolbMenu(w, 191, 8, 0); truelight@0: } truelight@0: truelight@0: static void ToolbarPlayersClick(Window *w) truelight@0: { truelight@0: PopupMainPlayerToolbMenu(w, 213, 9, 0); truelight@0: } truelight@0: truelight@0: static void ToolbarGraphsClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 236, 10, STR_0154_OPERATING_PROFIT_GRAPH, 6); truelight@0: } truelight@0: truelight@0: static void ToolbarLeagueClick(Window *w) truelight@0: { dominik@116: PopupMainToolbMenu(w, 258, 11, STR_015A_COMPANY_LEAGUE_TABLE, 2); truelight@0: } truelight@0: truelight@0: static void ToolbarIndustryClick(Window *w) truelight@0: { darkvater@197: PopupMainToolbMenu(w, 280, 12, STR_INDUSTRY_DIR, 2); truelight@0: } truelight@0: truelight@0: static void ToolbarTrainClick(Window *w) truelight@0: { truelight@0: Vehicle *v; truelight@0: int dis = -1; truelight@0: FOR_ALL_VEHICLES(v) bjarni@1067: if (v->type == VEH_Train && v->subtype == TS_Front_Engine) CLRBIT(dis, v->owner); truelight@0: PopupMainPlayerToolbMenu(w, 310, 13, dis); truelight@0: } truelight@0: truelight@0: static void ToolbarRoadClick(Window *w) truelight@0: { truelight@0: Vehicle *v; truelight@0: int dis = -1; truelight@0: FOR_ALL_VEHICLES(v) truelight@0: if (v->type == VEH_Road) CLRBIT(dis, v->owner); truelight@0: PopupMainPlayerToolbMenu(w, 332, 14, dis); truelight@0: } truelight@0: truelight@0: static void ToolbarShipClick(Window *w) truelight@0: { truelight@0: Vehicle *v; truelight@0: int dis = -1; truelight@0: FOR_ALL_VEHICLES(v) truelight@0: if (v->type == VEH_Ship) CLRBIT(dis, v->owner); truelight@0: PopupMainPlayerToolbMenu(w, 354, 15, dis); truelight@0: } truelight@0: truelight@0: static void ToolbarAirClick(Window *w) truelight@0: { truelight@0: Vehicle *v; truelight@0: int dis = -1; truelight@0: FOR_ALL_VEHICLES(v) truelight@0: if (v->type == VEH_Aircraft) CLRBIT(dis, v->owner); truelight@0: PopupMainPlayerToolbMenu(w, 376, 16, dis); truelight@0: } truelight@0: darkvater@152: /* Zooms a viewport in a window in or out */ darkvater@152: /* No button handling or what so ever */ darkvater@152: bool DoZoomInOutWindow(int how, Window *w) truelight@0: { truelight@0: ViewPort *vp; truelight@0: int button; truelight@193: truelight@0: switch(_game_mode) { truelight@0: case GM_EDITOR: button = 9; break; truelight@0: case GM_NORMAL: button = 17; break; truelight@0: default: return false; truelight@0: } truelight@0: truelight@0: assert(w); truelight@0: vp = w->viewport; truelight@0: truelight@0: if (how == ZOOM_IN) { truelight@0: if (vp->zoom == 0) return false; truelight@0: vp->zoom--; truelight@0: vp->virtual_width >>= 1; truelight@0: vp->virtual_height >>= 1; truelight@0: truelight@0: WP(w,vp_d).scrollpos_x += vp->virtual_width >> 1; truelight@0: WP(w,vp_d).scrollpos_y += vp->virtual_height >> 1; truelight@0: truelight@0: SetWindowDirty(w); truelight@0: } else if (how == ZOOM_OUT) { truelight@0: if (vp->zoom == 2) return false; truelight@0: vp->zoom++; truelight@0: truelight@0: WP(w,vp_d).scrollpos_x -= vp->virtual_width >> 1; truelight@0: WP(w,vp_d).scrollpos_y -= vp->virtual_height >> 1; truelight@0: truelight@0: vp->virtual_width <<= 1; truelight@0: vp->virtual_height <<= 1; truelight@0: truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: darkvater@152: // routine to disable/enable the zoom buttons. Didn't know where to place these otherwise darkvater@152: { darkvater@168: Window *wt = NULL; darkvater@152: switch (w->window_class) { darkvater@152: case WC_MAIN_WINDOW: darkvater@152: wt = FindWindowById(WC_MAIN_TOOLBAR, 0); darkvater@152: break; darkvater@152: case WC_EXTRA_VIEW_PORT: darkvater@152: wt = FindWindowById(WC_EXTRA_VIEW_PORT, w->window_number); darkvater@682: button = 5; darkvater@152: break; darkvater@152: } truelight@0: darkvater@152: assert(wt); darkvater@152: darkvater@152: // update the toolbar button too darkvater@152: CLRBIT(wt->disabled_state, button); darkvater@152: CLRBIT(wt->disabled_state, button + 1); darkvater@152: if (vp->zoom == 0) SETBIT(wt->disabled_state, button); darkvater@152: else if (vp->zoom == 2) SETBIT(wt->disabled_state, button + 1); darkvater@152: SetWindowDirty(wt); darkvater@152: } truelight@193: truelight@0: return true; truelight@0: } truelight@0: tron@1093: static void MaxZoomIn(void) truelight@0: { darkvater@152: while (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0) ) ) {} truelight@0: } truelight@0: truelight@0: static void ToolbarZoomInClick(Window *w) truelight@0: { darkvater@152: if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) { truelight@0: HandleButtonClick(w, 17); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: } truelight@0: } truelight@0: truelight@0: static void ToolbarZoomOutClick(Window *w) truelight@0: { darkvater@152: if (DoZoomInOutWindow(ZOOM_OUT,FindWindowById(WC_MAIN_WINDOW, 0))) { truelight@0: HandleButtonClick(w, 18); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: } truelight@0: } truelight@0: truelight@0: static void ToolbarBuildRailClick(Window *w) truelight@0: { truelight@0: Player *p = DEREF_PLAYER(_local_player); truelight@0: Window *w2; truelight@0: w2 = PopupMainToolbMenu(w, 457, 19, STR_1015_RAILROAD_CONSTRUCTION, p->max_railtype); truelight@0: WP(w2,menu_d).sel_index = _last_built_railtype; truelight@0: } truelight@0: truelight@0: static void ToolbarBuildRoadClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 479, 20, STR_180A_ROAD_CONSTRUCTION, 1); truelight@0: } truelight@0: truelight@0: static void ToolbarBuildWaterClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 501, 21, STR_9800_DOCK_CONSTRUCTION, 1); truelight@0: } truelight@0: truelight@0: static void ToolbarBuildAirClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 0x1E0, 22, STR_A01D_AIRPORT_CONSTRUCTION, 1); truelight@0: } truelight@0: truelight@0: static void ToolbarForestClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 0x1E0, 23, STR_LANDSCAPING, 3); truelight@0: } truelight@0: truelight@0: static void ToolbarMusicClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 0x1E0, 24, STR_01D3_SOUND_MUSIC, 1); truelight@0: } truelight@0: truelight@0: static void ToolbarNewspaperClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 0x1E0, 25, STR_0200_LAST_MESSAGE_NEWS_REPORT, _newspaper_flag != 2 ? 3 : 4); truelight@0: } truelight@0: truelight@0: static void ToolbarHelpClick(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 0x1E0, 26, STR_02D5_LAND_BLOCK_INFO, 5); truelight@0: } truelight@0: truelight@0: static void ToolbarOptionsClick(Window *w) truelight@0: { truelight@0: uint16 x; truelight@0: darkvater@1015: w = PopupMainToolbMenu(w, 43, 2, STR_02C3_GAME_OPTIONS, 12); truelight@0: truelight@0: x = (uint16)-1; darkvater@1015: if (_display_opt & DO_SHOW_TOWN_NAMES) x &= ~(1<<5); darkvater@1015: if (_display_opt & DO_SHOW_STATION_NAMES) x &= ~(1<<6); darkvater@1015: if (_display_opt & DO_SHOW_SIGNS) x &= ~(1<<7); darkvater@1015: if (_display_opt & DO_WAYPOINTS) x &= ~(1<<8); darkvater@1015: if (_display_opt & DO_FULL_ANIMATION) x &= ~(1<<9); darkvater@1015: if (_display_opt & DO_FULL_DETAIL) x &= ~(1<<10); darkvater@1015: if (_display_opt & DO_TRANS_BUILDINGS) x &= ~(1<<11); truelight@0: WP(w,menu_d).checked_items = x; truelight@0: } truelight@0: truelight@0: truelight@0: static void ToolbarScenSaveOrLoad(Window *w) truelight@0: { truelight@0: PopupMainToolbMenu(w, 0x2C, 3, STR_0292_SAVE_SCENARIO, 5); truelight@0: } truelight@0: truelight@0: static void ToolbarScenDateBackward(Window *w) truelight@0: { truelight@0: // don't allow too fast scrolling truelight@0: if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { truelight@0: HandleButtonClick(w, 6); truelight@0: InvalidateWidget(w, 5); truelight@193: tron@349: if (_date > MinDate) truelight@0: SetDate(ConvertYMDToDay(_cur_year - 1, 0, 1)); truelight@0: } truelight@0: _left_button_clicked = false; truelight@0: } truelight@0: truelight@0: static void ToolbarScenDateForward(Window *w) truelight@0: { truelight@0: // don't allow too fast scrolling truelight@0: if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { truelight@0: HandleButtonClick(w, 7); truelight@0: InvalidateWidget(w, 5); truelight@0: tron@349: if (_date < MaxDate) truelight@0: SetDate(ConvertYMDToDay(_cur_year + 1, 0, 1)); truelight@0: } truelight@0: _left_button_clicked = false; truelight@0: } truelight@0: truelight@0: static void ToolbarScenMapTownDir(Window *w) truelight@0: { tron@355: PopupMainToolbMenu(w, 0x16A, 8 | (17<<8), STR_02DE_MAP_OF_WORLD, 3); truelight@0: } truelight@0: truelight@0: static void ToolbarScenZoomIn(Window *w) truelight@0: { darkvater@152: if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) { truelight@0: HandleButtonClick(w, 9); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: } truelight@0: } truelight@0: truelight@0: static void ToolbarScenZoomOut(Window *w) truelight@0: { darkvater@152: if (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0))) { truelight@0: HandleButtonClick(w, 10); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: } truelight@0: } truelight@0: truelight@193: void ZoomInOrOutToCursorWindow(bool in, Window *w) truelight@0: { darkvater@152: ViewPort * vp; truelight@0: Point pt; truelight@0: truelight@0: assert(w != 0); truelight@0: truelight@0: vp = w->viewport; truelight@0: truelight@0: if (_game_mode != GM_MENU) { truelight@0: if ((in && vp->zoom == 0) || (!in && vp->zoom == 2)) truelight@0: return; truelight@0: darkvater@152: pt = GetTileZoomCenterWindow(in,w); truelight@0: if (pt.x != -1) { darkvater@152: ScrollWindowTo(pt.x, pt.y, w); truelight@0: darkvater@152: DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w); truelight@0: } truelight@0: } truelight@0: } truelight@0: tron@1093: static void ResetLandscape(void) truelight@0: { signde@206: _random_seeds[0][0] = InteractiveRandom(); signde@206: _random_seeds[0][1] = InteractiveRandom(); truelight@193: truelight@0: GenerateWorld(1); truelight@0: MarkWholeScreenDirty(); truelight@193: } truelight@0: truelight@0: static const Widget _ask_reset_landscape_widgets[] = { truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_NULL}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 4, 11, 179, 0, 13, STR_022C_RESET_LANDSCAPE, STR_NULL}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 4, 0, 179, 14, 91, 0x0, STR_NULL}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 12, 25, 84, 72, 83, STR_00C9_NO, STR_NULL}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 12, 95, 154, 72, 83, STR_00C8_YES, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: // Ask first to reset landscape or to make a random landscape truelight@0: static void AskResetLandscapeWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: uint mode = w->window_number; truelight@0: truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); truelight@0: DrawStringMultiCenter(90, 38, mode?STR_022D_ARE_YOU_SURE_YOU_WANT_TO:STR_GENERATE_RANDOM_LANDSCAPE , 168); truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 3: truelight@0: DeleteWindow(w); truelight@0: break; truelight@0: case 4: truelight@0: DeleteWindow(w); darkvater@999: DeleteWindowByClass(WC_INDUSTRY_VIEW); darkvater@999: DeleteWindowByClass(WC_TOWN_VIEW); tron@1019: DeleteWindowByClass(WC_LAND_INFO); darkvater@999: darkvater@999: if (mode) { // reset landscape truelight@0: ResetLandscape(); darkvater@999: } else { // make random landscape tron@541: SndPlayFx(SND_15_BEEP); truelight@0: _switch_mode = SM_GENRANDLAND; truelight@0: } truelight@193: truelight@0: break; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: static const WindowDesc _ask_reset_landscape_desc = { truelight@0: 230,205, 180, 92, truelight@0: WC_ASK_RESET_LANDSCAPE,0, truelight@0: WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _ask_reset_landscape_widgets, truelight@0: AskResetLandscapeWndProc, truelight@0: }; truelight@0: truelight@0: static void AskResetLandscape(uint mode) truelight@0: { truelight@0: AllocateWindowDescFront(&_ask_reset_landscape_desc, mode); truelight@0: } truelight@0: truelight@0: static void CommonRaiseLowerBigLand(uint tile, int mode) truelight@0: { truelight@0: int size; truelight@543: byte h; truelight@0: truelight@0: _error_message_2 = mode ? STR_0808_CAN_T_RAISE_LAND_HERE : STR_0809_CAN_T_LOWER_LAND_HERE; truelight@0: truelight@0: _generating_world = true; truelight@0: tron@926: // tile = TILE_FROM_XY(TileX(tile) * 16 + _tile_fract_coords.x + 8, TileY(tile) * 16 + _tile_fract_coords.y + 8); truelight@0: truelight@0: if (_terraform_size == 1) { darkvater@1014: DoCommandP(tile, 8, (uint32)mode, CcTerraform, CMD_TERRAFORM_LAND | CMD_AUTO | CMD_MSG(_error_message_2)); truelight@0: } else { tron@541: SndPlayTileFx(SND_1F_SPLAT, tile); truelight@0: truelight@0: size = _terraform_size; truelight@0: assert(size != 0); truelight@0: if (mode != 0) { truelight@0: /* Raise land */ truelight@0: h = 15; truelight@0: BEGIN_TILE_LOOP(tile2, size, size, tile) tron@1044: h = min(h, TileHeight(tile2)); truelight@0: END_TILE_LOOP(tile2, size, size, tile) truelight@0: } else { truelight@0: /* Lower land */ truelight@0: h = 0; truelight@0: BEGIN_TILE_LOOP(tile2, size, size, tile) tron@1044: h = max(h, TileHeight(tile2)); truelight@0: END_TILE_LOOP(tile2, size, size, tile) truelight@0: } truelight@0: truelight@0: BEGIN_TILE_LOOP(tile2, size, size, tile) tron@1044: if (TileHeight(tile2) == h) { truelight@0: DoCommandP(tile2, 8, (uint32)mode, NULL, CMD_TERRAFORM_LAND | CMD_AUTO); truelight@0: } truelight@0: END_TILE_LOOP(tile2, size, size, tile) truelight@0: } truelight@0: truelight@0: _generating_world = false; truelight@0: } truelight@0: tron@410: static void PlaceProc_RaiseBigLand(uint tile) truelight@0: { truelight@0: CommonRaiseLowerBigLand(tile, 1); truelight@0: } truelight@0: tron@410: static void PlaceProc_LowerBigLand(uint tile) truelight@0: { truelight@0: CommonRaiseLowerBigLand(tile, 0); truelight@0: } truelight@0: truelight@543: //void CcDemolish(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: //{ truelight@0: // if (success) { truelight@0: //SndPlayTileFx(0x10, tile); tron@926: //CreateEffectVehicleAbove(TileX(tile) * 16 + 8, TileY(tile) * 16 + 8, 2, EV_DEMOLISH); truelight@0: // } truelight@0: //} truelight@0: truelight@0: //void PlaceProc_Demolish(uint tile) truelight@0: //{ truelight@0: // DoCommandP(tile, 0, 0, CcDemolish, CMD_LANDSCAPE_CLEAR | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); truelight@0: //} truelight@0: truelight@0: tron@410: static void PlaceProc_RockyArea(uint tile) truelight@0: { tron@1035: if (!IsTileType(tile, MP_CLEAR) && !IsTileType(tile, MP_TREES)) truelight@0: return; truelight@0: darkvater@872: ModifyTile(tile, MP_SETTYPE(MP_CLEAR) | MP_MAP5, (_map5[tile] & ~0x1C) | 0xB); tron@541: SndPlayTileFx(SND_1F_SPLAT, tile); truelight@0: } truelight@0: tron@410: static void PlaceProc_LightHouse(uint tile) truelight@0: { truelight@0: TileInfo ti; truelight@0: truelight@0: FindLandscapeHeightByTile(&ti, tile); truelight@0: if (ti.type != MP_CLEAR || (ti.tileh & 0x10)) truelight@0: return; truelight@0: truelight@0: ModifyTile(tile, MP_SETTYPE(MP_UNMOVABLE) | MP_MAP5, 1); tron@541: SndPlayTileFx(SND_1F_SPLAT, tile); truelight@0: } truelight@0: tron@410: static void PlaceProc_Transmitter(uint tile) truelight@0: { truelight@0: TileInfo ti; truelight@0: truelight@0: FindLandscapeHeightByTile(&ti, tile); truelight@0: if (ti.type != MP_CLEAR || (ti.tileh & 0x10)) truelight@0: return; truelight@0: truelight@0: ModifyTile(tile, MP_SETTYPE(MP_UNMOVABLE) | MP_MAP5, 0); tron@541: SndPlayTileFx(SND_1F_SPLAT, tile); truelight@0: } truelight@0: tron@410: static void PlaceProc_Desert(uint tile) truelight@0: { truelight@0: SetMapExtraBits(tile, GetMapExtraBits(tile) == 1 ? 0 : 1); truelight@0: } truelight@0: truelight@0: static const Widget _scen_edit_land_gen_widgets[] = { truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 153, 0, 13, STR_0223_LAND_GENERATION,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 153, 14, 99, 0x0, STR_NULL}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 22, 43, 14, 35, 0x2B6, STR_018F_RAISE_A_CORNER_OF_LAND}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 44, 65, 14, 35, 0x2B7, STR_018E_LOWER_A_CORNER_OF_LAND}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 0, 21, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 125, 135, 43, 54, STR_0224, STR_0228_INCREASE_SIZE_OF_LAND_AREA}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 125, 135, 56, 67, STR_0225, STR_0229_DECREASE_SIZE_OF_LAND_AREA}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 20, 135, 75, 86, STR_0226_RANDOM_LAND, STR_022A_GENERATE_RANDOM_LAND}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 20, 135, 88, 99, STR_0227_RESET_LAND, STR_022B_RESET_LANDSCAPE}, truelight@0: truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 88, 109, 14, 35, 0xFF4, STR_028C_PLACE_ROCKY_AREAS_ON_LANDSCAPE}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 110, 131, 14, 35, 0xFF5, STR_028D_PLACE_LIGHTHOUSE}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 132, 153, 14, 35, 0xFF6, STR_028E_PLACE_TRANSMITTER}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 66, 87, 14, 35, SPR_OPENTTD_BASE+68, STR_LEVEL_LAND_TOOLTIP}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const int8 _multi_terraform_coords[][2] = { truelight@0: { 0, -2}, truelight@0: { 4, 0},{ -4, 0},{ 0, 2}, truelight@0: { -8, 2},{ -4, 4},{ 0, 6},{ 4, 4},{ 8, 2}, truelight@0: {-12, 0},{ -8, -2},{ -4, -4},{ 0, -6},{ 4, -4},{ 8, -2},{ 12, 0}, truelight@0: {-16, 2},{-12, 4},{ -8, 6},{ -4, 8},{ 0, 10},{ 4, 8},{ 8, 6},{ 12, 4},{ 16, 2}, truelight@0: {-20, 0},{-16, -2},{-12, -4},{ -8, -6},{ -4, -8},{ 0,-10},{ 4, -8},{ 8, -6},{ 12, -4},{ 16, -2},{ 20, 0}, truelight@0: {-24, 2},{-20, 4},{-16, 6},{-12, 8},{ -8, 10},{ -4, 12},{ 0, 14},{ 4, 12},{ 8, 10},{ 12, 8},{ 16, 6},{ 20, 4},{ 24, 2}, truelight@0: {-28, 0},{-24, -2},{-20, -4},{-16, -6},{-12, -8},{ -8,-10},{ -4,-12},{ 0,-14},{ 4,-12},{ 8,-10},{ 12, -8},{ 16, -6},{ 20, -4},{ 24, -2},{ 28, 0}, truelight@0: }; truelight@0: truelight@0: static void ScenEditLandGenWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: darkvater@989: // XXX - lighthouse button is widget 11!! Don't forget when changing tron@1019: w->widget[11].tooltips = (_opt.landscape == LT_DESERT) ? STR_028F_DEFINE_DESERT_AREA : STR_028D_PLACE_LIGHTHOUSE; truelight@0: DrawWindowWidgets(w); truelight@193: truelight@0: { truelight@0: int n = _terraform_size * _terraform_size; truelight@0: const int8 *coords = &_multi_terraform_coords[0][0]; truelight@0: truelight@0: assert(n != 0); truelight@0: do { truelight@0: DrawSprite(0xFEF, 77 + coords[0], 55 + coords[1]); truelight@0: coords += 2; truelight@0: } while (--n); truelight@0: } truelight@0: truelight@0: if (_thd.window_class == WC_SCEN_LAND_GEN && (w->click_state&(1<<3|1<<4))) { truelight@0: SetTileSelectSize(_terraform_size, _terraform_size); truelight@0: } truelight@0: break; truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 3: /* raise corner */ truelight@0: HandlePlacePushButton(w, 3, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseBigLand); truelight@0: break; truelight@0: case 4: /* lower corner */ truelight@0: HandlePlacePushButton(w, 4, ANIMCURSOR_LOWERLAND, 2, PlaceProc_LowerBigLand); truelight@0: break; truelight@0: case 5: /* demolish */ truelight@0: HandlePlacePushButton(w, 5, ANIMCURSOR_DEMOLISH, 1, PlaceProc_DemolishArea); truelight@0: break; truelight@0: { truelight@0: int size; truelight@0: case 6: /* increase terraform size */ truelight@0: HandleButtonClick(w, 6); truelight@0: size = 1; truelight@0: goto terraform_size_common; truelight@0: case 7: /* decrease terraform size */ truelight@0: HandleButtonClick(w, 7); truelight@0: size = -1; truelight@0: terraform_size_common:; truelight@0: size += _terraform_size; truelight@0: if (!IS_INT_INSIDE(size, 1, 8+1)) truelight@0: return; truelight@0: _terraform_size = size; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: truelight@0: case 8: /* gen random land */ truelight@0: HandleButtonClick(w, 8); truelight@0: AskResetLandscape(0); truelight@0: break; truelight@0: truelight@0: case 9: /* reset landscape */ truelight@0: HandleButtonClick(w,9); truelight@0: AskResetLandscape(1); truelight@0: break; truelight@0: truelight@0: case 10: /* place rocky areas */ truelight@0: HandlePlacePushButton(w, 10, 0xFF7, 1, PlaceProc_RockyArea); truelight@0: break; truelight@193: truelight@0: case 11: /* place lighthouse */ truelight@0: HandlePlacePushButton(w, 11, 0xFF8, 1, _opt.landscape == LT_DESERT ? PlaceProc_Desert : PlaceProc_LightHouse); truelight@0: break; truelight@0: truelight@0: case 12: /* place transmitter */ truelight@0: HandlePlacePushButton(w, 12, 0xFF9, 1, PlaceProc_Transmitter); truelight@0: break; truelight@0: truelight@0: case 13: /* level Land */ truelight@0: HandlePlacePushButton(w, 13, SPR_OPENTTD_BASE+69, 2, PlaceProc_LevelLand); truelight@0: break; truelight@0: } truelight@0: break; truelight@0: case WE_TIMEOUT: truelight@0: UnclickSomeWindowButtons(w, ~(1<<3 | 1<<4 | 1<<5 | 1<<10|1<<11|1<<12)); truelight@0: break; truelight@0: case WE_PLACE_OBJ: truelight@0: _place_proc(e->place.tile); truelight@0: break; truelight@0: case WE_PLACE_DRAG: { truelight@0: VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata & 0xF); truelight@0: return; truelight@0: } truelight@0: case WE_PLACE_MOUSEUP: truelight@0: if (e->click.pt.x != -1) { truelight@0: uint start_tile = e->place.starttile; truelight@0: uint end_tile = e->place.tile; truelight@0: if (e->place.userdata == VPM_X_AND_Y) { truelight@0: DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); truelight@0: } else if (e->place.userdata == (VPM_X_AND_Y | (2<<4))) { truelight@0: DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_LEVEL_LAND | CMD_AUTO); truelight@0: } truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_ABORT_PLACE_OBJ: truelight@0: w->click_state = 0; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const WindowDesc _scen_edit_land_gen_desc = { truelight@0: -1,-1, 154, 100, truelight@0: WC_SCEN_LAND_GEN,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _scen_edit_land_gen_widgets, truelight@0: ScenEditLandGenWndProc, truelight@0: }; truelight@0: truelight@0: static void ToolbarScenGenLand(Window *w) truelight@0: { truelight@0: HandleButtonClick(w, 11); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: truelight@0: AllocateWindowDescFront(&_scen_edit_land_gen_desc, 0); truelight@0: } truelight@0: truelight@543: void CcBuildTown(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (success) { tron@541: SndPlayTileFx(SND_1F_SPLAT, tile); truelight@0: ResetObjectToPlace(); truelight@0: } truelight@0: } truelight@0: tron@410: static void PlaceProc_Town(uint tile) truelight@0: { truelight@0: DoCommandP(tile, 0, 0, CcBuildTown, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE)); truelight@0: } truelight@0: truelight@0: truelight@0: static const Widget _scen_edit_town_gen_widgets[] = { truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 159, 0, 13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 159, 14, 81, 0x0, STR_NULL}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 16, 27, STR_0234_NEW_TOWN, STR_0235_CONSTRUCT_NEW_TOWN}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 29, 40, STR_023D_RANDOM_TOWN, STR_023E_BUILD_TOWN_IN_RANDOM_LOCATION}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 157, 42, 53, STR_MANY_RANDOM_TOWNS, STR_RANDOM_TOWNS_TIP}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 53, 68, 79, STR_02A1_SMALL, STR_02A4_SELECT_TOWN_SIZE}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 54, 105, 68, 79, STR_02A2_MEDIUM, STR_02A4_SELECT_TOWN_SIZE}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 106, 157, 68, 79, STR_02A3_LARGE, STR_02A4_SELECT_TOWN_SIZE}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static void ScenEditTownGenWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: w->click_state = (w->click_state & ~(1<<6 | 1<<7 | 1<<8) ) | (1 << (_new_town_size + 6)); truelight@0: DrawWindowWidgets(w); truelight@0: DrawStringCentered(80, 56, STR_02A5_TOWN_SIZE, 0); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 3: /* new town */ truelight@0: HandlePlacePushButton(w, 3, 0xFF0, 1, PlaceProc_Town); truelight@0: break; truelight@0: case 4: {/* random town */ truelight@0: Town *t; truelight@0: truelight@0: HandleButtonClick(w, 4); truelight@0: _generating_world = true; truelight@0: t = CreateRandomTown(); truelight@0: _generating_world = false; truelight@0: if (t != NULL) truelight@0: ScrollMainWindowToTile(t->xy); truelight@0: break; truelight@0: } truelight@0: case 5: {/* many random towns */ truelight@0: HandleButtonClick(w, 5); truelight@0: _generating_world = true; truelight@0: _game_mode = GM_NORMAL; // little hack to avoid towns of the same size truelight@0: GenerateTowns(); truelight@0: _generating_world = false; truelight@0: _game_mode = GM_EDITOR; truelight@0: break; truelight@0: } truelight@0: truelight@0: case 6: case 7: case 8: truelight@0: _new_town_size = e->click.widget - 6; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_TIMEOUT: truelight@0: UnclickSomeWindowButtons(w, 1<<4 | 1<<5); truelight@0: break; truelight@0: case WE_PLACE_OBJ: truelight@0: _place_proc(e->place.tile); truelight@0: break; truelight@0: case WE_ABORT_PLACE_OBJ: truelight@0: w->click_state = 0; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const WindowDesc _scen_edit_town_gen_desc = { truelight@0: -1,-1, 160, 82, truelight@0: WC_SCEN_TOWN_GEN,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _scen_edit_town_gen_widgets, truelight@0: ScenEditTownGenWndProc, truelight@0: }; truelight@0: truelight@0: static void ToolbarScenGenTown(Window *w) truelight@0: { truelight@0: HandleButtonClick(w, 12); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: truelight@0: AllocateWindowDescFront(&_scen_edit_town_gen_desc, 0); truelight@0: } truelight@0: truelight@0: truelight@0: static const Widget _scenedit_industry_normal_widgets[] = { truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_NULL}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_023F_INDUSTRY_GENERATION, STR_NULL}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 169, 14, 224, 0x0, STR_NULL}, darkvater@176: truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_MANY_RANDOM_INDUSTRIES, STR_RANDOM_INDUSTRIES_TIP}, truelight@867: truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0240_COAL_MINE, STR_0262_CONSTRUCT_COAL_MINE}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0242_SAWMILL, STR_0264_CONSTRUCT_SAWMILL}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 81, 92, STR_0243_FOREST, STR_0265_PLANT_FOREST}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 94, 105, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 107, 118, STR_0245_OIL_RIG, STR_0267_CONSTRUCT_OIL_RIG_CAN_ONLY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 120, 131, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 133, 144, STR_0247_STEEL_MILL, STR_0269_CONSTRUCT_STEEL_MILL}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 146, 157, STR_0248_FARM, STR_026A_CONSTRUCT_FARM}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 159, 170, STR_0249_IRON_ORE_MINE, STR_026B_CONSTRUCT_IRON_ORE_MINE}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 172, 183, STR_024A_OIL_WELLS, STR_026C_CONSTRUCT_OIL_WELLS}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 185, 196, STR_024B_BANK, STR_026D_CONSTRUCT_BANK_CAN_ONLY}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: truelight@0: static const Widget _scenedit_industry_hilly_widgets[] = { truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_NULL}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_023F_INDUSTRY_GENERATION, STR_NULL}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 169, 14, 224, 0x0, STR_NULL}, darkvater@176: truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_MANY_RANDOM_INDUSTRIES, STR_RANDOM_INDUSTRIES_TIP}, truelight@867: truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0240_COAL_MINE, STR_0262_CONSTRUCT_COAL_MINE}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 81, 92, STR_0243_FOREST, STR_0265_PLANT_FOREST}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 94, 105, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 107, 118, STR_024D_FOOD_PROCESSING_PLANT, STR_026F_CONSTRUCT_FOOD_PROCESSING}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 120, 131, STR_024E_PRINTING_WORKS, STR_0270_CONSTRUCT_PRINTING_WORKS}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 133, 144, STR_024F_GOLD_MINE, STR_0271_CONSTRUCT_GOLD_MINE}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 146, 157, STR_0248_FARM, STR_026A_CONSTRUCT_FARM}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 159, 170, STR_024B_BANK, STR_0272_CONSTRUCT_BANK_CAN_ONLY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 172, 183, STR_024A_OIL_WELLS, STR_026C_CONSTRUCT_OIL_WELLS}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const Widget _scenedit_industry_desert_widgets[] = { truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_NULL}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_023F_INDUSTRY_GENERATION, STR_NULL}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 169, 14, 224, 0x0, STR_NULL}, darkvater@176: truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_MANY_RANDOM_INDUSTRIES, STR_RANDOM_INDUSTRIES_TIP}, truelight@867: truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0250_LUMBER_MILL, STR_0273_CONSTRUCT_LUMBER_MILL_TO}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0251_FRUIT_PLANTATION, STR_0274_PLANT_FRUIT_PLANTATION}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0252_RUBBER_PLANTATION,STR_0275_PLANT_RUBBER_PLANTATION}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 81, 92, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 94, 105, STR_024D_FOOD_PROCESSING_PLANT, STR_026F_CONSTRUCT_FOOD_PROCESSING}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 107, 118, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 120, 131, STR_0253_WATER_SUPPLY, STR_0276_CONSTRUCT_WATER_SUPPLY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 133, 144, STR_0248_FARM, STR_026A_CONSTRUCT_FARM}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 146, 157, STR_0254_WATER_TOWER, STR_0277_CONSTRUCT_WATER_TOWER_CAN}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 159, 170, STR_024A_OIL_WELLS, STR_026C_CONSTRUCT_OIL_WELLS}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 172, 183, STR_024B_BANK, STR_0272_CONSTRUCT_BANK_CAN_ONLY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 185, 196, STR_0255_DIAMOND_MINE, STR_0278_CONSTRUCT_DIAMOND_MINE}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 198, 209, STR_0256_COPPER_ORE_MINE, STR_0279_CONSTRUCT_COPPER_ORE_MINE}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const Widget _scenedit_industry_candy_widgets[] = { truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_NULL}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_023F_INDUSTRY_GENERATION,STR_NULL}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 169, 14, 224, 0x0, STR_NULL}, darkvater@176: truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_MANY_RANDOM_INDUSTRIES, STR_RANDOM_INDUSTRIES_TIP}, truelight@867: truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0257_COTTON_CANDY_FOREST,STR_027A_PLANT_COTTON_CANDY_FOREST}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0258_CANDY_FACTORY, STR_027B_CONSTRUCT_CANDY_FACTORY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0259_BATTERY_FARM, STR_027C_CONSTRUCT_BATTERY_FARM}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 81, 92, STR_025A_COLA_WELLS, STR_027D_CONSTRUCT_COLA_WELLS}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 94, 105, STR_025B_TOY_SHOP, STR_027E_CONSTRUCT_TOY_SHOP}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 107, 118, STR_025C_TOY_FACTORY, STR_027F_CONSTRUCT_TOY_FACTORY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 120, 131, STR_025D_PLASTIC_FOUNTAINS, STR_0280_CONSTRUCT_PLASTIC_FOUNTAINS}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 133, 144, STR_025E_FIZZY_DRINK_FACTORY,STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 146, 157, STR_025F_BUBBLE_GENERATOR, STR_0282_CONSTRUCT_BUBBLE_GENERATOR}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 159, 170, STR_0260_TOFFEE_QUARRY, STR_0283_CONSTRUCT_TOFFEE_QUARRY}, truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 172, 183, STR_0261_SUGAR_MINE, STR_0284_CONSTRUCT_SUGAR_MINE}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: int _industry_type_to_place; truelight@0: tron@1093: static bool AnyTownExists(void) tron@1093: { truelight@0: Town *t; truelight@0: FOR_ALL_TOWNS(t) { truelight@0: if (t->xy) truelight@0: return true; truelight@0: } truelight@0: return false; truelight@0: } truelight@0: truelight@0: extern Industry *CreateNewIndustry(uint tile, int type); truelight@0: truelight@0: static bool TryBuildIndustry(TileIndex tile, int type) truelight@0: { truelight@0: int n; truelight@0: dominik@7: if (CreateNewIndustry(tile, type)) return true; dominik@7: truelight@0: n = 100; truelight@0: do { truelight@0: if (CreateNewIndustry(AdjustTileCoordRandomly(tile, 1), type)) return true; truelight@0: } while (--n); truelight@0: truelight@0: n = 200; truelight@0: do { truelight@0: if (CreateNewIndustry(AdjustTileCoordRandomly(tile, 2), type)) return true; truelight@0: } while (--n); truelight@0: truelight@0: n = 700; truelight@0: do { truelight@0: if (CreateNewIndustry(AdjustTileCoordRandomly(tile, 4), type)) return true; truelight@0: } while (--n); truelight@0: truelight@0: return false; truelight@0: } truelight@0: truelight@0: truelight@0: static const byte _industry_type_list[4][16] = { truelight@0: {0, 1, 2, 3, 4, 5, 6, 8, 9, 18, 11, 12}, truelight@0: {0, 1, 14, 3, 4, 13, 7, 15, 9, 16, 11, 12}, truelight@0: {25, 19, 20, 4, 13, 23, 21, 24, 22, 11, 16, 17, 10}, truelight@0: {26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36}, truelight@0: }; truelight@0: dominik@7: bool _ignore_restrictions; dominik@7: truelight@0: static void ScenEditIndustryWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: int button; truelight@0: truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: truelight@193: if ((button=e->click.widget) == 3) { truelight@0: HandleButtonClick(w, 3); truelight@0: truelight@0: if (!AnyTownExists()) { truelight@0: ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0); truelight@0: return; truelight@0: } truelight@0: truelight@0: _generating_world = true; truelight@0: GenerateIndustries(); truelight@0: _generating_world = false; truelight@0: } truelight@193: truelight@0: if ((button=e->click.widget) >= 4) { truelight@0: if (HandlePlacePushButton(w, button, 0xFF1, 1, NULL)) truelight@0: _industry_type_to_place = _industry_type_list[_opt.landscape][button - 4]; truelight@0: } truelight@0: break; truelight@0: case WE_PLACE_OBJ: { truelight@0: int type; truelight@0: truelight@0: // Show error if no town exists at all truelight@0: type = _industry_type_to_place; truelight@0: if (!AnyTownExists()) { tron@534: SetDParam(0, type + STR_4802_COAL_MINE); truelight@0: ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST,STR_0285_CAN_T_BUILD_HERE,e->place.pt.x, e->place.pt.y); truelight@0: return; truelight@0: } truelight@0: truelight@0: _current_player = OWNER_NONE; truelight@0: _generating_world = true; dominik@7: _ignore_restrictions = true; truelight@0: if (!TryBuildIndustry(e->place.tile,type)) { tron@534: SetDParam(0, type + STR_4802_COAL_MINE); truelight@0: ShowErrorMessage(_error_message, STR_0285_CAN_T_BUILD_HERE,e->place.pt.x, e->place.pt.y); truelight@0: } dominik@7: _ignore_restrictions = false; truelight@0: _generating_world = false; truelight@0: break; truelight@0: } truelight@0: case WE_ABORT_PLACE_OBJ: truelight@0: w->click_state = 0; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: case WE_TIMEOUT: truelight@0: UnclickSomeWindowButtons(w, 1<<3); truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const WindowDesc _scenedit_industry_normal_desc = { truelight@0: -1,-1, 170, 225, truelight@0: WC_SCEN_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _scenedit_industry_normal_widgets, truelight@0: ScenEditIndustryWndProc, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _scenedit_industry_hilly_desc = { truelight@0: -1,-1, 170, 225, truelight@0: WC_SCEN_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _scenedit_industry_hilly_widgets, truelight@0: ScenEditIndustryWndProc, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _scenedit_industry_desert_desc = { truelight@0: -1,-1, 170, 225, truelight@0: WC_SCEN_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _scenedit_industry_desert_widgets, truelight@0: ScenEditIndustryWndProc, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _scenedit_industry_candy_desc = { truelight@0: -1,-1, 170, 225, truelight@0: WC_SCEN_INDUSTRY,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _scenedit_industry_candy_widgets, truelight@0: ScenEditIndustryWndProc, truelight@0: }; truelight@0: truelight@0: static const WindowDesc * const _scenedit_industry_descs[] = { truelight@0: &_scenedit_industry_normal_desc, truelight@0: &_scenedit_industry_hilly_desc, truelight@0: &_scenedit_industry_desert_desc, truelight@0: &_scenedit_industry_candy_desc, truelight@0: }; truelight@0: truelight@0: truelight@0: static void ToolbarScenGenIndustry(Window *w) truelight@0: { truelight@0: HandleButtonClick(w, 13); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: AllocateWindowDescFront(_scenedit_industry_descs[_opt.landscape],0); truelight@0: } truelight@0: truelight@0: static void ToolbarScenBuildRoad(Window *w) truelight@0: { truelight@0: HandleButtonClick(w, 14); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: ShowBuildRoadScenToolbar(); truelight@0: } truelight@0: truelight@0: static void ToolbarScenPlantTrees(Window *w) truelight@0: { truelight@0: HandleButtonClick(w, 15); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: ShowBuildTreesScenToolbar(); truelight@0: } truelight@0: truelight@0: static void ToolbarScenPlaceSign(Window *w) truelight@0: { truelight@0: HandleButtonClick(w, 16); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SelectSignTool(); truelight@0: } truelight@0: truelight@0: static void ToolbarBtn_NULL(Window *w) truelight@0: { truelight@0: } truelight@0: truelight@0: static ToolbarButtonProc* const _toolbar_button_procs[] = { truelight@0: ToolbarPauseClick, truelight@0: ToolbarFastForwardClick, truelight@0: ToolbarOptionsClick, truelight@0: ToolbarSaveClick, truelight@0: ToolbarMapClick, truelight@0: ToolbarTownClick, truelight@0: ToolbarSubsidiesClick, truelight@0: ToolbarStationsClick, truelight@0: ToolbarMoneyClick, truelight@0: ToolbarPlayersClick, truelight@0: ToolbarGraphsClick, truelight@0: ToolbarLeagueClick, truelight@0: ToolbarIndustryClick, truelight@0: ToolbarTrainClick, truelight@0: ToolbarRoadClick, truelight@0: ToolbarShipClick, truelight@0: ToolbarAirClick, truelight@0: ToolbarZoomInClick, truelight@0: ToolbarZoomOutClick, truelight@0: ToolbarBuildRailClick, truelight@0: ToolbarBuildRoadClick, truelight@0: ToolbarBuildWaterClick, truelight@0: ToolbarBuildAirClick, truelight@0: ToolbarForestClick, truelight@0: ToolbarMusicClick, truelight@0: ToolbarNewspaperClick, truelight@0: ToolbarHelpClick, truelight@0: }; truelight@0: truelight@0: static void MainToolbarWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: truelight@0: // Draw brown-red toolbar bg. truelight@0: GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2); truelight@0: GfxFillRect(0, 0, w->width-1, w->height-1, 0x80B4); truelight@0: truelight@0: // if spectator, disable things darkvater@1: if (_current_player == OWNER_SPECTATOR){ darkvater@213: w->disabled_state |= (1 << 19) | (1<<20) | (1<<21) | (1<<22) | (1<<23); truelight@0: } else { darkvater@213: w->disabled_state &= ~((1 << 19) | (1<<20) | (1<<21) | (1<<22) | (1<<23)); truelight@0: } truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_CLICK: { truelight@0: if (_game_mode != GM_MENU && !HASBIT(w->disabled_state, e->click.widget)) truelight@0: _toolbar_button_procs[e->click.widget](w); truelight@0: } break; truelight@0: truelight@0: case WE_KEYPRESS: { truelight@0: int local = _local_player; truelight@0: if (local == 0xff) local = 0; // spectator truelight@0: truelight@0: switch(e->keypress.keycode) { tron@424: case WKC_F1: tron@424: case WKC_PAUSE: tron@424: ToolbarPauseClick(w); tron@424: break; truelight@0: case WKC_F2: ShowGameOptions(); break; truelight@0: case WKC_F3: MenuClickSaveLoad(0); break; truelight@0: case WKC_F4: ShowSmallMap(); break; truelight@0: case WKC_F5: ShowTownDirectory(); break; truelight@0: case WKC_F6: ShowSubsidiesList(); break; truelight@0: case WKC_F7: ShowPlayerStations(local); break; truelight@0: case WKC_F8: ShowPlayerFinances(local); break; truelight@0: case WKC_F9: ShowPlayerCompany(local); break; truelight@0: case WKC_F10:ShowOperatingProfitGraph(); break; truelight@0: case WKC_F11: ShowCompanyLeagueTable(); break; truelight@0: case WKC_F12: ShowBuildIndustryWindow(); break; tron@588: case WKC_SHIFT | WKC_F1: ShowPlayerTrains(local, -1); break; tron@588: case WKC_SHIFT | WKC_F2: ShowPlayerRoadVehicles(local, -1); break; tron@588: case WKC_SHIFT | WKC_F3: ShowPlayerShips(local, -1); break; tron@588: case WKC_SHIFT | WKC_F4: ShowPlayerAircraft(local, -1); break; truelight@0: case WKC_SHIFT | WKC_F5: ToolbarZoomInClick(w); break; truelight@0: case WKC_SHIFT | WKC_F6: ToolbarZoomOutClick(w); break; truelight@0: case WKC_SHIFT | WKC_F7: ShowBuildRailToolbar(_last_built_railtype,-1); break; truelight@0: case WKC_SHIFT | WKC_F8: ShowBuildRoadToolbar(); break; truelight@0: case WKC_SHIFT | WKC_F9: ShowBuildDocksToolbar(); break; truelight@0: case WKC_SHIFT | WKC_F10:ShowBuildAirToolbar(); break; truelight@0: case WKC_SHIFT | WKC_F11: ShowBuildTreesToolbar(); break; truelight@0: case WKC_SHIFT | WKC_F12: ShowMusicWindow(); break; truelight@0: case WKC_CTRL | 'S': _make_screenshot = 1; break; dominik@130: case WKC_CTRL | 'G': _make_screenshot = 2; break; truelight@543: case WKC_CTRL | WKC_ALT | 'C': if (!_networking) ShowCheatWindow(); break; truelight@0: } truelight@0: } break; truelight@193: truelight@0: case WE_PLACE_OBJ: { truelight@0: _place_proc(e->place.tile); truelight@0: } break; truelight@0: truelight@0: case WE_ABORT_PLACE_OBJ: { truelight@0: w->click_state &= ~(1<<25); truelight@0: SetWindowDirty(w); truelight@0: } break; truelight@0: truelight@0: case WE_ON_EDIT_TEXT: HandleOnEditText(e); break; truelight@0: truelight@0: case WE_MOUSELOOP: truelight@193: truelight@0: if (((w->click_state) & 1) != (uint)!!_pause) { truelight@0: w->click_state ^= (1 << 0); truelight@0: SetWindowDirty(w); truelight@0: } truelight@193: truelight@0: if (((w->click_state >> 1) & 1) != (uint)!!_fast_forward) { truelight@0: w->click_state ^= (1 << 1); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_TIMEOUT: truelight@0: UnclickSomeWindowButtons(w, ~(1<<0 | 1<<1)); truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _toolb_normal_widgets[] = { truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 0, 21, 0, 21, 0x2D6, STR_0171_PAUSE_GAME}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 22, 43, 0, 21, SPR_OPENTTD_BASE + 57, STR_FAST_FORWARD}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 44, 65, 0, 21, 0x2EF, STR_0187_OPTIONS}, truelight@867: { WWT_PANEL_2, RESIZE_NONE, 14, 66, 87, 0, 21, 0x2D4, STR_0172_SAVE_GAME_ABANDON_GAME}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 96, 117, 0, 21, 0x2C4, STR_0174_DISPLAY_MAP}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 118, 139, 0, 21, 0xFED, STR_0176_DISPLAY_TOWN_DIRECTORY}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 140, 161, 0, 21, 0x2A7, STR_02DC_DISPLAY_SUBSIDIES}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 162, 183, 0, 21, 0x513, STR_0173_DISPLAY_LIST_OF_COMPANY}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 191, 212, 0, 21, 0x2E1, STR_0177_DISPLAY_COMPANY_FINANCES}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 213, 235, 0, 21, 0x2E7, STR_0178_DISPLAY_COMPANY_GENERAL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 236, 257, 0, 21, 0x2E9, STR_0179_DISPLAY_GRAPHS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 258, 279, 0, 21, 0x2AC, STR_017A_DISPLAY_COMPANY_LEAGUE}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 280, 301, 0, 21, 0x2E5, STR_0312_FUND_CONSTRUCTION_OF_NEW}, truelight@0: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 310, 331, 0, 21, 0x2DB, STR_017B_DISPLAY_LIST_OF_COMPANY}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 332, 353, 0, 21, 0x2DC, STR_017C_DISPLAY_LIST_OF_COMPANY}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 354, 375, 0, 21, 0x2DD, STR_017D_DISPLAY_LIST_OF_COMPANY}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 376, 397, 0, 21, 0x2DE, STR_017E_DISPLAY_LIST_OF_COMPANY}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 406, 427, 0, 21, 0x2DF, STR_017F_ZOOM_THE_VIEW_IN}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 428, 449, 0, 21, 0x2E0, STR_0180_ZOOM_THE_VIEW_OUT}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 457, 478, 0, 21, 0x2D7, STR_0181_BUILD_RAILROAD_TRACK}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 479, 500, 0, 21, 0x2D8, STR_0182_BUILD_ROADS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 501, 522, 0, 21, 0x2D9, STR_0183_BUILD_SHIP_DOCKS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 523, 544, 0, 21, 0x2DA, STR_0184_BUILD_AIRPORTS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 545, 566, 0, 21, 0xFF3, STR_LANDSCAPING_TOOLBAR_TIP}, // tree icon is 0x2E6 truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 574, 595, 0, 21, 0x2C9, STR_01D4_SHOW_SOUND_MUSIC_WINDOW}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 596, 617, 0, 21, 0x2A8, STR_0203_SHOW_LAST_MESSAGE_NEWS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 618, 639, 0, 21, 0x2D3, STR_0186_LAND_BLOCK_INFORMATION}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _toolb_normal_desc = { truelight@0: 0, 0, 640, 22, truelight@0: WC_MAIN_TOOLBAR,0, truelight@0: WDF_STD_TOOLTIPS | WDF_DEF_WIDGET, truelight@0: _toolb_normal_widgets, truelight@0: MainToolbarWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _toolb_intro_desc = { truelight@0: 0, -22, 640, 22, truelight@0: WC_MAIN_TOOLBAR,0, truelight@0: WDF_STD_TOOLTIPS | WDF_DEF_WIDGET, truelight@0: _toolb_normal_widgets, truelight@0: MainToolbarWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: static const Widget _toolb_scen_widgets[] = { truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 0, 21, 0, 21, 0x2D6, STR_0171_PAUSE_GAME}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 22, 43, 0, 21, SPR_OPENTTD_BASE + 57, STR_FAST_FORWARD}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 44, 65, 0, 21, 0x2EF, STR_0187_OPTIONS}, truelight@867: { WWT_PANEL_2, RESIZE_NONE, 14, 66, 87, 0, 21, 0x2D4, STR_0297_SAVE_SCENARIO_LOAD_SCENARIO}, darkvater@176: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 96, 225, 0, 21, 0x0, STR_NULL}, darkvater@176: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 233, 362, 0, 21, 0x0, STR_NULL}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 236, 246, 5, 16, STR_0225, STR_029E_MOVE_THE_STARTING_DATE}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 347, 357, 5, 16, STR_0224, STR_029F_MOVE_THE_STARTING_DATE}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 371, 392, 0, 21, 0x2C4, STR_0175_DISPLAY_MAP_TOWN_DIRECTORY}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 400, 421, 0, 21, 0x2DF, STR_017F_ZOOM_THE_VIEW_IN}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 422, 443, 0, 21, 0x2E0, STR_0180_ZOOM_THE_VIEW_OUT}, truelight@867: truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 452, 473, 0, 21, 0xFF3, STR_022E_LANDSCAPE_GENERATION}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 474, 495, 0, 21, 0xFED, STR_022F_TOWN_GENERATION}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 496, 517, 0, 21, 0x2E5, STR_0230_INDUSTRY_GENERATION}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 518, 539, 0, 21, 0x2D8, STR_0231_ROAD_CONSTRUCTION}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 540, 561, 0, 21, 0x2E6, STR_0288_PLANT_TREES}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 562, 583, 0, 21, 0xFF2, STR_0289_PLACE_SIGN}, truelight@867: truelight@867: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, truelight@867: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, truelight@867: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, truelight@867: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, truelight@867: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, truelight@867: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, truelight@867: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 596, 617, 0, 21, 0x2C9, STR_01D4_SHOW_SOUND_MUSIC_WINDOW}, truelight@867: { WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 618, 639, 0, 21, 0x2D3, STR_0186_LAND_BLOCK_INFORMATION}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static ToolbarButtonProc* const _scen_toolbar_button_procs[] = { truelight@0: ToolbarPauseClick, truelight@0: ToolbarFastForwardClick, truelight@0: ToolbarOptionsClick, truelight@0: ToolbarScenSaveOrLoad, truelight@0: ToolbarBtn_NULL, truelight@0: ToolbarBtn_NULL, truelight@0: ToolbarScenDateBackward, truelight@0: ToolbarScenDateForward, truelight@0: ToolbarScenMapTownDir, truelight@0: ToolbarScenZoomIn, truelight@0: ToolbarScenZoomOut, truelight@0: ToolbarScenGenLand, truelight@0: ToolbarScenGenTown, truelight@0: ToolbarScenGenIndustry, truelight@0: ToolbarScenBuildRoad, truelight@0: ToolbarScenPlantTrees, truelight@0: ToolbarScenPlaceSign, truelight@0: NULL, truelight@0: NULL, truelight@0: NULL, truelight@0: NULL, truelight@0: NULL, truelight@0: NULL, truelight@0: NULL, truelight@0: ToolbarMusicClick, truelight@0: NULL, truelight@0: ToolbarHelpClick, truelight@0: }; truelight@0: truelight@0: static void ScenEditToolbarWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: tron@349: /* XXX look for better place for these */ tron@349: if (_date <= MinDate) tron@349: SETBIT(w->disabled_state, 6); tron@349: else tron@349: CLRBIT(w->disabled_state, 6); tron@349: if (_date >= MaxDate) tron@349: SETBIT(w->disabled_state, 7); tron@349: else tron@349: CLRBIT(w->disabled_state, 7); tron@349: truelight@0: // Draw brown-red toolbar bg. truelight@0: GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2); truelight@0: GfxFillRect(0, 0, w->width-1, w->height-1, 0x80B4); truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: tron@534: SetDParam(0, _date); truelight@0: DrawStringCentered(298, 6, STR_00AF, 0); truelight@0: tron@534: SetDParam(0, _date); darkvater@74: DrawStringCentered(161, 1, STR_0221_OPENTTD, 0); truelight@0: DrawStringCentered(161, 11,STR_0222_SCENARIO_EDITOR, 0); truelight@0: truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: if (_game_mode == GM_MENU) truelight@0: return; truelight@0: _scen_toolbar_button_procs[e->click.widget](w); truelight@0: } break; truelight@0: truelight@0: case WE_KEYPRESS: { truelight@0: switch(e->keypress.keycode) { truelight@0: case WKC_F1: ToolbarPauseClick(w); break; truelight@0: case WKC_F2: ShowGameOptions(); break; truelight@0: case WKC_F3: MenuClickSaveLoad(0); break; truelight@0: case WKC_F4: ToolbarScenGenLand(w); break; truelight@0: case WKC_F5: ToolbarScenGenTown(w); break; truelight@0: case WKC_F6: ToolbarScenGenIndustry(w); break; truelight@0: case WKC_F7: ToolbarScenBuildRoad(w); break; truelight@0: case WKC_F8: ToolbarScenPlantTrees(w); break; truelight@0: case WKC_F9: ToolbarScenPlaceSign(w); break; truelight@0: case WKC_F10: ShowMusicWindow(); break; truelight@0: case WKC_F11: PlaceLandBlockInfo(); break; truelight@0: case WKC_CTRL | 'S': _make_screenshot = 1; break; truelight@0: case WKC_CTRL | 'G': _make_screenshot = 2; break; truelight@0: } truelight@0: break; truelight@0: } truelight@193: truelight@0: case WE_PLACE_OBJ: { truelight@0: _place_proc(e->place.tile); truelight@0: } break; truelight@0: truelight@0: case WE_ABORT_PLACE_OBJ: { truelight@0: w->click_state &= ~(1<<25); truelight@0: SetWindowDirty(w); truelight@0: } break; truelight@0: truelight@0: case WE_ON_EDIT_TEXT: HandleOnEditText(e); break; truelight@0: truelight@0: case WE_MOUSELOOP: dominik@24: if (((w->click_state) & 1) != (uint)!!_pause) { dominik@24: w->click_state ^= (1 << 0); dominik@24: SetWindowDirty(w); dominik@24: } dominik@24: truelight@0: if (((w->click_state >> 1) & 1) != (uint)!!_fast_forward) { truelight@0: w->click_state ^= (1 << 1); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: break; truelight@0: truelight@0: } truelight@0: } truelight@0: truelight@0: static const WindowDesc _toolb_scen_desc = { truelight@0: 0, 0, 640, 22, truelight@0: WC_MAIN_TOOLBAR,0, truelight@0: WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _toolb_scen_widgets, truelight@0: ScenEditToolbarWndProc truelight@0: }; truelight@0: truelight@0: extern GetNewsStringCallbackProc * const _get_news_string_callback[]; truelight@0: truelight@0: truelight@0: static bool DrawScrollingStatusText(NewsItem *ni, int pos) truelight@0: { truelight@0: StringID str; truelight@0: byte *s, *d; truelight@0: DrawPixelInfo tmp_dpi, *old_dpi; truelight@0: int x; truelight@0: byte buffer[256]; truelight@0: truelight@0: if (ni->display_mode == 3) { truelight@0: str = _get_news_string_callback[ni->callback](ni); truelight@0: } else { truelight@0: COPY_IN_DPARAM(0, ni->params, lengthof(ni->params)); truelight@193: str = ni->string_id; truelight@0: } truelight@0: truelight@0: GetString(str_buffr, str); truelight@0: assert(strlen(str_buffr) < sizeof(str_buffr) - 1); truelight@0: truelight@0: s = str_buffr; truelight@0: d = buffer; truelight@0: truelight@0: for(;;s++) { truelight@0: if (*s == 0) { truelight@0: *d = 0; truelight@0: break; truelight@0: } else if (*s == 0x0D) { truelight@0: d[0] = d[1] = d[2] = d[3] = ' '; truelight@0: d+=4; truelight@0: } else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) { truelight@0: *d++ = *s; truelight@0: } truelight@0: } truelight@0: truelight@0: if (!FillDrawPixelInfo(&tmp_dpi, NULL, 141, 1, 358, 11)) truelight@0: return true; truelight@0: truelight@0: old_dpi = _cur_dpi; truelight@0: _cur_dpi = &tmp_dpi; truelight@0: truelight@0: x = DoDrawString(buffer, pos, 0, 13); truelight@0: _cur_dpi = old_dpi; truelight@0: truelight@0: return x > 0; truelight@0: } truelight@0: tron@410: static void StatusBarWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: Player *p; truelight@0: truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); tron@534: SetDParam(0, _date); truelight@0: DrawStringCentered(70, 1, ((_pause||_patches.status_long_date)?STR_00AF:STR_00AE), 0); truelight@193: darkvater@1: p = _local_player == OWNER_SPECTATOR ? NULL : DEREF_PLAYER(_local_player); truelight@0: truelight@0: if (p) { truelight@0: // Draw player money tron@534: SetDParam64(0, p->money64); truelight@0: DrawStringCentered(570, 1, p->player_money >= 0 ? STR_0004 : STR_0005, 0); truelight@0: } truelight@0: truelight@0: // Draw status bar truelight@0: if (_do_autosave) { truelight@0: DrawStringCentered(320, 1, STR_032F_AUTOSAVE, 0); truelight@0: } else if (_pause) { truelight@0: DrawStringCentered(320, 1, STR_0319_PAUSED, 0); truelight@0: } else if (WP(w,def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) { truelight@0: // Draw the scrolling news text truelight@0: if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w,def_d).data_1)) truelight@0: WP(w,def_d).data_1 = -1280; truelight@0: } else { truelight@0: if (p) { truelight@0: // This is the default text tron@534: SetDParam(0, p->name_1); tron@534: SetDParam(1, p->name_2); truelight@0: DrawStringCentered(320, 1, STR_02BA, 0); truelight@0: } truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_CLICK: truelight@0: if (e->click.widget == 1) { truelight@0: ShowLastNewsMessage(); truelight@0: } else if (e->click.widget == 2) { darkvater@1: if (_local_player != OWNER_SPECTATOR) ShowPlayerFinances(_local_player); truelight@0: } else { truelight@0: ResetObjectToPlace(); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_TICK: { truelight@0: if (_pause || WP(w,def_d).data_1 <= -1280) truelight@0: return; truelight@0: WP(w,def_d).data_1 -= 2; truelight@0: InvalidateWidget(w, 1); truelight@0: break; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: static void ScrollMainViewport(int x, int y) truelight@0: { truelight@0: if (_game_mode != GM_MENU) { truelight@0: Window *w = FindWindowById(WC_MAIN_WINDOW, 0); truelight@0: assert(w); truelight@0: truelight@0: WP(w,vp_d).scrollpos_x += x << w->viewport->zoom; truelight@0: WP(w,vp_d).scrollpos_y += y << w->viewport->zoom; truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: static const Widget _main_status_widgets[] = { truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 0, 139, 0, 11, 0x0, STR_NULL}, truelight@867: { WWT_PUSHIMGBTN, RESIZE_NONE, 14, 140, 499, 0, 11, 0x0, STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS}, truelight@867: { WWT_PUSHIMGBTN, RESIZE_NONE, 14, 500, 639, 0, 11, 0x0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static WindowDesc _main_status_desc = { truelight@0: WDP_CENTER, 0, 640, 12, truelight@0: WC_STATUS_BAR,0, truelight@0: WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _main_status_widgets, truelight@0: StatusBarWndProc truelight@0: }; truelight@0: truelight@0: extern void DebugProc(int i); truelight@0: truelight@0: static void MainWindowWndProc(Window *w, WindowEvent *e) { truelight@0: int off_x; truelight@0: truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawWindowViewport(w); truelight@0: if (_game_mode == GM_MENU) { darkvater@581: off_x = _screen.width / 2; truelight@0: darkvater@582: DrawSprite(SPR_OTTD_O, off_x - 120, 50); darkvater@582: DrawSprite(SPR_OTTD_P, off_x - 86, 50); darkvater@582: DrawSprite(SPR_OTTD_E, off_x - 53, 50); darkvater@582: DrawSprite(SPR_OTTD_N, off_x - 22, 50); truelight@193: darkvater@582: DrawSprite(SPR_OTTD_T, off_x + 34, 50); darkvater@582: DrawSprite(SPR_OTTD_T, off_x + 65, 50); darkvater@582: DrawSprite(SPR_OTTD_D, off_x + 96, 50); truelight@670: darkvater@581: /* darkvater@581: DrawSprite(SPR_OTTD_R, off_x + 119, 50); darkvater@581: DrawSprite(SPR_OTTD_A, off_x + 148, 50); darkvater@581: DrawSprite(SPR_OTTD_N, off_x + 181, 50); darkvater@581: DrawSprite(SPR_OTTD_S, off_x + 215, 50); darkvater@581: DrawSprite(SPR_OTTD_P, off_x + 246, 50); darkvater@581: DrawSprite(SPR_OTTD_O, off_x + 275, 50); darkvater@581: DrawSprite(SPR_OTTD_R, off_x + 307, 50); darkvater@581: DrawSprite(SPR_OTTD_T, off_x + 337, 50); darkvater@581: darkvater@581: DrawSprite(SPR_OTTD_T, off_x + 390, 50); darkvater@581: DrawSprite(SPR_OTTD_Y, off_x + 417, 50); darkvater@581: DrawSprite(SPR_OTTD_C, off_x + 447, 50); darkvater@581: DrawSprite(SPR_OTTD_O, off_x + 478, 50); darkvater@581: DrawSprite(SPR_OTTD_O, off_x + 509, 50); darkvater@581: DrawSprite(SPR_OTTD_N, off_x + 541, 50); darkvater@581: */ truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_KEYPRESS: truelight@0: if (_game_mode == GM_MENU) truelight@0: break; truelight@0: truelight@0: // this is a hack, but this needs to be called at a constant interval and i found truelight@0: // no other window event that was suited for that purpose. truelight@0: { truelight@0: static const int8 scrollamt[16][2] = { truelight@0: {0,0}, truelight@0: {-1,0}, // 1:left truelight@0: {0,-1}, // 2:up truelight@0: {-1,-1}, // 3:left + up truelight@0: {1,0}, // 4:right truelight@0: {0,0}, // 5:left + right truelight@0: {1,-1}, // 6:right + up truelight@0: {0,0}, // 7:impossible truelight@0: {0,1}, // 8:down truelight@0: {-1,1}, // 9:down+left truelight@0: {0,0}, // 10:impossible truelight@0: {0,0}, // 11:impossible truelight@0: {1,1}, // 12:down+right truelight@0: {0,0}, // 13:impossible truelight@0: {0,0}, // 14:impossible truelight@0: {0,0}, // 15:impossible truelight@0: }; truelight@0: truelight@0: if (_dirkeys) { truelight@0: int factor = _shift_pressed ? 50 : 10; truelight@0: ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor); truelight@0: } truelight@0: } truelight@0: truelight@0: switch(e->keypress.keycode) { truelight@0: case 'C': truelight@0: case 'Z': { truelight@0: Point pt; truelight@0: pt = GetTileBelowCursor(); truelight@0: if (pt.x != -1) { truelight@0: ScrollMainWindowTo(pt.x, pt.y); truelight@0: if (e->keypress.keycode == 'Z') truelight@0: MaxZoomIn(); truelight@0: } truelight@0: break; truelight@0: } truelight@193: truelight@0: case WKC_ESC: ResetObjectToPlace(); break; truelight@0: case WKC_DELETE: DeleteNonVitalWindows(); break; darkvater@763: case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break; truelight@0: case 'Q' | WKC_CTRL: AskExitGame(); break; truelight@0: case 'Q' | WKC_META: AskExitGame(); break; // this enables command + Q on mac truelight@0: case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break; truelight@0: case '0' | WKC_ALT: truelight@0: case '1' | WKC_ALT: truelight@0: case '2' | WKC_ALT: truelight@0: case '3' | WKC_ALT: truelight@0: case '4' | WKC_ALT: truelight@0: #if defined(_DEBUG) truelight@0: DebugProc(e->keypress.keycode - ('0' | WKC_ALT)); truelight@0: #endif truelight@0: break; truelight@0: case 'A' | WKC_CTRL: truelight@0: disable_computer^=1; truelight@0: ShowInfoF("Disable Computer: %s", disable_computer?"ON":"OFF"); truelight@0: break; truelight@0: case 'B' | WKC_CTRL: truelight@0: _local_player^=1; truelight@0: ShowInfoF("Play as computer: %s", _local_player?"ON":"OFF"); truelight@0: break; truelight@0: truelight@0: // invoke autorail truelight@0: case 'A': dominik@658: ShowBuildRailToolbar(_last_built_railtype, 4); truelight@0: break; truelight@0: truelight@670: case 'L': truelight@670: ShowTerraformToolbar(); dominik@616: break; dominik@616: truelight@0: case 'X': truelight@0: _display_opt ^= DO_TRANS_BUILDINGS; truelight@0: MarkWholeScreenDirty(); truelight@0: break; truelight@0: truelight@670: case WKC_BACKQUOTE: truelight@670: IConsoleSwitch(); truelight@670: e->keypress.cont=false; dominik@616: break; dominik@616: truelight@543: #ifdef ENABLE_NETWORK dominik@649: case WKC_RETURN: truelight@543: case 'T' | WKC_SHIFT: dominik@649: if(_networking) dominik@649: ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0); truelight@543: break; truelight@543: #endif /* ENABLE_NETWORK */ truelight@543: truelight@0: default: truelight@0: return; truelight@0: } truelight@0: e->keypress.cont = false; truelight@0: break; truelight@193: truelight@0: } truelight@0: } truelight@0: truelight@0: tron@1093: void ShowSelectGameWindow(void); darkvater@774: extern void ShowJoinStatusWindowAfterJoin(void); truelight@0: tron@1093: void SetupColorsAndInitialWindow(void) truelight@0: { truelight@0: int i; truelight@0: byte *b; truelight@0: Window *w; truelight@0: int width,height; truelight@0: truelight@0: for(i=0; i!=16; i++) { truelight@0: b = GetSpritePtr(0x307 + i); truelight@0: assert(b); truelight@0: _color_list[i] = *(ColorList*)(b + 0xC6); truelight@0: } truelight@0: truelight@0: width = _screen.width; truelight@0: height = _screen.height; truelight@0: truelight@0: // XXX: these are not done truelight@0: switch(_game_mode) { truelight@0: case GM_MENU: truelight@0: w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL); truelight@0: AssignWindowViewport(w, 0, 0, width, height, 0x8080, 0); truelight@0: // w = AllocateWindowDesc(&_toolb_intro_desc); truelight@0: // w->flags4 &= ~WF_WHITE_BORDER_MASK; truelight@0: ShowSelectGameWindow(); truelight@0: break; truelight@0: case GM_NORMAL: truelight@0: w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL); truelight@0: AssignWindowViewport(w, 0, 0, width, height, 0x8080, 0); truelight@0: darkvater@983: ShowVitalWindows(); truelight@0: truelight@670: /* Bring joining GUI to front till the client is really joined */ truelight@670: if (_networking && !_network_server) truelight@670: ShowJoinStatusWindowAfterJoin(); truelight@670: truelight@0: break; truelight@0: case GM_EDITOR: truelight@0: w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL); truelight@0: AssignWindowViewport(w, 0, 0, width, height, 0, 0); truelight@0: truelight@0: w = AllocateWindowDesc(&_toolb_scen_desc); truelight@0: w->disabled_state = 1 << 9; darkvater@983: CLRBITS(w->flags4, WF_WHITE_BORDER_MASK); truelight@193: darkvater@68: PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_scen_desc) truelight@0: break; truelight@0: default: truelight@0: NOT_REACHED(); truelight@0: } truelight@0: } truelight@0: darkvater@983: void ShowVitalWindows(void) darkvater@983: { darkvater@983: Window *w; darkvater@983: darkvater@983: w = AllocateWindowDesc(&_toolb_normal_desc); darkvater@983: w->disabled_state = 1 << 17; // disable zoom-in button (by default game is zoomed in) darkvater@983: CLRBITS(w->flags4, WF_WHITE_BORDER_MASK); darkvater@983: darkvater@983: if (_networking) { // if networking, disable fast-forward button darkvater@983: SETBIT(w->disabled_state, 1); darkvater@983: if (!_network_server) // if not server, disable pause button darkvater@983: SETBIT(w->disabled_state, 0); darkvater@983: } tron@1019: darkvater@983: PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_normal_desc) darkvater@983: darkvater@983: _main_status_desc.top = _screen.height - 12; darkvater@983: w = AllocateWindowDesc(&_main_status_desc); darkvater@983: CLRBITS(w->flags4, WF_WHITE_BORDER_MASK); darkvater@983: darkvater@983: WP(w,def_d).data_1 = -1280; darkvater@983: } darkvater@983: tron@1093: void GameSizeChanged(void) truelight@0: { truelight@0: RelocateAllWindows(_screen.width, _screen.height); truelight@0: ScreenSizeChanged(); truelight@0: MarkWholeScreenDirty(); truelight@0: }