forked from civfanatics/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimSidePanelSupport.lua
117 lines (101 loc) · 4.19 KB
/
AnimSidePanelSupport.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
-- ===========================================================================
-- Contains scaffolding for animating in/out large panels from the side of
-- the screen.
-- ===========================================================================
function CreateScreenAnimation( slideAnimControl:table, onCloseCallback:ifunction )
if slideAnimControl == nil then
UI.DataError("Cannot create kAnim for "..ContextPtr:GetID()..", no slide animation control passed into create.");
return nil;
end
local kAnim:table = {};
kAnim["_animControl"] = slideAnimControl;
kAnim["_closeCallback"] = onCloseCallback;
-- ===========================================================================
-- CONSTANTS
-- ===========================================================================
kAnim.TOP_BAR_SIZE = 30;
-- ===========================================================================
-- MEMBERS
-- ===========================================================================
kAnim.State = {
Closed = "CLOSED",
In = "IN",
Open = "OPEN",
Out = "OUT"
};
kAnim.m_state = kAnim.State.Closed;
-- ===========================================================================
-- Animate in
-- ===========================================================================
kAnim.Show = function()
if(kAnim.m_state ~= kAnim.State.Open and kAnim.m_state ~= kAnim.State.In) then
kAnim.m_state = kAnim.State.In;
ContextPtr:SetHide(false);
kAnim["_animControl"]:SetToBeginning();
kAnim["_animControl"]:RegisterEndCallback( kAnim.OnEndIn );
kAnim["_animControl"]:Play();
end
end
-- ===========================================================================
-- Animate out
-- ===========================================================================
kAnim.Hide = function()
if(kAnim.m_state ~= kAnim.State.Closed and kAnim.m_state ~= kAnim.State.Out) then
kAnim.m_state = kAnim.State.Out;
kAnim["_animControl"]:RegisterEndCallback( kAnim.OnEndOut );
kAnim["_animControl"]:Reverse();
if(kAnim["_closeCallback"] ~= nil) then
kAnim["_closeCallback"]();
end
end
end
-- ===========================================================================
-- Return whether panel is currently visible (or animating in)
-- ===========================================================================
kAnim.IsVisible = function()
return kAnim.m_state == kAnim.State.Open or kAnim.m_state == kAnim.State.In;
end
-- ===========================================================================
-- Callback when completeing a show.
-- ===========================================================================
kAnim.OnEndIn = function()
kAnim.m_state = kAnim.State.Open;
kAnim["_animControl"]:ClearEndCallback();
end
-- ===========================================================================
-- Callback when completeing a hide.
-- ===========================================================================
kAnim.OnEndOut = function()
kAnim.m_state = kAnim.State.Closed;
kAnim["_animControl"]:ClearEndCallback();
ContextPtr:SetHide(true);
end
-- ===========================================================================
-- Resize area based on screen
-- ===========================================================================
kAnim.Resize = function()
local width:number , height:number = UIManager:GetScreenSizeVal();
kAnim["_animControl"]:SetSizeY( height - kAnim.TOP_BAR_SIZE );
end
-- ===========================================================================
-- UI EVENT
-- ===========================================================================
kAnim.OnUpdateUI = function(type:number, tag:string, iData1:number, iData2:number, strData1:string)
if type == SystemUpdateUI.ScreenResize then
kAnim.Resize();
end
end
-- ===========================================================================
-- KEYBOARD INPUT UI EVENT
-- ===========================================================================
kAnim.OnInputHandler = function( input:table )
if (input:GetMessageType() == KeyEvents.KeyUp and input:GetKey() == Keys.VK_ESCAPE) then
kAnim.Hide();
return true;
end
return false;
end
-- Resize after construction
kAnim.Resize();
return kAnim;
end