-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPauseMenuUI.lua
More file actions
174 lines (139 loc) · 6.89 KB
/
PauseMenuUI.lua
File metadata and controls
174 lines (139 loc) · 6.89 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
-- Main table for "PauseMenuUI" data and functions.
PauseMenuUI = {
Menus = {}, -- menu cache, so we can have more than one menu :p
Internal = {Data = {BlockedMenus = {}, CurrentMenu = nil, MenuReady = false, CurrentMenuFocus = 0, ColumnPool = {}}} -- Internal code that SHOULD be kept to local script use ONLY
}
PauseMenuUI.Internal.PlaySound = function(Audio)
PlaySoundFrontend(-1, Audio, 'HUD_FRONTEND_DEFAULT_SOUNDSET', 1)
end
PauseMenuUI.Internal.IsColumnBlocked = function(Column)
return PauseMenuUI.Internal.Data.BlockedMenus[tostring(Column)] or false
end
PauseMenuUI.BlockMenu = function(...)
for i, var in ipairs({...}) do
PauseMenuUI.Internal.Data.BlockedMenus[var] = true
end
end
PauseMenuUI.SetMenuFocus = function(Data)
if not PauseMenuUI.Internal.IsColumnBlocked(Data) then
PauseMenuUI.Internal.Data.ForceFlush = true -- just flush the buttons incase of left-over buttons get left somehow
PauseMenuUI.Internal.Data.CurrentMenuFocus = Data
BeginScaleformMovieMethodOnFrontend('SET_COLUMN_FOCUS')
ScaleformMovieMethodAddParamInt(Data) --// column index // _loc7_
ScaleformMovieMethodAddParamInt(1)-- // highlightIndex // _loc6_
ScaleformMovieMethodAddParamInt(1) --// scriptSetUniqID // _loc4_
ScaleformMovieMethodAddParamInt(0) --// scriptSetMenuState // _loc5_
EndScaleformMovieMethod()
end
end
PauseMenuUI.CloseAny = function()
PauseMenuUI.Internal.CloseMenu()
end
PauseMenuUI.IsAnyMenuOpen = function()
return PauseMenuUI.Internal.Data.CurrentMenu or false
end
PauseMenuUI.Close = function(MenuID)
if PauseMenuUI.Internal.Data.CurrentMenu == MenuID then
PauseMenuUI.Internal.CloseMenu()
end
end
PauseMenuUI.Internal.CloseMenu = function()
SetFrontendActive(false)
TriggerScreenblurFadeOut(1000)
PauseMenuUI.Internal.PlaySound('QUIT')
PauseMenuUI.Internal.Data.Buttons = {['0'] = {}, ['3'] = {}}
PauseMenuUI.Internal.Data.ButtonRegister = {['0'] = 0, ['3'] = 0}
PauseMenuUI.Internal.Data.RegisteredButtons = 0
PauseMenuUI.Internal.Data.TextBox = {}
PauseMenuUI.Internal.Data.Details = {}
PauseMenuUI.Internal.Data.BlockedColumn = {}
PauseMenuUI.Internal.Data.CurrentMenuFocus = 0
PauseMenuUI.Internal.Data.ColumnPool = {}
PauseMenuUI.Internal.Data.CurrentMenu = nil
PauseMenuUI.Internal.Data.MenuReady = false
end
PauseMenuUI.Open = function(MenuID)
if PauseMenuUI.Internal.Data.CurrentMenu == nil then
assert(PauseMenuUI.Menus[MenuID] ~= nil, 'A menu with ID '..MenuID..' is not non-existing.')
PauseMenuUI.Internal.Data.RegisteredButtons = 0
PauseMenuUI.Internal.Data.LoadedButtons = 0
PauseMenuUI.Internal.Data.CurrentMenuHeaderFocus = 0
TriggerScreenblurFadeIn(1000)
ActivateFrontendMenu('FE_MENU_VERSION_CORONA', false, -1)
PauseMenuActivateContext('FE_MENU_VERSION_CORONA')
Wait(100) -- Requires a wait, because menu needs to be opened before it can be "edited"
PauseMenuUI.Internal.Init(PauseMenuUI.Menus[MenuID].Header)
PauseMenuUI.Internal.Data.CurrentMenu = MenuID
CreateThread(function()
Wait(2000)
PauseMenuUI.Internal.Data.MenuReady = true
end)
end
end
-- Create a menu, this is the "root" of the menu, MenuID is required to be a string.
PauseMenuUI.CreateMenu = function(MenuID, Title, Subtitle, MenuHeader, ListHeader, DetailHeader, CanMenuBeIndexed, CanMenuBeManuallyClosed)
assert(PauseMenuUI.Menus[MenuID] == nil, 'A menu with ID '..MenuID..' is already existing.')
assert(type(MenuID) == 'string', '"MenuID" is required to be a string.')
PauseMenuUI.Menus[MenuID] = {
Header = {
Title = Title,
Subtitle = Subtitle,
MenuHeader = MenuHeader,
ListHeader = ListHeader,
DetailHeader = DetailHeader,
AllowHeadIndex = CanMenuBeIndexed or false,
CanMenuBeManuallyClosed = CanMenuBeManuallyClosed or false,
},
}
return MenuID
end
-- Main menu handle, handle your menu inside of this!
PauseMenuUI.Handle = function(MenuID, cb)
CreateThread(function()
while true do Wait(1)
if PauseMenuUI.Internal.Data.CurrentMenu == MenuID and PauseMenuUI.Internal.Data.MenuReady then
cb(PauseMenuUI.Internal.Data.CurrentMenuHeaderFocus)
-- Handle buttons in real-time
if (PauseMenuUI.Internal.Data.LoadedButtons or 0) < PauseMenuUI.Internal.Data.RegisteredButtons or PauseMenuUI.Internal.Data.ForceFlush then
PauseMenuUI.Internal.RenderButtons()
if PauseMenuUI.Internal.Data.ForceFlush then
PauseMenuUI.Internal.Data.Buttons = {['0'] = {}, ['3'] = {}}
PauseMenuUI.Internal.Data.LoadedButtons = 0
end
PauseMenuUI.Internal.Data.ForceFlush = false
elseif (PauseMenuUI.Internal.Data.LoadedButtons or 0) > PauseMenuUI.Internal.Data.RegisteredButtons then
PauseMenuUI.Internal.Data.Buttons = {['0'] = {}, ['3'] = {}}
PauseMenuUI.Internal.Data.LoadedButtons = 0
end
PauseMenuUI.Internal.Data.RegisteredButtons = 0
PauseMenuUI.Internal.Data.ButtonRegister = {['0'] = 0, ['3'] = 0}
-- Handle details page
PauseMenuUI.Internal.RenderDetails()
PauseMenuUI.Internal.Data.Details = {}
-- Handle textbox page(s)
PauseMenuUI.Internal.RenderTextBox()
PauseMenuUI.Internal.Data.TextBox = {}
-- Handle locked menu indexes
PauseMenuUI.Internal.RenderLockedMenus()
PauseMenuUI.Internal.Data.BlockedMenus = {}
-- Handle focus for top-header-menu
if PauseMenuUI.Menus[MenuID].Header.AllowHeadIndex then
PauseMenuUI.Internal.HandleHeaderMenuFocus()
end
-- If menu can be manually closed then can close with "ESC".
if PauseMenuUI.Menus[MenuID].Header.CanMenuBeManuallyClosed then
PauseMenuUI.Internal.HandleManuallyClose()
end
end
end
end)
end
-- Set the main header details, this should be done right after creating the main menu.
PauseMenuUI.SetHeaderDetails = function(MenuID, ShowPlayerCard, ShowHeaderStrip, HeaderColor, StripColor, MenuFocus)
assert(PauseMenuUI.Menus[MenuID] ~= nil, 'A menu with ID '..MenuID..' is not non-existing.')
PauseMenuUI.Menus[MenuID].Header.ShowPlayerCard = ShowPlayerCard
PauseMenuUI.Menus[MenuID].Header.ShowHeaderStrip = ShowHeaderStrip
PauseMenuUI.Menus[MenuID].Header.HeaderColor = HeaderColor
PauseMenuUI.Menus[MenuID].Header.StripColor = StripColor
PauseMenuUI.Menus[MenuID].Header.MenuFocus = MenuFocus
end