-
Notifications
You must be signed in to change notification settings - Fork 1
/
ifs_opt_pckeyboard.lua
228 lines (187 loc) · 6.68 KB
/
ifs_opt_pckeyboard.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
-- pc keyboard options screen
-----------------------------------
-- key press popup
ifs_opt_pckeyboard_Popup_KeyPress = NewPopup {
ScreenRelativeX = 0.5, -- centered onscreen
ScreenRelativeY = 0.5,
height = 100,
width = 180,
ZPos = 50,
title = NewIFText {
string = "ifs.GameOpt.pc_keybindpopup",
font = "meu_myriadpro_small",
textw = 160,
texth = 80,
y = -40,
inert = 1,
},
buttons = NewIFContainer {
},
Input_GeneralUp = function(this)
end,
Input_GeneralDown = function(this)
end,
Input_GeneralLeft = function(this)
end,
Input_GeneralRight = function(this)
end,
Enter = function(this)
print("Entered the enter function")
this.gDelay = 0.35
end,
Input_Back = function(this)
end,
Update = function(this, fDt)
gIFShellScreenTemplate_fnUpdate(this, fDt) -- call base class
this.gDelay = this.gDelay - fDt
if (this.gDelay > 0.0) then
return
end
rtype = ScriptCB_SetBinding(ifs_opt_pckeyboard_listbox_layout.SelectedIdx)
if(rtype == 1) then
print("Detected Input")
ifs_opt_pckeyboard.RepaintListbox(ifs_opt_pckeyboard)
gPopup_fnInput_Back(this)
end
end
}
--AddVerticalButtons(ifs_opt_pckeyboard_Popup_KeyPress.buttons,Vertical_YesNoButtons_layout)
CreatePopupInC(ifs_opt_pckeyboard_Popup_KeyPress,"ifs_opt_pckeyboard_Popup_KeyPress")
---------------------------------------------
-- Helper function. Given a layout (x,y,width, height), returns a
-- fully-built item.
function ifs_opt_pckeyboard_Listbox_CreateItem(layout)
-- Make a coordinate system pegged to the top-left of where the cursor would go.
local Temp = NewIFContainer {
x = layout.x - 0.5 * layout.width, y=layout.y - 10
}
Temp.actionStr = NewIFText{
x = 10, y = 0, textw = 0.25 * layout.width, valign = "vcenter", halign = "left", font = "meu_myriadpro_small",
--ColorR= 255, ColorG = 255, ColorB = 255,
flashy = 0,
texth = layout.height,
}
Temp.keyStr = NewIFText{
x = layout.width*.33, y = 0,
textw = 0.75 * layout.width, valign = "vcenter", halign = "left", font = "meu_myriadpro_small",
ColorR= 255, ColorG = 255, ColorB = 255,
flashy = 0,
texth = layout.height,
}
return Temp
end
-- Helper function. For a destination item (previously created w/
-- CreateItem), fills it in with data, which may be nil (==blank it)
function ifs_opt_pckeyboard_Listbox_PopulateItem(Dest, Data, bSelected, iColorR, iColorG, iColorB, fAlpha)
if(Data) then
IFText_fnSetString(Dest.actionStr,Data.actionStr)
IFText_fnSetString(Dest.keyStr,Data.keyStr)
IFObj_fnSetColor(Dest.actionStr, iColorR, iColorG, iColorB)
IFObj_fnSetAlpha(Dest.actionStr, fAlpha)
IFObj_fnSetColor(Dest.keyStr, iColorR, iColorG, iColorB)
IFObj_fnSetAlpha(Dest.keyStr, fAlpha)
end
IFObj_fnSetVis(Dest,Data) -- Show if there are contents
end
ifs_opt_pckeyboard_listbox_layout = {
showcount = 20,
-- yTop = -130 + 13,
yHeight = 22,
ySpacing = 7,
width = 430,
x = 0,
slider = 1,
CreateFn = ifs_opt_pckeyboard_Listbox_CreateItem,
PopulateFn = ifs_opt_pckeyboard_Listbox_PopulateItem,
font = "meu_myriadpro_small",
}
ifs_opt_pckeyboard_listbox_contents = {
-- { actionStr = "Fire", keyStr = "Ctrl"},
}
ifs_opt_pckeyboard = NewIFShellScreen {
nologo = 1,
bNohelptext = 1,
movieIntro = nil, -- played before the screen is displayed
movieBackground = nil, -- played while the screen is displayed
title = NewIFText {
string = "ifs.GameOpt.pc_keyconfigtitle",
font = "meu_myriadpro_small",
y = 0,
textw = 460, -- center on screen. Fixme: do real centering!
ScreenRelativeX = 0.5, -- center
ScreenRelativeY = 0, -- top
ColorR= 255, ColorG = 255, ColorB = 255, -- Something that's readable!
},
Enter = function(this)
-- Reset listbox, show it. [Remember, Lua starts at 1!]
ifs_opt_pckeyboard_listbox_layout.FirstShownIdx = 1
ifs_opt_pckeyboard_listbox_layout.SelectedIdx = 1
ifs_opt_pckeyboard_listbox_layout.CursorIdx = 1
ScriptCB_GetKeyBoardCmds()
ListManager_fnFillContents(this.listbox,ifs_opt_pckeyboard_listbox_contents,ifs_opt_pckeyboard_listbox_layout)
end,
-- Accept button bumps the page
Input_Accept = function(this)
-- If base class handled this work, then we're done
if(gShellScreen_fnDefaultInputAccept(this)) then
return
end
ifs_opt_pckeyboard_Popup_KeyPress:fnActivate(1)
end,
Input_GeneralUp = function(this)
-- If base class handled this work, then we're done
if(gShellScreen_fnDefaultInputUp(this)) then
return
end
-- ListManager_fnNavUp(this.listbox,ifs_opt_pckeyboard_listbox_contents,ifs_opt_pckeyboard_listbox_layout)
end,
Input_GeneralDown = function(this)
-- If base class handled this work, then we're done
if(gShellScreen_fnDefaultInputDown(this)) then
return
end
-- ListManager_fnNavDown(this.listbox,ifs_opt_pckeyboard_listbox_contents,ifs_opt_pckeyboard_listbox_layout)
end,
Input_GeneralLeft = function(this)
end,
Input_GeneralRight = function(this)
end,
Input_Misc2 = function(this)
ListManager_fnNavDown(this.listbox,ifs_opt_pckeyboard_listbox_contents,ifs_opt_pckeyboard_listbox_layout)
end,
Input_Misc1 = function(this)
ListManager_fnNavUp(this.listbox,ifs_opt_pckeyboard_listbox_contents,ifs_opt_pckeyboard_listbox_layout)
end,
-- Update = function(this, fDt)
-- -- Call default base class's update function (make button bounce)
-- gIFShellScreenTemplate_fnUpdate(this,fDt)
-- end,
-- Callback (from C++) to repaint the listbox with the current contents
-- in the global stats_listbox_contents
RepaintListbox = function(this)
ScriptCB_GetKeyBoardCmds()
ListManager_fnFillContents(this.listbox,ifs_opt_pckeyboard_listbox_contents,ifs_opt_pckeyboard_listbox_layout)
end,
}
-- Helper function, sets up parts of this screen that need any
-- programmatic work (i.e. scaling to screensize)
function ifs_opt_pckeyboard_fnInitScreen(this)
-- Inset slightly from fulls screen size
local w,h = ScriptCB_GetSafeScreenInfo()
w = w * 0.95
h = h * 0.92
this.listbox = NewButtonWindow { ZPos = 200, x=0, y = 0,
ScreenRelativeX = 0.5, -- center
ScreenRelativeY = 0.54, -- middle of screen
width = w,
height = h,
}
ifs_opt_pckeyboard_listbox_layout.width = w - 50
ifs_opt_pckeyboard_listbox_layout.showcount = math.floor(h / (ifs_opt_pckeyboard_listbox_layout.yHeight + ifs_opt_pckeyboard_listbox_layout.ySpacing)) - 1
ListManager_fnInitList(ifs_opt_pckeyboard.listbox,ifs_opt_pckeyboard_listbox_layout)
end
ifs_opt_pckeyboard_fnInitScreen(ifs_opt_pckeyboard)
AddIFScreen(ifs_opt_pckeyboard,"ifs_opt_pckeyboard")