Merge branch 'master' into jgrpp

# Conflicts:
#	.github/workflows/ci-build.yml
#	.github/workflows/codeql.yml
#	.github/workflows/commit-checker.yml
#	.github/workflows/release-linux-legacy.yml
#	.github/workflows/release-linux.yml
#	.github/workflows/release-macos.yml
#	.github/workflows/release-windows-store.yml
#	.github/workflows/release-windows.yml
#	.github/workflows/upload-cdn.yml
#	.github/workflows/upload-gog.yml
#	.github/workflows/upload-steam.yml
#	src/console_cmds.cpp
#	src/core/math_func.hpp
#	src/fios.cpp
#	src/fios.h
#	src/intro_gui.cpp
#	src/network/network_server.cpp
#	src/openttd.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/settings_internal.h
#	src/settings_table.cpp
#	src/settings_type.h
#	src/table/settings.h.preamble
#	src/table/settings/company_settings.ini
#	src/table/settings/currency_settings.ini
#	src/table/settings/difficulty_settings.ini
#	src/table/settings/economy_settings.ini
#	src/table/settings/game_settings.ini
#	src/table/settings/gui_settings.ini
#	src/table/settings/linkgraph_settings.ini
#	src/table/settings/locale_settings.ini
#	src/table/settings/misc_settings.ini
#	src/table/settings/multimedia_settings.ini
#	src/table/settings/network_private_settings.ini
#	src/table/settings/network_settings.ini
#	src/table/settings/news_display_settings.ini
#	src/table/settings/old_gameopt_settings.ini
#	src/table/settings/pathfinding_settings.ini
#	src/table/settings/script_settings.ini
#	src/table/settings/win32_settings.ini
#	src/table/settings/window_settings.ini
#	src/table/settings/world_settings.ini
#	src/viewport.cpp
#	src/viewport_func.h
#	src/window.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-15 23:48:36 +00:00
99 changed files with 4793 additions and 2649 deletions

View File

