diff --git a/Source/Game-Lib/Game-Lib/Scripting/Handlers/GlobalHandler.cpp b/Source/Game-Lib/Game-Lib/Scripting/Handlers/GlobalHandler.cpp index b564df2d..6dcde52f 100644 --- a/Source/Game-Lib/Game-Lib/Scripting/Handlers/GlobalHandler.cpp +++ b/Source/Game-Lib/Game-Lib/Scripting/Handlers/GlobalHandler.cpp @@ -14,13 +14,6 @@ namespace Scripting { - struct Panel - { - public: - vec3 position; - vec3 extents; - }; - void GlobalHandler::Register(lua_State* state) { LuaManager* luaManager = ServiceLocator::GetLuaManager(); diff --git a/Source/Game-Lib/Game-Lib/Scripting/LuaManager.cpp b/Source/Game-Lib/Game-Lib/Scripting/LuaManager.cpp index 5aff0e12..ffa225fa 100644 --- a/Source/Game-Lib/Game-Lib/Scripting/LuaManager.cpp +++ b/Source/Game-Lib/Game-Lib/Scripting/LuaManager.cpp @@ -75,6 +75,10 @@ namespace Scripting //auto uiHandler = GetLuaHandler(LuaHandlerType::UI); //uiHandler->Clear(); } + else + { + _isDirty = false; + } isDirty = result; } @@ -214,9 +218,7 @@ namespace Scripting i32 result = ctx.LoadBytecode(bytecodeEntry.filePath, bytecodeEntry.bytecode, 0); if (result != LUA_OK) { - std::string error = lua_tostring(state, -1); - - luaL_error(state, "error requiring module, failed to load module"); + lua_error(state); return false; } diff --git a/Source/Game-Lib/Game-Lib/Scripting/UI/Panel.cpp b/Source/Game-Lib/Game-Lib/Scripting/UI/Panel.cpp index f2e684f9..5c709467 100644 --- a/Source/Game-Lib/Game-Lib/Scripting/UI/Panel.cpp +++ b/Source/Game-Lib/Game-Lib/Scripting/UI/Panel.cpp @@ -2,6 +2,7 @@ #include "Game-Lib/Application/EnttRegistries.h" #include "Game-Lib/ECS/Components/UI/Widget.h" +#include "Game-Lib/ECS/Components/UI/PanelTemplate.h" #include "Game-Lib/ECS/Util/Transform2D.h" #include "Game-Lib/ECS/Util/UIUtil.h" #include "Game-Lib/Scripting/LuaState.h" @@ -21,6 +22,9 @@ namespace Scripting::UI { "SetWidth", PanelMethods::SetWidth }, { "SetHeight", PanelMethods::SetHeight }, + { "SetBackground", PanelMethods::SetBackground }, + { "SetForeground", PanelMethods::SetForeground }, + { nullptr, nullptr } }; @@ -152,5 +156,61 @@ namespace Scripting::UI return 0; } + + i32 SetBackground(lua_State* state) + { + LuaState ctx(state); + + Widget* widget = ctx.GetUserData(nullptr, 1); + if (widget == nullptr) + { + luaL_error(state, "Widget is null"); + } + + entt::registry* registry = ServiceLocator::GetEnttRegistries()->uiRegistry; + auto& panelMethods = registry->get(widget->entity); + + const char* texture = ctx.Get(nullptr, 2); + if (texture) + { + panelMethods.background = texture; + panelMethods.setFlags.background = true; + } + else + { + panelMethods.background = ""; + panelMethods.setFlags.background = false; + } + + return 0; + } + + i32 SetForeground(lua_State* state) + { + LuaState ctx(state); + + Widget* widget = ctx.GetUserData(nullptr, 1); + if (widget == nullptr) + { + luaL_error(state, "Widget is null"); + } + + entt::registry* registry = ServiceLocator::GetEnttRegistries()->uiRegistry; + auto& panelMethods = registry->get(widget->entity); + + const char* texture = ctx.Get(nullptr, 2); + if (texture) + { + panelMethods.foreground = texture; + panelMethods.setFlags.foreground = true; + } + else + { + panelMethods.foreground = ""; + panelMethods.setFlags.foreground = false; + } + + return 0; + } } } \ No newline at end of file diff --git a/Source/Game-Lib/Game-Lib/Scripting/UI/Panel.h b/Source/Game-Lib/Game-Lib/Scripting/UI/Panel.h index a8a598d8..92b0d000 100644 --- a/Source/Game-Lib/Game-Lib/Scripting/UI/Panel.h +++ b/Source/Game-Lib/Game-Lib/Scripting/UI/Panel.h @@ -20,5 +20,7 @@ namespace Scripting::UI i32 SetSize(lua_State* state); i32 SetWidth(lua_State* state); i32 SetHeight(lua_State* state); + i32 SetBackground(lua_State* state); + i32 SetForeground(lua_State* state); }; } \ No newline at end of file diff --git a/Source/Scripts/API/UI/LoadingScreen.luau b/Source/Scripts/API/UI/LoadingScreen.luau index 9d6482fd..7ebc9a41 100644 --- a/Source/Scripts/API/UI/LoadingScreen.luau +++ b/Source/Scripts/API/UI/LoadingScreen.luau @@ -14,7 +14,7 @@ loadScreenPanel:SetAnchor(0.5, 0.5) loadScreenPanel:SetRelativePoint(0.5, 0.5) loadScreenPanel:SetEnabled(false) -local loadBarFrame = loadScreenPanel:NewPanel(0, 0, 1024, 64, 1, "DefaultLoadingBarFrame") +local loadBarFrame = loadScreenPanel:NewPanel(0, 64, 1024, 64, 1, "DefaultLoadingBarFrame") loadBarFrame:SetAnchor(0.5, 0.0) loadBarFrame:SetRelativePoint(0.5, 0.0) @@ -36,9 +36,23 @@ __LoadingScreenData = loadingBarFramePanel = loadBarFrame, loadingBarSlider = loadBarSlider, + nameToTextureMap = + { + ["None"] = "Data/Texture/interface/glues/loading.dds", + ["Default"] = "Data/Texture/interface/glues/loading.dds", + ["EasternKingdom"] = "Data/Texture/interface/glues/loadingscreens/loadscreeneasternkingdom.dds", + ["Kalimdor"] = "Data/Texture/interface/glues/loadingscreens/loadscreenkalimdor.dds", + ["Outland"] = "Data/Texture/interface/glues/loadingscreens/loadscreenoutland.dds", + ["Northrend"] = "Data/Texture/interface/glues/loadingscreens/loadscreennorthrend.dds", + ["ArathiBasin"] = "Data/Texture/interface/glues/loadingscreens/loadscreenarathibasin.dds", + ["WarsongGulch"] = "Data/Texture/interface/glues/loadingscreens/loadscreenwarsonggulch.dds", + ["ScarletMonastery"] = "Data/Texture/interface/glues/loadingscreens/loadscreenmonastery.dds" + }, + OnGameUpdated = function(eventID : number, deltaTime : number) local progress = __LoadingScreenData.loadingBarSlider:GetProgress() if (progress >= 1.0) then + __LoadingScreenData.loadingScreenPanel:SetEnabled(false) return end @@ -52,9 +66,12 @@ __LoadingScreenData = RegisterGameEvent(GameEvent.Updated, __LoadingScreenData.OnGameUpdated) function Module.SetLoadingScreen(texturePath) - local texture = texturePath or "Data/Texture/interface/glues/loading.dds" + local texture = texturePath or "Default" + local nameToTextureVal = __LoadingScreenData.nameToTextureMap[texture] + texture = nameToTextureVal or texture __LoadingScreenData.loadingBarSlider:SetProgress(0) + __LoadingScreenData.loadingScreenPanel:SetBackground(texture) __LoadingScreenData.loadingScreenPanel:SetEnabled(true) end