src/rail_gui.cpp
changeset 10207 c291a21b304e
parent 9886 0aba4fa1e667
child 10208 72c00af5c95d
equal deleted inserted replaced
10206:0050610c0368 10207:c291a21b304e
   841  */
   841  */
   842 void ShowBuildRailToolbar(RailType railtype, int button)
   842 void ShowBuildRailToolbar(RailType railtype, int button)
   843 {
   843 {
   844 	BuildRailToolbarWindow *w;
   844 	BuildRailToolbarWindow *w;
   845 
   845 
   846 	if (!IsValidPlayerID(_current_player)) return;
   846 	if (!IsValidCompanyID(_current_company)) return;
   847 	if (!ValParamRailtype(railtype)) return;
   847 	if (!ValParamRailtype(railtype)) return;
   848 
   848 
   849 	// don't recreate the window if we're clicking on a button and the window exists.
   849 	// don't recreate the window if we're clicking on a button and the window exists.
   850 	if (button < 0 || !(w = dynamic_cast<BuildRailToolbarWindow*>(FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL)))) {
   850 	if (button < 0 || !(w = dynamic_cast<BuildRailToolbarWindow*>(FindWindowById(WC_BUILD_TOOLBAR, TRANSPORT_RAIL)))) {
   851 		DeleteWindowByClass(WC_BUILD_TOOLBAR);
   851 		DeleteWindowByClass(WC_BUILD_TOOLBAR);
  1716 }
  1716 }
  1717 
  1717 
  1718 /** Set the initial (default) railtype to use */
  1718 /** Set the initial (default) railtype to use */
  1719 static void SetDefaultRailGui()
  1719 static void SetDefaultRailGui()
  1720 {
  1720 {
  1721 	if (_local_player == PLAYER_SPECTATOR || !IsValidPlayerID(_local_player)) return;
  1721 	if (_local_company == COMPANY_SPECTATOR || !IsValidCompanyID(_local_company)) return;
  1722 
  1722 
  1723 	extern RailType _last_built_railtype;
  1723 	extern RailType _last_built_railtype;
  1724 	RailType rt = (RailType)_settings_client.gui.default_rail_type;
  1724 	RailType rt = (RailType)_settings_client.gui.default_rail_type;
  1725 	if (rt >= RAILTYPE_END) {
  1725 	if (rt >= RAILTYPE_END) {
  1726 		if (rt == RAILTYPE_END + 2) {
  1726 		if (rt == RAILTYPE_END + 2) {
  1743 			if (count[rt] == 0) rt = RAILTYPE_END;
  1743 			if (count[rt] == 0) rt = RAILTYPE_END;
  1744 		}
  1744 		}
  1745 		switch (rt) {
  1745 		switch (rt) {
  1746 			case RAILTYPE_END + 0:
  1746 			case RAILTYPE_END + 0:
  1747 				rt = RAILTYPE_RAIL;
  1747 				rt = RAILTYPE_RAIL;
  1748 				while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_player, rt)) rt++;
  1748 				while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_company, rt)) rt++;
  1749 				break;
  1749 				break;
  1750 
  1750 
  1751 			case RAILTYPE_END + 1:
  1751 			case RAILTYPE_END + 1:
  1752 				rt = GetBestRailtype(_local_player);
  1752 				rt = GetBestRailtype(_local_company);
  1753 				break;
  1753 				break;
  1754 
  1754 
  1755 			default:
  1755 			default:
  1756 				break;
  1756 				break;
  1757 		}
  1757 		}