# HG changeset patch # User rubidium # Date 2008-08-13 06:05:01 # Node ID 5ef4371179690a61fe85e942622ea24bc1071cb8 # Parent fb038aa0523ce963f6f3d46df63f2e4022ec3538 (svn r14063) -Codechange: replace some "magic" constants with enumified constants. diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1091,7 +1091,7 @@ struct BuildVehicleWindow : Window { case VEH_AIRCRAFT: str = STR_A039_RENAME_AIRCRAFT_TYPE; break; } SetDParam(0, sel_eng); - ShowQueryString(STR_ENGINE_NAME, str, 31, 160, this, CS_ALPHANUMERAL); + ShowQueryString(STR_ENGINE_NAME, str, MAX_LENGTH_ENGINE_NAME_BYTES, MAX_LENGTH_ENGINE_NAME_PIXELS, this, CS_ALPHANUMERAL); } break; } diff --git a/src/engine_type.h b/src/engine_type.h --- a/src/engine_type.h +++ b/src/engine_type.h @@ -140,7 +140,9 @@ enum { }; enum { - NUM_VEHICLE_TYPES = 6 + NUM_VEHICLE_TYPES = 6, + MAX_LENGTH_ENGINE_NAME_BYTES = 31, ///< The maximum length of an engine name in bytes including '\0' + MAX_LENGTH_ENGINE_NAME_PIXELS = 160, ///< The maximum length of an engine name in pixels }; static const EngineID INVALID_ENGINE = 0xFFFF; diff --git a/src/group_gui.cpp b/src/group_gui.cpp --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -554,7 +554,7 @@ public: const Group *g = GetGroup(this->group_sel); SetDParam(0, g->index); - ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, 31, 150, this, CS_ALPHANUMERAL); + ShowQueryString(STR_GROUP_NAME, STR_GROUP_RENAME_CAPTION, MAX_LENGTH_GROUP_NAME_BYTES, MAX_LENGTH_GROUP_NAME_PIXELS, this, CS_ALPHANUMERAL); } break; diff --git a/src/group_type.h b/src/group_type.h --- a/src/group_type.h +++ b/src/group_type.h @@ -11,6 +11,9 @@ enum { ALL_GROUP = 0xFFFD, DEFAULT_GROUP = 0xFFFE, ///< ungrouped vehicles are in this group. INVALID_GROUP = 0xFFFF, + + MAX_LENGTH_GROUP_NAME_BYTES = 31, ///< The maximum length of a group name in bytes including '\0' + MAX_LENGTH_GROUP_NAME_PIXELS = 150, ///< The maximum length of a group name in pixels }; struct Group; diff --git a/src/main_gui.cpp b/src/main_gui.cpp --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -145,7 +145,7 @@ void ShowRenameWaypointWindow(const Wayp _rename_id = id; _rename_what = 1; SetDParam(0, id); - ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, 30, 180, NULL, CS_ALPHANUMERAL); + ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, NULL, CS_ALPHANUMERAL); } diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -224,7 +224,7 @@ static bool IsUniqueCompanyName(const ch */ CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (StrEmpty(_cmd_text) || strlen(_cmd_text) > MAX_LENGTH_COMPANY_NAME) return CMD_ERROR; + if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR; if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); @@ -260,7 +260,7 @@ static bool IsUniquePresidentName(const */ CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - if (StrEmpty(_cmd_text) || strlen(_cmd_text) > MAX_LENGTH_PRESIDENT_NAME) return CMD_ERROR; + if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR; if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); diff --git a/src/network/core/config.h b/src/network/core/config.h --- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -24,7 +24,7 @@ enum { NETWORK_MASTER_SERVER_VERSION = 1, ///< What version of master-server-protocol do we use? NETWORK_NAME_LENGTH = 80, ///< The maximum length of the server name and map name, in bytes including '\0' - NETWORK_COMPANY_NAME_LENGTH = 32, ///< The maximum length of the company name, in bytes including '\0' + NETWORK_COMPANY_NAME_LENGTH = 31, ///< The maximum length of the company name, in bytes including '\0' NETWORK_HOSTNAME_LENGTH = 80, ///< The maximum length of the host name, in bytes including '\0' NETWORK_UNIQUE_ID_LENGTH = 33, ///< The maximum length of the unique id of the clients, in bytes including '\0' NETWORK_REVISION_LENGTH = 15, ///< The maximum length of the revision, in bytes including '\0' diff --git a/src/network/network.cpp b/src/network/network.cpp --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -72,7 +72,7 @@ uint8 _network_advertise_retries; /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); -assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME + 1); +assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_BYTES); // global variables (declared in network_data.h) CommandPacket *_local_command_queue; diff --git a/src/player_gui.cpp b/src/player_gui.cpp --- a/src/player_gui.cpp +++ b/src/player_gui.cpp @@ -1222,7 +1222,7 @@ struct PlayerCompanyWindow : Window /* "xxx (Manager)" */ SetDParam(0, p->index); - DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, 94); + DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, MAX_LENGTH_PRESIDENT_NAME_PIXELS); /* "Inaugurated:" */ SetDParam(0, p->inaugurated_year); @@ -1257,13 +1257,13 @@ struct PlayerCompanyWindow : Window case PCW_WIDGET_PRESIDENT_NAME: this->query_widget = PCW_WIDGET_PRESIDENT_NAME; SetDParam(0, this->window_number); - ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, MAX_LENGTH_PRESIDENT_NAME, 94, this, CS_ALPHANUMERAL); + ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, MAX_LENGTH_PRESIDENT_NAME_BYTES, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL); break; case PCW_WIDGET_COMPANY_NAME: this->query_widget = PCW_WIDGET_COMPANY_NAME; SetDParam(0, this->window_number); - ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, MAX_LENGTH_COMPANY_NAME, 150, this, CS_ALPHANUMERAL); + ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, MAX_LENGTH_COMPANY_NAME_BYTES, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL); break; case PCW_WIDGET_BUILD_VIEW_HQ: { diff --git a/src/player_type.h b/src/player_type.h --- a/src/player_type.h +++ b/src/player_type.h @@ -31,8 +31,10 @@ enum Owner { DECLARE_POSTFIX_INCREMENT(Owner); enum { - MAX_LENGTH_PRESIDENT_NAME = 31, ///< The maximum length for a president's name - MAX_LENGTH_COMPANY_NAME = 31, ///< The maximum length for a company's name + MAX_LENGTH_PRESIDENT_NAME_BYTES = 31, ///< The maximum length of a president name in bytes including '\0' + MAX_LENGTH_PRESIDENT_NAME_PIXELS = 94, ///< The maximum length of a president name in pixels + MAX_LENGTH_COMPANY_NAME_BYTES = 31, ///< The maximum length of a company name in bytes including '\0' + MAX_LENGTH_COMPANY_NAME_PIXELS = 150, ///< The maximum length of a company name in pixels }; /** Define basic enum properties */ diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -188,7 +188,7 @@ enum QueryEditSignWidgets { struct SignWindow : QueryStringBaseWindow, SignList { SignID cur_sign; - SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(31, desc) + SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_BYTES, desc) { SetBit(_no_scroll, SCROLL_EDIT); this->caption = STR_280B_EDIT_SIGN_TEXT; @@ -218,7 +218,7 @@ struct SignWindow : QueryStringBaseWindo *last_of = '\0'; this->cur_sign = si->index; - InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 255); + InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, MAX_LENGTH_SIGN_NAME_PIXELS); this->InvalidateWidget(QUERY_EDIT_SIGN_WIDGET_TEXT); } diff --git a/src/signs_type.h b/src/signs_type.h --- a/src/signs_type.h +++ b/src/signs_type.h @@ -10,6 +10,9 @@ struct Sign; enum { INVALID_SIGN = 0xFFFF, + + MAX_LENGTH_SIGN_NAME_BYTES = 31, ///< The maximum length of a sign name in bytes including '\0' + MAX_LENGTH_SIGN_NAME_PIXELS = 255, ///< The maximum length of a sign name in pixels }; #endif /* SIGNS_TYPE_H */ diff --git a/src/station_gui.cpp b/src/station_gui.cpp --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -911,7 +911,7 @@ struct StationViewWindow : public Window case SVW_RENAME: SetDParam(0, this->window_number); - ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, this, CS_ALPHANUMERAL); + ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, MAX_LENGTH_STATION_NAME_BYTES, MAX_LENGTH_STATION_NAME_PIXELS, this, CS_ALPHANUMERAL); break; case SVW_TRAINS: { // Show a list of scheduled trains to this station diff --git a/src/station_type.h b/src/station_type.h --- a/src/station_type.h +++ b/src/station_type.h @@ -62,4 +62,9 @@ enum CatchmentArea { MAX_CATCHMENT = 10, ///< Airports have a catchment up to this number. }; +enum { + MAX_LENGTH_STATION_NAME_BYTES = 31, ///< The maximum length of a station name in bytes including '\0' + MAX_LENGTH_STATION_NAME_PIXELS = 180, ///< The maximum length of a station name in pixels +}; + #endif /* STATION_TYPE_H */ diff --git a/src/town_gui.cpp b/src/town_gui.cpp --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -370,7 +370,7 @@ public: case TVW_CHANGENAME: /* rename */ SetDParam(0, this->window_number); - ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, 31, 130, this, CS_ALPHANUMERAL); + ShowQueryString(STR_TOWN, STR_2007_RENAME_TOWN, MAX_LENGTH_TOWN_NAME_BYTES, MAX_LENGTH_TOWN_NAME_PIXELS, this, CS_ALPHANUMERAL); break; case TVW_EXPAND: /* expand town - only available on Scenario editor */ diff --git a/src/town_type.h b/src/town_type.h --- a/src/town_type.h +++ b/src/town_type.h @@ -81,4 +81,9 @@ enum TownLayout { template <> struct EnumPropsT : MakeEnumPropsT {}; typedef TinyEnumT TownLayoutByte; //typedefing-enumification of TownLayout +enum { + MAX_LENGTH_TOWN_NAME_BYTES = 31, ///< The maximum length of a town name in bytes including '\0' + MAX_LENGTH_TOWN_NAME_PIXELS = 130, ///< The maximum length of a town name in pixels +}; + #endif /* TOWN_TYPE_H */ diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1475,7 +1475,7 @@ struct VehicleDetailsWindow : Window { case VLD_WIDGET_RENAME_VEHICLE: {// rename const Vehicle *v = GetVehicle(this->window_number); SetDParam(0, v->index); - ShowQueryString(STR_VEHICLE_NAME, _name_vehicle_title[v->type], 31, 150, this, CS_ALPHANUMERAL); + ShowQueryString(STR_VEHICLE_NAME, _name_vehicle_title[v->type], MAX_LENGTH_VEHICLE_NAME_BYTES, MAX_LENGTH_VEHICLE_NAME_PIXELS, this, CS_ALPHANUMERAL); } break; case VLD_WIDGET_INCREASE_SERVICING_INTERVAL: // increase int diff --git a/src/vehicle_type.h b/src/vehicle_type.h --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -56,4 +56,9 @@ enum DepotCommand { DEPOT_COMMAND_MASK = 0xF, }; +enum { + MAX_LENGTH_VEHICLE_NAME_BYTES = 31, ///< The maximum length of a vehicle name in bytes including '\0' + MAX_LENGTH_VEHICLE_NAME_PIXELS = 150, ///< The maximum length of a vehicle name in pixels +}; + #endif /* VEHICLE_TYPE_H */ diff --git a/src/waypoint_type.h b/src/waypoint_type.h --- a/src/waypoint_type.h +++ b/src/waypoint_type.h @@ -8,4 +8,9 @@ typedef uint16 WaypointID; struct Waypoint; +enum { + MAX_LENGTH_WAYPOINT_NAME_BYTES = 31, ///< The maximum length of a waypoint name in bytes including '\0' + MAX_LENGTH_WAYPOINT_NAME_PIXELS = 180, ///< The maximum length of a waypoint name in pixels +}; + #endif /* WAYPOINT_TYPE_H */