Merge branch 'master' into jgrpp
# Conflicts: # cmake/CompileFlags.cmake # src/cargomonitor.cpp # src/core/CMakeLists.txt # src/economy.cpp # src/landscape.cpp # src/linkgraph/flowmapper.cpp # src/linkgraph/linkgraph_gui.cpp # src/linkgraph/linkgraphschedule.cpp # src/misc_gui.cpp # src/newgrf_generic.cpp # src/newgrf_storage.cpp # src/rail_gui.cpp # src/saveload/afterload.cpp # src/saveload/station_sl.cpp # src/script/script_gui.cpp # src/station_cmd.cpp # src/station_gui.cpp # src/string_func.h # src/terraform_cmd.cpp
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
#ifndef GAME_HPP
|
||||
#define GAME_HPP
|
||||
|
||||
#include "../core/string_compare_type.hpp"
|
||||
#include "game_scanner.hpp"
|
||||
|
||||
#include "../script/api/script_event_types.hpp"
|
||||
|
||||
@@ -199,7 +199,7 @@ struct GSConfigWindow : public Window {
|
||||
StringID str;
|
||||
TextColour colour;
|
||||
uint idx = 0;
|
||||
if (StrEmpty(config_item.description)) {
|
||||
if (config_item.description.empty()) {
|
||||
str = STR_JUST_STRING;
|
||||
colour = TC_ORANGE;
|
||||
} else {
|
||||
@@ -217,9 +217,10 @@ struct GSConfigWindow : public Window {
|
||||
} else {
|
||||
DrawArrowButtons(br.left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
||||
}
|
||||
if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) {
|
||||
auto config_iterator = config_item.labels.find(current_value);
|
||||
if (config_iterator != config_item.labels.end()) {
|
||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
||||
SetDParamStr(idx++, config_item.labels->Find(current_value)->second);
|
||||
SetDParamStr(idx++, config_iterator->second);
|
||||
} else {
|
||||
SetDParam(idx++, STR_JUST_INT);
|
||||
SetDParam(idx++, current_value);
|
||||
@@ -276,9 +277,7 @@ struct GSConfigWindow : public Window {
|
||||
int num = (pt.y - r.top) / this->line_height + this->vscroll->GetPosition();
|
||||
if (num >= (int)this->visible_settings.size()) break;
|
||||
|
||||
VisibleSettingsList::const_iterator it = this->visible_settings.begin();
|
||||
for (int i = 0; i < num; i++) it++;
|
||||
const ScriptConfigItem config_item = **it;
|
||||
const ScriptConfigItem &config_item = *this->visible_settings[num];
|
||||
if (!this->IsEditableItem(config_item)) return;
|
||||
|
||||
if (this->clicked_row != num) {
|
||||
@@ -317,7 +316,7 @@ struct GSConfigWindow : public Window {
|
||||
|
||||
DropDownList list;
|
||||
for (int i = config_item.min_value; i <= config_item.max_value; i++) {
|
||||
list.emplace_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false));
|
||||
list.emplace_back(new DropDownListCharStringItem(config_item.labels.find(i)->second, i, false));
|
||||
}
|
||||
|
||||
ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE);
|
||||
@@ -432,9 +431,7 @@ private:
|
||||
|
||||
void SetValue(int value)
|
||||
{
|
||||
VisibleSettingsList::const_iterator it = this->visible_settings.begin();
|
||||
for (int i = 0; i < this->clicked_row; i++) it++;
|
||||
const ScriptConfigItem config_item = **it;
|
||||
const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
|
||||
if (_game_mode == GM_NORMAL && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
|
||||
this->gs_config->SetSetting(config_item.name, value);
|
||||
this->SetDirty();
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "game_info.hpp"
|
||||
#include "game_scanner.hpp"
|
||||
|
||||
#include "../3rdparty/fmt/format.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
|
||||
@@ -21,9 +23,9 @@ void GameScannerInfo::Initialize()
|
||||
ScriptScanner::Initialize("GSScanner");
|
||||
}
|
||||
|
||||
void GameScannerInfo::GetScriptName(ScriptInfo *info, char *name, const char *last)
|
||||
std::string GameScannerInfo::GetScriptName(ScriptInfo *info)
|
||||
{
|
||||
seprintf(name, last, "%s", info->GetName());
|
||||
return info->GetName();
|
||||
}
|
||||
|
||||
void GameScannerInfo::RegisterAPI(class Squirrel *engine)
|
||||
@@ -31,39 +33,35 @@ void GameScannerInfo::RegisterAPI(class Squirrel *engine)
|
||||
GameInfo::RegisterAPI(engine);
|
||||
}
|
||||
|
||||
GameInfo *GameScannerInfo::FindInfo(const char *nameParam, int versionParam, bool force_exact_match)
|
||||
GameInfo *GameScannerInfo::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
{
|
||||
if (this->info_list.size() == 0) return nullptr;
|
||||
if (nameParam == nullptr) return nullptr;
|
||||
if (name == nullptr) return nullptr;
|
||||
|
||||
char game_name[1024];
|
||||
strecpy(game_name, nameParam, lastof(game_name));
|
||||
strtolower(game_name);
|
||||
|
||||
if (versionParam == -1) {
|
||||
if (version == -1) {
|
||||
/* We want to load the latest version of this Game script; so find it */
|
||||
if (this->info_single_list.find(game_name) != this->info_single_list.end()) return static_cast<GameInfo *>(this->info_single_list[game_name]);
|
||||
auto it = this->info_single_list.find(name);
|
||||
if (it != this->info_single_list.end()) return static_cast<GameInfo *>(it->second);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (force_exact_match) {
|
||||
/* Try to find a direct 'name.version' match */
|
||||
char game_name_tmp[1024];
|
||||
seprintf(game_name_tmp, lastof(game_name_tmp), "%s.%d", game_name, versionParam);
|
||||
strtolower(game_name_tmp);
|
||||
if (this->info_list.find(game_name_tmp) != this->info_list.end()) return static_cast<GameInfo *>(this->info_list[game_name_tmp]);
|
||||
std::string name_with_version = fmt::format("{}.{}", name, version);
|
||||
auto it = this->info_list.find(name_with_version);
|
||||
if (it != this->info_list.end()) return static_cast<GameInfo *>(it->second);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GameInfo *info = nullptr;
|
||||
int version = -1;
|
||||
int highest_version = -1;
|
||||
|
||||
/* See if there is a compatible Game script which goes by that name, with the highest
|
||||
* version which allows loading the requested version */
|
||||
for (const auto &item : this->info_list) {
|
||||
GameInfo *i = static_cast<GameInfo *>(item.second);
|
||||
if (StrEqualsIgnoreCase(game_name, i->GetName()) && i->CanLoadFromVersion(versionParam) && (version == -1 || i->GetVersion() > version)) {
|
||||
version = item.second->GetVersion();
|
||||
if (StrEqualsIgnoreCase(name, i->GetName()) && i->CanLoadFromVersion(version) && (highest_version == -1 || i->GetVersion() > highest_version)) {
|
||||
highest_version = item.second->GetVersion();
|
||||
info = i;
|
||||
}
|
||||
}
|
||||
@@ -77,10 +75,10 @@ void GameScannerLibrary::Initialize()
|
||||
ScriptScanner::Initialize("GSScanner");
|
||||
}
|
||||
|
||||
void GameScannerLibrary::GetScriptName(ScriptInfo *info, char *name, const char *last)
|
||||
std::string GameScannerLibrary::GetScriptName(ScriptInfo *info)
|
||||
{
|
||||
GameLibrary *library = static_cast<GameLibrary *>(info);
|
||||
seprintf(name, last, "%s.%s", library->GetCategory(), library->GetInstanceName());
|
||||
return fmt::format("{}.{}", library->GetCategory(), library->GetInstanceName());
|
||||
}
|
||||
|
||||
void GameScannerLibrary::RegisterAPI(class Squirrel *engine)
|
||||
@@ -91,9 +89,7 @@ void GameScannerLibrary::RegisterAPI(class Squirrel *engine)
|
||||
GameLibrary *GameScannerLibrary::FindLibrary(const char *library, int version)
|
||||
{
|
||||
/* Internally we store libraries as 'library.version' */
|
||||
char library_name[1024];
|
||||
seprintf(library_name, lastof(library_name), "%s.%d", library, version);
|
||||
strtolower(library_name);
|
||||
std::string library_name = fmt::format("{}.{}", library, version);
|
||||
|
||||
/* Check if the library + version exists */
|
||||
ScriptInfoList::iterator it = this->info_list.find(library_name);
|
||||
|
||||
@@ -18,15 +18,15 @@ public:
|
||||
|
||||
/**
|
||||
* Check if we have a game by name and version available in our list.
|
||||
* @param nameParam The name of the game script.
|
||||
* @param versionParam The version of the game script, or -1 if you want the latest.
|
||||
* @param name The name of the game script.
|
||||
* @param version The version of the game script, or -1 if you want the latest.
|
||||
* @param force_exact_match Only match name+version, never latest.
|
||||
* @return nullptr if no match found, otherwise the game script that matched.
|
||||
*/
|
||||
class GameInfo *FindInfo(const char *nameParam, int versionParam, bool force_exact_match);
|
||||
class GameInfo *FindInfo(const char *name, int version, bool force_exact_match);
|
||||
|
||||
protected:
|
||||
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
const char *GetFileName() const override { return PATHSEP "info.nut"; }
|
||||
Subdirectory GetDirectory() const override { return GAME_DIR; }
|
||||
const char *GetScannerName() const override { return "Game Scripts"; }
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
class GameLibrary *FindLibrary(const char *library, int version);
|
||||
|
||||
protected:
|
||||
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
const char *GetFileName() const override { return PATHSEP "library.nut"; }
|
||||
Subdirectory GetDirectory() const override { return GAME_LIBRARY_DIR; }
|
||||
const char *GetScannerName() const override { return "GS Libraries"; }
|
||||
|
||||
@@ -385,7 +385,7 @@ void RegisterGameTranslation(Squirrel *engine)
|
||||
|
||||
int idx = 0;
|
||||
for (const auto &p : _current_data->string_names) {
|
||||
sq_pushstring(vm, p.c_str(), -1);
|
||||
sq_pushstring(vm, p, -1);
|
||||
sq_pushinteger(vm, idx);
|
||||
sq_rawset(vm, -3);
|
||||
idx++;
|
||||
|
||||
Reference in New Issue
Block a user