@@ -47,12 +47,12 @@
#include "network/network_gui.h"
#include "network/network_survey.h"
#include "video/video_driver.hpp"
#include "social_integration.h"
#include <vector>
#include <functional>
#include <iterator>
#include <set>
#include <cmath>
#include "safeguards.h"
@@ -181,6 +181,184 @@ static const std::map<int, StringID> _volume_labels = {
{ 127, STR_GAME_OPTIONS_VOLUME_100 },
};
static const NWidgetPart _nested_social_plugins_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_FRAME, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_TITLE), SetDataTip(STR_JUST_STRING2, STR_NULL),
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_PLATFORM, STR_NULL),
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_PLATFORM), SetMinimalSize(100, 12), SetDataTip(STR_JUST_RAW_STRING, STR_NULL), SetAlignment(SA_RIGHT),
EndContainer(),
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE, STR_NULL),
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_STATE), SetMinimalSize(100, 12), SetDataTip(STR_JUST_STRING1, STR_NULL), SetAlignment(SA_RIGHT),
EndContainer(),
EndContainer(),
EndContainer(),
};
static const NWidgetPart _nested_social_plugins_none_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGINS_NONE, STR_NULL),
EndContainer(),
};
class NWidgetSocialPlugins : public NWidgetVertical {
public:
NWidgetSocialPlugins()
{
this->plugins = SocialIntegration::GetPlugins();
if (this->plugins.empty()) {
auto widget = MakeNWidgets(std::begin(_nested_social_plugins_none_widgets), std::end(_nested_social_plugins_none_widgets), nullptr);
this->Add(std::move(widget));
} else {
for (size_t i = 0; i < this->plugins.size(); i++) {
auto widget = MakeNWidgets(std::begin(_nested_social_plugins_widgets), std::end(_nested_social_plugins_widgets), nullptr);
this->Add(std::move(widget));
}
}
this->SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0);
}
void FillWidgetLookup(WidgetLookup &widget_lookup) override
{
widget_lookup[WID_GO_SOCIAL_PLUGINS] = this;
NWidgetVertical::FillWidgetLookup(widget_lookup);
}
void SetupSmallestSize(Window *w) override
{
this->current_index = -1;
NWidgetVertical::SetupSmallestSize(w);
}
/**
* Find of all the plugins the one where the member is the widest (in pixels).
*
* @param member The member to check with.
* @return The plugin that has the widest value (in pixels) for the given member.
*/
template <typename T>
std::string &GetWidestPlugin(T SocialIntegrationPlugin::*member) const
{
std::string *longest = &(this->plugins[0]->*member);
int longest_length = 0;
for (auto *plugin : this->plugins) {
int length = GetStringBoundingBox(plugin->*member).width;
if (length > longest_length) {
longest_length = length;
longest = &(plugin->*member);
}
}
return *longest;
}
void SetStringParameters(int widget) const
{
switch (widget) {
case WID_GO_SOCIAL_PLUGIN_TITLE:
/* For SetupSmallestSize, use the longest string we have. */
if (this->current_index < 0) {
SetDParamStr(0, GetWidestPlugin(&SocialIntegrationPlugin::name));
SetDParamStr(1, GetWidestPlugin(&SocialIntegrationPlugin::version));
break;
}
if (this->plugins[this->current_index]->name.empty()) {
SetDParam(0, STR_JUST_RAW_STRING);
SetDParamStr(1, this->plugins[this->current_index]->basepath);
} else {
SetDParam(0, STR_GAME_OPTIONS_SOCIAL_PLUGIN_TITLE);
SetDParamStr(1, this->plugins[this->current_index]->name);
SetDParamStr(2, this->plugins[this->current_index]->version);
}
break;
case WID_GO_SOCIAL_PLUGIN_PLATFORM:
/* For SetupSmallestSize, use the longest string we have. */
if (this->current_index < 0) {
SetDParamStr(0, GetWidestPlugin(&SocialIntegrationPlugin::social_platform));
break;
}
SetDParamStr(0, this->plugins[this->current_index]->social_platform);
break;
case WID_GO_SOCIAL_PLUGIN_STATE: {
static const std::pair<SocialIntegrationPlugin::State, StringID> state_to_string[] = {
{ SocialIntegrationPlugin::RUNNING, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_RUNNING },
{ SocialIntegrationPlugin::FAILED, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_FAILED },
{ SocialIntegrationPlugin::PLATFORM_NOT_RUNNING, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_PLATFORM_NOT_RUNNING },
{ SocialIntegrationPlugin::UNLOADED, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_UNLOADED },
{ SocialIntegrationPlugin::DUPLICATE, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_DUPLICATE },
{ SocialIntegrationPlugin::UNSUPPORTED_API, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_UNSUPPORTED_API },
{ SocialIntegrationPlugin::INVALID_SIGNATURE, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_INVALID_SIGNATURE },
};
/* For SetupSmallestSize, use the longest string we have. */
if (this->current_index < 0) {
auto longest_plugin = GetWidestPlugin(&SocialIntegrationPlugin::social_platform);
/* Set the longest plugin when looking for the longest status. */
SetDParamStr(0, longest_plugin);
StringID longest = STR_NULL;
int longest_length = 0;
for (auto state : state_to_string) {
int length = GetStringBoundingBox(state.second).width;
if (length > longest_length) {
longest_length = length;
longest = state.second;
}
}
SetDParam(0, longest);
SetDParamStr(1, longest_plugin);
break;
}
auto plugin = this->plugins[this->current_index];
/* Default string, in case no state matches. */
SetDParam(0, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_FAILED);
SetDParamStr(1, plugin->social_platform);
/* Find the string for the state. */
for (auto state : state_to_string) {
if (plugin->state == state.first) {
SetDParam(0, state.second);
break;
}
}
}
break;
}
}
void Draw(const Window *w) override
{
this->current_index = 0;
for (auto &wid : this->children) {
wid->Draw(w);
this->current_index++;
}
}
private:
int current_index = -1;
std::vector<SocialIntegrationPlugin *> plugins;
};
/** Construct nested container widget for managing the list of social plugins. */
std::unique_ptr<NWidgetBase> MakeNWidgetSocialPlugins()
{
return std::make_unique<NWidgetSocialPlugins>();
}
struct GameOptionsWindow : Window {
GameSettings *opt;
bool reload;
@@ -372,6 +550,16 @@ struct GameOptionsWindow : Window {
}
break;
}
case WID_GO_SOCIAL_PLUGIN_TITLE:
case WID_GO_SOCIAL_PLUGIN_PLATFORM:
case WID_GO_SOCIAL_PLUGIN_STATE: {
const NWidgetSocialPlugins *plugin = this->GetWidget<NWidgetSocialPlugins>(WID_GO_SOCIAL_PLUGINS);
assert(plugin != nullptr);
plugin->SetStringParameters(widget);
break;
}
}
}
@@ -414,7 +602,7 @@ struct GameOptionsWindow : Window {
void SetTab(WidgetID widget)
{
this->SetWidgetsLoweredState(false, WID_GO_TAB_GENERAL, WID_GO_TAB_GRAPHICS, WID_GO_TAB_SOUND);
this->SetWidgetsLoweredState(false, WID_GO_TAB_GENERAL, WID_GO_TAB_GRAPHICS, WID_GO_TAB_SOUND, WID_GO_TAB_SOCIAL);
this->LowerWidget(widget);
GameOptionsWindow::active_tab = widget;
@@ -423,6 +611,7 @@ struct GameOptionsWindow : Window {
case WID_GO_TAB_GENERAL: pane = 0; break;
case WID_GO_TAB_GRAPHICS: pane = 1; break;
case WID_GO_TAB_SOUND: pane = 2; break;
case WID_GO_TAB_SOCIAL: pane = 3; break;
default: NOT_REACHED();
}
@@ -517,6 +706,7 @@ struct GameOptionsWindow : Window {
case WID_GO_TAB_GENERAL:
case WID_GO_TAB_GRAPHICS:
case WID_GO_TAB_SOUND:
case WID_GO_TAB_SOCIAL:
this->SetTab(widget);
break;
@@ -879,6 +1069,7 @@ static constexpr NWidgetPart _nested_game_options_widgets[] = {
NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GO_TAB_GENERAL), SetMinimalTextLines(2, 0), SetDataTip(STR_GAME_OPTIONS_TAB_GENERAL, STR_GAME_OPTIONS_TAB_GENERAL_TT), SetFill(1, 0),
NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GO_TAB_GRAPHICS), SetMinimalTextLines(2, 0), SetDataTip(STR_GAME_OPTIONS_TAB_GRAPHICS, STR_GAME_OPTIONS_TAB_GRAPHICS_TT), SetFill(1, 0),
NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GO_TAB_SOUND), SetMinimalTextLines(2, 0), SetDataTip(STR_GAME_OPTIONS_TAB_SOUND, STR_GAME_OPTIONS_TAB_SOUND_TT), SetFill(1, 0),
NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GO_TAB_SOCIAL), SetMinimalTextLines(2, 0), SetDataTip(STR_GAME_OPTIONS_TAB_SOCIAL, STR_GAME_OPTIONS_TAB_SOCIAL_TT), SetFill(1, 0),
EndContainer(),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY),
@@ -1039,6 +1230,11 @@ static constexpr NWidgetPart _nested_game_options_widgets[] = {
EndContainer(),
EndContainer(),
EndContainer(),
/* Social tab */
NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.sparse), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0),
NWidgetFunction(MakeNWidgetSocialPlugins),
EndContainer(),
EndContainer(),
EndContainer(),
};
@@ -1146,9 +1342,6 @@ struct SettingEntry : BaseSettingEntry {
bool UpdateFilterState(SettingFilter &filter, bool force_visible) override;
void SetButtons(byte new_val);
StringID GetHelpText() const;
void SetValueDParams(uint first_param, int32_t value) const;
protected:
SettingEntry(const IntSettingDesc *setting);
@@ -1159,24 +1352,6 @@ private:
bool IsVisibleByRestrictionMode(RestrictionMode mode) const;
};
/**
* Get the help text of a single setting.
* @return The requested help text.
*/
StringID SettingEntry::GetHelpText() const
{
StringID str = this->setting->str_help;
if (this->setting->guiproc != nullptr) {
SettingOnGuiCtrlData data;
data.type = SOGCT_DESCRIPTION_TEXT;
data.text = str;
if (this->setting->guiproc(data)) {
str = data.text;
}
}
return str;
}
/** Cargodist per-cargo setting */
struct CargoDestPerCargoSettingEntry : SettingEntry {
CargoID cargo;
@@ -1414,7 +1589,7 @@ uint SettingEntry::Length() const
*/
uint SettingEntry::GetMaxHelpHeight(int maxw)
{
return GetStringHeight(this->GetHelpText(), maxw);
return GetStringHeight(this->setting->GetHelp(), maxw);
}
/**
@@ -1480,8 +1655,8 @@ bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
filter.string.ResetState();
SetDParam(0, STR_EMPTY);
filter.string.AddLine(sd->str);
filter.string.AddLine(this->GetHelpText());
filter.string.AddLine(sd->GetTitle());
filter.string.AddLine(sd->GetHelp());
visible = filter.string.GetState();
}
@@ -1513,52 +1688,6 @@ static const void *ResolveObject(const GameSettings *settings_ptr, const IntSett
return settings_ptr;
}
/**
* Set the DParams for drawing the value of a setting.
* @param first_param First DParam to use
* @param value Setting value to set params for.
*/
void SettingEntry::SetValueDParams(uint first_param, int32_t value) const
{
const uint initial_first_param = first_param;
if (this->setting->IsBoolSetting()) {
SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
} else if (this->setting->flags & SF_DEC1SCALE) {
double scale = std::exp2(((double)value) / 10);
int log = -std::min(0, (int)std::floor(std::log10(scale)) - 2);
SetDParam(first_param++, STR_JUST_RAW_STRING);
auto tmp_params = MakeParameters(value, (int64_t)(scale * std::pow(10.f, (float)log)), log);
SetDParamStr(first_param++, GetStringWithArgs(this->setting->str_val, tmp_params));
} else {
if ((this->setting->flags & SF_ENUM) != 0) {
StringID str = STR_UNDEFINED;
for (const SettingDescEnumEntry *enumlist = this->setting->enumlist; enumlist != nullptr && enumlist->str != STR_NULL; enumlist++) {
if (enumlist->val == value) {
str = enumlist->str;
break;
}
}
SetDParam(first_param++, str);
} else if ((this->setting->flags & SF_GUI_DROPDOWN) != 0) {
SetDParam(first_param++, this->setting->str_val - this->setting->min + value);
} else if ((this->setting->flags & SF_GUI_NEGATIVE_IS_SPECIAL) != 0) {
SetDParam(first_param++, this->setting->str_val + ((value >= 0) ? 1 : 0));
value = abs(value);
} else {
SetDParam(first_param++, this->setting->str_val + ((value == 0 && (this->setting->flags & SF_GUI_0_IS_SPECIAL) != 0) ? 1 : 0));
}
SetDParam(first_param++, value);
}
if (this->setting->guiproc != nullptr) {
SettingOnGuiCtrlData data;
data.type = SOGCT_VALUE_DPARAMS;
data.offset = initial_first_param;
data.val = value;
this->setting->guiproc(data);
}
}
/**
* Function to draw setting value (button + text + current value)
* @param settings_ptr Pointer to current values of all settings
@@ -1599,8 +1728,9 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
void SettingEntry::DrawSettingString(uint left, uint right, int y, bool highlight, int32_t value) const
{
this->SetValueDParams(1, value);
int edge = DrawString(left, right, y, this->setting->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
const IntSettingDesc *sd = this->setting;
sd->SetValueDParams(1, value);
int edge = DrawString(left, right, y, sd->GetTitle(), highlight ? TC_WHITE : TC_LIGHT_BLUE);
if (this->setting->guiproc != nullptr && edge != 0) {
SettingOnGuiCtrlData data;
@@ -1632,7 +1762,7 @@ void CargoDestPerCargoSettingEntry::DrawSettingString(uint left, uint right, int
assert(this->setting->str == STR_CONFIG_SETTING_DISTRIBUTION_PER_CARGO);
SetDParam(0, CargoSpec::Get(this->cargo)->name);
SetDParam(1, STR_CONFIG_SETTING_VALUE);
this->SetValueDParams(2, value);
this->setting->SetValueDParams(2, value);
DrawString(left, right, y, STR_CONFIG_SETTING_DISTRIBUTION_PER_CARGO_PARAM, highlight ? TC_WHITE : TC_LIGHT_BLUE);
}
@@ -2824,7 +2954,7 @@ struct GameSettingsWindow : Window {
DrawString(tr, STR_CONFIG_SETTING_TYPE);
tr.top += GetCharacterHeight(FS_NORMAL);
this->last_clicked->SetValueDParams(0, sd->def);
sd->SetValueDParams(0, sd->def);
DrawString(tr, STR_CONFIG_SETTING_DEFAULT_VALUE);
tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
@@ -2854,7 +2984,7 @@ struct GameSettingsWindow : Window {
}
}
DrawStringMultiLine(tr, this->last_clicked->GetHelpText(), TC_WHITE);
DrawStringMultiLine(tr, sd->GetHelp(), TC_WHITE);
}
break;
@@ -2992,7 +3122,8 @@ struct GameSettingsWindow : Window {
}
}
assert_msg(val >= sd->min && val <= (int)sd->max, "min: %d, max: %d, val: %d", sd->min, sd->max, val);
list.push_back(std::make_unique<DropDownListStringItem>(sd->str_val + val - sd->min, val, false));
sd->SetValueDParams(0, val);
list.push_back(std::make_unique<DropDownListStringItem>(STR_JUST_STRING2, val, false));
}
} else if ((sd->flags & SF_ENUM)) {
for (const SettingDescEnumEntry *enumlist = sd->enumlist; enumlist != nullptr && enumlist->str != STR_NULL; enumlist++) {
@@ -3064,7 +3195,7 @@ struct GameSettingsWindow : Window {
if (sd->flags & SF_GUI_VELOCITY) value64 = ConvertKmhishSpeedToDisplaySpeed((uint)value64, VEH_TRAIN);
this->valuewindow_entry = pe;
if (sd->flags & SF_DECIMAL1 || (sd->flags & SF_GUI_VELOCITY && _settings_game.locale.units_velocity == 3)) {
if (sd->flags & SF_GUI_VELOCITY && _settings_game.locale.units_velocity == 3) {
CharSetFilter charset_filter = CS_NUMERAL_DECIMAL; //default, only numeric input and decimal point allowed
if (sd->min < 0) charset_filter = CS_NUMERAL_DECIMAL_SIGNED; // special case, also allow '-' sign for negative input
@@ -3103,7 +3234,7 @@ struct GameSettingsWindow : Window {
int32_t value;
if (!StrEmpty(str)) {
long long llvalue;
if (sd->flags & SF_DECIMAL1 || (sd->flags & SF_GUI_VELOCITY && _settings_game.locale.units_velocity == 3)) {
if (sd->flags & SF_GUI_VELOCITY && _settings_game.locale.units_velocity == 3) {
llvalue = atof(str) * 10;
} else {
llvalue = atoll(str);