2020-12-18 23:21:10 +01:00
|
|
|
#ifndef MWLUA_PLAYERSCRIPTS_H
|
|
|
|
#define MWLUA_PLAYERSCRIPTS_H
|
|
|
|
|
2021-07-09 20:18:23 +02:00
|
|
|
#include <SDL_events.h>
|
|
|
|
|
2022-02-21 19:49:00 +00:00
|
|
|
#include <components/sdlutil/events.hpp>
|
|
|
|
|
2021-06-26 23:10:24 +02:00
|
|
|
#include "../mwbase/luamanager.hpp"
|
|
|
|
|
2024-01-10 19:27:39 +01:00
|
|
|
#include "inputprocessor.hpp"
|
2020-12-18 23:21:10 +01:00
|
|
|
#include "localscripts.hpp"
|
|
|
|
|
|
|
|
namespace MWLua
|
|
|
|
{
|
|
|
|
|
|
|
|
class PlayerScripts : public LocalScripts
|
|
|
|
{
|
|
|
|
public:
|
2022-05-20 21:47:13 +02:00
|
|
|
PlayerScripts(LuaUtil::LuaState* lua, const LObject& obj)
|
|
|
|
: LocalScripts(lua, obj)
|
2024-01-10 19:27:39 +01:00
|
|
|
, mInputProcessor(this)
|
2020-12-18 23:21:10 +01:00
|
|
|
{
|
2024-01-10 19:27:39 +01:00
|
|
|
registerEngineHandlers({ &mConsoleCommandHandlers, &mOnFrameHandlers, &mQuestUpdate, &mUiModeChanged });
|
2020-12-18 23:21:10 +01:00
|
|
|
}
|
|
|
|
|
2021-06-26 23:10:24 +02:00
|
|
|
void processInputEvent(const MWBase::LuaManager::InputEvent& event)
|
|
|
|
{
|
2024-01-10 19:27:39 +01:00
|
|
|
mInputProcessor.processInputEvent(event);
|
2021-06-26 23:10:24 +02:00
|
|
|
}
|
2020-12-18 23:21:10 +01:00
|
|
|
|
2022-05-13 18:22:59 +02:00
|
|
|
void onFrame(float dt) { callEngineHandlers(mOnFrameHandlers, dt); }
|
2023-06-12 21:35:00 -05:00
|
|
|
void onQuestUpdate(std::string_view questId, int stage) { callEngineHandlers(mQuestUpdate, questId, stage); }
|
2021-11-17 03:05:50 +01:00
|
|
|
|
2022-04-09 23:07:57 +02:00
|
|
|
bool consoleCommand(
|
|
|
|
const std::string& consoleMode, const std::string& command, const sol::object& selectedObject)
|
|
|
|
{
|
|
|
|
callEngineHandlers(mConsoleCommandHandlers, consoleMode, command, selectedObject);
|
|
|
|
return !mConsoleCommandHandlers.mList.empty();
|
|
|
|
}
|
|
|
|
|
2023-07-09 08:42:09 +02:00
|
|
|
// `arg` is either forwarded from MWGui::pushGuiMode or empty
|
2023-10-21 13:04:02 +02:00
|
|
|
void uiModeChanged(ObjectId arg, bool byLuaAction)
|
2023-07-09 08:42:09 +02:00
|
|
|
{
|
2023-10-21 13:04:02 +02:00
|
|
|
if (arg.isZeroOrUnset())
|
2023-09-07 02:16:22 +02:00
|
|
|
callEngineHandlers(mUiModeChanged, byLuaAction);
|
2023-07-09 08:42:09 +02:00
|
|
|
else
|
2023-09-07 02:16:22 +02:00
|
|
|
callEngineHandlers(mUiModeChanged, byLuaAction, LObject(arg));
|
2023-07-09 08:42:09 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 23:21:10 +01:00
|
|
|
private:
|
2024-01-11 00:55:29 +01:00
|
|
|
friend class MWLua::InputProcessor<PlayerScripts>;
|
|
|
|
InputProcessor<PlayerScripts> mInputProcessor;
|
2022-04-09 23:07:57 +02:00
|
|
|
EngineHandlerList mConsoleCommandHandlers{ "onConsoleCommand" };
|
2022-05-13 18:22:59 +02:00
|
|
|
EngineHandlerList mOnFrameHandlers{ "onFrame" };
|
2023-06-12 21:35:00 -05:00
|
|
|
EngineHandlerList mQuestUpdate{ "onQuestUpdate" };
|
2023-07-09 08:42:09 +02:00
|
|
|
EngineHandlerList mUiModeChanged{ "_onUiModeChanged" };
|
2020-12-18 23:21:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MWLUA_PLAYERSCRIPTS_H
|