Skip to content

Commit

Permalink
4SB: adjust title panel
Browse files Browse the repository at this point in the history
  • Loading branch information
4z0t committed Aug 18, 2022
1 parent 9e1fe52 commit 1b44b55
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 26 deletions.
8 changes: 8 additions & 0 deletions mods/4SB/modules/Animations/AnimationFactory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,26 @@ local function Init()
delayedAnimationFactory = DelayedAnimationFactory()
end

---comment
---@return BaseAnimationFactory
function GetAnimationFactory()
return baseFactory
end

---comment
---@return AlphaAnimationFactory
function GetAlphaAnimationFactory()
return alphaAnimationFactory
end

---comment
---@return ColorAnimationFactory
function GetColorAnimationFactory()
return colorAnimationFactory
end

---comment
---@return DelayedAnimationFactory
function GetDelayAnimationFactory()
return delayedAnimationFactory
end
Expand Down
11 changes: 4 additions & 7 deletions mods/4SB/modules/InfoPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local LayoutFor = LayoutHelpers.ReusedLayoutFor
local Tooltip = import('/lua/ui/game/tooltip.lua')



local textFont = "Zeroes Three"
local textSize = 12

Expand All @@ -16,6 +17,8 @@ local panelHeight = 20

local bgColor = "ff000000"



function GetSizeInKM(size)
return math.ceil(size / 51.2 - 0.5)
end
Expand All @@ -33,7 +36,6 @@ InfoPanel = Class(Group)
__init = function(self, parent)
Group.__init(self, parent)

self._bg = Bitmap(self)
self._mapName = Text(self)
self._mapSize = Text(self)

Expand All @@ -47,11 +49,6 @@ InfoPanel = Class(Group)

_Layout = function(self)

LayoutFor(self._bg)
:Fill(self)
:Color(bgColor)
:Alpha(0.4)
:DisableHitTest()

self._mapName:SetFont(textFont, textSize)
LayoutFor(self._mapName)
Expand Down Expand Up @@ -101,6 +98,6 @@ InfoPanel = Class(Group)
self._mapName:SetText(mapName)

Tooltip.AddForcedControlTooltipManual(self._mapName, sessionInfo.name, mapDescription)
end
end,

}
142 changes: 134 additions & 8 deletions mods/4SB/modules/TitlePanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ local LayoutHelpers = import('/lua/maui/layouthelpers.lua')
local Text = import("/lua/maui/text.lua").Text
local UIUtil = import('/lua/ui/uiutil.lua')
local LayoutFor = LayoutHelpers.ReusedLayoutFor
local InfoPanel = import("InfoPanel.lua").InfoPanel

local alphaAnimator = import("Animations/Animator.lua").Animator(GetFrame(0))
local animationFactory = import("Animations/AnimationFactory.lua").GetAnimationFactory()
local alphaAnimationFactory = import("Animations/AnimationFactory.lua").GetAlphaAnimationFactory()

local timeTextFont = "Zeroes Three"
local timeTextSize = 12
Expand All @@ -19,14 +24,15 @@ local titlePanelHeight = 20

local bgColor = "ff000000"

TitlePanel = Class(Group)


local TopInfoPanel = Class(Group)
{
__init = function(self, parent)
Group.__init(self, parent)
self._gameSpeed = 0


self._bg = Bitmap(self)
self._time = Text(self)
self._speed = Text(self)
self._quality = Text(self)
Expand All @@ -40,12 +46,6 @@ TitlePanel = Class(Group)

_Layout = function(self)

LayoutFor(self._bg)
:Fill(self)
:Color(bgColor)
:Alpha(0.4)
:DisableHitTest()

LayoutFor(self._time)
:AtLeftIn(self, 10)
:AtVerticalCenterIn(self)
Expand Down Expand Up @@ -99,3 +99,129 @@ TitlePanel = Class(Group)
end
end
}
local animationSpeed = 300

