Mercurial > hg > openttd
changeset 9913:a1cc2bf90049 draft
(svn r14063) -Codechange: replace some "magic" constants with enumified constants.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 13 Aug 2008 06:05:01 +0000 |
parents | 03046a395eb0 |
children | 711da94fe0d7 |
files | src/build_vehicle_gui.cpp src/engine_type.h src/group_gui.cpp src/group_type.h src/main_gui.cpp src/misc_cmd.cpp src/network/core/config.h src/network/network.cpp src/player_gui.cpp src/player_type.h src/signs_gui.cpp src/signs_type.h src/station_gui.cpp src/station_type.h src/town_gui.cpp src/town_type.h src/vehicle_gui.cpp src/vehicle_type.h src/waypoint_type.h |
diffstat | 19 files changed, 48 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1091,7 +1091,7 @@ 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; }
--- a/src/engine_type.h +++ b/src/engine_type.h @@ -140,7 +140,9 @@ }; 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;
--- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -554,7 +554,7 @@ 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;
--- a/src/group_type.h +++ b/src/group_type.h @@ -11,6 +11,9 @@ 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;
--- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -145,7 +145,7 @@ _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); }
--- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -224,7 +224,7 @@ */ 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 @@ */ 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);
--- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -24,7 +24,7 @@ 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'
--- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -72,7 +72,7 @@ /* 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;
--- a/src/player_gui.cpp +++ b/src/player_gui.cpp @@ -1222,7 +1222,7 @@ /* "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 @@ 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: {
--- a/src/player_type.h +++ b/src/player_type.h @@ -31,8 +31,10 @@ 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 */
--- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -188,7 +188,7 @@ 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 @@ *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); }
--- a/src/signs_type.h +++ b/src/signs_type.h @@ -10,6 +10,9 @@ 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 */
--- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -911,7 +911,7 @@ 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
--- a/src/station_type.h +++ b/src/station_type.h @@ -62,4 +62,9 @@ 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 */
--- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -370,7 +370,7 @@ 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 */
--- a/src/town_type.h +++ b/src/town_type.h @@ -81,4 +81,9 @@ template <> struct EnumPropsT<TownLayout> : MakeEnumPropsT<TownLayout, byte, TL_NO_ROADS, NUM_TLS, NUM_TLS> {}; typedef TinyEnumT<TownLayout> 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 */
--- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1475,7 +1475,7 @@ 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
--- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -56,4 +56,9 @@ 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 */
--- 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 */