Repository navigation
Expand file tree
/
Copy pathEnhancedInputTL.lua
More file actions
193 lines (172 loc) · 4.41 KB
/
Copy pathEnhancedInputTL.lua
File metadata and controls
193 lines (172 loc) · 4.41 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
local threadLoop <const> = require("threadLoop")
local Vec2 <const> = require("Vec2")
local ImGui <const> = require("ImGui")
local App <const> = require("App")
local loop <const> = require("loop")
local InputManager <const> = require("InputManager")
local Node <const> = require("Node")
local Keyboard = require("Keyboard")
local KeyName = Keyboard.KeyName
local Controller = require("Controller")
local ButtonName = Controller.ButtonName
local Trigger <const> = InputManager.Trigger
local function QTEContext(keyName, buttonName, timeWindow)
return {
QTE = Trigger.Sequence({
Trigger.Selector({
Trigger.Selector({
Trigger.KeyPressed(keyName),
Trigger.Block(Trigger.AnyKeyPressed()),
}),
Trigger.Selector({
Trigger.ButtonPressed(buttonName),
Trigger.Block(Trigger.AnyButtonPressed()),
}),
}),
Trigger.Selector({
Trigger.KeyTimed(keyName, timeWindow),
Trigger.ButtonTimed(buttonName, timeWindow),
}),
}),
}
end
local inputManager = InputManager.CreateManager({
Default = {
Confirm = Trigger.Hold({
{ button = "y" },
{ key = "Return" },
}, 1),
MoveDown = Trigger.Pressed({
{ button = "dpdown" },
{ key = "S" },
}),
},
Test = {
Confirm = Trigger.Hold({
{ button = "x" },
{ key = "LCtrl" },
}, 0.3),
},
Phase1 = QTEContext("J", "a", 3),
Phase2 = QTEContext("K", "b", 2),
Phase3 = QTEContext("L", "x", 1),
})
inputManager:pushContext("Default")
InputManager.CreateGamePad({ inputManager = inputManager })
local phase = "None"
local text = ""
local holdTime = 0.0
local node = Node()
inputManager:on("Confirm", function(event)
if event.state == "Completed" then
holdTime = 1
elseif event.state == "Ongoing" then
holdTime = event.progress
end
end)
inputManager:onCompleted("MoveDown", function(event)
print(event.state, event.progress, event.value)
end)
inputManager:on("QTE", function(event)
local state = event.state
local progress = event.progress
if phase == "Phase1" then
if state == "Canceled" then
phase = "None"
inputManager:popContext()
text = "Failed!"
holdTime = progress
elseif state == "Completed" then
phase = "Phase2"
inputManager:pushContext("Phase2")
text = "Button B or Key K"
elseif state == "Ongoing" then
holdTime = progress
end
elseif phase == "Phase2" then
if state == "Canceled" then
phase = "None"
inputManager:popContext(2);
text = "Failed!"
holdTime = progress
elseif state == "Completed" then
phase = "Phase3"
inputManager:pushContext("Phase3")
text = "Button X or Key L"
elseif state == "Ongoing" then
holdTime = progress
end
elseif phase == "Phase3" then
if state == "Canceled" or state == "Completed" then
phase = "None"
inputManager:popContext(3)
text = state == "Completed" and "Success!" or "Failed!"
holdTime = progress
elseif state == "Ongoing" then
holdTime = progress
end
end
end)
local function QTEButton()
if ImGui.Button("Start QTE") then
phase = "Phase1"
text = "Button A or Key J"
inputManager:pushContext("Phase1")
end
end
local countDownFlags = {
"NoResize",
"NoSavedSettings",
"NoTitleBar",
"NoMove",
"AlwaysAutoResize",
}
node:schedule(loop(function()
local visualSize = App.visualSize
local width = visualSize.width
local height = visualSize.height
ImGui.SetNextWindowPos(Vec2(width / 2 - 160, height / 2 - 100))
ImGui.SetNextWindowSize(Vec2(300, 100), "Always")
ImGui.Begin("CountDown", countDownFlags, function()
if phase == "None" then
QTEButton()
else
ImGui.BeginDisabled(QTEButton)
end
ImGui.SameLine()
ImGui.Text(text)
ImGui.ProgressBar(holdTime, Vec2(-1, 30))
end)
return false
end))
local checked = false
local windowFlags = {
"NoDecoration",
"AlwaysAutoResize",
"NoSavedSettings",
"NoFocusOnAppearing",
"NoMove",
}
threadLoop(function()
local width = App.visualSize.width
ImGui.SetNextWindowBgAlpha(0.35)
ImGui.SetNextWindowPos(Vec2(width - 10, 10), "Always", Vec2(1, 0))
ImGui.SetNextWindowSize(Vec2(240, 0), "FirstUseEver")
ImGui.Begin("EnhancedInput", windowFlags, function()
ImGui.Text("Enhanced Input (Teal)")
ImGui.Separator()
ImGui.TextWrapped("Change input context to alter input mapping")
if phase == "None" then
local changed, result = ImGui.Checkbox("hold X to confirm (instead Y)", checked)
if changed then
if checked then
inputManager:popContext()
else
inputManager:pushContext("Test")
end
checked = result
end
end
end)
return false
end)