tron@2186: /* $Id$ */ tron@2186: belugas@6527: /** @file main_gui.cpp */ belugas@6527: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" truelight@4300: #include "heightmap.h" tron@2292: #include "currency.h" tron@1349: #include "spritecache.h" truelight@0: #include "gui.h" rubidium@8603: #include "window_gui.h" rubidium@8603: #include "window_func.h" rubidium@8603: #include "textbuf_gui.h" rubidium@8720: #include "viewport_func.h" rubidium@8612: #include "command_func.h" rubidium@9259: #include "news_func.h" truelight@0: #include "town.h" dominik@126: #include "console.h" rubidium@9286: #include "signs_func.h" truelight@1542: #include "waypoint.h" tron@2159: #include "variables.h" bjarni@2676: #include "train.h" maedhros@7353: #include "roadveh.h" maedhros@7698: #include "bridge_map.h" belugas@4184: #include "screenshot.h" truelight@4300: #include "genworld.h" bjarni@4668: #include "vehicle_gui.h" peter1138@6923: #include "transparency_gui.h" peter1138@5237: #include "newgrf_config.h" rubidium@8607: #include "rail_gui.h" rubidium@8607: #include "road_gui.h" rubidium@8636: #include "date_func.h" rubidium@8627: #include "functions.h" rubidium@8640: #include "vehicle_func.h" rubidium@8653: #include "sound_func.h" belugas@8645: #include "fios.h" rubidium@8701: #include "terraform_gui.h" belugas@4942: #include "industry.h" belugas@8345: #include "transparency.h" rubidium@8610: #include "strings_func.h" rubidium@8619: #include "zoom_func.h" rubidium@8710: #include "string_func.h" rubidium@8750: #include "player_base.h" rubidium@8750: #include "player_func.h" rubidium@8750: #include "player_gui.h" rubidium@8766: #include "settings_type.h" rubidium@9219: #include "toolbar_gui.h" truelight@0: rubidium@8760: #include "network/network.h" rubidium@8760: #include "network/network_data.h" rubidium@8760: #include "network/network_client.h" rubidium@8760: #include "network/network_server.h" rubidium@8760: #include "network/network_gui.h" rubidium@8760: rubidium@8760: #include "table/sprites.h" rubidium@8760: #include "table/strings.h" rubidium@8760: Darkvater@5664: static int _rename_id = 1; Darkvater@5664: static int _rename_what = -1; truelight@0: KUDr@5116: RailType _last_built_railtype; rubidium@7162: RoadType _last_built_roadtype; rubidium@8139: bool _draw_bounding_boxes = false; rubidium@8139: truelight@543: rubidium@7343: void CcGiveMoney(bool success, TileIndex tile, uint32 p1, uint32 p2) rubidium@7343: { rubidium@7394: #ifdef ENABLE_NETWORK rubidium@8153: if (!success || !_patches.give_money) return; rubidium@7343: rubidium@7343: char msg[20]; rubidium@7343: /* Inform the player of this action */ rubidium@7343: snprintf(msg, sizeof(msg), "%d", p1); rubidium@7343: rubidium@7343: if (!_network_server) { rubidium@7343: SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg); rubidium@7343: } else { rubidium@7343: NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, NETWORK_SERVER_INDEX); rubidium@7343: } rubidium@7394: #endif /* ENABLE_NETWORK */ rubidium@7343: } rubidium@7343: Darkvater@5682: void HandleOnEditText(const char *str) Darkvater@1799: { Darkvater@5682: int id = _rename_id; Darkvater@5682: _cmd_text = str; truelight@193: Darkvater@1799: switch (_rename_what) { belugas@6527: case 1: // Rename a waypoint Darkvater@5682: if (*str == '\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 belugas@6527: case 3: { // Give money, you can only give money in excess of loan celestar@1962: const Player *p = GetPlayer(_current_player); rubidium@8001: Money money = min(p->player_money - p->current_loan, (Money)(atoi(str) / _currency->rate)); Darkvater@1799: skidd13@8418: uint32 money_c = Clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0 truelight@813: belugas@6527: /* Give 'id' the money, and substract it from ourself */ rubidium@7486: DoCommandP(0, money_c, id, CcGiveMoney, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS)); rubidium@6988: } break; Darkvater@5664: #endif /* ENABLE_NETWORK */ Darkvater@5664: default: NOT_REACHED(); truelight@543: } Darkvater@5664: Darkvater@5664: _rename_id = _rename_what = -1; 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 dominik@1070: * @return true if the button is clicked, false if it's unclicked dominik@1070: */ rubidium@8385: bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, ViewportHighlightMode mode, PlaceProc *placeproc) truelight@0: { rubidium@8493: if (w->IsWidgetDisabled(widget)) return false; truelight@0: tron@2621: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: rubidium@8493: if (w->IsWidgetLowered(widget)) { truelight@0: ResetObjectToPlace(); truelight@0: return false; truelight@0: } truelight@0: peter1138@5919: SetObjectToPlace(cursor, PAL_NONE, mode, w->window_class, w->window_number); rubidium@8493: w->LowerWidget(widget); truelight@0: _place_proc = placeproc; truelight@0: return true; truelight@0: } truelight@0: truelight@0: tron@1977: void CcPlaySound10(bool success, TileIndex tile, uint32 p1, uint32 p2) truelight@0: { tron@541: if (success) SndPlayTileFx(SND_12_EXPLOSION, tile); truelight@0: } truelight@0: truelight@0: tron@410: static void MenuClickSettings(int index) truelight@0: { tron@2631: switch (index) { tron@2631: case 0: ShowGameOptions(); return; tron@2631: case 1: ShowGameDifficulty(); return; tron@2631: case 2: ShowPatchesSelection(); return; Darkvater@5352: case 3: ShowNewGRFSettings(!_networking, true, true, &_grfconfig); return; truelight@7511: case 4: ShowTransparencyToolbar(); break; truelight@7511: skidd13@8428: case 6: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break; skidd13@8428: case 7: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break; skidd13@8428: case 8: ToggleBit(_display_opt, DO_SHOW_SIGNS); break; skidd13@8428: case 9: ToggleBit(_display_opt, DO_WAYPOINTS); break; skidd13@8428: case 10: ToggleBit(_display_opt, DO_FULL_ANIMATION); break; skidd13@8428: case 11: ToggleBit(_display_opt, DO_FULL_DETAIL); break; belugas@8948: case 12: ToggleTransparency(TO_HOUSES); break; belugas@8345: case 13: ToggleTransparency(TO_SIGNS); break; truelight@0: } tron@2631: MarkWholeScreenDirty(); truelight@0: } truelight@0: rubidium@9219: void MenuClickSaveLoad(int index) truelight@0: { truelight@0: if (_game_mode == GM_EDITOR) { tron@2631: switch (index) { Darkvater@6145: case 0: ShowSaveLoadDialog(SLD_SAVE_SCENARIO); break; Darkvater@6145: case 1: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break; Darkvater@6145: case 2: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break; Darkvater@6145: case 3: AskExitToGameMenu(); break; Darkvater@6145: case 5: HandleExitGameRequest(); break; truelight@0: } truelight@0: } else { tron@2631: switch (index) { tron@2631: case 0: ShowSaveLoadDialog(SLD_SAVE_GAME); break; tron@2631: case 1: ShowSaveLoadDialog(SLD_LOAD_GAME); break; tron@2631: case 2: AskExitToGameMenu(); break; rubidium@4548: case 3: HandleExitGameRequest(); break; truelight@0: } truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickMap(int index) truelight@0: { tron@2631: switch (index) { tron@2631: case 0: ShowSmallMap(); break; tron@2631: case 1: ShowExtraViewPortWindow(); break; tron@2631: case 2: ShowSignList(); 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: { tron@2631: switch (index) { tron@2631: case 0: ShowSmallMap(); break; tron@2631: case 1: ShowExtraViewPortWindow(); break; tron@2631: case 2: ShowSignList(); break; peter1138@7621: case 3: 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: { rubidium@5838: ShowPlayerStations((PlayerID)index); truelight@0: } truelight@0: tron@410: static void MenuClickFinances(int index) truelight@0: { rubidium@5838: ShowPlayerFinances((PlayerID)index); truelight@0: } truelight@0: tron@410: static void MenuClickCompany(int index) truelight@0: { truelight@543: if (_networking && index == 0) { truelight@543: ShowClientList(); truelight@543: } else { truelight@543: if (_networking) index--; rubidium@5838: ShowPlayerCompany((PlayerID)index); truelight@543: } truelight@0: } truelight@193: tron@410: static void MenuClickGraphs(int index) truelight@0: { tron@2631: switch (index) { tron@2631: case 0: ShowOperatingProfitGraph(); break; tron@2631: case 1: ShowIncomeGraph(); break; tron@2631: case 2: ShowDeliveredCargoGraph(); break; tron@2631: case 3: ShowPerformanceHistoryGraph(); break; tron@2631: case 4: ShowCompanyValueGraph(); break; tron@2631: case 5: ShowCargoPaymentRates(); break; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickLeague(int index) truelight@0: { tron@2631: switch (index) { tron@2631: case 0: ShowCompanyLeagueTable(); break; tron@2631: case 1: ShowPerformanceRatingDetail(); break; dominik@116: } truelight@0: } truelight@0: tron@410: static void MenuClickIndustry(int index) truelight@0: { tron@2631: switch (index) { tron@2631: case 0: ShowIndustryDirectory(); break; tron@2631: case 1: ShowBuildIndustryWindow(); break; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickShowTrains(int index) truelight@0: { rubidium@6585: ShowVehicleListWindow((PlayerID)index, VEH_TRAIN); truelight@0: } truelight@0: tron@410: static void MenuClickShowRoad(int index) truelight@0: { rubidium@6585: ShowVehicleListWindow((PlayerID)index, VEH_ROAD); truelight@0: } truelight@0: tron@410: static void MenuClickShowShips(int index) truelight@0: { rubidium@6585: ShowVehicleListWindow((PlayerID)index, VEH_SHIP); truelight@0: } truelight@0: tron@410: static void MenuClickShowAir(int index) truelight@0: { rubidium@6585: ShowVehicleListWindow((PlayerID)index, VEH_AIRCRAFT); truelight@0: } truelight@0: tron@410: static void MenuClickBuildRail(int index) truelight@0: { rubidium@5838: _last_built_railtype = (RailType)index; truelight@0: ShowBuildRailToolbar(_last_built_railtype, -1); truelight@0: } truelight@0: tron@410: static void MenuClickBuildRoad(int index) truelight@0: { rubidium@7162: _last_built_roadtype = (RoadType)index; rubidium@7162: ShowBuildRoadToolbar(_last_built_roadtype); 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 Darkvater@4830: void ShowNetworkGiveMoneyWindow(PlayerID player) truelight@543: { truelight@543: _rename_id = player; truelight@543: _rename_what = 3; Darkvater@5682: ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, NULL, CS_NUMERAL); truelight@543: } truelight@543: #endif /* ENABLE_NETWORK */ truelight@543: tron@2116: void ShowRenameWaypointWindow(const Waypoint *wp) truelight@0: { truelight@1542: int id = wp->index; truelight@697: truelight@697: /* Are we allowed to change the name of the waypoint? */ truelight@1542: if (!CheckTileOwnership(wp->xy)) { tron@926: ShowErrorMessage(_error_message, STR_CANT_CHANGE_WAYPOINT_NAME, celestar@3422: TileX(wp->xy) * TILE_SIZE, TileY(wp->xy) * TILE_SIZE); truelight@697: return; truelight@697: } truelight@697: truelight@0: _rename_id = id; truelight@0: _rename_what = 1; tron@534: SetDParam(0, id); Darkvater@5682: ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, 30, 180, NULL, CS_ALPHANUMERAL); truelight@0: } truelight@0: rubidium@9219: void SelectSignTool() truelight@0: { tron@2639: if (_cursor.sprite == SPR_CURSOR_SIGN) { truelight@0: ResetObjectToPlace(); tron@2639: } else { rubidium@8385: SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, VHM_RECT, WC_MAIN_TOOLBAR, 0); truelight@0: _place_proc = PlaceProc_Sign; truelight@0: } truelight@0: } truelight@0: tron@410: static void MenuClickForest(int index) truelight@0: { tron@2631: switch (index) { tron@2631: case 0: ShowTerraformToolbar(); break; tron@2631: case 1: ShowBuildTreesToolbar(); break; tron@2631: 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: { tron@2631: switch (index) { tron@2631: case 0: ShowLastNewsMessage(); break; tron@2631: case 1: ShowMessageOptions(); break; tron@2631: case 2: ShowMessageHistory(); break; truelight@0: } truelight@0: } truelight@0: rubidium@9219: void MenuClickSmallScreenshot() belugas@4184: { belugas@4184: SetScreenshotType(SC_VIEWPORT); belugas@4184: } belugas@4184: rubidium@9219: void MenuClickWorldScreenshot() belugas@4184: { belugas@4184: SetScreenshotType(SC_WORLD); belugas@4184: } belugas@4184: tron@410: static void MenuClickHelp(int index) truelight@0: { Darkvater@2432: switch (index) { belugas@4184: case 0: PlaceLandBlockInfo(); break; belugas@4184: case 2: IConsoleSwitch(); break; belugas@4184: case 3: MenuClickSmallScreenshot(); break; belugas@4184: case 4: MenuClickWorldScreenshot(); break; belugas@4184: case 5: ShowAboutWindow(); break; truelight@0: } truelight@0: } truelight@0: tron@2639: tron@2639: typedef void MenuClickedProc(int index); tron@2639: truelight@0: static MenuClickedProc * const _menu_clicked_procs[] = { rubidium@4344: NULL, /* 0 */ rubidium@4344: NULL, /* 1 */ rubidium@4344: MenuClickSettings, /* 2 */ rubidium@4344: MenuClickSaveLoad, /* 3 */ rubidium@4344: MenuClickMap, /* 4 */ rubidium@4344: MenuClickTown, /* 5 */ rubidium@4344: MenuClickSubsidies, /* 6 */ rubidium@4344: MenuClickStations, /* 7 */ rubidium@4344: MenuClickFinances, /* 8 */ rubidium@4344: MenuClickCompany, /* 9 */ rubidium@4344: MenuClickGraphs, /* 10 */ rubidium@4344: MenuClickLeague, /* 11 */ rubidium@4344: MenuClickIndustry, /* 12 */ rubidium@4344: MenuClickShowTrains, /* 13 */ rubidium@4344: MenuClickShowRoad, /* 14 */ rubidium@4344: MenuClickShowShips, /* 15 */ rubidium@4344: MenuClickShowAir, /* 16 */ rubidium@4344: MenuClickScenMap, /* 17 */ rubidium@4344: NULL, /* 18 */ rubidium@4344: MenuClickBuildRail, /* 19 */ rubidium@4344: MenuClickBuildRoad, /* 20 */ rubidium@4344: MenuClickBuildWater, /* 21 */ rubidium@4344: MenuClickBuildAir, /* 22 */ rubidium@4344: MenuClickForest, /* 23 */ truelight@0: MenuClickMusicWindow, /* 24 */ rubidium@4344: MenuClickNewspaper, /* 25 */ rubidium@4344: MenuClickHelp, /* 26 */ truelight@0: }; truelight@0: truelight@0: static void MenuWndProc(Window *w, WindowEvent *e) truelight@0: { tron@2639: switch (e->event) { Darkvater@4820: case WE_CREATE: w->widget[0].right = w->width - 1; break; Darkvater@4820: truelight@0: case WE_PAINT: { Darkvater@4822: int x, y; Darkvater@4822: Darkvater@4822: byte count = WP(w, menu_d).item_count; Darkvater@4822: byte sel = WP(w, menu_d).sel_index; Darkvater@4822: uint16 chk = WP(w, menu_d).checked_items; Darkvater@4822: StringID string = WP(w, menu_d).string_id; Darkvater@4822: byte dis = WP(w, menu_d).disabled_items; truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: x = 1; truelight@0: y = 1; truelight@0: Darkvater@4822: for (; count != 0; count--, string++, sel--) { skidd13@8424: TextColour color = HasBit(dis, 0) ? TC_GREY : (sel == 0) ? TC_WHITE : TC_BLACK; Darkvater@4822: if (sel == 0) GfxFillRect(x, y, x + w->width - 3, y + 9, 0); Darkvater@4822: skidd13@8424: if (HasBit(chk, 0)) DrawString(x + 2, y, STR_CHECKMARK, color); Darkvater@4822: DrawString(x + 2, y, string, color); Darkvater@4822: truelight@0: y += 10; truelight@0: chk >>= 1; Darkvater@4822: dis >>= 1; Darkvater@4822: } truelight@0: } break; truelight@0: truelight@0: case WE_DESTROY: { truelight@0: Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0); rubidium@8578: v->RaiseWidget(WP(w, menu_d).main_button); truelight@0: SetWindowDirty(v); truelight@0: return; truelight@0: } truelight@193: truelight@0: case WE_POPUPMENU_SELECT: { belugas@4634: int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.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); rubidium@8578: if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w, menu_d).main_button) rubidium@8578: index = WP(w, menu_d).sel_index; truelight@0: } truelight@0: rubidium@8578: action_id = WP(w, menu_d).action_id; truelight@0: DeleteWindow(w); truelight@193: Darkvater@4822: if (index >= 0) { Darkvater@4822: assert((uint)index <= lengthof(_menu_clicked_procs)); Darkvater@4822: _menu_clicked_procs[action_id](index); Darkvater@4822: } truelight@193: truelight@0: break; truelight@0: } tron@2639: truelight@0: case WE_POPUPMENU_OVER: { belugas@4634: int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y); truelight@0: rubidium@8578: if (index == -1 || index == WP(w, menu_d).sel_index) return; truelight@0: rubidium@8578: WP(w, menu_d).sel_index = index; truelight@0: SetWindowDirty(w); truelight@0: return; truelight@0: } truelight@0: } truelight@0: } truelight@0: Darkvater@4820: /* Dynamic widget length determined by toolbar-string length. Darkvater@4820: * See PopupMainToolbMenu en MenuWndProc */ truelight@867: static const Widget _menu_widgets[] = { Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 0, 0, 0, 0x0, STR_NULL}, Darkvater@4820: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: truelight@867: static const Widget _player_menu_widgets[] = { Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 240, 0, 81, 0x0, STR_NULL}, Darkvater@4938: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: truelight@0: static int GetPlayerIndexFromMenu(int index) truelight@0: { truelight@0: if (index >= 0) { belugas@4171: const Player *p; tron@2630: truelight@0: FOR_ALL_PLAYERS(p) { tron@2639: if (p->is_active && --index < 0) return p->index; truelight@193: } truelight@0: } truelight@0: return -1; truelight@0: } truelight@0: truelight@0: static void UpdatePlayerMenuHeight(Window *w) truelight@0: { Darkvater@4824: byte num = ActivePlayerCount(); truelight@193: belugas@6527: /* Increase one to fit in PlayerList in the menu when in network */ rubidium@8578: if (_networking && WP(w, menu_d).main_button == 9) num++; truelight@543: rubidium@8578: if (WP(w, menu_d).item_count != num) { rubidium@8578: 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; rubidium@9222: w->top = GetToolbarDropdownPos(0, w->width, w->height).y; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } truelight@0: truelight@0: static void PlayerMenuWndProc(Window *w, WindowEvent *e) truelight@0: { tron@2639: switch (e->event) { truelight@0: case WE_PAINT: { truelight@0: int x,y; belugas@8320: byte sel; belugas@8320: TextColour 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; rubidium@8578: sel = WP(w, menu_d).sel_index; rubidium@8578: chk = WP(w, menu_d).checked_items; // let this mean gray items. truelight@193: belugas@6527: /* 9 = playerlist */ rubidium@8578: 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: } belugas@8320: DrawString(x + 19, y, STR_NETWORK_CLIENT_LIST, TC_FROMSTRING); 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: peter1138@7554: SetDParam(0, p->index); peter1138@7554: SetDParam(1, p->index); truelight@193: belugas@8320: color = (p->index == sel) ? TC_WHITE : TC_BLACK; belugas@8320: if (chk&1) color = TC_GREY; 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); rubidium@8578: v->RaiseWidget(WP(w, menu_d).main_button); truelight@0: SetWindowDirty(v); truelight@0: return; truelight@0: } truelight@193: truelight@0: case WE_POPUPMENU_SELECT: { belugas@4634: int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y); rubidium@8578: int action_id = WP(w, menu_d).action_id; truelight@0: belugas@6527: /* We have a new entry at the top of the list of menu 9 when networking belugas@6527: * so keep that in count */ rubidium@8578: if (_networking && WP(w, menu_d).main_button == 9) { tron@2639: if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1; tron@2639: } else { truelight@724: index = GetPlayerIndexFromMenu(index); tron@2639: } truelight@543: truelight@0: if (index < 0) { truelight@0: Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0); rubidium@8578: if (GetWidgetFromPos(w2, e->we.popupmenu.pt.x - w2->left, e->we.popupmenu.pt.y - w2->top) == WP(w, menu_d).main_button) rubidium@8578: 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); belugas@4634: index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y); truelight@543: belugas@6527: /* We have a new entry at the top of the list of menu 9 when networking belugas@6527: * so keep that in count */ rubidium@8578: if (_networking && WP(w, menu_d).main_button == 9) { tron@2639: if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1; tron@2639: } else { truelight@724: index = GetPlayerIndexFromMenu(index); tron@2639: } tron@2639: rubidium@8578: if (index == -1 || index == WP(w, menu_d).sel_index) return; truelight@0: rubidium@8578: WP(w, menu_d).sel_index = index; truelight@0: SetWindowDirty(w); truelight@0: return; truelight@0: } truelight@0: } truelight@0: } truelight@0: Darkvater@4820: /** Get the maximum length of a given string in a string-list. This is an Darkvater@4820: * implicit string-list where the ID's are consecutive Darkvater@4820: * @param base_string StringID of the first string in the list Darkvater@4820: * @param count amount of StringID's in the list Darkvater@4820: * @return the length of the longest string */ Darkvater@4820: static int GetStringListMaxWidth(StringID base_string, byte count) truelight@0: { Darkvater@4820: char buffer[512]; Darkvater@4820: int width, max_width; Darkvater@4820: byte i; Darkvater@4820: Darkvater@4820: max_width = 0; Darkvater@4820: for (i = 0; i != count; i++) { Darkvater@4912: GetString(buffer, base_string + i, lastof(buffer)); Darkvater@4820: width = GetStringBoundingBox(buffer).width; Darkvater@4820: if (width > max_width) max_width = width; Darkvater@4820: } Darkvater@4820: Darkvater@4820: return max_width; Darkvater@4820: } Darkvater@4820: Darkvater@4821: /** Show a general dropdown menu. The positioning of the dropdown menu Darkvater@4821: * defaults to the left side of the parent_button, eg the button that caused Darkvater@4821: * this window to appear. The only exceptions are when the right side of this Darkvater@4821: * dropdown would fall outside the main toolbar window, in that case it is Darkvater@4821: * aligned with the toolbar's right side. Darkvater@4821: * Since the disable-mask is only 8 bits right now, these dropdowns are Darkvater@4821: * restricted to 8 items max if any bits of disabled_mask are active. Darkvater@4821: * @param w Pointer to a window this dropdown menu belongs to. Has no effect Darkvater@4821: * whatsoever, only graphically for positioning. Darkvater@4821: * @param parent_button The widget identifier of the button that was clicked for Darkvater@4821: * this dropdown. The created dropdown then knows what button to raise (button) on Darkvater@4821: * action and whose function to execute (action). Darkvater@4821: * It is possible to appoint another button for an action event by setting the Darkvater@4821: * upper 8 bits of this parameter. If non is set, action is presumed to be the same Darkvater@4821: * as button. So
Darkvater@4821: * button bits 0 - 7 - widget clicked to get dropdown Darkvater@4821: * action bits 8 - 15 - function of widget to execute on select (defaults to bits 0 - 7) Darkvater@4821: * @param base_string The first StringID shown in the dropdown list. All others are Darkvater@4821: * consecutive indeces from the language file. XXX - fix? Use ingame-string tables? Darkvater@4821: * @param item_count Number of strings in the list, see previous parameter Darkvater@4821: * @param disabled_mask Bitmask of disabled strings in the list Darkvater@4821: * @return Return a pointer to the newly created dropdown window */ rubidium@9219: Window *PopupMainToolbMenu(Window *w, uint16 parent_button, StringID base_string, byte item_count, byte disabled_mask) Darkvater@4820: { Darkvater@4820: assert(disabled_mask == 0 || item_count <= 8); rubidium@8493: w->LowerWidget(parent_button); glx@8524: w->InvalidateWidget(parent_button); truelight@0: truelight@0: DeleteWindowById(WC_TOOLBAR_MENU, 0); truelight@0: rubidium@9219: // Extend the dropdown toolbar to the longest string in the list rubidium@9222: int width = max(GetStringListMaxWidth(base_string, item_count) + 6, 140); rubidium@9222: int height = item_count * 10 + 2; Darkvater@4820: rubidium@9222: Point pos = GetToolbarDropdownPos(parent_button, width, height); rubidium@9219: rubidium@9219: w = AllocateWindow(pos.x, pos.y, width, height, 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: rubidium@8578: WP(w, menu_d).item_count = item_count; rubidium@8578: WP(w, menu_d).sel_index = 0; rubidium@8578: WP(w, menu_d).main_button = GB(parent_button, 0, 8); rubidium@8578: WP(w, menu_d).action_id = (GB(parent_button, 8, 8) != 0) ? GB(parent_button, 8, 8) : parent_button; rubidium@8578: WP(w, menu_d).string_id = base_string; rubidium@8578: WP(w, menu_d).checked_items = 0; rubidium@8578: WP(w, menu_d).disabled_items = disabled_mask; truelight@0: truelight@0: _popup_menu_active = true; truelight@193: tron@541: SndPlayFx(SND_15_BEEP); truelight@0: return w; truelight@0: } truelight@0: rubidium@9219: Window *PopupMainPlayerToolbMenu(Window *w, int main_button, int gray) truelight@0: { rubidium@8493: w->LowerWidget(main_button); glx@8524: w->InvalidateWidget(main_button); truelight@0: truelight@0: DeleteWindowById(WC_TOOLBAR_MENU, 0); rubidium@9222: Point pos = GetToolbarDropdownPos(main_button, 241, 82); rubidium@9219: w = AllocateWindow(pos.x, pos.y, 241, 82, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets); truelight@0: w->flags4 &= ~WF_WHITE_BORDER_MASK; rubidium@8578: WP(w, menu_d).item_count = 0; rubidium@8578: WP(w, menu_d).sel_index = (_local_player != PLAYER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0); truelight@724: if (_networking && main_button == 9) { Darkvater@4848: if (_local_player != PLAYER_SPECTATOR) { rubidium@8578: WP(w, menu_d).sel_index++; tron@2639: } else { truelight@724: /* Select client list by default for spectators */ rubidium@8578: WP(w, menu_d).sel_index = 0; tron@2639: } truelight@543: } rubidium@8578: WP(w, menu_d).action_id = main_button; rubidium@8578: WP(w, menu_d).main_button = main_button; rubidium@8578: WP(w, menu_d).checked_items = gray; rubidium@8578: WP(w, menu_d).disabled_items = 0; truelight@0: _popup_menu_active = true; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: return w; 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; Darkvater@5045: Darkvater@5045: assert(w != NULL); truelight@0: vp = w->viewport; truelight@0: Darkvater@5044: switch (how) { Darkvater@5044: case ZOOM_IN: truelight@7122: if (vp->zoom == ZOOM_LVL_MIN) return false; smatz@8591: vp->zoom = (ZoomLevel)((int)vp->zoom - 1); Darkvater@5044: vp->virtual_width >>= 1; Darkvater@5044: vp->virtual_height >>= 1; Darkvater@5044: rubidium@8578: WP(w, vp_d).scrollpos_x += vp->virtual_width >> 1; rubidium@8578: WP(w, vp_d).scrollpos_y += vp->virtual_height >> 1; rubidium@8578: WP(w, vp_d).dest_scrollpos_x = WP(w,vp_d).scrollpos_x; rubidium@8578: WP(w, vp_d).dest_scrollpos_y = WP(w,vp_d).scrollpos_y; Darkvater@5044: break; Darkvater@5044: case ZOOM_OUT: truelight@7122: if (vp->zoom == ZOOM_LVL_MAX) return false; smatz@8591: vp->zoom = (ZoomLevel)((int)vp->zoom + 1); Darkvater@5044: rubidium@8578: WP(w, vp_d).scrollpos_x -= vp->virtual_width >> 1; rubidium@8578: WP(w, vp_d).scrollpos_y -= vp->virtual_height >> 1; rubidium@8578: WP(w, vp_d).dest_scrollpos_x = WP(w,vp_d).scrollpos_x; rubidium@8578: WP(w, vp_d).dest_scrollpos_y = WP(w,vp_d).scrollpos_y; Darkvater@5044: Darkvater@5044: vp->virtual_width <<= 1; Darkvater@5044: vp->virtual_height <<= 1; Darkvater@5044: break; truelight@0: } KUDr@5214: if (vp != NULL) { // the vp can be null when how == ZOOM_NONE KUDr@5214: vp->virtual_left = WP(w, vp_d).scrollpos_x; KUDr@5214: vp->virtual_top = WP(w, vp_d).scrollpos_y; KUDr@5214: } Darkvater@5044: SetWindowDirty(w); Darkvater@5045: /* Update the windows that have zoom-buttons to perhaps disable their buttons */ Darkvater@5045: SendWindowMessageClass(w->window_class, how, w->window_number, 0); truelight@0: return true; truelight@0: } truelight@0: truelight@193: void ZoomInOrOutToCursorWindow(bool in, Window *w) truelight@0: { rubidium@9219: assert(w != NULL); truelight@0: rubidium@4536: if (_game_mode != GM_MENU) { rubidium@9219: ViewPort *vp = w->viewport; truelight@7122: if ((in && vp->zoom == ZOOM_LVL_MIN) || (!in && vp->zoom == ZOOM_LVL_MAX)) truelight@0: return; truelight@0: rubidium@9219: Point pt = GetTileZoomCenterWindow(in,w); truelight@0: if (pt.x != -1) { peter1138@7226: ScrollWindowTo(pt.x, pt.y, w, true); truelight@0: darkvater@152: DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w); truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: extern GetNewsStringCallbackProc * const _get_news_string_callback[]; truelight@0: truelight@0: rubidium@7855: static bool DrawScrollingStatusText(const NewsItem *ni, int pos, int width) truelight@0: { tron@1336: char buf[512]; truelight@0: StringID str; glx@9080: const char *s, *last; tron@1329: char *d; truelight@0: DrawPixelInfo tmp_dpi, *old_dpi; truelight@0: int x; tron@1329: char buffer[256]; truelight@0: belugas@8350: if (ni->display_mode == NM_CALLBACK) { truelight@0: str = _get_news_string_callback[ni->callback](ni); truelight@0: } else { rubidium@7762: CopyInDParam(0, ni->params, lengthof(ni->params)); truelight@193: str = ni->string_id; truelight@0: } truelight@0: Darkvater@4912: GetString(buf, str, lastof(buf)); truelight@0: tron@1336: s = buf; truelight@0: d = buffer; glx@9080: last = lastof(buffer); truelight@0: peter1138@5108: for (;;) { peter1138@5108: WChar c = Utf8Consume(&s); peter1138@5108: if (c == 0) { truelight@0: break; glx@9080: } else if (c == 0x0D) { glx@9080: if (d + 4 >= last) break; truelight@0: d[0] = d[1] = d[2] = d[3] = ' '; tron@2639: d += 4; peter1138@5108: } else if (IsPrintable(c)) { glx@9080: if (d + Utf8CharLen(c) >= last) break; peter1138@5108: d += Utf8Encode(d, c); truelight@0: } truelight@0: } glx@9080: *d = '\0'; truelight@0: rubidium@7855: if (!FillDrawPixelInfo(&tmp_dpi, 141, 1, width, 11)) return true; truelight@0: truelight@0: old_dpi = _cur_dpi; truelight@0: _cur_dpi = &tmp_dpi; truelight@0: belugas@8320: x = DoDrawString(buffer, pos, 0, TC_LIGHT_BLUE); 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: { Darkvater@1885: switch (e->event) { Darkvater@1885: case WE_PAINT: { Darkvater@4848: const Player *p = (_local_player == PLAYER_SPECTATOR) ? NULL : GetPlayer(_local_player); Darkvater@1885: truelight@0: DrawWindowWidgets(w); tron@534: SetDParam(0, _date); tron@2639: DrawStringCentered( belugas@8320: 70, 1, (_pause_game || _patches.status_long_date) ? STR_00AF : STR_00AE, TC_FROMSTRING tron@2639: ); truelight@193: rubidium@4536: if (p != NULL) { belugas@6527: /* Draw player money */ rubidium@7498: SetDParam(0, p->player_money); belugas@8320: DrawStringCentered(w->widget[2].left + 70, 1, STR_0004, TC_FROMSTRING); truelight@0: } truelight@0: belugas@6527: /* Draw status bar */ Darkvater@1885: if (w->message.msg) { // true when saving is active belugas@8320: DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING); Darkvater@1885: } else if (_do_autosave) { belugas@8320: DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING); truelight@6557: } else if (_pause_game) { belugas@8320: DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_0319_PAUSED, TC_FROMSTRING); rubidium@8578: } else if (WP(w, def_d).data_1 > -1280 && FindWindowById(WC_NEWS_WINDOW,0) == NULL && _statusbar_news_item.string_id != 0) { belugas@6527: /* Draw the scrolling news text */ rubidium@8578: if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w, def_d).data_1, w->widget[1].right - w->widget[1].left - 2)) { rubidium@8578: WP(w, def_d).data_1 = -1280; rubidium@7855: if (p != NULL) { rubidium@7855: /* This is the default text */ rubidium@7855: SetDParam(0, p->index); belugas@8320: DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING); rubidium@7855: } rubidium@7855: } truelight@0: } else { rubidium@4536: if (p != NULL) { belugas@6527: /* This is the default text */ peter1138@7554: SetDParam(0, p->index); belugas@8320: DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_02BA, TC_FROMSTRING); truelight@0: } truelight@0: } Darkvater@1688: rubidium@7855: if (WP(w, def_d).data_2 > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, w->widget[1].right - 11, 2); Darkvater@1885: } break; Darkvater@1885: Darkvater@1885: case WE_MESSAGE: belugas@4634: w->message.msg = e->we.message.msg; Darkvater@1885: SetWindowDirty(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { Darkvater@1885: case 1: ShowLastNewsMessage(); break; Darkvater@4848: case 2: if (_local_player != PLAYER_SPECTATOR) ShowPlayerFinances(_local_player); break; Darkvater@1885: default: ResetObjectToPlace(); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_TICK: { truelight@6557: if (_pause_game) return; Darkvater@1688: belugas@6527: if (WP(w, def_d).data_1 > -1280) { // Scrolling text Darkvater@1688: WP(w, def_d).data_1 -= 2; glx@8524: w->InvalidateWidget(1); Darkvater@1688: } Darkvater@1688: belugas@6527: if (WP(w, def_d).data_2 > 0) { // Red blot to show there are new unread newsmessages Darkvater@1688: WP(w, def_d).data_2 -= 2; Darkvater@1688: } else if (WP(w, def_d).data_2 < 0) { Darkvater@1688: WP(w, def_d).data_2 = 0; glx@8524: w->InvalidateWidget(1); Darkvater@1688: } Darkvater@1688: truelight@0: break; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _main_status_widgets[] = { Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 139, 0, 11, 0x0, STR_NULL}, rubidium@7856: { WWT_PUSHBTN, RESIZE_RIGHT, 14, 140, 179, 0, 11, 0x0, STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS}, rubidium@7856: { WWT_PUSHBTN, RESIZE_LR, 14, 180, 319, 0, 11, 0x0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static WindowDesc _main_status_desc = { rubidium@7856: WDP_CENTER, 0, 320, 12, 640, 12, rubidium@6144: WC_STATUS_BAR, WC_NONE, truelight@0: WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _main_status_widgets, truelight@0: StatusBarWndProc truelight@0: }; truelight@0: rubidium@6573: extern void UpdateAllStationVirtCoord(); truelight@0: belugas@4171: static void MainWindowWndProc(Window *w, WindowEvent *e) tron@4077: { truelight@0: int off_x; truelight@0: tron@2952: 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: peter1138@5919: DrawSprite(SPR_OTTD_O, PAL_NONE, off_x - 120, 50); peter1138@5919: DrawSprite(SPR_OTTD_P, PAL_NONE, off_x - 86, 50); peter1138@5919: DrawSprite(SPR_OTTD_E, PAL_NONE, off_x - 53, 50); peter1138@5919: DrawSprite(SPR_OTTD_N, PAL_NONE, off_x - 22, 50); truelight@193: peter1138@5919: DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 34, 50); peter1138@5919: DrawSprite(SPR_OTTD_T, PAL_NONE, off_x + 65, 50); peter1138@5919: DrawSprite(SPR_OTTD_D, PAL_NONE, 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: belugas@4634: switch (e->we.keypress.keycode) { tron@2639: case 'Q' | WKC_CTRL: tron@2639: case 'Q' | WKC_META: rubidium@4548: HandleExitGameRequest(); tron@2639: break; bjarni@2501: } Darkvater@1500: rubidium@4536: /* Disable all key shortcuts, except quit shortcuts when rubidium@4536: * generating the world, otherwise they create threading rubidium@4536: * problem during the generating, resulting in random rubidium@4536: * assertions that are hard to trigger and debug */ rubidium@4536: if (IsGeneratingWorld()) break; rubidium@4536: belugas@4634: if (e->we.keypress.keycode == WKC_BACKQUOTE) { rubidium@4536: IConsoleSwitch(); belugas@4634: e->we.keypress.cont = false; rubidium@4536: break; rubidium@4536: } rubidium@4536: rubidium@8139: if (e->we.keypress.keycode == ('B' | WKC_CTRL)) { rubidium@8139: e->we.keypress.cont = false; rubidium@8139: _draw_bounding_boxes = !_draw_bounding_boxes; rubidium@8139: MarkWholeScreenDirty(); rubidium@8139: break; rubidium@8139: } rubidium@8139: rubidium@4536: if (_game_mode == GM_MENU) break; truelight@0: belugas@4634: switch (e->we.keypress.keycode) { tron@2639: case 'C': tron@2639: case 'Z': { tron@2639: Point pt = GetTileBelowCursor(); tron@2639: if (pt.x != -1) { peter1138@8672: if (e->we.keypress.keycode == 'Z') MaxZoomInOut(ZOOM_IN, w); tron@2639: ScrollMainWindowTo(pt.x, pt.y); tron@2639: } tron@2639: break; truelight@0: } tron@2639: tron@2639: case WKC_ESC: ResetObjectToPlace(); break; tron@2639: case WKC_DELETE: DeleteNonVitalWindows(); break; tron@2639: case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break; tron@2639: case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break; tron@2639: Darkvater@1772: #if defined(_DEBUG) belugas@6527: case '0' | WKC_ALT: // Crash the game tron@2639: *(byte*)0 = 0; tron@2639: break; tron@2639: belugas@6527: case '1' | WKC_ALT: // Gimme money tron@2639: /* Server can not cheat in advertise mode either! */ tron@2639: if (!_networking || !_network_server || !_network_advertise) rubidium@5838: DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT); tron@2639: break; tron@2639: belugas@6527: case '2' | WKC_ALT: // Update the coordinates of all station signs tron@2639: UpdateAllStationVirtCoord(); tron@2639: break; tron@2639: #endif tron@2639: peter1138@6923: case '1' | WKC_CTRL: peter1138@6923: case '2' | WKC_CTRL: peter1138@6923: case '3' | WKC_CTRL: peter1138@6923: case '4' | WKC_CTRL: peter1138@6923: case '5' | WKC_CTRL: peter1138@6923: case '6' | WKC_CTRL: peter1138@6923: case '7' | WKC_CTRL: belugas@8345: case '8' | WKC_CTRL: smatz@9025: case '9' | WKC_CTRL: peter1138@6923: /* Transparency toggle hot keys */ belugas@8345: ToggleTransparency((TransparencyOption)(e->we.keypress.keycode - ('1' | WKC_CTRL))); tron@2639: MarkWholeScreenDirty(); tron@2639: break; truelight@0: peter1138@6923: case 'X' | WKC_CTRL: peter1138@6923: ShowTransparencyToolbar(); peter1138@6923: break; peter1138@6923: peter1138@6990: case 'X': belugas@8345: ResetRestoreAllTransparency(); peter1138@6923: break; peter1138@6923: truelight@543: #ifdef ENABLE_NETWORK Darkvater@5107: case WKC_RETURN: case 'T': // smart chat; send to team if any, otherwise to all Darkvater@4887: if (_networking) { Darkvater@5107: const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index); Darkvater@5107: bool teamchat = false; Darkvater@5107: Darkvater@5923: if (cio == NULL) break; Darkvater@5923: Darkvater@5107: /* Only players actually playing can speak to team. Eg spectators cannot */ Darkvater@5107: if (_patches.prefer_teamchat && IsValidPlayer(cio->client_playas)) { Darkvater@5107: const NetworkClientInfo *ci; Darkvater@5107: FOR_ALL_ACTIVE_CLIENT_INFOS(ci) { Darkvater@5107: if (ci->client_playas == cio->client_playas && ci != cio) { Darkvater@5107: teamchat = true; Darkvater@5107: break; Darkvater@5107: } Darkvater@5107: } Darkvater@5107: } Darkvater@5107: Darkvater@5107: ShowNetworkChatQueryWindow(teamchat ? DESTTYPE_TEAM : DESTTYPE_BROADCAST, cio->client_playas); Darkvater@4887: } Darkvater@4887: break; Darkvater@4887: Darkvater@4887: case WKC_SHIFT | WKC_RETURN: case WKC_SHIFT | 'T': // send text message to all players tron@2639: if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0); tron@2639: break; Darkvater@4887: Darkvater@4887: case WKC_CTRL | WKC_RETURN: case WKC_CTRL | 'T': // send text to all team mates Darkvater@4887: if (_networking) { Darkvater@5923: const NetworkClientInfo *cio = NetworkFindClientInfoFromIndex(_network_own_client_index); Darkvater@5923: if (cio == NULL) break; Darkvater@5923: Darkvater@5923: ShowNetworkChatQueryWindow(DESTTYPE_TEAM, cio->client_playas); Darkvater@4887: } Darkvater@4887: break; Darkvater@1772: #endif Darkvater@1772: tron@2639: default: return; truelight@0: } belugas@4634: e->we.keypress.cont = false; truelight@0: break; truelight@4335: truelight@4335: case WE_SCROLL: { truelight@4335: ViewPort *vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y); truelight@4335: truelight@4335: if (vp == NULL) { truelight@4335: _cursor.fix_at = false; truelight@4335: _scrolling_viewport = false; truelight@4335: } truelight@4335: truelight@7150: WP(w, vp_d).scrollpos_x += ScaleByZoom(e->we.scroll.delta.x, vp->zoom); truelight@7150: WP(w, vp_d).scrollpos_y += ScaleByZoom(e->we.scroll.delta.y, vp->zoom); peter1138@7226: WP(w, vp_d).dest_scrollpos_x = WP(w, vp_d).scrollpos_x; peter1138@7226: WP(w, vp_d).dest_scrollpos_y = WP(w, vp_d).scrollpos_y; truelight@4335: } break; truelight@4337: truelight@4337: case WE_MOUSEWHEEL: belugas@4634: ZoomInOrOutToCursorWindow(e->we.wheel.wheel < 0, w); truelight@4337: break; Darkvater@5045: Darkvater@5045: case WE_MESSAGE: Darkvater@5045: /* Forward the message to the appropiate toolbar (ingame or scenario editor) */ Darkvater@5045: SendWindowMessage(WC_MAIN_TOOLBAR, 0, e->we.message.msg, e->we.message.wparam, e->we.message.lparam); Darkvater@5045: break; truelight@0: } truelight@0: } truelight@0: truelight@0: rubidium@6573: void ShowSelectGameWindow(); rubidium@6573: rubidium@6573: void SetupColorsAndInitialWindow() truelight@0: { tron@2639: uint i; truelight@0: Window *w; Darkvater@5664: int width, height; truelight@0: tron@2639: for (i = 0; i != 16; i++) { belugas@4171: const byte *b = GetNonSprite(PALETTE_RECOLOR_START + i); tron@1357: truelight@0: assert(b); tron@4444: memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i])); truelight@0: } truelight@0: truelight@0: width = _screen.width; truelight@0: height = _screen.height; truelight@0: Darkvater@5683: w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL); truelight@7120: AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), ZOOM_LVL_VIEWPORT); Darkvater@5683: belugas@6527: /* XXX: these are not done */ tron@2639: switch (_game_mode) { Darkvater@5683: default: NOT_REACHED(); Darkvater@5683: case GM_MENU: Darkvater@5683: ShowSelectGameWindow(); Darkvater@5683: break; truelight@0: Darkvater@5683: case GM_NORMAL: Darkvater@5683: case GM_EDITOR: Darkvater@5683: ShowVitalWindows(); Darkvater@5683: break; truelight@0: } truelight@0: } truelight@0: rubidium@6573: void ShowVitalWindows() darkvater@983: { rubidium@9219: Window *w = AllocateToolbar(); Darkvater@5048: DoZoomInOutWindow(ZOOM_NONE, w); Darkvater@5048: darkvater@983: CLRBITS(w->flags4, WF_WHITE_BORDER_MASK); darkvater@983: rubidium@8493: w->SetWidgetDisabledState(0, _networking && !_network_server); // if not server, disable pause button rubidium@8493: w->SetWidgetDisabledState(1, _networking); // if networking, disable fast-forward button tron@1019: truelight@4300: /* 'w' is for sure a WC_MAIN_TOOLBAR */ truelight@4300: PositionMainToolbar(w); truelight@4300: truelight@4300: /* Status bad only for normal games */ truelight@4300: if (_game_mode == GM_EDITOR) return; 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: rubidium@8578: WP(w, def_d).data_1 = -1280; darkvater@983: } darkvater@983: rubidium@6573: void GameSizeChanged() truelight@0: { Darkvater@2429: _cur_resolution[0] = _screen.width; Darkvater@2429: _cur_resolution[1] = _screen.height; truelight@0: RelocateAllWindows(_screen.width, _screen.height); truelight@0: ScreenSizeChanged(); truelight@0: MarkWholeScreenDirty(); truelight@0: } celestar@3622: rubidium@6573: void InitializeMainGui() celestar@3622: { celestar@3622: /* Clean old GUI values */ rubidium@5838: _last_built_railtype = RAILTYPE_RAIL; rubidium@7162: _last_built_roadtype = ROADTYPE_ROAD; celestar@3622: } KUDr@5116: peter1138@5237: peter1138@5919: belugas@8320: belugas@8552: