mirror of https://github.com/OpenTTD/OpenTTD
Codechange: If something is a vector of strings, use a vector of strings instead of an AutoFreeSmallVector.
parent
c7b9987d08
commit
e804173595
|
@ -553,7 +553,7 @@ DEF_CONSOLE_CMD(ConUnBan)
|
||||||
/* Try by IP. */
|
/* Try by IP. */
|
||||||
uint index;
|
uint index;
|
||||||
for (index = 0; index < _network_ban_list.size(); index++) {
|
for (index = 0; index < _network_ban_list.size(); index++) {
|
||||||
if (strcmp(_network_ban_list[index], argv[1]) == 0) break;
|
if (_network_ban_list[index] == argv[1]) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try by index. */
|
/* Try by index. */
|
||||||
|
@ -563,9 +563,8 @@ DEF_CONSOLE_CMD(ConUnBan)
|
||||||
|
|
||||||
if (index < _network_ban_list.size()) {
|
if (index < _network_ban_list.size()) {
|
||||||
char msg[64];
|
char msg[64];
|
||||||
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index]);
|
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index].c_str());
|
||||||
IConsolePrint(CC_DEFAULT, msg);
|
IConsolePrint(CC_DEFAULT, msg);
|
||||||
free(_network_ban_list[index]);
|
|
||||||
_network_ban_list.erase(_network_ban_list.begin() + index);
|
_network_ban_list.erase(_network_ban_list.begin() + index);
|
||||||
} else {
|
} else {
|
||||||
IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
|
IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
|
||||||
|
@ -585,8 +584,8 @@ DEF_CONSOLE_CMD(ConBanList)
|
||||||
IConsolePrint(CC_DEFAULT, "Banlist: ");
|
IConsolePrint(CC_DEFAULT, "Banlist: ");
|
||||||
|
|
||||||
uint i = 1;
|
uint i = 1;
|
||||||
for (char *entry : _network_ban_list) {
|
for (const auto &entry : _network_ban_list) {
|
||||||
IConsolePrintF(CC_DEFAULT, " %d) %s", i, entry);
|
IConsolePrintF(CC_DEFAULT, " %d) %s", i, entry.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -99,6 +99,4 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef AutoFreeSmallVector<char*> StringList; ///< Type for a list of strings.
|
|
||||||
|
|
||||||
#endif /* SMALLVEC_TYPE_HPP */
|
#endif /* SMALLVEC_TYPE_HPP */
|
||||||
|
|
|
@ -111,7 +111,7 @@ std::unique_ptr<LanguageStrings> ReadRawLanguageStrings(const char *file)
|
||||||
while (i > 0 && (buffer[i - 1] == '\r' || buffer[i - 1] == '\n' || buffer[i - 1] == ' ')) i--;
|
while (i > 0 && (buffer[i - 1] == '\r' || buffer[i - 1] == '\n' || buffer[i - 1] == ' ')) i--;
|
||||||
buffer[i] = '\0';
|
buffer[i] = '\0';
|
||||||
|
|
||||||
ret->lines.push_back(stredup(buffer, buffer + to_read - 1));
|
ret->lines.emplace_back(buffer, buffer + to_read - 1);
|
||||||
|
|
||||||
if (len > to_read) {
|
if (len > to_read) {
|
||||||
to_read = 0;
|
to_read = 0;
|
||||||
|
@ -129,8 +129,8 @@ std::unique_ptr<LanguageStrings> ReadRawLanguageStrings(const char *file)
|
||||||
|
|
||||||
/** A reader that simply reads using fopen. */
|
/** A reader that simply reads using fopen. */
|
||||||
struct StringListReader : StringReader {
|
struct StringListReader : StringReader {
|
||||||
const char * const *p; ///< The current location of the iteration.
|
StringList::const_iterator p; ///< The current location of the iteration.
|
||||||
const char * const *end; ///< The end of the iteration.
|
StringList::const_iterator end; ///< The end of the iteration.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the reader.
|
* Create the reader.
|
||||||
|
@ -140,7 +140,7 @@ struct StringListReader : StringReader {
|
||||||
* @param translation Are we reading a translation?
|
* @param translation Are we reading a translation?
|
||||||
*/
|
*/
|
||||||
StringListReader(StringData &data, const LanguageStrings &strings, bool master, bool translation) :
|
StringListReader(StringData &data, const LanguageStrings &strings, bool master, bool translation) :
|
||||||
StringReader(data, strings.language, master, translation), p(strings.lines.data()), end(p + strings.lines.size())
|
StringReader(data, strings.language, master, translation), p(strings.lines.begin()), end(strings.lines.end())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ struct StringListReader : StringReader {
|
||||||
{
|
{
|
||||||
if (this->p == this->end) return NULL;
|
if (this->p == this->end) return NULL;
|
||||||
|
|
||||||
strecpy(buffer, *this->p, last);
|
strecpy(buffer, this->p->c_str(), last);
|
||||||
this->p++;
|
this->p++;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
|
@ -157,13 +157,13 @@ struct StringListReader : StringReader {
|
||||||
|
|
||||||
/** Class for writing an encoded language. */
|
/** Class for writing an encoded language. */
|
||||||
struct TranslationWriter : LanguageWriter {
|
struct TranslationWriter : LanguageWriter {
|
||||||
StringList *strings; ///< The encoded strings.
|
StringList &strings; ///< The encoded strings.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writer for the encoded data.
|
* Writer for the encoded data.
|
||||||
* @param strings The string table to add the strings to.
|
* @param strings The string table to add the strings to.
|
||||||
*/
|
*/
|
||||||
TranslationWriter(StringList *strings) : strings(strings)
|
TranslationWriter(StringList &strings) : strings(strings)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,28 +184,25 @@ struct TranslationWriter : LanguageWriter {
|
||||||
|
|
||||||
void Write(const byte *buffer, size_t length)
|
void Write(const byte *buffer, size_t length)
|
||||||
{
|
{
|
||||||
char *dest = MallocT<char>(length + 1);
|
this->strings.emplace_back((const char *)buffer, length);
|
||||||
memcpy(dest, buffer, length);
|
|
||||||
dest[length] = '\0';
|
|
||||||
this->strings->push_back(dest);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Class for writing the string IDs. */
|
/** Class for writing the string IDs. */
|
||||||
struct StringNameWriter : HeaderWriter {
|
struct StringNameWriter : HeaderWriter {
|
||||||
StringList *strings; ///< The string names.
|
StringList &strings; ///< The string names.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writer for the string names.
|
* Writer for the string names.
|
||||||
* @param strings The string table to add the strings to.
|
* @param strings The string table to add the strings to.
|
||||||
*/
|
*/
|
||||||
StringNameWriter(StringList *strings) : strings(strings)
|
StringNameWriter(StringList &strings) : strings(strings)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteStringID(const char *name, int stringid)
|
void WriteStringID(const char *name, int stringid)
|
||||||
{
|
{
|
||||||
if (stringid == (int)this->strings->size()) this->strings->push_back(stredup(name));
|
if (stringid == (int)this->strings.size()) this->strings.emplace_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Finalise(const StringData &data)
|
void Finalise(const StringData &data)
|
||||||
|
@ -314,7 +311,7 @@ void GameStrings::Compile()
|
||||||
|
|
||||||
this->version = data.Version();
|
this->version = data.Version();
|
||||||
|
|
||||||
StringNameWriter id_writer(&this->string_names);
|
StringNameWriter id_writer(this->string_names);
|
||||||
id_writer.WriteHeader(data);
|
id_writer.WriteHeader(data);
|
||||||
|
|
||||||
for (const auto &p : this->raw_strings) {
|
for (const auto &p : this->raw_strings) {
|
||||||
|
@ -324,7 +321,7 @@ void GameStrings::Compile()
|
||||||
if (_errors != 0) throw std::exception();
|
if (_errors != 0) throw std::exception();
|
||||||
|
|
||||||
this->compiled_strings.emplace_back(new LanguageStrings(p->language));
|
this->compiled_strings.emplace_back(new LanguageStrings(p->language));
|
||||||
TranslationWriter writer(&this->compiled_strings.back()->lines);
|
TranslationWriter writer(this->compiled_strings.back()->lines);
|
||||||
writer.WriteLang(data);
|
writer.WriteLang(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,7 +337,7 @@ GameStrings *_current_data = NULL;
|
||||||
const char *GetGameStringPtr(uint id)
|
const char *GetGameStringPtr(uint id)
|
||||||
{
|
{
|
||||||
if (id >= _current_data->cur_language->lines.size()) return GetStringPtr(STR_UNDEFINED);
|
if (id >= _current_data->cur_language->lines.size()) return GetStringPtr(STR_UNDEFINED);
|
||||||
return _current_data->cur_language->lines[id];
|
return _current_data->cur_language->lines[id].c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -359,8 +356,8 @@ void RegisterGameTranslation(Squirrel *engine)
|
||||||
if (SQ_FAILED(sq_get(vm, -2))) return;
|
if (SQ_FAILED(sq_get(vm, -2))) return;
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (const char * const p : _current_data->string_names) {
|
for (const auto &p : _current_data->string_names) {
|
||||||
sq_pushstring(vm, p, -1);
|
sq_pushstring(vm, p.c_str(), -1);
|
||||||
sq_pushinteger(vm, idx);
|
sq_pushinteger(vm, idx);
|
||||||
sq_rawset(vm, -3);
|
sq_rawset(vm, -3);
|
||||||
idx++;
|
idx++;
|
||||||
|
|
|
@ -156,7 +156,7 @@ bool NetworkAddress::IsFamily(int family)
|
||||||
* @note netmask without /n assumes all bits need to match.
|
* @note netmask without /n assumes all bits need to match.
|
||||||
* @return true if this IP is within the netmask.
|
* @return true if this IP is within the netmask.
|
||||||
*/
|
*/
|
||||||
bool NetworkAddress::IsInNetmask(char *netmask)
|
bool NetworkAddress::IsInNetmask(const char *netmask)
|
||||||
{
|
{
|
||||||
/* Resolve it if we didn't do it already */
|
/* Resolve it if we didn't do it already */
|
||||||
if (!this->IsResolved()) this->GetAddress();
|
if (!this->IsResolved()) this->GetAddress();
|
||||||
|
@ -166,17 +166,16 @@ bool NetworkAddress::IsInNetmask(char *netmask)
|
||||||
NetworkAddress mask_address;
|
NetworkAddress mask_address;
|
||||||
|
|
||||||
/* Check for CIDR separator */
|
/* Check for CIDR separator */
|
||||||
char *chr_cidr = strchr(netmask, '/');
|
const char *chr_cidr = strchr(netmask, '/');
|
||||||
if (chr_cidr != NULL) {
|
if (chr_cidr != NULL) {
|
||||||
int tmp_cidr = atoi(chr_cidr + 1);
|
int tmp_cidr = atoi(chr_cidr + 1);
|
||||||
|
|
||||||
/* Invalid CIDR, treat as single host */
|
/* Invalid CIDR, treat as single host */
|
||||||
if (tmp_cidr > 0 || tmp_cidr < cidr) cidr = tmp_cidr;
|
if (tmp_cidr > 0 || tmp_cidr < cidr) cidr = tmp_cidr;
|
||||||
|
|
||||||
/* Remove and then replace the / so that NetworkAddress works on the IP portion */
|
/* Remove the / so that NetworkAddress works on the IP portion */
|
||||||
*chr_cidr = '\0';
|
std::string ip_str(netmask, chr_cidr - netmask);
|
||||||
mask_address = NetworkAddress(netmask, 0, this->address.ss_family);
|
mask_address = NetworkAddress(ip_str.c_str(), 0, this->address.ss_family);
|
||||||
*chr_cidr = '/';
|
|
||||||
} else {
|
} else {
|
||||||
mask_address = NetworkAddress(netmask, 0, this->address.ss_family);
|
mask_address = NetworkAddress(netmask, 0, this->address.ss_family);
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFamily(int family);
|
bool IsFamily(int family);
|
||||||
bool IsInNetmask(char *netmask);
|
bool IsInNetmask(const char *netmask);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare the address of this class with the address of another.
|
* Compare the address of this class with the address of another.
|
||||||
|
|
|
@ -54,13 +54,13 @@ public:
|
||||||
|
|
||||||
/* Check if the client is banned */
|
/* Check if the client is banned */
|
||||||
bool banned = false;
|
bool banned = false;
|
||||||
for (char *entry : _network_ban_list) {
|
for (const auto &entry : _network_ban_list) {
|
||||||
banned = address.IsInNetmask(entry);
|
banned = address.IsInNetmask(entry.c_str());
|
||||||
if (banned) {
|
if (banned) {
|
||||||
Packet p(Tban_packet);
|
Packet p(Tban_packet);
|
||||||
p.PrepareToSend();
|
p.PrepareToSend();
|
||||||
|
|
||||||
DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry);
|
DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry.c_str());
|
||||||
|
|
||||||
if (send(s, (const char*)p.buffer, p.size, 0) < 0) {
|
if (send(s, (const char*)p.buffer, p.size, 0) < 0) {
|
||||||
DEBUG(net, 0, "send failed with error %d", GET_LAST_ERROR());
|
DEBUG(net, 0, "send failed with error %d", GET_LAST_ERROR());
|
||||||
|
|
|
@ -632,8 +632,8 @@ void NetworkAddServer(const char *b)
|
||||||
*/
|
*/
|
||||||
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
|
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
|
||||||
{
|
{
|
||||||
for (char *iter : _network_bind_list) {
|
for (const auto &iter : _network_bind_list) {
|
||||||
addresses->emplace_back(iter, port);
|
addresses->emplace_back(iter.c_str(), port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No address, so bind to everything. */
|
/* No address, so bind to everything. */
|
||||||
|
@ -647,10 +647,10 @@ void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
|
||||||
* by the function that generates the config file. */
|
* by the function that generates the config file. */
|
||||||
void NetworkRebuildHostList()
|
void NetworkRebuildHostList()
|
||||||
{
|
{
|
||||||
_network_host_list.Clear();
|
_network_host_list.clear();
|
||||||
|
|
||||||
for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
|
for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
|
||||||
if (item->manually) _network_host_list.push_back(stredup(item->address.GetAddressAsString(false)));
|
if (item->manually) _network_host_list.emplace_back(item->address.GetAddressAsString(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1045,8 +1045,8 @@ void ShowNetworkGameWindow()
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
/* Add all servers from the config file to our list. */
|
/* Add all servers from the config file to our list. */
|
||||||
for (char *iter : _network_host_list) {
|
for (const auto &iter : _network_host_list) {
|
||||||
NetworkAddServer(iter);
|
NetworkAddServer(iter.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2083,13 +2083,13 @@ uint NetworkServerKickOrBanIP(const char *ip, bool ban)
|
||||||
/* Add address to ban-list */
|
/* Add address to ban-list */
|
||||||
if (ban) {
|
if (ban) {
|
||||||
bool contains = false;
|
bool contains = false;
|
||||||
for (char *iter : _network_ban_list) {
|
for (const auto &iter : _network_ban_list) {
|
||||||
if (strcmp(iter, ip) == 0) {
|
if (iter == ip) {
|
||||||
contains = true;
|
contains = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!contains) _network_ban_list.push_back(stredup(ip));
|
if (!contains) _network_ban_list.emplace_back(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint n = 0;
|
uint n = 0;
|
||||||
|
@ -2098,7 +2098,7 @@ uint NetworkServerKickOrBanIP(const char *ip, bool ban)
|
||||||
NetworkClientSocket *cs;
|
NetworkClientSocket *cs;
|
||||||
FOR_ALL_CLIENT_SOCKETS(cs) {
|
FOR_ALL_CLIENT_SOCKETS(cs) {
|
||||||
if (cs->client_id == CLIENT_ID_SERVER) continue;
|
if (cs->client_id == CLIENT_ID_SERVER) continue;
|
||||||
if (cs->client_address.IsInNetmask(const_cast<char *>(ip))) {
|
if (cs->client_address.IsInNetmask(ip)) {
|
||||||
NetworkServerKickClient(cs->client_id);
|
NetworkServerKickClient(cs->client_id);
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -565,8 +565,6 @@ void ShowNewGRFTextfileWindow(TextfileType file_type, const GRFConfig *c)
|
||||||
new NewGRFTextfileWindow(file_type, c);
|
new NewGRFTextfileWindow(file_type, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GRFPresetList _grf_preset_list; ///< List of known NewGRF presets. @see GetGRFPresetList
|
|
||||||
|
|
||||||
typedef std::map<uint32, const GRFConfig *> GrfIdMap; ///< Map of grfid to the grf config.
|
typedef std::map<uint32, const GRFConfig *> GrfIdMap; ///< Map of grfid to the grf config.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -605,6 +603,8 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
StringFilter string_filter; ///< Filter for available grf.
|
StringFilter string_filter; ///< Filter for available grf.
|
||||||
QueryString filter_editbox; ///< Filter editbox;
|
QueryString filter_editbox; ///< Filter editbox;
|
||||||
|
|
||||||
|
StringList grf_presets; ///< List of known NewGRF presets.
|
||||||
|
|
||||||
GRFConfig *actives; ///< Temporary active grf list to which changes are made.
|
GRFConfig *actives; ///< Temporary active grf list to which changes are made.
|
||||||
GRFConfig *active_sel; ///< Selected active grf item.
|
GRFConfig *active_sel; ///< Selected active grf item.
|
||||||
|
|
||||||
|
@ -632,7 +632,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
this->active_over = -1;
|
this->active_over = -1;
|
||||||
|
|
||||||
CopyGRFConfigList(&this->actives, *orig_list, false);
|
CopyGRFConfigList(&this->actives, *orig_list, false);
|
||||||
GetGRFPresetList(&_grf_preset_list);
|
this->grf_presets = GetGRFPresetList();
|
||||||
|
|
||||||
this->CreateNestedTree();
|
this->CreateNestedTree();
|
||||||
this->vscroll = this->GetScrollbar(WID_NS_SCROLLBAR);
|
this->vscroll = this->GetScrollbar(WID_NS_SCROLLBAR);
|
||||||
|
@ -673,7 +673,6 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
|
|
||||||
/* Remove the temporary copy of grf-list used in window */
|
/* Remove the temporary copy of grf-list used in window */
|
||||||
ClearGRFConfigList(&this->actives);
|
ClearGRFConfigList(&this->actives);
|
||||||
_grf_preset_list.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -747,12 +746,10 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
|
|
||||||
case WID_NS_PRESET_LIST: {
|
case WID_NS_PRESET_LIST: {
|
||||||
Dimension d = GetStringBoundingBox(STR_NUM_CUSTOM);
|
Dimension d = GetStringBoundingBox(STR_NUM_CUSTOM);
|
||||||
for (uint i = 0; i < _grf_preset_list.size(); i++) {
|
for (const auto &i : this->grf_presets) {
|
||||||
if (_grf_preset_list[i] != NULL) {
|
SetDParamStr(0, i.c_str());
|
||||||
SetDParamStr(0, _grf_preset_list[i]);
|
|
||||||
d = maxdim(d, GetStringBoundingBox(STR_JUST_RAW_STRING));
|
d = maxdim(d, GetStringBoundingBox(STR_JUST_RAW_STRING));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
d.width += padding.width;
|
d.width += padding.width;
|
||||||
*size = maxdim(d, *size);
|
*size = maxdim(d, *size);
|
||||||
break;
|
break;
|
||||||
|
@ -783,7 +780,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
SetDParam(0, STR_NUM_CUSTOM);
|
SetDParam(0, STR_NUM_CUSTOM);
|
||||||
} else {
|
} else {
|
||||||
SetDParam(0, STR_JUST_RAW_STRING);
|
SetDParam(0, STR_JUST_RAW_STRING);
|
||||||
SetDParamStr(1, _grf_preset_list[this->preset]);
|
SetDParamStr(1, this->grf_presets[this->preset].c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -929,10 +926,8 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
/* Add 'None' option for clearing list */
|
/* Add 'None' option for clearing list */
|
||||||
list.emplace_back(new DropDownListStringItem(STR_NONE, -1, false));
|
list.emplace_back(new DropDownListStringItem(STR_NONE, -1, false));
|
||||||
|
|
||||||
for (uint i = 0; i < _grf_preset_list.size(); i++) {
|
for (uint i = 0; i < this->grf_presets.size(); i++) {
|
||||||
if (_grf_preset_list[i] != NULL) {
|
list.emplace_back(new DropDownListCharStringItem(this->grf_presets[i].c_str(), i, false));
|
||||||
list.emplace_back(new DropDownListCharStringItem(_grf_preset_list[i], i, false));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
||||||
|
@ -949,14 +944,14 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_NS_PRESET_SAVE:
|
case WID_NS_PRESET_SAVE:
|
||||||
ShowSavePresetWindow((this->preset == -1) ? NULL : _grf_preset_list[this->preset]);
|
ShowSavePresetWindow((this->preset == -1) ? NULL : this->grf_presets[this->preset].c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_NS_PRESET_DELETE:
|
case WID_NS_PRESET_DELETE:
|
||||||
if (this->preset == -1) return;
|
if (this->preset == -1) return;
|
||||||
|
|
||||||
DeleteGRFPresetFromConfig(_grf_preset_list[this->preset]);
|
DeleteGRFPresetFromConfig(this->grf_presets[this->preset].c_str());
|
||||||
GetGRFPresetList(&_grf_preset_list);
|
this->grf_presets = GetGRFPresetList();
|
||||||
this->preset = -1;
|
this->preset = -1;
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
||||||
|
@ -1156,7 +1151,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
this->preset = index;
|
this->preset = index;
|
||||||
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
this->actives = LoadGRFPresetFromConfig(_grf_preset_list[index]);
|
this->actives = LoadGRFPresetFromConfig(this->grf_presets[index].c_str());
|
||||||
}
|
}
|
||||||
this->avails.ForceRebuild();
|
this->avails.ForceRebuild();
|
||||||
|
|
||||||
|
@ -1172,11 +1167,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
if (str == NULL) return;
|
if (str == NULL) return;
|
||||||
|
|
||||||
SaveGRFPresetToConfig(str, this->actives);
|
SaveGRFPresetToConfig(str, this->actives);
|
||||||
GetGRFPresetList(&_grf_preset_list);
|
this->grf_presets = GetGRFPresetList();
|
||||||
|
|
||||||
/* Switch to this preset */
|
/* Switch to this preset */
|
||||||
for (uint i = 0; i < _grf_preset_list.size(); i++) {
|
for (uint i = 0; i < this->grf_presets.size(); i++) {
|
||||||
if (_grf_preset_list[i] != NULL && strcmp(_grf_preset_list[i], str) == 0) {
|
if (this->grf_presets[i] == str) {
|
||||||
this->preset = i;
|
this->preset = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2038,7 +2033,7 @@ static WindowDesc _save_preset_desc(
|
||||||
/** Class for the save preset window. */
|
/** Class for the save preset window. */
|
||||||
struct SavePresetWindow : public Window {
|
struct SavePresetWindow : public Window {
|
||||||
QueryString presetname_editbox; ///< Edit box of the save preset.
|
QueryString presetname_editbox; ///< Edit box of the save preset.
|
||||||
GRFPresetList presets; ///< Available presets.
|
StringList presets; ///< Available presets.
|
||||||
Scrollbar *vscroll; ///< Pointer to the scrollbar widget.
|
Scrollbar *vscroll; ///< Pointer to the scrollbar widget.
|
||||||
int selected; ///< Selected entry in the preset list, or \c -1 if none selected.
|
int selected; ///< Selected entry in the preset list, or \c -1 if none selected.
|
||||||
|
|
||||||
|
@ -2048,11 +2043,11 @@ struct SavePresetWindow : public Window {
|
||||||
*/
|
*/
|
||||||
SavePresetWindow(const char *initial_text) : Window(&_save_preset_desc), presetname_editbox(32)
|
SavePresetWindow(const char *initial_text) : Window(&_save_preset_desc), presetname_editbox(32)
|
||||||
{
|
{
|
||||||
GetGRFPresetList(&this->presets);
|
this->presets = GetGRFPresetList();
|
||||||
this->selected = -1;
|
this->selected = -1;
|
||||||
if (initial_text != NULL) {
|
if (initial_text != NULL) {
|
||||||
for (uint i = 0; i < this->presets.size(); i++) {
|
for (uint i = 0; i < this->presets.size(); i++) {
|
||||||
if (!strcmp(initial_text, this->presets[i])) {
|
if (this->presets[i] == initial_text) {
|
||||||
this->selected = i;
|
this->selected = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2083,7 +2078,7 @@ struct SavePresetWindow : public Window {
|
||||||
resize->height = FONT_HEIGHT_NORMAL + 2U;
|
resize->height = FONT_HEIGHT_NORMAL + 2U;
|
||||||
size->height = 0;
|
size->height = 0;
|
||||||
for (uint i = 0; i < this->presets.size(); i++) {
|
for (uint i = 0; i < this->presets.size(); i++) {
|
||||||
Dimension d = GetStringBoundingBox(this->presets[i]);
|
Dimension d = GetStringBoundingBox(this->presets[i].c_str());
|
||||||
size->width = max(size->width, d.width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
|
size->width = max(size->width, d.width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
|
||||||
resize->height = max(resize->height, d.height);
|
resize->height = max(resize->height, d.height);
|
||||||
}
|
}
|
||||||
|
@ -2108,7 +2103,7 @@ struct SavePresetWindow : public Window {
|
||||||
for (uint i = min_index; i < max_index; i++) {
|
for (uint i = min_index; i < max_index; i++) {
|
||||||
if ((int)i == this->selected) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 2, PC_DARK_BLUE);
|
if ((int)i == this->selected) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 2, PC_DARK_BLUE);
|
||||||
|
|
||||||
const char *text = this->presets[i];
|
const char *text = this->presets[i].c_str();
|
||||||
DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y + offset_y, text, ((int)i == this->selected) ? TC_WHITE : TC_SILVER);
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y + offset_y, text, ((int)i == this->selected) ? TC_WHITE : TC_SILVER);
|
||||||
y += step_height;
|
y += step_height;
|
||||||
}
|
}
|
||||||
|
@ -2124,7 +2119,7 @@ struct SavePresetWindow : public Window {
|
||||||
uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SVP_PRESET_LIST);
|
uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SVP_PRESET_LIST);
|
||||||
if (row < this->presets.size()) {
|
if (row < this->presets.size()) {
|
||||||
this->selected = row;
|
this->selected = row;
|
||||||
this->presetname_editbox.text.Assign(this->presets[row]);
|
this->presetname_editbox.text.Assign(this->presets[row].c_str());
|
||||||
this->SetWidgetDirty(WID_SVP_PRESET_LIST);
|
this->SetWidgetDirty(WID_SVP_PRESET_LIST);
|
||||||
this->SetWidgetDirty(WID_SVP_EDITBOX);
|
this->SetWidgetDirty(WID_SVP_EDITBOX);
|
||||||
}
|
}
|
||||||
|
|
|
@ -445,8 +445,8 @@ struct AfterNewGRFScan : NewGRFScanCallback {
|
||||||
if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
|
if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
|
||||||
|
|
||||||
if (dedicated_host != NULL) {
|
if (dedicated_host != NULL) {
|
||||||
_network_bind_list.Clear();
|
_network_bind_list.clear();
|
||||||
_network_bind_list.push_back(stredup(dedicated_host));
|
_network_bind_list.emplace_back(dedicated_host);
|
||||||
}
|
}
|
||||||
if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
|
if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
|
||||||
|
|
||||||
|
|
|
@ -129,14 +129,14 @@ static const SaveLoad _game_language_string[] = {
|
||||||
SLE_END()
|
SLE_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
static void SaveReal_GSTR(LanguageStrings *ls)
|
static void SaveReal_GSTR(const LanguageStrings *ls)
|
||||||
{
|
{
|
||||||
_game_saveload_string = ls->language;
|
_game_saveload_string = ls->language;
|
||||||
_game_saveload_strings = (uint)ls->lines.size();
|
_game_saveload_strings = (uint)ls->lines.size();
|
||||||
|
|
||||||
SlObject(NULL, _game_language_header);
|
SlObject(NULL, _game_language_header);
|
||||||
for (uint i = 0; i < _game_saveload_strings; i++) {
|
for (const auto &i : ls->lines) {
|
||||||
_game_saveload_string = ls->lines[i];
|
_game_saveload_string = i.c_str();
|
||||||
SlObject(NULL, _game_language_string);
|
SlObject(NULL, _game_language_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ static void Load_GSTR()
|
||||||
std::unique_ptr<LanguageStrings> ls(new LanguageStrings(_game_saveload_string != NULL ? _game_saveload_string : ""));
|
std::unique_ptr<LanguageStrings> ls(new LanguageStrings(_game_saveload_string != NULL ? _game_saveload_string : ""));
|
||||||
for (uint i = 0; i < _game_saveload_strings; i++) {
|
for (uint i = 0; i < _game_saveload_strings; i++) {
|
||||||
SlObject(NULL, _game_language_string);
|
SlObject(NULL, _game_language_string);
|
||||||
ls->lines.push_back(stredup(_game_saveload_string != NULL ? _game_saveload_string : ""));
|
ls->lines.emplace_back(_game_saveload_string != NULL ? _game_saveload_string : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
_current_data->raw_strings.push_back(std::move(ls));
|
_current_data->raw_strings.push_back(std::move(ls));
|
||||||
|
|
|
@ -84,7 +84,7 @@ static ErrorList _settings_error_list; ///< Errors while loading minimal setting
|
||||||
|
|
||||||
|
|
||||||
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
|
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
|
||||||
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList *list);
|
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
|
||||||
|
|
||||||
static bool IsSignedVarMemType(VarType vt);
|
static bool IsSignedVarMemType(VarType vt);
|
||||||
|
|
||||||
|
@ -718,16 +718,16 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||||
* @param grpname character string identifying the section-header of the ini file that will be parsed
|
* @param grpname character string identifying the section-header of the ini file that will be parsed
|
||||||
* @param list new list with entries of the given section
|
* @param list new list with entries of the given section
|
||||||
*/
|
*/
|
||||||
static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList *list)
|
static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &list)
|
||||||
{
|
{
|
||||||
IniGroup *group = ini->GetGroup(grpname);
|
IniGroup *group = ini->GetGroup(grpname);
|
||||||
|
|
||||||
if (group == NULL || list == NULL) return;
|
if (group == NULL) return;
|
||||||
|
|
||||||
list->Clear();
|
list.clear();
|
||||||
|
|
||||||
for (const IniItem *item = group->item; item != NULL; item = item->next) {
|
for (const IniItem *item = group->item; item != NULL; item = item->next) {
|
||||||
if (item->name != NULL) list->push_back(stredup(item->name));
|
if (item->name != NULL) list.emplace_back(item->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,15 +740,15 @@ static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList *li
|
||||||
* @param list pointer to an string(pointer) array that will be used as the
|
* @param list pointer to an string(pointer) array that will be used as the
|
||||||
* source to be saved into the relevant ini section
|
* source to be saved into the relevant ini section
|
||||||
*/
|
*/
|
||||||
static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList *list)
|
static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &list)
|
||||||
{
|
{
|
||||||
IniGroup *group = ini->GetGroup(grpname);
|
IniGroup *group = ini->GetGroup(grpname);
|
||||||
|
|
||||||
if (group == NULL || list == NULL) return;
|
if (group == NULL) return;
|
||||||
group->Clear();
|
group->Clear();
|
||||||
|
|
||||||
for (char *iter : *list) {
|
for (const auto &iter : list) {
|
||||||
group->GetItem(iter, true)->SetValue("");
|
group->GetItem(iter.c_str(), true)->SetValue("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1699,9 +1699,9 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP
|
||||||
proc(ini, _currency_settings,"currency", &_custom_currency);
|
proc(ini, _currency_settings,"currency", &_custom_currency);
|
||||||
proc(ini, _company_settings, "company", &_settings_client.company);
|
proc(ini, _company_settings, "company", &_settings_client.company);
|
||||||
|
|
||||||
proc_list(ini, "server_bind_addresses", &_network_bind_list);
|
proc_list(ini, "server_bind_addresses", _network_bind_list);
|
||||||
proc_list(ini, "servers", &_network_host_list);
|
proc_list(ini, "servers", _network_host_list);
|
||||||
proc_list(ini, "bans", &_network_ban_list);
|
proc_list(ini, "bans", _network_ban_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1767,21 +1767,20 @@ void SaveToConfig()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of known NewGrf presets.
|
* Get the list of known NewGrf presets.
|
||||||
* @param[in,out] list Pointer to list for storing the preset names.
|
* @returns List of preset names.
|
||||||
*/
|
*/
|
||||||
void GetGRFPresetList(GRFPresetList *list)
|
StringList GetGRFPresetList()
|
||||||
{
|
{
|
||||||
list->Clear();
|
StringList list;
|
||||||
|
|
||||||
IniFile *ini = IniLoadConfig();
|
std::unique_ptr<IniFile> ini(IniLoadConfig());
|
||||||
IniGroup *group;
|
for (IniGroup *group = ini->group; group != NULL; group = group->next) {
|
||||||
for (group = ini->group; group != NULL; group = group->next) {
|
|
||||||
if (strncmp(group->name, "preset-", 7) == 0) {
|
if (strncmp(group->name, "preset-", 7) == 0) {
|
||||||
list->push_back(stredup(group->name + 7));
|
list.emplace_back(group->name + 7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete ini;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "core/smallvec_type.hpp"
|
#include "core/smallvec_type.hpp"
|
||||||
#include "company_type.h"
|
#include "company_type.h"
|
||||||
|
#include "string_type.h"
|
||||||
|
|
||||||
struct IniFile;
|
struct IniFile;
|
||||||
|
|
||||||
|
@ -28,11 +29,7 @@ void SaveToConfig();
|
||||||
void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc);
|
void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc);
|
||||||
void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc);
|
void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc);
|
||||||
|
|
||||||
/* Functions to load and save NewGRF settings to a separate
|
StringList GetGRFPresetList();
|
||||||
* configuration file, used for presets. */
|
|
||||||
typedef AutoFreeSmallVector<char *> GRFPresetList;
|
|
||||||
|
|
||||||
void GetGRFPresetList(GRFPresetList *list);
|
|
||||||
struct GRFConfig *LoadGRFPresetFromConfig(const char *config_name);
|
struct GRFConfig *LoadGRFPresetFromConfig(const char *config_name);
|
||||||
void SaveGRFPresetToConfig(const char *config_name, struct GRFConfig *config);
|
void SaveGRFPresetToConfig(const char *config_name, struct GRFConfig *config);
|
||||||
void DeleteGRFPresetFromConfig(const char *config_name);
|
void DeleteGRFPresetFromConfig(const char *config_name);
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#define STRING_TYPE_H
|
#define STRING_TYPE_H
|
||||||
|
|
||||||
#include "core/enum_type.hpp"
|
#include "core/enum_type.hpp"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
/** A non-breaking space. */
|
/** A non-breaking space. */
|
||||||
#define NBSP "\xC2\xA0"
|
#define NBSP "\xC2\xA0"
|
||||||
|
@ -53,4 +55,8 @@ enum StringValidationSettings {
|
||||||
};
|
};
|
||||||
DECLARE_ENUM_AS_BIT_SET(StringValidationSettings)
|
DECLARE_ENUM_AS_BIT_SET(StringValidationSettings)
|
||||||
|
|
||||||
|
|
||||||
|
/** Type for a list of strings. */
|
||||||
|
typedef std::vector<std::string> StringList;
|
||||||
|
|
||||||
#endif /* STRING_TYPE_H */
|
#endif /* STRING_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue