Skip to content

Commit

Permalink
Update UI
Browse files Browse the repository at this point in the history
Added SetBackground/SetForeground for Panels
Fixed an issue where if a API lua file failed to compile, it would cause an infinite reload state in the LuaManager
  • Loading branch information
NixAJ committed Sep 19, 2024
1 parent 671463e commit f5e374e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 12 deletions.
7 changes: 0 additions & 7 deletions Source/Game-Lib/Game-Lib/Scripting/Handlers/GlobalHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@

namespace Scripting
{
struct Panel
{
public:
vec3 position;
vec3 extents;
};

void GlobalHandler::Register(lua_State* state)
{
LuaManager* luaManager = ServiceLocator::GetLuaManager();
Expand Down
8 changes: 5 additions & 3 deletions Source/Game-Lib/Game-Lib/Scripting/LuaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ namespace Scripting
//auto uiHandler = GetLuaHandler<UI::UIHandler*>(LuaHandlerType::UI);
//uiHandler->Clear();
}
else
{
_isDirty = false;
}

isDirty = result;
}
Expand Down Expand Up @@ -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;
}

Expand Down
60 changes: 60 additions & 0 deletions Source/Game-Lib/Game-Lib/Scripting/UI/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,6 +22,9 @@ namespace Scripting::UI
{ "SetWidth", PanelMethods::SetWidth },
{ "SetHeight", PanelMethods::SetHeight },

{ "SetBackground", PanelMethods::SetBackground },
{ "SetForeground", PanelMethods::SetForeground },

{ nullptr, nullptr }
};

Expand Down Expand Up @@ -152,5 +156,61 @@ namespace Scripting::UI

return 0;
}

i32 SetBackground(lua_State* state)
{
LuaState ctx(state);

Widget* widget = ctx.GetUserData<Widget>(nullptr, 1);
if (widget == nullptr)
{
luaL_error(state, "Widget is null");
}

entt::registry* registry = ServiceLocator::GetEnttRegistries()->uiRegistry;
auto& panelMethods = registry->get<ECS::Components::UI::PanelTemplate>(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<Widget>(nullptr, 1);
if (widget == nullptr)
{
luaL_error(state, "Widget is null");
}

entt::registry* registry = ServiceLocator::GetEnttRegistries()->uiRegistry;
auto& panelMethods = registry->get<ECS::Components::UI::PanelTemplate>(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;
}
}
}
2 changes: 2 additions & 0 deletions Source/Game-Lib/Game-Lib/Scripting/UI/Panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
21 changes: 19 additions & 2 deletions Source/Scripts/API/UI/LoadingScreen.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit f5e374e

Please sign in to comment.