local expandAnimation = animationFactory
:OnStart(function(control, state, target)
state = state or {}
state.target = target
return state
end)
:OnFrame(function(control, delta, state)

if control.Top() > state.target.Bottom() then
return true
end
control.Top:Set(control.Top() + delta * animationSpeed)
end)
:OnFinish(function(control, state)
control.Top:Set(state.target.Bottom)
control:EnableHitTest(true)
end)
:Create()

local contractAnimation = animationFactory
:OnStart(function(control, state, target)
state = state or {}
state.target = target
return state
end)
:OnFrame(function(control, delta, state)
if control.Top() < state.target.Top() then
return true
end
control.Top:Set(control.Top() - delta * animationSpeed)
end)
:OnFinish(function(control, state)
control.Top:Set(state.target.Top)
control:DisableHitTest(true)
end)
:Create()

local appearAnimation = alphaAnimationFactory
:StartWith(0)
:ToAppear()
:For(0.3)
:EndWith(1)
:ApplyToChildren()
:Create(alphaAnimator)

local fadeAnimation = alphaAnimationFactory
:StartWith(1)
:ToFade()
:For(0.3)
:EndWith(0)
:ApplyToChildren()
:Create(alphaAnimator)


TitlePanel = Class(Group)
{
__init = function(self, parent)
Group.__init(self, parent)

self._bg = Bitmap(self)
self._top = TopInfoPanel(self)

self._info = InfoPanel(self)
self._info:Setup()

self._arrow = Text(self)
self._arrow.state = true
self._arrow:SetText("^")
self._arrow.HandleEvent = function(control, event)
if event.Type == 'ButtonPress' or event.Type == 'ButtonDClick' then
if control.state then
contractAnimation:Apply(self._info, self._top)
fadeAnimation:Apply(self._info)
self._arrow:SetText("v")
else
expandAnimation:Apply(self._info, self._top)
appearAnimation:Apply(self._info)
self._arrow:SetText("^")
end
control.state = not control.state
return true
end
end
self._arrow:SetFont("Arial", 16)

end,

__post_init = function(self)
self:_Layout()
end,

_Layout = function(self)


LayoutFor(self._bg)
:Fill(self)
:Color(bgColor)
:Alpha(0.4)
:DisableHitTest()

LayoutFor(self._top)
:AtRightTopIn(self)

LayoutFor(self._info)
:Top(self._top.Bottom)
:Right(self.Right)

LayoutFor(self._arrow)
:AtRightTopIn(self._top, 2, 2)
:Over(self._top)

LayoutFor(self)
:Width(self._top.Width)
:Bottom(self._info.Bottom)
end,

SetQuality = function(self, quality)
self._top:SetQuality(quality)
end,

Update = function(self, data, gameSpeed)
self._top:Update(data, gameSpeed)
end
}
13 changes: 2 additions & 11 deletions mods/4SB/modules/scoreboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@ ScoreBoard = Class(Group)
if isTitle then
self._title = TitlePanel(self)
self._title:SetQuality(SessionGetScenarioInfo().Options.Quality)
self._info = InfoPanel(self)
self._info:Setup()
end
end,

__post_init = function(self)
if self._title then
LayoutFor(self._title)
:AtRightTopIn(self)

LayoutFor(self._info)
:Right(self.Right)
:AnchorToBottom(self._title)
end
self:_InitArmyViews()
self:_Layout()
Expand All @@ -53,7 +47,7 @@ ScoreBoard = Class(Group)
if i == 1 then
if self._title then
LayoutFor(armyView)
:AnchorToBottom(self._info)
:AnchorToBottom(self._title)
:Right(self.Right)
else
LayoutFor(armyView)
Expand Down Expand Up @@ -180,11 +174,8 @@ ReplayScoreBoard = Class(ScoreBoard)
if self._title then
LayoutFor(self._title)
:AtRightTopIn(self)
LayoutFor(self._info)
:Right(self.Right)
:AnchorToBottom(self._title)
LayoutFor(self._armiesContainer)
:AnchorToBottom(self._info)
:AnchorToBottom(self._title)
:Right(self.Right)
else
LayoutFor(self._armiesContainer)
Expand Down

0 comments on commit 1b44b55

Please sign in to comment.