mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
12 Commits
77fae3469b
...
435281a757
Author | SHA1 | Date |
---|---|---|
|
435281a757 | |
|
9ce2aca949 | |
|
55098a2f2e | |
|
7ff0c67f77 | |
|
b2de1ff66f | |
|
fc924161ab | |
|
61a299bc99 | |
|
7b68c184fb | |
|
2f4c5e6737 | |
|
016970154d | |
|
a92619be89 | |
|
679f95d1de |
|
@ -103,14 +103,14 @@ void SpriteFontCache::ClearFontCache()
|
|||
|
||||
const Sprite *SpriteFontCache::GetGlyph(GlyphID key)
|
||||
{
|
||||
SpriteID sprite = this->GetUnicodeGlyph(static_cast<char32_t>(key & ~SPRITE_GLYPH));
|
||||
SpriteID sprite = static_cast<SpriteID>(key & ~SPRITE_GLYPH);
|
||||
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
|
||||
return GetSprite(sprite, SpriteType::Font);
|
||||
}
|
||||
|
||||
uint SpriteFontCache::GetGlyphWidth(GlyphID key)
|
||||
{
|
||||
SpriteID sprite = this->GetUnicodeGlyph(static_cast<char32_t>(key & ~SPRITE_GLYPH));
|
||||
SpriteID sprite = static_cast<SpriteID>(key & ~SPRITE_GLYPH);
|
||||
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
|
||||
return SpriteExists(sprite) ? GetSprite(sprite, SpriteType::Font)->width + ScaleFontTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ GlyphID SpriteFontCache::MapCharToGlyph(char32_t key, [[maybe_unused]] bool allo
|
|||
assert(IsPrintable(key));
|
||||
SpriteID sprite = this->GetUnicodeGlyph(key);
|
||||
if (sprite == 0) return 0;
|
||||
return SPRITE_GLYPH | key;
|
||||
return SPRITE_GLYPH | sprite;
|
||||
}
|
||||
|
||||
bool SpriteFontCache::GetDrawGlyphShadow()
|
||||
|
|
108
src/hotkeys.cpp
108
src/hotkeys.cpp
|
@ -27,8 +27,16 @@ static std::vector<HotkeyList*> *_hotkey_lists = nullptr;
|
|||
|
||||
/** String representation of a keycode */
|
||||
struct KeycodeNames {
|
||||
const std::string_view name; ///< Name of the keycode
|
||||
std::string_view name; ///< Name of the keycode
|
||||
WindowKeyCodes keycode; ///< The keycode
|
||||
std::string_view short_name;
|
||||
|
||||
KeycodeNames(const std::string_view name, const WindowKeyCodes keycode, const std::string_view short_name = "")
|
||||
{
|
||||
this->name = name;
|
||||
this->keycode = keycode;
|
||||
this->short_name = short_name.empty() ? name : short_name;
|
||||
}
|
||||
};
|
||||
|
||||
/** Array of non-standard keycodes that can be used in the hotkeys config file. */
|
||||
|
@ -38,16 +46,17 @@ static const std::initializer_list<KeycodeNames> _keycode_to_name = {
|
|||
{"ALT", WKC_ALT},
|
||||
{"META", WKC_META},
|
||||
{"GLOBAL", WKC_GLOBAL_HOTKEY},
|
||||
{"ESC", WKC_ESC},
|
||||
{"BACKSPACE", WKC_BACKSPACE},
|
||||
{"INS", WKC_INSERT},
|
||||
{"DEL", WKC_DELETE},
|
||||
{"PAGEUP", WKC_PAGEUP},
|
||||
{"PAGEDOWN", WKC_PAGEDOWN},
|
||||
{"END", WKC_END},
|
||||
{"HOME", WKC_HOME},
|
||||
{"RETURN", WKC_RETURN},
|
||||
{"SPACE", WKC_SPACE},
|
||||
{"ESC", WKC_ESC, "Esc"},
|
||||
{"TAB", WKC_TAB, "Tab"},
|
||||
{"BACKSPACE", WKC_BACKSPACE, "BS"},
|
||||
{"INS", WKC_INSERT, "Ins"},
|
||||
{"DEL", WKC_DELETE, "Del"},
|
||||
{"PAGEUP", WKC_PAGEUP, "Page up"},
|
||||
{"PAGEDOWN", WKC_PAGEDOWN, "Page down"},
|
||||
{"END", WKC_END, "End"},
|
||||
{"HOME", WKC_HOME, "Home"},
|
||||
{"RETURN", WKC_RETURN, "Enter"},
|
||||
{"SPACE", WKC_SPACE, "Space"},
|
||||
{"F1", WKC_F1},
|
||||
{"F2", WKC_F2},
|
||||
{"F3", WKC_F3},
|
||||
|
@ -61,31 +70,31 @@ static const std::initializer_list<KeycodeNames> _keycode_to_name = {
|
|||
{"F11", WKC_F11},
|
||||
{"F12", WKC_F12},
|
||||
{"BACKQUOTE", WKC_BACKQUOTE},
|
||||
{"PAUSE", WKC_PAUSE},
|
||||
{"NUM_DIV", WKC_NUM_DIV},
|
||||
{"NUM_MUL", WKC_NUM_MUL},
|
||||
{"NUM_MINUS", WKC_NUM_MINUS},
|
||||
{"NUM_PLUS", WKC_NUM_PLUS},
|
||||
{"NUM_ENTER", WKC_NUM_ENTER},
|
||||
{"NUM_DOT", WKC_NUM_DECIMAL},
|
||||
{"SLASH", WKC_SLASH},
|
||||
{"PAUSE", WKC_PAUSE, "Pause"},
|
||||
{"NUM_DIV", WKC_NUM_DIV, "Num /"},
|
||||
{"NUM_MUL", WKC_NUM_MUL, "Num *"},
|
||||
{"NUM_MINUS", WKC_NUM_MINUS, "Num -"},
|
||||
{"NUM_PLUS", WKC_NUM_PLUS, "Num +"},
|
||||
{"NUM_ENTER", WKC_NUM_ENTER, "Num Enter"},
|
||||
{"NUM_DOT", WKC_NUM_DECIMAL, "Num ."},
|
||||
{"SLASH", WKC_SLASH, "/"},
|
||||
{"/", WKC_SLASH}, /* deprecated, use SLASH */
|
||||
{"SEMICOLON", WKC_SEMICOLON},
|
||||
{"SEMICOLON", WKC_SEMICOLON, ";"},
|
||||
{";", WKC_SEMICOLON}, /* deprecated, use SEMICOLON */
|
||||
{"EQUALS", WKC_EQUALS},
|
||||
{"EQUALS", WKC_EQUALS, "="},
|
||||
{"=", WKC_EQUALS}, /* deprecated, use EQUALS */
|
||||
{"L_BRACKET", WKC_L_BRACKET},
|
||||
{"L_BRACKET", WKC_L_BRACKET, "["},
|
||||
{"[", WKC_L_BRACKET}, /* deprecated, use L_BRACKET */
|
||||
{"BACKSLASH", WKC_BACKSLASH},
|
||||
{"BACKSLASH", WKC_BACKSLASH, "\\"},
|
||||
{"\\", WKC_BACKSLASH}, /* deprecated, use BACKSLASH */
|
||||
{"R_BRACKET", WKC_R_BRACKET},
|
||||
{"R_BRACKET", WKC_R_BRACKET, "]"},
|
||||
{"]", WKC_R_BRACKET}, /* deprecated, use R_BRACKET */
|
||||
{"SINGLEQUOTE", WKC_SINGLEQUOTE},
|
||||
{"SINGLEQUOTE", WKC_SINGLEQUOTE, "'"},
|
||||
{"'", WKC_SINGLEQUOTE}, /* deprecated, use SINGLEQUOTE */
|
||||
{"COMMA", WKC_COMMA},
|
||||
{"PERIOD", WKC_PERIOD},
|
||||
{"COMMA", WKC_COMMA, ","},
|
||||
{"PERIOD", WKC_PERIOD, "."},
|
||||
{".", WKC_PERIOD}, /* deprecated, use PERIOD */
|
||||
{"MINUS", WKC_MINUS},
|
||||
{"MINUS", WKC_MINUS, "-"},
|
||||
{"-", WKC_MINUS}, /* deprecated, use MINUS */
|
||||
};
|
||||
|
||||
|
@ -196,6 +205,40 @@ static std::string KeycodeToString(uint16_t keycode)
|
|||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* A short representation of the keycode, for printing as a hotkey hint.
|
||||
* @param keycode The keycode to convert to a string.
|
||||
* @return A string representation of this keycode.
|
||||
*/
|
||||
std::string KeycodeToShortString(uint16_t keycode)
|
||||
{
|
||||
std::string str;
|
||||
if (keycode & WKC_SHIFT) {
|
||||
// TODO
|
||||
str += "»";
|
||||
}
|
||||
if (keycode & WKC_CTRL) {
|
||||
str += "^";
|
||||
}
|
||||
if (keycode & WKC_ALT) {
|
||||
str += "A+";
|
||||
}
|
||||
if (keycode & WKC_META) {
|
||||
str += "M+";
|
||||
}
|
||||
keycode = keycode & ~WKC_SPECIAL_KEYS;
|
||||
|
||||
for (const auto &kn : _keycode_to_name) {
|
||||
if (kn.keycode == keycode) {
|
||||
str += kn.short_name;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
assert(keycode < 128);
|
||||
str.push_back(keycode);
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all keycodes attached to a hotkey to a single string. If multiple
|
||||
* keycodes are attached to the hotkey they are split by a comma.
|
||||
|
@ -350,3 +393,12 @@ void HandleGlobalHotkeys([[maybe_unused]] char32_t key, uint16_t keycode)
|
|||
}
|
||||
}
|
||||
|
||||
const Hotkey* HotkeyList::GetHotkeyByNum(int num) const
|
||||
{
|
||||
for (const Hotkey &hotkey : this->items) {
|
||||
if (hotkey.num == num) {
|
||||
return &hotkey;
|
||||
}
|
||||
}
|
||||
return (const Hotkey*) nullptr;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ struct HotkeyList {
|
|||
void Save(IniFile &ini) const;
|
||||
|
||||
int CheckMatch(uint16_t keycode, bool global_only = false) const;
|
||||
const Hotkey* GetHotkeyByNum(int num) const;
|
||||
|
||||
GlobalHotkeyHandlerFunc global_hotkey_handler;
|
||||
private:
|
||||
|
@ -64,5 +65,6 @@ void SaveHotkeysToConfig();
|
|||
|
||||
|
||||
void HandleGlobalHotkeys(char32_t key, uint16_t keycode);
|
||||
std::string KeycodeToShortString(uint16_t keycode);
|
||||
|
||||
#endif /* HOTKEYS_H */
|
||||
|
|
|
@ -105,8 +105,8 @@ static ChangeInfoResult RoadStopChangeInfo(uint first, uint last, int prop, Byte
|
|||
AddStringForMapping(GRFStringID{buf.ReadWord()}, [rs = rs.get()](StringID str) { RoadStopClass::Get(rs->class_index)->name = str; });
|
||||
break;
|
||||
|
||||
case 0x0C: // The draw mode
|
||||
rs->draw_mode = static_cast<RoadStopDrawMode>(buf.ReadByte());
|
||||
case 0x0C: // The draw modes
|
||||
rs->draw_mode = static_cast<RoadStopDrawModes>(buf.ReadByte());
|
||||
break;
|
||||
|
||||
case 0x0D: // Cargo types for random triggers
|
||||
|
|
|
@ -298,7 +298,7 @@ void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec,
|
|||
|
||||
RoadStopDrawModes draw_mode;
|
||||
if (spec->flags.Test(RoadStopSpecFlag::DrawModeRegister)) {
|
||||
draw_mode = static_cast<RoadStopDrawMode>(object.GetRegister(0x100));
|
||||
draw_mode = static_cast<RoadStopDrawModes>(object.GetRegister(0x100));
|
||||
} else {
|
||||
draw_mode = spec->draw_mode;
|
||||
}
|
||||
|
|
|
@ -469,14 +469,14 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
|
||||
/** Hotkeys for order window. */
|
||||
enum OrderHotKeys : int32_t {
|
||||
OHK_SKIP,
|
||||
OHK_DELETE,
|
||||
OHK_GOTO,
|
||||
OHK_NONSTOP,
|
||||
OHK_FULLLOAD,
|
||||
OHK_UNLOAD,
|
||||
OHK_NEAREST_DEPOT,
|
||||
OHK_ALWAYS_SERVICE,
|
||||
OHK_SKIP = WID_O_SKIP,
|
||||
OHK_DELETE = WID_O_DELETE,
|
||||
OHK_GOTO = WID_O_GOTO,
|
||||
OHK_NONSTOP = WID_O_NON_STOP,
|
||||
OHK_FULLLOAD = WID_O_FULL_LOAD,
|
||||
OHK_UNLOAD = WID_O_UNLOAD,
|
||||
OHK_ALWAYS_SERVICE = WID_O_DEPOT_ACTION,
|
||||
OHK_NEAREST_DEPOT = WID_O_END,
|
||||
OHK_TRANSFER,
|
||||
OHK_NO_UNLOAD,
|
||||
OHK_NO_LOAD,
|
||||
|
|
|
@ -76,7 +76,7 @@ ScriptController::ScriptController(::CompanyID company) :
|
|||
|
||||
/* static */ uint ScriptController::GetTick()
|
||||
{
|
||||
return ScriptObject::GetActiveInstance().GetController()->ticks;
|
||||
return ScriptObject::GetActiveInstance().GetController().ticks;
|
||||
}
|
||||
|
||||
/* static */ int ScriptController::GetOpsTillSuspend()
|
||||
|
@ -96,9 +96,9 @@ ScriptController::ScriptController(::CompanyID company) :
|
|||
|
||||
/* static */ HSQOBJECT ScriptController::Import(const std::string &library, const std::string &class_name, int version)
|
||||
{
|
||||
ScriptController *controller = ScriptObject::GetActiveInstance().GetController();
|
||||
Squirrel *engine = ScriptObject::GetActiveInstance().engine;
|
||||
HSQUIRRELVM vm = engine->GetVM();
|
||||
ScriptController &controller = ScriptObject::GetActiveInstance().GetController();
|
||||
Squirrel &engine = *ScriptObject::GetActiveInstance().engine;
|
||||
HSQUIRRELVM vm = engine.GetVM();
|
||||
|
||||
ScriptInfo *lib = ScriptObject::GetActiveInstance().FindLibrary(library, version);
|
||||
if (lib == nullptr) {
|
||||
|
@ -114,11 +114,11 @@ ScriptController::ScriptController(::CompanyID company) :
|
|||
|
||||
std::string fake_class;
|
||||
|
||||
LoadedLibraryList::iterator it = controller->loaded_library.find(library_name);
|
||||
if (it != controller->loaded_library.end()) {
|
||||
LoadedLibraryList::iterator it = controller.loaded_library.find(library_name);
|
||||
if (it != controller.loaded_library.end()) {
|
||||
fake_class = (*it).second;
|
||||
} else {
|
||||
int next_number = ++controller->loaded_library_count;
|
||||
int next_number = ++controller.loaded_library_count;
|
||||
|
||||
/* Create a new fake internal name */
|
||||
fake_class = fmt::format("_internalNA{}", next_number);
|
||||
|
@ -128,14 +128,14 @@ ScriptController::ScriptController(::CompanyID company) :
|
|||
sq_pushstring(vm, fake_class);
|
||||
sq_newclass(vm, SQFalse);
|
||||
/* Load the library */
|
||||
if (!engine->LoadScript(vm, lib->GetMainScript(), false)) {
|
||||
if (!engine.LoadScript(vm, lib->GetMainScript(), false)) {
|
||||
throw sq_throwerror(vm, fmt::format("there was a compile error when importing '{}' version {}", library, version));
|
||||
}
|
||||
/* Create the fake class */
|
||||
sq_newslot(vm, -3, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
|
||||
controller->loaded_library[library_name] = fake_class;
|
||||
controller.loaded_library[library_name] = fake_class;
|
||||
}
|
||||
|
||||
/* Find the real class inside the fake class (like 'sets.Vector') */
|
||||
|
|
|
@ -45,7 +45,7 @@ void SimpleCountedObject::Release()
|
|||
* Get the storage associated with the current ScriptInstance.
|
||||
* @return The storage.
|
||||
*/
|
||||
static ScriptStorage *GetStorage()
|
||||
static ScriptStorage &GetStorage()
|
||||
{
|
||||
return ScriptObject::GetActiveInstance().GetStorage();
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
|||
}
|
||||
|
||||
ScriptObject::DisableDoCommandScope::DisableDoCommandScope()
|
||||
: AutoRestoreBackup(GetStorage()->allow_do_command, false)
|
||||
: AutoRestoreBackup(GetStorage().allow_do_command, false)
|
||||
{}
|
||||
|
||||
/* static */ ScriptInstance &ScriptObject::GetActiveInstance()
|
||||
|
@ -78,181 +78,181 @@ ScriptObject::DisableDoCommandScope::DisableDoCommandScope()
|
|||
/* static */ void ScriptObject::SetDoCommandDelay(uint ticks)
|
||||
{
|
||||
assert(ticks > 0);
|
||||
GetStorage()->delay = ticks;
|
||||
GetStorage().delay = ticks;
|
||||
}
|
||||
|
||||
/* static */ uint ScriptObject::GetDoCommandDelay()
|
||||
{
|
||||
return GetStorage()->delay;
|
||||
return GetStorage().delay;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetDoCommandMode(ScriptModeProc *proc, ScriptObject *instance)
|
||||
{
|
||||
GetStorage()->mode = proc;
|
||||
GetStorage()->mode_instance = instance;
|
||||
GetStorage().mode = proc;
|
||||
GetStorage().mode_instance = instance;
|
||||
}
|
||||
|
||||
/* static */ ScriptModeProc *ScriptObject::GetDoCommandMode()
|
||||
{
|
||||
return GetStorage()->mode;
|
||||
return GetStorage().mode;
|
||||
}
|
||||
|
||||
/* static */ ScriptObject *ScriptObject::GetDoCommandModeInstance()
|
||||
{
|
||||
return GetStorage()->mode_instance;
|
||||
return GetStorage().mode_instance;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetDoCommandAsyncMode(ScriptAsyncModeProc *proc, ScriptObject *instance)
|
||||
{
|
||||
GetStorage()->async_mode = proc;
|
||||
GetStorage()->async_mode_instance = instance;
|
||||
GetStorage().async_mode = proc;
|
||||
GetStorage().async_mode_instance = instance;
|
||||
}
|
||||
|
||||
/* static */ ScriptAsyncModeProc *ScriptObject::GetDoCommandAsyncMode()
|
||||
{
|
||||
return GetStorage()->async_mode;
|
||||
return GetStorage().async_mode;
|
||||
}
|
||||
|
||||
/* static */ ScriptObject *ScriptObject::GetDoCommandAsyncModeInstance()
|
||||
{
|
||||
return GetStorage()->async_mode_instance;
|
||||
return GetStorage().async_mode_instance;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCommand(const CommandDataBuffer &data, Commands cmd)
|
||||
{
|
||||
ScriptStorage *s = GetStorage();
|
||||
Debug(script, 6, "SetLastCommand company={:02d} cmd={} data={}", s->root_company, cmd, FormatArrayAsHex(data));
|
||||
s->last_data = data;
|
||||
s->last_cmd = cmd;
|
||||
ScriptStorage &s = GetStorage();
|
||||
Debug(script, 6, "SetLastCommand company={:02d} cmd={} data={}", s.root_company, cmd, FormatArrayAsHex(data));
|
||||
s.last_data = data;
|
||||
s.last_cmd = cmd;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObject::CheckLastCommand(const CommandDataBuffer &data, Commands cmd)
|
||||
{
|
||||
ScriptStorage *s = GetStorage();
|
||||
Debug(script, 6, "CheckLastCommand company={:02d} cmd={} data={}", s->root_company, cmd, FormatArrayAsHex(data));
|
||||
if (s->last_cmd != cmd) return false;
|
||||
if (s->last_data != data) return false;
|
||||
ScriptStorage &s = GetStorage();
|
||||
Debug(script, 6, "CheckLastCommand company={:02d} cmd={} data={}", s.root_company, cmd, FormatArrayAsHex(data));
|
||||
if (s.last_cmd != cmd) return false;
|
||||
if (s.last_data != data) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetDoCommandCosts(Money value)
|
||||
{
|
||||
GetStorage()->costs = CommandCost(INVALID_EXPENSES, value); // Expense type is never read.
|
||||
GetStorage().costs = CommandCost(INVALID_EXPENSES, value); // Expense type is never read.
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::IncreaseDoCommandCosts(Money value)
|
||||
{
|
||||
GetStorage()->costs.AddCost(value);
|
||||
GetStorage().costs.AddCost(value);
|
||||
}
|
||||
|
||||
/* static */ Money ScriptObject::GetDoCommandCosts()
|
||||
{
|
||||
return GetStorage()->costs.GetCost();
|
||||
return GetStorage().costs.GetCost();
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastError(ScriptErrorType last_error)
|
||||
{
|
||||
GetStorage()->last_error = last_error;
|
||||
GetStorage().last_error = last_error;
|
||||
}
|
||||
|
||||
/* static */ ScriptErrorType ScriptObject::GetLastError()
|
||||
{
|
||||
return GetStorage()->last_error;
|
||||
return GetStorage().last_error;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCost(Money last_cost)
|
||||
{
|
||||
GetStorage()->last_cost = last_cost;
|
||||
GetStorage().last_cost = last_cost;
|
||||
}
|
||||
|
||||
/* static */ Money ScriptObject::GetLastCost()
|
||||
{
|
||||
return GetStorage()->last_cost;
|
||||
return GetStorage().last_cost;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetRoadType(RoadType road_type)
|
||||
{
|
||||
GetStorage()->road_type = road_type;
|
||||
GetStorage().road_type = road_type;
|
||||
}
|
||||
|
||||
/* static */ RoadType ScriptObject::GetRoadType()
|
||||
{
|
||||
return GetStorage()->road_type;
|
||||
return GetStorage().road_type;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetRailType(RailType rail_type)
|
||||
{
|
||||
GetStorage()->rail_type = rail_type;
|
||||
GetStorage().rail_type = rail_type;
|
||||
}
|
||||
|
||||
/* static */ RailType ScriptObject::GetRailType()
|
||||
{
|
||||
return GetStorage()->rail_type;
|
||||
return GetStorage().rail_type;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCommandRes(bool res)
|
||||
{
|
||||
GetStorage()->last_command_res = res;
|
||||
GetStorage().last_command_res = res;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObject::GetLastCommandRes()
|
||||
{
|
||||
return GetStorage()->last_command_res;
|
||||
return GetStorage().last_command_res;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCommandResData(CommandDataBuffer data)
|
||||
{
|
||||
GetStorage()->last_cmd_ret = std::move(data);
|
||||
GetStorage().last_cmd_ret = std::move(data);
|
||||
}
|
||||
|
||||
/* static */ const CommandDataBuffer &ScriptObject::GetLastCommandResData()
|
||||
{
|
||||
return GetStorage()->last_cmd_ret;
|
||||
return GetStorage().last_cmd_ret;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetCompany(::CompanyID company)
|
||||
{
|
||||
if (GetStorage()->root_company == INVALID_OWNER) GetStorage()->root_company = company;
|
||||
GetStorage()->company = company;
|
||||
if (GetStorage().root_company == INVALID_OWNER) GetStorage().root_company = company;
|
||||
GetStorage().company = company;
|
||||
|
||||
_current_company = company;
|
||||
}
|
||||
|
||||
/* static */ ::CompanyID ScriptObject::GetCompany()
|
||||
{
|
||||
return GetStorage()->company;
|
||||
return GetStorage().company;
|
||||
}
|
||||
|
||||
/* static */ ::CompanyID ScriptObject::GetRootCompany()
|
||||
{
|
||||
return GetStorage()->root_company;
|
||||
return GetStorage().root_company;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObject::CanSuspend()
|
||||
{
|
||||
Squirrel *squirrel = ScriptObject::GetActiveInstance().engine;
|
||||
return GetStorage()->allow_do_command && squirrel->CanSuspend();
|
||||
return GetStorage().allow_do_command && squirrel->CanSuspend();
|
||||
}
|
||||
|
||||
/* static */ ScriptEventQueue &ScriptObject::GetEventQueue()
|
||||
{
|
||||
return GetStorage()->event_queue;
|
||||
return GetStorage().event_queue;
|
||||
}
|
||||
|
||||
/* static */ ScriptLogTypes::LogData &ScriptObject::GetLogData()
|
||||
{
|
||||
return GetStorage()->log_data;
|
||||
return GetStorage().log_data;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetCallbackVariable(int index, int value)
|
||||
{
|
||||
if (static_cast<size_t>(index) >= GetStorage()->callback_value.size()) GetStorage()->callback_value.resize(index + 1);
|
||||
GetStorage()->callback_value[index] = value;
|
||||
if (static_cast<size_t>(index) >= GetStorage().callback_value.size()) GetStorage().callback_value.resize(index + 1);
|
||||
GetStorage().callback_value[index] = value;
|
||||
}
|
||||
|
||||
/* static */ int ScriptObject::GetCallbackVariable(int index)
|
||||
{
|
||||
return GetStorage()->callback_value[index];
|
||||
return GetStorage().callback_value[index];
|
||||
}
|
||||
|
||||
/* static */ CommandCallbackData *ScriptObject::GetDoCommandCallback()
|
||||
|
@ -310,8 +310,8 @@ ScriptObject::DisableDoCommandScope::DisableDoCommandScope()
|
|||
IncreaseDoCommandCosts(res.GetCost());
|
||||
if (!_generating_world) {
|
||||
/* Charge a nominal fee for asynchronously executed commands */
|
||||
Squirrel *engine = ScriptObject::GetActiveInstance().engine;
|
||||
Squirrel::DecreaseOps(engine->GetVM(), 100);
|
||||
Squirrel &engine = *ScriptObject::GetActiveInstance().engine;
|
||||
Squirrel::DecreaseOps(engine.GetVM(), 100);
|
||||
}
|
||||
if (callback != nullptr) {
|
||||
/* Insert return value into to stack and throw a control code that
|
||||
|
|
|
@ -100,7 +100,7 @@ void ScriptInstance::Initialize(const std::string &main_script, const std::strin
|
|||
|
||||
void ScriptInstance::RegisterAPI()
|
||||
{
|
||||
squirrel_register_std(this->engine);
|
||||
squirrel_register_std(*this->engine);
|
||||
}
|
||||
|
||||
bool ScriptInstance::LoadCompatibilityScript(std::string_view api_version, Subdirectory dir)
|
||||
|
@ -318,9 +318,10 @@ void ScriptInstance::CollectGarbage()
|
|||
}
|
||||
|
||||
|
||||
ScriptStorage *ScriptInstance::GetStorage()
|
||||
ScriptStorage &ScriptInstance::GetStorage()
|
||||
{
|
||||
return this->storage;
|
||||
assert(this->storage != nullptr);
|
||||
return *this->storage;
|
||||
}
|
||||
|
||||
ScriptLogTypes::LogData &ScriptInstance::GetLogData()
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
/**
|
||||
* Get the storage of this script.
|
||||
*/
|
||||
class ScriptStorage *GetStorage();
|
||||
class ScriptStorage &GetStorage();
|
||||
|
||||
/**
|
||||
* Get the log pointer of this script.
|
||||
|
@ -146,7 +146,11 @@ public:
|
|||
/**
|
||||
* Get the controller attached to the instance.
|
||||
*/
|
||||
class ScriptController *GetController() { return controller; }
|
||||
class ScriptController &GetController()
|
||||
{
|
||||
assert(this->controller != nullptr);
|
||||
return *this->controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the "this script died" value
|
||||
|
|
|
@ -536,7 +536,7 @@ void Squirrel::Initialize()
|
|||
sq_setforeignptr(this->vm, this);
|
||||
|
||||
sq_pushroottable(this->vm);
|
||||
squirrel_register_global_std(this);
|
||||
squirrel_register_global_std(*this);
|
||||
|
||||
/* Set consts table as delegate of root table, so consts/enums defined via require() are accessible */
|
||||
sq_pushconsttable(this->vm);
|
||||
|
|
|
@ -82,20 +82,20 @@ SQInteger SquirrelStd::notifyallexceptions(HSQUIRRELVM vm)
|
|||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
void squirrel_register_global_std(Squirrel *engine)
|
||||
void squirrel_register_global_std(Squirrel &engine)
|
||||
{
|
||||
/* We don't use squirrel_helper here, as we want to register to the global
|
||||
* scope and not to a class. */
|
||||
engine->AddMethod("require", &SquirrelStd::require, ".s");
|
||||
engine->AddMethod("notifyallexceptions", &SquirrelStd::notifyallexceptions, ".b");
|
||||
engine.AddMethod("require", &SquirrelStd::require, ".s");
|
||||
engine.AddMethod("notifyallexceptions", &SquirrelStd::notifyallexceptions, ".b");
|
||||
}
|
||||
|
||||
void squirrel_register_std(Squirrel *engine)
|
||||
void squirrel_register_std(Squirrel &engine)
|
||||
{
|
||||
/* We don't use squirrel_helper here, as we want to register to the global
|
||||
* scope and not to a class. */
|
||||
engine->AddMethod("min", &SquirrelStd::min, ".ii");
|
||||
engine->AddMethod("max", &SquirrelStd::max, ".ii");
|
||||
engine.AddMethod("min", &SquirrelStd::min, ".ii");
|
||||
engine.AddMethod("max", &SquirrelStd::max, ".ii");
|
||||
|
||||
sqstd_register_mathlib(engine->GetVM());
|
||||
sqstd_register_mathlib(engine.GetVM());
|
||||
}
|
||||
|
|
|
@ -52,12 +52,12 @@ public:
|
|||
/**
|
||||
* Register all standard functions we want to give to a script.
|
||||
*/
|
||||
void squirrel_register_std(Squirrel *engine);
|
||||
void squirrel_register_std(Squirrel &engine);
|
||||
|
||||
/**
|
||||
* Register all standard functions that are available on first startup.
|
||||
* @note this set is very limited, and is only meant to load other scripts and things like that.
|
||||
*/
|
||||
void squirrel_register_global_std(Squirrel *engine);
|
||||
void squirrel_register_global_std(Squirrel &engine);
|
||||
|
||||
#endif /* SQUIRREL_STD_HPP */
|
||||
|
|
|
@ -3331,7 +3331,7 @@ draw_default_foundation:
|
|||
auto result = GetRoadStopLayout(ti, stopspec, st, type, view, regs100);
|
||||
if (result.has_value()) {
|
||||
if (stopspec->flags.Test(RoadStopSpecFlag::DrawModeRegister)) {
|
||||
stop_draw_mode = static_cast<RoadStopDrawMode>(regs100[0]);
|
||||
stop_draw_mode = static_cast<RoadStopDrawModes>(regs100[0]);
|
||||
}
|
||||
if (type == StationType::RoadWaypoint && stop_draw_mode.Test(RoadStopDrawMode::WaypGround)) {
|
||||
draw_ground = true;
|
||||
|
|
|
@ -427,6 +427,7 @@ struct TimetableWindow : Window {
|
|||
void DrawTimetablePanel(const Rect &r) const
|
||||
{
|
||||
const Vehicle *v = this->vehicle;
|
||||
if (v->GetNumOrders() == 0) return;
|
||||
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
|
||||
int i = this->vscroll->GetPosition();
|
||||
VehicleOrderID order_id = (i + 1) / 2;
|
||||
|
|
|
@ -2305,29 +2305,29 @@ static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
|
|||
};
|
||||
|
||||
enum MainToolbarEditorHotkeys : int32_t {
|
||||
MTEHK_PAUSE,
|
||||
MTEHK_FASTFORWARD,
|
||||
MTEHK_SETTINGS,
|
||||
MTEHK_SAVEGAME,
|
||||
MTEHK_GENLAND,
|
||||
MTEHK_GENTOWN,
|
||||
MTEHK_GENINDUSTRY,
|
||||
MTEHK_BUILD_ROAD,
|
||||
MTEHK_BUILD_TRAM,
|
||||
MTEHK_BUILD_DOCKS,
|
||||
MTEHK_BUILD_TREES,
|
||||
MTEHK_SIGN,
|
||||
MTEHK_MUSIC,
|
||||
MTEHK_LANDINFO,
|
||||
MTEHK_PAUSE = WID_TE_PAUSE,
|
||||
MTEHK_FASTFORWARD = WID_TE_FAST_FORWARD,
|
||||
MTEHK_SETTINGS = WID_TE_SETTINGS,
|
||||
MTEHK_SAVEGAME = WID_TE_SAVE,
|
||||
MTEHK_GENLAND = WID_TE_LAND_GENERATE,
|
||||
MTEHK_GENTOWN = WID_TE_TOWN_GENERATE,
|
||||
MTEHK_GENINDUSTRY = WID_TE_INDUSTRY,
|
||||
MTEHK_BUILD_ROAD = WID_TE_ROADS,
|
||||
MTEHK_BUILD_TRAM = WID_TE_TRAMS,
|
||||
MTEHK_BUILD_DOCKS = WID_TE_WATER,
|
||||
MTEHK_BUILD_TREES = WID_TE_TREES,
|
||||
MTEHK_SIGN = WID_TE_SIGNS,
|
||||
MTEHK_MUSIC = WID_TE_MUSIC_SOUND,
|
||||
MTEHK_LANDINFO = WID_TE_HELP,
|
||||
MTEHK_ZOOM_IN = WID_TE_ZOOM_IN,
|
||||
MTEHK_ZOOM_OUT = WID_TE_ZOOM_OUT,
|
||||
MTEHK_SMALLMAP = WID_TE_SMALL_MAP,
|
||||
MTEHK_TERRAFORM = WID_TE_END,
|
||||
MTEHK_EXTRA_VIEWPORT,
|
||||
MTEHK_SMALL_SCREENSHOT,
|
||||
MTEHK_ZOOMEDIN_SCREENSHOT,
|
||||
MTEHK_DEFAULTZOOM_SCREENSHOT,
|
||||
MTEHK_GIANT_SCREENSHOT,
|
||||
MTEHK_ZOOM_IN,
|
||||
MTEHK_ZOOM_OUT,
|
||||
MTEHK_TERRAFORM,
|
||||
MTEHK_SMALLMAP,
|
||||
MTEHK_EXTRA_VIEWPORT,
|
||||
};
|
||||
|
||||
struct ScenarioEditorToolbarWindow : Window {
|
||||
|
|
|
@ -10,47 +10,52 @@
|
|||
#ifndef TOOLBAR_GUI_H
|
||||
#define TOOLBAR_GUI_H
|
||||
|
||||
#include "widgets/toolbar_widget.h"
|
||||
|
||||
// TODO: Replace all instances of "MTHK_blah" with "WID_blah" where we can,
|
||||
// then redefine this as AdditionalMainToolbarHotkeys, or something like that.
|
||||
enum MainToolbarHotkeys : int32_t {
|
||||
MTHK_PAUSE,
|
||||
MTHK_FASTFORWARD,
|
||||
MTHK_SETTINGS,
|
||||
MTHK_SAVEGAME,
|
||||
MTHK_LOADGAME,
|
||||
MTHK_SMALLMAP,
|
||||
MTHK_TOWNDIRECTORY,
|
||||
MTHK_SUBSIDIES,
|
||||
MTHK_STATIONS,
|
||||
MTHK_FINANCES,
|
||||
MTHK_COMPANIES,
|
||||
MTHK_STORY,
|
||||
MTHK_GOAL,
|
||||
MTHK_GRAPHS,
|
||||
MTHK_LEAGUE,
|
||||
MTHK_INDUSTRIES,
|
||||
MTHK_TRAIN_LIST,
|
||||
MTHK_ROADVEH_LIST,
|
||||
MTHK_SHIP_LIST,
|
||||
MTHK_AIRCRAFT_LIST,
|
||||
MTHK_ZOOM_IN,
|
||||
MTHK_ZOOM_OUT,
|
||||
MTHK_BUILD_RAIL,
|
||||
MTHK_BUILD_ROAD,
|
||||
MTHK_BUILD_TRAM,
|
||||
MTHK_BUILD_DOCKS,
|
||||
MTHK_BUILD_AIRPORT,
|
||||
MTHK_PAUSE = WID_TN_PAUSE,
|
||||
MTHK_FASTFORWARD = WID_TN_FAST_FORWARD,
|
||||
MTHK_SETTINGS = WID_TN_SETTINGS,
|
||||
MTHK_SAVEGAME = WID_TN_SAVE,
|
||||
MTHK_SMALLMAP = WID_TN_SMALL_MAP,
|
||||
MTHK_TOWNDIRECTORY = WID_TN_TOWNS,
|
||||
MTHK_SUBSIDIES = WID_TN_SUBSIDIES,
|
||||
MTHK_STATIONS = WID_TN_STATIONS,
|
||||
MTHK_FINANCES = WID_TN_FINANCES,
|
||||
MTHK_COMPANIES = WID_TN_COMPANIES,
|
||||
MTHK_STORY = WID_TN_STORY,
|
||||
MTHK_GOAL = WID_TN_GOAL,
|
||||
MTHK_GRAPHS = WID_TN_GRAPHS,
|
||||
MTHK_LEAGUE = WID_TN_LEAGUE,
|
||||
MTHK_INDUSTRIES = WID_TN_INDUSTRIES,
|
||||
MTHK_TRAIN_LIST = WID_TN_TRAINS,
|
||||
MTHK_ROADVEH_LIST = WID_TN_ROADVEHS,
|
||||
MTHK_SHIP_LIST = WID_TN_SHIPS,
|
||||
MTHK_AIRCRAFT_LIST = WID_TN_AIRCRAFT,
|
||||
MTHK_ZOOM_IN = WID_TN_ZOOM_IN,
|
||||
MTHK_ZOOM_OUT = WID_TN_ZOOM_OUT,
|
||||
MTHK_BUILD_RAIL = WID_TN_RAILS,
|
||||
MTHK_BUILD_ROAD = WID_TN_ROADS,
|
||||
MTHK_BUILD_TRAM = WID_TN_TRAMS,
|
||||
MTHK_BUILD_DOCKS = WID_TN_WATER,
|
||||
MTHK_BUILD_AIRPORT = WID_TN_AIR,
|
||||
MTHK_TERRAFORM = WID_TN_LANDSCAPE,
|
||||
MTHK_MUSIC = WID_TN_MUSIC_SOUND,
|
||||
MTHK_LANDINFO = WID_TN_HELP,
|
||||
// Hotkeys without associated widgets.
|
||||
MTHK_LOADGAME = WID_TN_END,
|
||||
MTHK_BUILD_TREES,
|
||||
MTHK_MUSIC,
|
||||
MTHK_LANDINFO,
|
||||
MTHK_SCRIPT_DEBUG,
|
||||
MTHK_SMALL_SCREENSHOT,
|
||||
MTHK_ZOOMEDIN_SCREENSHOT,
|
||||
MTHK_DEFAULTZOOM_SCREENSHOT,
|
||||
MTHK_GIANT_SCREENSHOT,
|
||||
MTHK_CHEATS,
|
||||
MTHK_TERRAFORM,
|
||||
MTHK_EXTRA_VIEWPORT,
|
||||
MTHK_CLIENT_LIST,
|
||||
MTHK_SIGN_LIST
|
||||
MTHK_SIGN_LIST,
|
||||
};
|
||||
|
||||
void AllocateToolbar();
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
|
||||
#include "safeguards.h"
|
||||
|
||||
#include "widgets/toolbar_widget.h"
|
||||
#include "hotkeys.h"
|
||||
|
||||
WidgetDimensions WidgetDimensions::scaled = {};
|
||||
|
||||
static std::string GetStringForWidget(const Window *w, const NWidgetCore *nwid, bool secondary = false)
|
||||
|
@ -3108,6 +3111,87 @@ void NWidgetLeaf::Draw(const Window *w)
|
|||
}
|
||||
|
||||
DrawOutline(w, this);
|
||||
|
||||
// TODO: Draw hints only if Alt is being held.
|
||||
// Don't draw hotkey hints on disabled widgets or editboxes with focus.
|
||||
if (!(this->IsDisabled() || (this->type == WWT_EDITBOX && w->nested_focus == this))) {
|
||||
this->DrawHotkeyHint(w);
|
||||
}
|
||||
}
|
||||
|
||||
void NWidgetLeaf::DrawHotkeyHint(const Window* w) {
|
||||
// TODO: Use global hotkey for autoroads for rail, road, tram, etc. if
|
||||
// they have been set.
|
||||
|
||||
const uint o = ScaleGUITrad(1);
|
||||
Rect r = this->GetCurrentRect().Shrink(o);
|
||||
std::string hint;
|
||||
uint16_t keycode = 0;
|
||||
|
||||
if (w->window_desc.cls == WC_MAIN_TOOLBAR && this->index == WID_TN_FAST_FORWARD) {
|
||||
// Special-case hint text for Fast-forwards because it's not really a hotkey
|
||||
hint = "Tab";
|
||||
} else if (w->window_desc.hotkeys != nullptr) {
|
||||
// Widget IDs can coincidentally overlap with hotkey IDs if
|
||||
// they aren't assigned properly. Avoid this.
|
||||
auto hk = w->window_desc.hotkeys->GetHotkeyByNum(this->index);
|
||||
if (hk != nullptr && hk->keycodes.size()) {
|
||||
// Find the "best" of the available keycodes
|
||||
// TODO: maybe don't repeat this work so much
|
||||
keycode = *(hk->keycodes.begin());
|
||||
hint = KeycodeToShortString(keycode);
|
||||
for (auto k : hk->keycodes) {
|
||||
if (!(keycode & WKC_GLOBAL_HOTKEY) && (k & WKC_GLOBAL_HOTKEY)) {
|
||||
keycode = k;
|
||||
} else {
|
||||
auto h = KeycodeToShortString(k);
|
||||
if (hint.length() > h.length()) {
|
||||
keycode = k;
|
||||
hint = h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert to a string
|
||||
// TODO: Glyphs for Shift, Alt, etc. Colour for global.
|
||||
// - On screen keyboard has a sprite for shift.
|
||||
hint = KeycodeToShortString(keycode);
|
||||
}
|
||||
}
|
||||
|
||||
if (hint.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Choose the font-size
|
||||
auto fontsize = FS_SMALL;
|
||||
// It's better to have a single consistent size.
|
||||
/*auto availableSize = Dimension(r.right - r.left, r.bottom - r.top);*/
|
||||
/*auto desiredSize = GetStringBoundingBox(hint, FS_NORMAL);*/
|
||||
/*if (availableSize < desiredSize) {*/
|
||||
/* fontsize = FS_SMALL;*/
|
||||
/*}*/
|
||||
|
||||
// Choose hint colour
|
||||
auto colour = TC_WHITE;
|
||||
if (keycode & WKC_GLOBAL_HOTKEY) {
|
||||
colour = TC_LIGHT_BLUE;
|
||||
}
|
||||
|
||||
auto alignment = SA_LEFT | SA_BOTTOM;
|
||||
|
||||
// Draw a slightly shoddy outline
|
||||
DrawStringMultiLine(r.Translate( o, o), hint, TC_BLACK | TC_NO_SHADE, alignment, false, fontsize);
|
||||
DrawStringMultiLine(r.Translate( o, -o), hint, TC_BLACK | TC_NO_SHADE, alignment, false, fontsize);
|
||||
DrawStringMultiLine(r.Translate(-o, o), hint, TC_BLACK | TC_NO_SHADE, alignment, false, fontsize);
|
||||
DrawStringMultiLine(r.Translate(-o, -o), hint, TC_BLACK | TC_NO_SHADE, alignment, false, fontsize);
|
||||
DrawStringMultiLine(r.Translate( o, 0), hint, TC_BLACK | TC_NO_SHADE, alignment, false, fontsize);
|
||||
DrawStringMultiLine(r.Translate(-o, 0), hint, TC_BLACK | TC_NO_SHADE, alignment, false, fontsize);
|
||||
DrawStringMultiLine(r.Translate( 0, o), hint, TC_BLACK | TC_NO_SHADE, alignment, false, fontsize);
|
||||
DrawStringMultiLine(r.Translate( 0, -o), hint, TC_BLACK | TC_NO_SHADE, alignment, false, fontsize);
|
||||
|
||||
// Draw the hint text
|
||||
DrawStringMultiLine(r, hint, colour | TC_NO_SHADE, alignment, false, fontsize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -922,6 +922,7 @@ public:
|
|||
|
||||
void SetupSmallestSize(Window *w) override;
|
||||
void Draw(const Window *w) override;
|
||||
void DrawHotkeyHint(const Window* window);
|
||||
|
||||
bool ButtonHit(const Point &pt);
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ enum OrderWidgets : WidgetID {
|
|||
WID_O_SEL_TOP_ROW, ///< #NWID_SELECTION widget for the top row of the 'your non-trains' order window.
|
||||
WID_O_SEL_BOTTOM_MIDDLE, ///< #NWID_SELECTION widget for the middle part of the bottom row of the 'your train' order window.
|
||||
WID_O_SHARED_ORDER_LIST, ///< Open list of shared vehicles.
|
||||
WID_O_END, ///< End of the list of widgets.
|
||||
};
|
||||
|
||||
#endif /* WIDGETS_ORDER_WIDGET_H */
|
||||
|
|
|
@ -73,6 +73,7 @@ enum ToolbarEditorWidgets : WidgetID {
|
|||
WID_TE_MUSIC_SOUND, ///< Music/sound configuration menu.
|
||||
WID_TE_HELP, ///< Help menu.
|
||||
WID_TE_SWITCH_BAR, ///< Only available when toolbar has been split to switch between different subsets.
|
||||
WID_TE_END,
|
||||
};
|
||||
|
||||
#endif /* WIDGETS_TOOLBAR_WIDGET_H */
|
||||
|
|
Loading…
Reference in New Issue