tibia-rme/source/lua/lua_overlay_manager.h
Victor d05ba30ff8
feat: add Lua API modules and Script Manager UI (#161)
This commit adds the full Lua scripting API and integrates the Script Manager into the application.
It builds on top of the scripting engine introduced in #158, exposing all the API modules that Lua scripts can use and making everything accessible from the UI.  
  
Changes:
- Added all Lua API modules: map, tile, item, brush, image, position, selection, creature, color, app, dialog, noise, algo, geo, json, http.
- Added map overlay system for scripts to draw on the map view.
- Added event system, context menu registration, persistent storage, and transaction support with undo/redo.
- Added support for package scripts (directory with manifest.lua) and script metadata tags.
- Added Scripts menu to the menubar with per-script execution and reload.
- Connected the Script Manager window to the UI.
- Added missing build dependencies and fixed MSVC compilation errors.

Notes:
- Build dependencies were added for HTTP and noise generation support.  
- Some code was adjusted to compile correctly on MSVC.
2026-03-28 19:15:57 -03:00

65 lines
1.8 KiB
C++

#ifndef RME_LUA_OVERLAY_MANAGER_H
#define RME_LUA_OVERLAY_MANAGER_H
#include "lua_engine.h"
#include "../map_overlay.h"
#include <string>
#include <string_view>
#include <vector>
#include <functional>
class Tile;
class Item;
using LuaLogFunc = std::function<void(const std::string &, bool)>;
class LuaOverlayManager {
public:
struct MapOverlay {
std::string id;
bool enabled = true;
int order = 0;
sol::function ondraw;
sol::function onhover;
};
struct MapOverlayShowItem {
std::string label;
std::string overlayId;
bool enabled = true;
sol::function ontoggle;
};
bool addMapOverlay(const std::string &id, sol::table options);
bool removeMapOverlay(std::string_view id);
bool setMapOverlayEnabled(std::string_view id, bool enabled);
bool registerMapOverlayShow(const std::string &label, const std::string &overlayId, bool enabled, sol::function ontoggle);
bool setMapOverlayShowEnabled(const std::string &overlayId, bool enabled);
bool isMapOverlayEnabled(std::string_view id) const;
const std::vector<MapOverlayShowItem> &getMapOverlayShows() const {
return mapOverlayShows;
}
void collectMapOverlayCommands(LuaEngine &engine, const MapViewInfo &view, std::vector<MapOverlayCommand> &out);
void updateMapOverlayHover(LuaEngine &engine, int map_x, int map_y, int map_z, int screen_x, int screen_y, Tile* tile, Item* topItem);
const MapOverlayHoverState &getMapOverlayHover() const {
return mapOverlayHover;
}
void clear();
void setLogFunc(LuaLogFunc func) {
logFunc = std::move(func);
}
private:
std::vector<MapOverlay> mapOverlays;
std::vector<MapOverlayShowItem> mapOverlayShows;
MapOverlayHoverState mapOverlayHover;
LuaLogFunc logFunc;
void log(const std::string &msg, bool isError) {
if (logFunc) {
logFunc(msg, isError);
}
}
};
#endif