mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use std::optional<std::string> over char * for text query results
parent
3819ab25bf
commit
14200212b7
|
@ -1853,11 +1853,11 @@ struct BuildVehicleWindow : Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
Command<CMD_RENAME_ENGINE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, str);
|
Command<CMD_RENAME_ENGINE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, *str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDropdownSelect(WidgetID widget, int index) override
|
void OnDropdownSelect(WidgetID widget, int index) override
|
||||||
|
|
|
@ -404,14 +404,14 @@ struct CheatWindow : Window {
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
/* Was 'cancel' pressed or nothing entered? */
|
/* Was 'cancel' pressed or nothing entered? */
|
||||||
if (str == nullptr || StrEmpty(str)) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
|
|
||||||
const CheatEntry *ce = &_cheats_ui[clicked_widget];
|
const CheatEntry *ce = &_cheats_ui[clicked_widget];
|
||||||
int oldvalue = (int32_t)ReadValue(ce->variable, ce->type);
|
int oldvalue = (int32_t)ReadValue(ce->variable, ce->type);
|
||||||
int value = atoi(str);
|
int value = atoi(str->c_str());
|
||||||
*ce->been_used = true;
|
*ce->been_used = true;
|
||||||
value = ce->proc(value, value - oldvalue);
|
value = ce->proc(value, value - oldvalue);
|
||||||
|
|
||||||
|
|
|
@ -1686,12 +1686,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
/* Set a new company manager face number */
|
/* Set a new company manager face number */
|
||||||
if (!StrEmpty(str)) {
|
if (!str->empty()) {
|
||||||
this->face = std::strtoul(str, nullptr, 10);
|
this->face = std::strtoul(str->c_str(), nullptr, 10);
|
||||||
ScaleAllCompanyManagerFaceBits(this->face);
|
ScaleAllCompanyManagerFaceBits(this->face);
|
||||||
ShowErrorMessage(STR_FACE_FACECODE_SET, INVALID_STRING_ID, WL_INFO);
|
ShowErrorMessage(STR_FACE_FACECODE_SET, INVALID_STRING_ID, WL_INFO);
|
||||||
this->UpdateData();
|
this->UpdateData();
|
||||||
|
@ -2520,25 +2520,25 @@ struct CompanyWindow : Window
|
||||||
this->RaiseButtons();
|
this->RaiseButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
switch (this->query_widget) {
|
switch (this->query_widget) {
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
|
||||||
case WID_C_GIVE_MONEY: {
|
case WID_C_GIVE_MONEY: {
|
||||||
Money money = std::strtoull(str, nullptr, 10) / GetCurrency().rate;
|
Money money = std::strtoull(str->c_str(), nullptr, 10) / GetCurrency().rate;
|
||||||
Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, (CompanyID)this->window_number);
|
Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, (CompanyID)this->window_number);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_C_PRESIDENT_NAME:
|
case WID_C_PRESIDENT_NAME:
|
||||||
Command<CMD_RENAME_PRESIDENT>::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, str);
|
Command<CMD_RENAME_PRESIDENT>::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, *str);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_C_COMPANY_NAME:
|
case WID_C_COMPANY_NAME:
|
||||||
Command<CMD_RENAME_COMPANY>::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, str);
|
Command<CMD_RENAME_COMPANY>::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, *str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -831,12 +831,12 @@ struct DepotWindow : Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
/* Do depot renaming */
|
/* Do depot renaming */
|
||||||
Command<CMD_RENAME_DEPOT>::Post(STR_ERROR_CAN_T_RENAME_DEPOT, this->GetDepotIndex(), str);
|
Command<CMD_RENAME_DEPOT>::Post(STR_ERROR_CAN_T_RENAME_DEPOT, this->GetDepotIndex(), *str);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnRightClick([[maybe_unused]] Point pt, WidgetID widget) override
|
bool OnRightClick([[maybe_unused]] Point pt, WidgetID widget) override
|
||||||
|
|
|
@ -368,10 +368,10 @@ struct GSConfigWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (StrEmpty(str)) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
int32_t value = atoi(str);
|
int32_t value = atoi(str->c_str());
|
||||||
SetValue(value);
|
SetValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -935,14 +935,14 @@ struct GenerateLandscapeWindow : public Window {
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
/* Was 'cancel' pressed? */
|
/* Was 'cancel' pressed? */
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
int32_t value;
|
int32_t value;
|
||||||
if (!StrEmpty(str)) {
|
if (!str->empty()) {
|
||||||
value = atoi(str);
|
value = atoi(str->c_str());
|
||||||
} else {
|
} else {
|
||||||
/* An empty string means revert to the default */
|
/* An empty string means revert to the default */
|
||||||
switch (this->widget_id) {
|
switch (this->widget_id) {
|
||||||
|
@ -1229,25 +1229,25 @@ struct CreateScenarioWindow : public Window
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (!StrEmpty(str)) {
|
if (!str.has_value() || str->empty()) return;
|
||||||
int32_t value = atoi(str);
|
|
||||||
|
|
||||||
switch (this->widget_id) {
|
int32_t value = atoi(str->c_str());
|
||||||
case WID_CS_START_DATE_TEXT:
|
|
||||||
this->SetWidgetDirty(WID_CS_START_DATE_TEXT);
|
|
||||||
_settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WID_CS_FLAT_LAND_HEIGHT_TEXT:
|
switch (this->widget_id) {
|
||||||
this->SetWidgetDirty(WID_CS_FLAT_LAND_HEIGHT_TEXT);
|
case WID_CS_START_DATE_TEXT:
|
||||||
_settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, GetMapHeightLimit());
|
this->SetWidgetDirty(WID_CS_START_DATE_TEXT);
|
||||||
break;
|
_settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
|
||||||
}
|
break;
|
||||||
|
|
||||||
this->SetDirty();
|
case WID_CS_FLAT_LAND_HEIGHT_TEXT:
|
||||||
|
this->SetWidgetDirty(WID_CS_FLAT_LAND_HEIGHT_TEXT);
|
||||||
|
_settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, GetMapHeightLimit());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -972,9 +972,9 @@ public:
|
||||||
_cursor.vehchain = false;
|
_cursor.vehchain = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str != nullptr) Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, 0, str);
|
if (str.has_value()) Command<CMD_ALTER_GROUP>::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, 0, *str);
|
||||||
this->group_rename = INVALID_GROUP;
|
this->group_rename = INVALID_GROUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1138,12 +1138,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (StrEmpty(str)) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
|
|
||||||
Industry *i = Industry::Get(this->window_number);
|
Industry *i = Industry::Get(this->window_number);
|
||||||
uint value = atoi(str);
|
uint value = atoi(str->c_str());
|
||||||
switch (this->editbox_line) {
|
switch (this->editbox_line) {
|
||||||
case IL_NONE: NOT_REACHED();
|
case IL_NONE: NOT_REACHED();
|
||||||
|
|
||||||
|
|
|
@ -1039,7 +1039,7 @@ struct QueryStringWindow : public Window
|
||||||
if (!this->editbox.handled && this->parent != nullptr) {
|
if (!this->editbox.handled && this->parent != nullptr) {
|
||||||
Window *parent = this->parent;
|
Window *parent = this->parent;
|
||||||
this->parent = nullptr; // so parent doesn't try to close us again
|
this->parent = nullptr; // so parent doesn't try to close us again
|
||||||
parent->OnQueryTextFinished(nullptr);
|
parent->OnQueryTextFinished(std::nullopt);
|
||||||
}
|
}
|
||||||
this->Window::Close();
|
this->Window::Close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -836,13 +836,13 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (!StrEmpty(str)) {
|
if (!str.has_value() || str->empty()) return;
|
||||||
_settings_client.network.connect_to_ip = str;
|
|
||||||
NetworkAddServer(str);
|
_settings_client.network.connect_to_ip = std::move(*str);
|
||||||
NetworkRebuildHostList();
|
NetworkAddServer(_settings_client.network.connect_to_ip);
|
||||||
}
|
NetworkRebuildHostList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnResize() override
|
void OnResize() override
|
||||||
|
@ -1135,14 +1135,14 @@ struct NetworkStartServerWindow : public Window {
|
||||||
this->RaiseWidgetsWhenLowered(WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU);
|
this->RaiseWidgetsWhenLowered(WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
if (this->widget_id == WID_NSS_SETPWD) {
|
if (this->widget_id == WID_NSS_SETPWD) {
|
||||||
_settings_client.network.server_password = str;
|
_settings_client.network.server_password = std::move(*str);
|
||||||
} else {
|
} else {
|
||||||
int32_t value = atoi(str);
|
int32_t value = atoi(str->c_str());
|
||||||
this->SetWidgetDirty(this->widget_id);
|
this->SetWidgetDirty(this->widget_id);
|
||||||
switch (this->widget_id) {
|
switch (this->widget_id) {
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
@ -1868,9 +1868,9 @@ public:
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
switch (this->query_widget) {
|
switch (this->query_widget) {
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
@ -1878,13 +1878,13 @@ public:
|
||||||
case WID_CL_SERVER_NAME_EDIT: {
|
case WID_CL_SERVER_NAME_EDIT: {
|
||||||
if (!_network_server) break;
|
if (!_network_server) break;
|
||||||
|
|
||||||
SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), str);
|
SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), *str);
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_CL_CLIENT_NAME_EDIT: {
|
case WID_CL_CLIENT_NAME_EDIT: {
|
||||||
SetSettingValue(GetSettingFromName("network.client_name")->AsStringSetting(), str);
|
SetSettingValue(GetSettingFromName("network.client_name")->AsStringSetting(), *str);
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2169,14 +2169,14 @@ struct NetworkJoinStatusWindow : Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (StrEmpty(str) || this->request == nullptr) {
|
if (!str.has_value() || str->empty() || this->request == nullptr) {
|
||||||
NetworkDisconnect();
|
NetworkDisconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->request->Reply(str);
|
this->request->Reply(*str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -595,11 +595,11 @@ struct NewGRFInspectWindow : Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (StrEmpty(str)) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
|
|
||||||
NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = std::strtol(str, nullptr, 16);
|
NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = std::strtol(str->c_str(), nullptr, 16);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1074,11 +1074,11 @@ struct SpriteAlignerWindow : Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (StrEmpty(str)) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
|
|
||||||
this->current_sprite = atoi(str);
|
this->current_sprite = atoi(str->c_str());
|
||||||
if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0;
|
if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0;
|
||||||
while (GetSpriteType(this->current_sprite) != SpriteType::Normal) {
|
while (GetSpriteType(this->current_sprite) != SpriteType::Normal) {
|
||||||
this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
|
this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID();
|
||||||
|
|
|
@ -443,10 +443,10 @@ struct NewGRFParametersWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (StrEmpty(str)) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
int32_t value = atoi(str);
|
int32_t value = atoi(str->c_str());
|
||||||
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
|
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
|
||||||
uint32_t val = Clamp<uint32_t>(value, par_info.min_value, par_info.max_value);
|
uint32_t val = Clamp<uint32_t>(value, par_info.min_value, par_info.max_value);
|
||||||
par_info.SetValue(this->grf_config, val);
|
par_info.SetValue(this->grf_config, val);
|
||||||
|
@ -1195,11 +1195,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
this->InvalidateData(GOID_NEWGRF_CHANGES_MADE);
|
this->InvalidateData(GOID_NEWGRF_CHANGES_MADE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
SaveGRFPresetToConfig(str, this->actives);
|
SaveGRFPresetToConfig(str->c_str(), this->actives);
|
||||||
this->grf_presets = GetGRFPresetList();
|
this->grf_presets = GetGRFPresetList();
|
||||||
|
|
||||||
/* Switch to this preset */
|
/* Switch to this preset */
|
||||||
|
|
|
@ -1375,27 +1375,27 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (!StrEmpty(str)) {
|
if (!str.has_value() || str->empty()) return;
|
||||||
VehicleOrderID sel = this->OrderGetSel();
|
|
||||||
uint value = atoi(str);
|
|
||||||
|
|
||||||
switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
|
VehicleOrderID sel = this->OrderGetSel();
|
||||||
case OCV_MAX_SPEED:
|
uint value = atoi(str->c_str());
|
||||||
value = ConvertDisplaySpeedToSpeed(value, this->vehicle->type);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OCV_RELIABILITY:
|
switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
|
||||||
case OCV_LOAD_PERCENTAGE:
|
case OCV_MAX_SPEED:
|
||||||
value = Clamp(value, 0, 100);
|
value = ConvertDisplaySpeedToSpeed(value, this->vehicle->type);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case OCV_RELIABILITY:
|
||||||
break;
|
case OCV_LOAD_PERCENTAGE:
|
||||||
}
|
value = Clamp(value, 0, 100);
|
||||||
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel, MOF_COND_VALUE, Clamp(value, 0, 2047));
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel, MOF_COND_VALUE, Clamp(value, 0, 2047));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDropdownSelect(WidgetID widget, int index) override
|
void OnDropdownSelect(WidgetID widget, int index) override
|
||||||
|
|
|
@ -515,10 +515,10 @@ struct ScriptSettingsWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (StrEmpty(str)) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
int32_t value = atoi(str);
|
int32_t value = atoi(str->c_str());
|
||||||
|
|
||||||
SetValue(value);
|
SetValue(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2726,17 +2726,17 @@ struct GameSettingsWindow : Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
/* The user pressed cancel */
|
/* The user pressed cancel */
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
assert(this->valuewindow_entry != nullptr);
|
assert(this->valuewindow_entry != nullptr);
|
||||||
const IntSettingDesc *sd = this->valuewindow_entry->setting;
|
const IntSettingDesc *sd = this->valuewindow_entry->setting;
|
||||||
|
|
||||||
int32_t value;
|
int32_t value;
|
||||||
if (!StrEmpty(str)) {
|
if (!str->empty()) {
|
||||||
long long llvalue = atoll(str);
|
long long llvalue = atoll(str->c_str());
|
||||||
|
|
||||||
/* Save the correct currency-translated value */
|
/* Save the correct currency-translated value */
|
||||||
if (sd->flags & SF_GUI_CURRENCY) llvalue /= GetCurrency().rate;
|
if (sd->flags & SF_GUI_CURRENCY) llvalue /= GetCurrency().rate;
|
||||||
|
@ -3128,29 +3128,29 @@ struct CustomCurrencyWindow : Window {
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
switch (this->query_widget) {
|
switch (this->query_widget) {
|
||||||
case WID_CC_RATE:
|
case WID_CC_RATE:
|
||||||
GetCustomCurrency().rate = Clamp(atoi(str), 1, UINT16_MAX);
|
GetCustomCurrency().rate = Clamp(atoi(str->c_str()), 1, UINT16_MAX);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_CC_SEPARATOR: // Thousands separator
|
case WID_CC_SEPARATOR: // Thousands separator
|
||||||
GetCustomCurrency().separator = str;
|
GetCustomCurrency().separator = std::move(*str);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_CC_PREFIX:
|
case WID_CC_PREFIX:
|
||||||
GetCustomCurrency().prefix = str;
|
GetCustomCurrency().prefix = std::move(*str);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_CC_SUFFIX:
|
case WID_CC_SUFFIX:
|
||||||
GetCustomCurrency().suffix = str;
|
GetCustomCurrency().suffix = std::move(*str);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_CC_YEAR: { // Year to switch to euro
|
case WID_CC_YEAR: { // Year to switch to euro
|
||||||
TimerGameCalendar::Year val = atoi(str);
|
TimerGameCalendar::Year val = atoi(str->c_str());
|
||||||
|
|
||||||
GetCustomCurrency().to_euro = (val < MIN_EURO_YEAR ? CF_NOEURO : std::min(val, CalendarTime::MAX_YEAR));
|
GetCustomCurrency().to_euro = (val < MIN_EURO_YEAR ? CF_NOEURO : std::min(val, CalendarTime::MAX_YEAR));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -2134,11 +2134,11 @@ struct StationViewWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
Command<CMD_RENAME_STATION>::Post(STR_ERROR_CAN_T_RENAME_STATION, this->window_number, str);
|
Command<CMD_RENAME_STATION>::Post(STR_ERROR_CAN_T_RENAME_STATION, this->window_number, *str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnResize() override
|
void OnResize() override
|
||||||
|
|
|
@ -740,12 +740,12 @@ struct TimetableWindow : Window {
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
const Vehicle *v = this->vehicle;
|
const Vehicle *v = this->vehicle;
|
||||||
uint64_t val = StrEmpty(str) ? 0 : std::strtoul(str, nullptr, 10);
|
uint64_t val = str->empty() ? 0 : std::strtoul(str->c_str(), nullptr, 10);
|
||||||
auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, query_widget == WID_VT_CHANGE_SPEED);
|
auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, query_widget == WID_VT_CHANGE_SPEED);
|
||||||
|
|
||||||
switch (query_widget) {
|
switch (query_widget) {
|
||||||
|
|
|
@ -2458,14 +2458,14 @@ struct ScenarioEditorToolbarWindow : Window {
|
||||||
HandleZoomMessage(this, GetMainWindow()->viewport, WID_TE_ZOOM_IN, WID_TE_ZOOM_OUT);
|
HandleZoomMessage(this, GetMainWindow()->viewport, WID_TE_ZOOM_IN, WID_TE_ZOOM_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
/* Was 'cancel' pressed? */
|
/* Was 'cancel' pressed? */
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
TimerGameCalendar::Year value;
|
TimerGameCalendar::Year value;
|
||||||
if (!StrEmpty(str)) {
|
if (!str->empty()) {
|
||||||
value = atoi(str);
|
value = atoi(str->c_str());
|
||||||
} else {
|
} else {
|
||||||
/* An empty string means revert to the default */
|
/* An empty string means revert to the default */
|
||||||
value = CalendarTime::DEF_START_YEAR.base();
|
value = CalendarTime::DEF_START_YEAR.base();
|
||||||
|
|
|
@ -607,11 +607,11 @@ public:
|
||||||
this->ResizeWindowAsNeeded();
|
this->ResizeWindowAsNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
Command<CMD_RENAME_TOWN>::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, str);
|
Command<CMD_RENAME_TOWN>::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, *str);
|
||||||
}
|
}
|
||||||
|
|
||||||
IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [this](auto) {
|
IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [this](auto) {
|
||||||
|
|
|
@ -3301,11 +3301,11 @@ public:
|
||||||
return Window::OnHotkey(hotkey);
|
return Window::OnHotkey(hotkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
Command<CMD_RENAME_VEHICLE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type, this->window_number, str);
|
Command<CMD_RENAME_VEHICLE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type, this->window_number, *str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
|
void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
|
||||||
|
|
|
@ -176,11 +176,11 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
Command<CMD_RENAME_WAYPOINT>::Post(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME, this->window_number, str);
|
Command<CMD_RENAME_WAYPOINT>::Post(STR_ERROR_CAN_T_CHANGE_WAYPOINT_NAME, this->window_number, *str);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -775,11 +775,11 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The query window opened from this window has closed.
|
* The query window opened from this window has closed.
|
||||||
* @param str the new value of the string, nullptr if the window
|
* @param str the new value of the string, \c std::nullopt if the window
|
||||||
* was cancelled or an empty string when the default
|
* was cancelled or an empty string when the default
|
||||||
* button was pressed, i.e. StrEmpty(str).
|
* button was pressed, i.e. \c str->empty().
|
||||||
*/
|
*/
|
||||||
virtual void OnQueryTextFinished([[maybe_unused]] char *str) {}
|
virtual void OnQueryTextFinished([[maybe_unused]] std::optional<std::string> str) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some data on this window has become invalid.
|
* Some data on this window has become invalid.
|
||||||
|
|
Loading…
Reference in New Issue