# main_gui.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "heightmap.h"`
`#include "currency.h"`
`#include "spritecache.h"`
`#include "gui.h"`
`#include "window_gui.h"`
`#include "window_func.h"`
`#include "textbuf_gui.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "news.h"`
`#include "town.h"`
`#include "console.h"`
`#include "signs.h"`
`#include "waypoint.h"`
`#include "variables.h"`
`#include "train.h"`
`#include "roadveh.h"`
`#include "bridge_map.h"`
`#include "screenshot.h"`
`#include "genworld.h"`
`#include "vehicle_gui.h"`
`#include "transparency_gui.h"`
`#include "newgrf_config.h"`
`#include "rail_gui.h"`
`#include "road_gui.h"`
`#include "date_func.h"`
`#include "functions.h"`
`#include "vehicle_func.h"`
`#include "sound_func.h"`
`#include "fios.h"`
`#include "terraform_gui.h"`
`#include "industry.h"`
`#include "transparency.h"`
`#include "strings_func.h"`
`#include "zoom_func.h"`
`#include "string_func.h"`
`#include "player_base.h"`
`#include "player_func.h"`
`#include "player_gui.h"`
`#include "settings_type.h"`
`#include "network/network.h"`
`#include "network/network_data.h"`
`#include "network/network_client.h"`
`#include "network/network_server.h"`
`#include "network/network_gui.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Typedefs

typedef void | MenuClickedProc (int index)
typedef void | ToolbarButtonProc (Window *w)

## Functions

void | GenerateIndustries ()
| This function will create ramdon industries during game creation.
bool | GenerateTowns ()
void | CcGiveMoney (bool success, TileIndex tile, uint32 p1, uint32 p2)
void | HandleOnEditText (const char *str)
bool | HandlePlacePushButton (Window *w, int widget, CursorID cursor, ViewportHighlightMode mode, PlaceProc *placeproc)
| This code is shared for the majority of the pushbuttons.
void | CcPlaySound10 (bool success, TileIndex tile, uint32 p1, uint32 p2)
static void | ToolbarPauseClick (Window *w)
static void | ToolbarFastForwardClick (Window *w)
static void | MenuClickSettings (int index)
static void | MenuClickSaveLoad (int index)
static void | MenuClickMap (int index)
static void | MenuClickTown (int index)
static void | MenuClickScenMap (int index)
static void | MenuClickSubsidies (int index)
static void | MenuClickStations (int index)
static void | MenuClickFinances (int index)
static void | MenuClickCompany (int index)
static void | MenuClickGraphs (int index)
static void | MenuClickLeague (int index)
static void | MenuClickIndustry (int index)
static void | MenuClickShowTrains (int index)
static void | MenuClickShowRoad (int index)
static void | MenuClickShowShips (int index)
static void | MenuClickShowAir (int index)
static void | MenuClickBuildRail (int index)
static void | MenuClickBuildRoad (int index)
static void | MenuClickBuildWater (int index)
static void | MenuClickBuildAir (int index)
void | ShowRenameWaypointWindow (const Waypoint *wp)
static void | SelectSignTool ()
static void | MenuClickForest (int index)
static void | MenuClickMusicWindow (int index)
static void | MenuClickNewspaper (int index)
static void | MenuClickSmallScreenshot ()
static void | MenuClickWorldScreenshot ()
static void | MenuClickHelp (int index)
static void | MenuWndProc (Window *w, WindowEvent *e)
static int | GetPlayerIndexFromMenu (int index)
static void | UpdatePlayerMenuHeight (Window *w)
static void | PlayerMenuWndProc (Window *w, WindowEvent *e)
static int | GetStringListMaxWidth (StringID base_string, byte count)
| Get the maximum length of a given string in a string-list.
static Window * | PopupMainToolbMenu (Window *w, uint16 parent_button, StringID base_string, byte item_count, byte disabled_mask)
| Show a general dropdown menu.
static Window * | PopupMainPlayerToolbMenu (Window *w, int main_button, int gray)
static void | ToolbarSaveClick (Window *w)
static void | ToolbarMapClick (Window *w)
static void | ToolbarTownClick (Window *w)
static void | ToolbarSubsidiesClick (Window *w)
static void | ToolbarStationsClick (Window *w)
static void | ToolbarMoneyClick (Window *w)
static void | ToolbarPlayersClick (Window *w)
static void | ToolbarGraphsClick (Window *w)
static void | ToolbarLeagueClick (Window *w)
static void | ToolbarIndustryClick (Window *w)
static void | ToolbarTrainClick (Window *w)
static void | ToolbarRoadClick (Window *w)
static void | ToolbarShipClick (Window *w)
static void | ToolbarAirClick (Window *w)
bool | DoZoomInOutWindow (int how, Window *w)
static void | ToolbarZoomInClick (Window *w)
static void | ToolbarZoomOutClick (Window *w)
static void | ToolbarBuildRailClick (Window *w)
static void | ToolbarBuildRoadClick (Window *w)
static void | ToolbarBuildWaterClick (Window *w)
static void | ToolbarBuildAirClick (Window *w)
static void | ToolbarForestClick (Window *w)
static void | ToolbarMusicClick (Window *w)
static void | ToolbarNewspaperClick (Window *w)
static void | ToolbarHelpClick (Window *w)
static void | ToolbarOptionsClick (Window *w)
static void | ToolbarScenSaveOrLoad (Window *w)
static void | ToolbarScenDateBackward (Window *w)
static void | ToolbarScenDateForward (Window *w)
static void | ToolbarScenMapTownDir (Window *w)
static void | ToolbarScenZoomIn (Window *w)
static void | ToolbarScenZoomOut (Window *w)
void | ZoomInOrOutToCursorWindow (bool in, Window *w)
static void | ToolbarScenGenLand (Window *w)
void | CcBuildTown (bool success, TileIndex tile, uint32 p1, uint32 p2)
static void | PlaceProc_Town (TileIndex tile)
static void | ScenEditTownGenWndProc (Window *w, WindowEvent *e)
static void | ToolbarScenGenTown (Window *w)
static void | ToolbarScenGenIndustry (Window *w)
static void | ToolbarScenBuildRoad (Window *w)
static void | ToolbarScenPlantTrees (Window *w)
static void | ToolbarScenPlaceSign (Window *w)
static void | ToolbarBtn_NULL (Window *w)
static void | MainToolbarWndProc (Window *w, WindowEvent *e)
static void | ScenEditToolbarWndProc (Window *w, WindowEvent *e)
static bool | DrawScrollingStatusText (const NewsItem *ni, int pos, int width)
static void | StatusBarWndProc (Window *w, WindowEvent *e)
void | UpdateAllStationVirtCoord ()
| Update the virtual coords needed to draw the station sign for all stations.
static void | MainWindowWndProc (Window *w, WindowEvent *e)
void | ShowSelectGameWindow ()
void | SetupColorsAndInitialWindow ()
void | ShowVitalWindows ()
void | GameSizeChanged ()
void | InitializeMainGui ()

## Variables

static int | _rename_id = 1
static int | _rename_what = -1
RailType | _last_built_railtype
RoadType | _last_built_roadtype
static int | _scengen_town_size = 1
bool | _draw_bounding_boxes = false
static MenuClickedProc *const | _menu_clicked_procs []
static const Widget | _menu_widgets []
static const Widget | _player_menu_widgets []
static const Widget | _scen_edit_town_gen_widgets []
static const WindowDesc | _scen_edit_town_gen_desc
static ToolbarButtonProc *const | _toolbar_button_procs []
static const Widget | _toolb_normal_widgets []
static const WindowDesc | _toolb_normal_desc
static const Widget | _toolb_scen_widgets []
static ToolbarButtonProc *const | _scen_toolbar_button_procs []
static const WindowDesc | _toolb_scen_desc
GetNewsStringCallbackProc *const | _get_news_string_callback []
static const Widget | _main_status_widgets []
static WindowDesc | _main_status_desc

## Detailed Description

Definition in file main_gui.cpp.

## Function Documentation

void GenerateIndustries | ( |  | ) |

This function will create ramdon industries during game creation.

It will scale the amount of industries by map size as well as difficulty level

Definition at line 1742 of file industry_cmd.cpp.

References IndustrySpec::appear_creation, IndustrySpec::check_proc, IndustrySpec::enabled, GetIndustrySpec(), GWP_INDUSTRY, IACT_MAPGENERATION, NUM_INDUSTRYTYPES, PlaceInitialIndustry(), ScaleByMapSize(), ScaleByMapSize1D(), and SetGeneratingWorldProgress().

static int GetStringListMaxWidth | ( | StringID | base_string,
|  | byte | count |
| ) |  |  | `[static]`

Get the maximum length of a given string in a string-list.

This is an implicit string-list where the ID's are consecutive

Parameters:

  | base_string | StringID of the first string in the list
  | count | amount of StringID's in the list

Returns:
  the length of the longest string

Definition at line 664 of file main_gui.cpp.

References GetStringBoundingBox().

Referenced by PopupMainToolbMenu().

bool HandlePlacePushButton | ( | Window * | w,
|  | int | widget,
|  | CursorID | cursor,
|  | ViewportHighlightMode | mode,
|  | PlaceProc * | placeproc |
| ) |  |  |

This code is shared for the majority of the pushbuttons.

Handles e.g. the pressing of a button (to build things), playing of click sound and sets certain parameters

Parameters:

  | w | Window which called the function
  | widget | ID of the widget (=button) that called this function
  | cursor | How should the cursor image change? E.g. cursor with depot image in it
  | mode | Tile highlighting mode, e.g. drawing a rectangle or a dot on the ground
  | placeproc | Procedure which will be called when someone clicks on the map

Returns:
  true if the button is clicked, false if it's unclicked

Definition at line 125 of file main_gui.cpp.

References SetWindowDirty().

Referenced by BuildRailClick_AutoSignals(), BuildRoadClick_AutoRoad(), BuildRoadClick_X_Dir(), BuildRoadClick_Y_Dir(), and EditorTerraformClick_Dynamite().

static Window* PopupMainToolbMenu | ( | Window * | w,
|  | uint16 | parent_button,
|  | StringID | base_string,
|  | byte | item_count,
|  | byte | disabled_mask |
| ) |  |  | `[static]`

Show a general dropdown menu.

The positioning of the dropdown menu defaults to the left side of the parent_button, eg the button that caused this window to appear. The only exceptions are when the right side of this dropdown would fall outside the main toolbar window, in that case it is aligned with the toolbar's right side. Since the disable-mask is only 8 bits right now, these dropdowns are restricted to 8 items max if any bits of disabled_mask are active.

Parameters:

  | w | Pointer to a window this dropdown menu belongs to. Has no effect whatsoever, only graphically for positioning.

  parent_button

  The widget identifier of the button that was clicked for this dropdown. The created dropdown then knows what button to raise (button) on action and whose function to execute (action). It is possible to appoint another button for an action event by setting the upper 8 bits of this parameter. If non is set, action is presumed to be the same as button. So
  button bits 0 - 7 - widget clicked to get dropdown action bits 8 - 15 - function of widget to execute on select (defaults to bits 0 - 7)

  | base_string | The first StringID shown in the dropdown list. All others are consecutive indeces from the language file. XXX - fix? Use ingame-string tables?
  | item_count | Number of strings in the list, see previous parameter
  | disabled_mask | Bitmask of disabled strings in the list

Returns:
  Return a pointer to the newly created dropdown window

Definition at line 702 of file main_gui.cpp.

References AllocateWindow(), Clamp(), GB(), GetStringListMaxWidth(), and max().

void UpdateAllStationVirtCoord | ( |  | ) |

Update the virtual coords needed to draw the station sign for all stations.

Definition at line 385 of file station_cmd.cpp.

Referenced by CmdRenameTown(), and InitializeWindowsAndCaches().

## Variable Documentation

GetNewsStringCallbackProc *const _get_news_string_callback

Initial value:

     {
      GetNewsStringNewVehicleAvail,
      GetNewsStringBankrupcy,
    }

Definition at line 84 of file news_gui.cpp.

WindowDesc _main_status_desc`[static]`

Initial value:

     {
      WDP_CENTER, 0, 320, 12, 640, 12,
      WC_STATUS_BAR, WC_NONE,
      WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
      _main_status_widgets,
      StatusBarWndProc
    }

Definition at line 1802 of file main_gui.cpp.

const Widget _main_status_widgets[]`[static]`

Initial value:

     {
    {      WWT_PANEL,   RESIZE_NONE,    14,     0,   139,     0,    11, 0x0, STR_NULL},
    {    WWT_PUSHBTN,   RESIZE_RIGHT,   14,   140,   179,     0,    11, 0x0, STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS},
    {    WWT_PUSHBTN,   RESIZE_LR,      14,   180,   319,     0,    11, 0x0, STR_NULL},
    {   WIDGETS_END},
    }

Definition at line 1795 of file main_gui.cpp.

MenuClickedProc* const _menu_clicked_procs[]`[static]`

Initial value:

     {
      NULL,
      NULL,
      MenuClickSettings,
      MenuClickSaveLoad,
      MenuClickMap,
      MenuClickTown,
      MenuClickSubsidies,
      MenuClickStations,
      MenuClickFinances,
      MenuClickCompany,
      MenuClickGraphs,
      MenuClickLeague,
      MenuClickIndustry,
      MenuClickShowTrains,
      MenuClickShowRoad,
      MenuClickShowShips,
      MenuClickShowAir,
      MenuClickScenMap,
      NULL,
      MenuClickBuildRail,
      MenuClickBuildRoad,
      MenuClickBuildWater,
      MenuClickBuildAir,
      MenuClickForest,
      MenuClickMusicWindow,
      MenuClickNewspaper,
      MenuClickHelp,
    }

Definition at line 407 of file main_gui.cpp.

const Widget _menu_widgets[]`[static]`

Initial value:

     {
    {    WWT_PANEL, RESIZE_NONE, 14, 0,  0, 0, 0, 0x0, STR_NULL},
    { WIDGETS_END},
    }

Definition at line 512 of file main_gui.cpp.

const Widget _player_menu_widgets[]`[static]`

Initial value:

     {
    {    WWT_PANEL, RESIZE_NONE, 14, 0, 240, 0, 81, 0x0, STR_NULL},
    { WIDGETS_END},
    }

Definition at line 518 of file main_gui.cpp.

const WindowDesc _scen_edit_town_gen_desc`[static]`

Initial value:

     {
      WDP_AUTO, WDP_AUTO, 160, 95, 160, 95,
      WC_SCEN_TOWN_GEN, WC_NONE,
      WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
      _scen_edit_town_gen_widgets,
      ScenEditTownGenWndProc,
    }

Definition at line 1169 of file main_gui.cpp.

const Widget _scen_edit_town_gen_widgets[]`[static]`

Initial value:

     {
    {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
    {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   147,     0,    13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
    {  WWT_STICKYBOX,   RESIZE_NONE,     7,   148,   159,     0,    13, 0x0,                      STR_STICKY_BUTTON},
    {      WWT_PANEL,   RESIZE_NONE,     7,     0,   159,    14,    94, 0x0,                      STR_NULL},
    {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   157,    16,    27, STR_0234_NEW_TOWN,        STR_0235_CONSTRUCT_NEW_TOWN},
    {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   157,    29,    40, STR_023D_RANDOM_TOWN,     STR_023E_BUILD_TOWN_IN_RANDOM_LOCATION},
    {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   157,    42,    53, STR_MANY_RANDOM_TOWNS,    STR_RANDOM_TOWNS_TIP},
    {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,    53,    68,    79, STR_02A1_SMALL,           STR_02A4_SELECT_TOWN_SIZE},
    {    WWT_TEXTBTN,   RESIZE_NONE,    14,    54,   105,    68,    79, STR_02A2_MEDIUM,          STR_02A4_SELECT_TOWN_SIZE},
    {    WWT_TEXTBTN,   RESIZE_NONE,    14,   106,   157,    68,    79, STR_02A3_LARGE,           STR_02A4_SELECT_TOWN_SIZE},
    {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   157,    81,    92, STR_SCENARIO_EDITOR_CITY, STR_02A4_SELECT_TOWN_SIZE},
    {      WWT_LABEL,   RESIZE_NONE,     7,     0,   147,    54,    67, STR_02A5_TOWN_SIZE,       STR_NULL},
    {   WIDGETS_END},
    }

Definition at line 1085 of file main_gui.cpp.

ToolbarButtonProc* const _scen_toolbar_button_procs[]`[static]`

Initial value:

     {
      ToolbarPauseClick,
      ToolbarFastForwardClick,
      ToolbarOptionsClick,
      ToolbarScenSaveOrLoad,
      ToolbarBtn_NULL,
      ToolbarBtn_NULL,
      ToolbarScenDateBackward,
      ToolbarScenDateForward,
      ToolbarScenMapTownDir,
      ToolbarScenZoomIn,
      ToolbarScenZoomOut,
      ToolbarScenGenLand,
      ToolbarScenGenTown,
      ToolbarScenGenIndustry,
      ToolbarScenBuildRoad,
      ToolbarScenPlantTrees,
      ToolbarScenPlaceSign,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      ToolbarMusicClick,
      NULL,
      ToolbarHelpClick,
    }

Definition at line 1468 of file main_gui.cpp.

const WindowDesc _toolb_normal_desc`[static]`

Initial value:

     {
      0, 0, 0, 22, 640, 22,
      WC_MAIN_TOOLBAR, WC_NONE,
      WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
      _toolb_normal_widgets,
      MainToolbarWndProc
    }

Definition at line 1422 of file main_gui.cpp.

const WindowDesc _toolb_scen_desc`[static]`

Initial value:

     {
      0, 0, 130, 22, 640, 22,
      WC_MAIN_TOOLBAR, WC_NONE,
      WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
      _toolb_scen_widgets,
      ScenEditToolbarWndProc
    }

Definition at line 1656 of file main_gui.cpp.

ToolbarButtonProc* const _toolbar_button_procs[]`[static]`

Initial value:

     {
      ToolbarPauseClick,
      ToolbarFastForwardClick,
      ToolbarOptionsClick,
      ToolbarSaveClick,
      ToolbarMapClick,
      ToolbarTownClick,
      ToolbarSubsidiesClick,
      ToolbarStationsClick,
      ToolbarMoneyClick,
      ToolbarPlayersClick,
      ToolbarGraphsClick,
      ToolbarLeagueClick,
      ToolbarIndustryClick,
      ToolbarTrainClick,
      ToolbarRoadClick,
      ToolbarShipClick,
      ToolbarAirClick,
      ToolbarZoomInClick,
      ToolbarZoomOutClick,
      ToolbarBuildRailClick,
      ToolbarBuildRoadClick,
      ToolbarBuildWaterClick,
      ToolbarBuildAirClick,
      ToolbarForestClick,
      ToolbarMusicClick,
      ToolbarNewspaperClick,
      ToolbarHelpClick,
    }

Definition at line 1220 of file main_gui.cpp.