Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Remove hardcoded loading
Browse files Browse the repository at this point in the history
Changes in UI script:
- Added a new function: `loadingGetProgress` - Returns a percentage of loaded assets during the game loading.
- Removed the hardcoded progress bar update and the button appearing.
  - Add the following code instead, to the `tick` callback:
  ```
  -- update splash screen
  local splash = f.getWidgetN("splash/Main")
  if splash then
    local progress = f.loadingGetProgress()
    f.getWidgetN("splash/Main/Frame/Progress").widget.valueData = progress
    if progress == 1 then
      f.getWidgetN("splash/Main/Frame/Button_Play"):show()
    end
  end
  ```
  • Loading branch information
jakubg1 committed Dec 31, 2022
1 parent 98a54ff commit b753158
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
11 changes: 1 addition & 10 deletions src/UI/Manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function UIManager:new()
self.scriptFunctions = {
loadMain = function() _Game:loadMain() end,
initSession = function() _Game:initSession() end,
loadingGetProgress = function() return _Game.resourceManager.stepLoadProcessedObjs / _Game.resourceManager.stepLoadTotalObjs end,

levelStart = function() _Game.session:startLevel() end,
levelBegin = function() _Game.session.level:begin() end,
Expand Down Expand Up @@ -117,16 +118,6 @@ function UIManager:update(dt)
end
end

-- TODO: HARDCODED - make it more flexible
if self.widgets.splash then
-- splash progress bar
self.widgets.splash.children.Frame.children.Progress.widget.valueData = _Game.resourceManager.stepLoadProcessedObjs / _Game.resourceManager.stepLoadTotalObjs
-- splash play button
if self.widgets.splash.children.Frame.children.Progress.widget.value == 1 then
self.widgets.splash.children.Frame.children.Button_Play:show()
end
end

for widgetN, widget in pairs(self.widgets) do
widget:update(dt)
end
Expand Down
2 changes: 1 addition & 1 deletion src/UI/Widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function UIWidget:update(dt)
-- instead, you need to clean up the black background manually!
end
end
if self.time and (not self.parent or self.parent:isVisible()) then
if self.time then
self.time = self.time - dt
if self.time <= 0 then
self.time = nil
Expand Down

0 comments on commit b753158

Please sign in to comment.