mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 07:43:01 +01:00
Move ui scripting API to libopenrct2ui
This commit is contained in:
@@ -64,7 +64,8 @@ endif ()
|
||||
# Includes
|
||||
target_include_directories(${PROJECT} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/.."
|
||||
${SPEEX_INCLUDE_DIRS})
|
||||
target_include_directories(${PROJECT} SYSTEM PRIVATE ${SDL2_INCLUDE_DIRS})
|
||||
target_include_directories(${PROJECT} SYSTEM PRIVATE ${SDL2_INCLUDE_DIRS}
|
||||
"${CMAKE_CURRENT_LIST_DIR}/../openrct2/thirdparty")
|
||||
|
||||
# Compiler flags
|
||||
if (WIN32)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "input/KeyboardShortcuts.h"
|
||||
#include "interface/InGameConsole.h"
|
||||
#include "interface/Theme.h"
|
||||
#include "scripting/UiExtensions.h"
|
||||
#include "title/TitleSequencePlayer.h"
|
||||
|
||||
#include <SDL.h>
|
||||
@@ -38,6 +39,7 @@
|
||||
#include <openrct2/interface/InteractiveConsole.h>
|
||||
#include <openrct2/localisation/StringIds.h>
|
||||
#include <openrct2/platform/Platform2.h>
|
||||
#include <openrct2/scripting/ScriptEngine.h>
|
||||
#include <openrct2/title/TitleSequencePlayer.h>
|
||||
#include <openrct2/ui/UiContext.h>
|
||||
#include <openrct2/ui/WindowManager.h>
|
||||
@@ -46,6 +48,7 @@
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Drawing;
|
||||
using namespace OpenRCT2::Input;
|
||||
using namespace OpenRCT2::Scripting;
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
#ifdef __MACOSX__
|
||||
@@ -115,6 +118,12 @@ public:
|
||||
delete _platformUiContext;
|
||||
}
|
||||
|
||||
void Initialise() override
|
||||
{
|
||||
auto& scriptEngine = GetContext()->GetScriptEngine();
|
||||
UiScriptExtensions::Extend(scriptEngine);
|
||||
}
|
||||
|
||||
void Update() override
|
||||
{
|
||||
_inGameConsole.Update();
|
||||
|
||||
@@ -5,62 +5,10 @@
|
||||
#include <string>
|
||||
#include "../common.h"
|
||||
#include "../Context.h"
|
||||
#include "../interface/Window.h"
|
||||
#include "../interface/Window_internal.h"
|
||||
#include "../ui/UiContext.h"
|
||||
#include "../ui/WindowManager.h"
|
||||
#include "ScWindow.hpp"
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
class ScWindow
|
||||
{
|
||||
private:
|
||||
rct_windowclass _class;
|
||||
rct_windownumber _number;
|
||||
|
||||
public:
|
||||
ScWindow(rct_windowclass c, rct_windownumber n)
|
||||
: _class(c),
|
||||
_number(n)
|
||||
{
|
||||
}
|
||||
|
||||
sint32 x_get() { return GetWindow()->x; }
|
||||
void x_set(sint32 value)
|
||||
{
|
||||
auto w = GetWindow();
|
||||
window_set_position(w, value, w->y);
|
||||
}
|
||||
sint32 y_get() { return GetWindow()->y; }
|
||||
void y_set(sint32 value)
|
||||
{
|
||||
auto w = GetWindow();
|
||||
window_set_position(w, w->x, value);
|
||||
}
|
||||
sint32 width_get() { return GetWindow()->width; }
|
||||
sint32 height_get() { return GetWindow()->height; }
|
||||
bool isSticky_get()
|
||||
{
|
||||
auto flags = GetWindow()->flags;
|
||||
return (flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) != 0;
|
||||
}
|
||||
|
||||
static void Register(duk_context * ctx)
|
||||
{
|
||||
dukglue_register_property(ctx, &ScWindow::x_get, &ScWindow::x_set, "x");
|
||||
dukglue_register_property(ctx, &ScWindow::y_get, &ScWindow::y_set, "y");
|
||||
dukglue_register_property(ctx, &ScWindow::width_get, nullptr, "width");
|
||||
dukglue_register_property(ctx, &ScWindow::height_get, nullptr, "height");
|
||||
dukglue_register_property(ctx, &ScWindow::isSticky_get, nullptr, "isSticky");
|
||||
}
|
||||
|
||||
private:
|
||||
rct_window * GetWindow() const
|
||||
{
|
||||
return window_find_by_number(_class, _number);
|
||||
}
|
||||
};
|
||||
|
||||
class ScUi
|
||||
{
|
||||
public:
|
||||
58
src/openrct2-ui/scripting/ScWindow.hpp
Normal file
58
src/openrct2-ui/scripting/ScWindow.hpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <dukglue/dukglue.h>
|
||||
#include "../common.h"
|
||||
#include "../interface/Window.h"
|
||||
#include "../interface/Window_internal.h"
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
class ScWindow
|
||||
{
|
||||
private:
|
||||
rct_windowclass _class;
|
||||
rct_windownumber _number;
|
||||
|
||||
public:
|
||||
ScWindow(rct_windowclass c, rct_windownumber n)
|
||||
: _class(c),
|
||||
_number(n)
|
||||
{
|
||||
}
|
||||
|
||||
sint32 x_get() { return GetWindow()->x; }
|
||||
void x_set(sint32 value)
|
||||
{
|
||||
auto w = GetWindow();
|
||||
window_set_position(w, value, w->y);
|
||||
}
|
||||
sint32 y_get() { return GetWindow()->y; }
|
||||
void y_set(sint32 value)
|
||||
{
|
||||
auto w = GetWindow();
|
||||
window_set_position(w, w->x, value);
|
||||
}
|
||||
sint32 width_get() { return GetWindow()->width; }
|
||||
sint32 height_get() { return GetWindow()->height; }
|
||||
bool isSticky_get()
|
||||
{
|
||||
auto flags = GetWindow()->flags;
|
||||
return (flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) != 0;
|
||||
}
|
||||
|
||||
static void Register(duk_context * ctx)
|
||||
{
|
||||
dukglue_register_property(ctx, &ScWindow::x_get, &ScWindow::x_set, "x");
|
||||
dukglue_register_property(ctx, &ScWindow::y_get, &ScWindow::y_set, "y");
|
||||
dukglue_register_property(ctx, &ScWindow::width_get, nullptr, "width");
|
||||
dukglue_register_property(ctx, &ScWindow::height_get, nullptr, "height");
|
||||
dukglue_register_property(ctx, &ScWindow::isSticky_get, nullptr, "isSticky");
|
||||
}
|
||||
|
||||
private:
|
||||
rct_window * GetWindow() const
|
||||
{
|
||||
return window_find_by_number(_class, _number);
|
||||
}
|
||||
};
|
||||
}
|
||||
16
src/openrct2-ui/scripting/UiExtensions.cpp
Normal file
16
src/openrct2-ui/scripting/UiExtensions.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <openrct2/scripting/ScriptEngine.h>
|
||||
#include "UiExtensions.h"
|
||||
#include "ScUi.hpp"
|
||||
#include "ScWindow.hpp"
|
||||
|
||||
using namespace OpenRCT2::Scripting;
|
||||
|
||||
void UiScriptExtensions::Extend(ScriptEngine& scriptEngine)
|
||||
{
|
||||
auto ctx = scriptEngine.GetContext();
|
||||
|
||||
dukglue_register_global(ctx, std::make_shared<ScUi>(), "ui");
|
||||
|
||||
ScUi::Register(ctx);
|
||||
ScWindow::Register(ctx);
|
||||
}
|
||||
12
src/openrct2-ui/scripting/UiExtensions.h
Normal file
12
src/openrct2-ui/scripting/UiExtensions.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
class ScriptEngine;
|
||||
|
||||
class UiScriptExtensions
|
||||
{
|
||||
public:
|
||||
static void Extend(ScriptEngine& scriptEngine);
|
||||
};
|
||||
}
|
||||
@@ -464,6 +464,7 @@ namespace OpenRCT2
|
||||
_gameState->InitAll(150);
|
||||
|
||||
_titleScreen = std::make_unique<TitleScreen>(*_gameState);
|
||||
_uiContext->Initialise();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "ScPark.hpp"
|
||||
#include "ScTile.hpp"
|
||||
#include "ScThing.hpp"
|
||||
#include "ScUi.hpp"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Scripting;
|
||||
@@ -64,14 +63,11 @@ void ScriptEngine::Initialise()
|
||||
ScTile::Register(ctx);
|
||||
ScTileElement::Register(ctx);
|
||||
ScThing::Register(ctx);
|
||||
ScUi::Register(ctx);
|
||||
ScWindow::Register(ctx);
|
||||
|
||||
dukglue_register_global(ctx, std::make_shared<ScConsole>(_console), "console");
|
||||
dukglue_register_global(ctx, std::make_shared<ScContext>(_execInfo, _hookEngine), "context");
|
||||
dukglue_register_global(ctx, std::make_shared<ScMap>(ctx), "map");
|
||||
dukglue_register_global(ctx, std::make_shared<ScPark>(), "park");
|
||||
dukglue_register_global(ctx, std::make_shared<ScUi>(), "ui");
|
||||
|
||||
LoadPlugins();
|
||||
StartPlugins();
|
||||
|
||||
@@ -92,6 +92,7 @@ namespace OpenRCT2::Scripting
|
||||
ScriptEngine(InteractiveConsole& console, IPlatformEnvironment& env);
|
||||
ScriptEngine(ScriptEngine&) = delete;
|
||||
|
||||
duk_context * GetContext() { return _context; }
|
||||
HookEngine& GetHookEngine() { return _hookEngine; }
|
||||
|
||||
void Update();
|
||||
|
||||
@@ -24,6 +24,9 @@ namespace OpenRCT2::Ui
|
||||
IWindowManager* const _windowManager = CreateDummyWindowManager();
|
||||
|
||||
public:
|
||||
void Initialise() override
|
||||
{
|
||||
}
|
||||
void Update() override
|
||||
{
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ namespace OpenRCT2
|
||||
{
|
||||
virtual ~IUiContext() = default;
|
||||
|
||||
virtual void Initialise() abstract;
|
||||
virtual void Update() abstract;
|
||||
virtual void Draw(rct_drawpixelinfo * dpi) abstract;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user