-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathPipboyOperationHandler.cpp
More file actions
425 lines (381 loc) · 18.2 KB
/
Copy pathPipboyOperationHandler.cpp
File metadata and controls
425 lines (381 loc) · 18.2 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#include "PipboyOperationHandler.h"
#include "vrcf/VRControllersHaptic.h"
#include "vrcf/VRControllersManager.h"
#include "Config.h"
#include "FRIK.h"
#include "common/CommonUtils.h"
#include "f4vr/scaleformUtils.h"
#include "utils.h"
using namespace RE::Scaleform;
using namespace std::chrono;
using namespace common;
namespace
{
bool isPrimaryTriggerPressed()
{
return vrcf::VRControllers.isPressed(vrcf::Hand::Primary, vr::k_EButton_SteamVR_Trigger);
}
bool isAButtonPressed()
{
return vrcf::VRControllers.isPressed(vrcf::Hand::Primary, vr::k_EButton_A);
}
bool isBButtonPressed()
{
return vrcf::VRControllers.isPressed(vrcf::Hand::Primary, vr::k_EButton_ApplicationMenu);
}
bool isPrimaryGripPressHeldDown()
{
return vrcf::VRControllers.isPressHeldDown(vrcf::Hand::Primary, vr::k_EButton_Grip);
}
bool isPrimaryThumbstickPressed()
{
return vrcf::VRControllers.isPressed(vrcf::Hand::Primary, vr::k_EButton_Axis0);
}
bool isWorldMapVisible(const GFx::Movie* root)
{
return f4vr::isElementVisible(root, "root.Menu_mc.CurrentPage.WorldMapHolder_mc");
}
std::string getCurrentMapPath(const GFx::Movie* root, const std::string& suffix = "")
{
return (isWorldMapVisible(root) ? "root.Menu_mc.CurrentPage.WorldMapHolder_mc" : "root.Menu_mc.CurrentPage.LocalMapHolder_mc") + suffix;
}
bool isQuestTabVisibleOnDataPage(const GFx::Movie* root)
{
return f4vr::isElementVisible(root, "root.Menu_mc.CurrentPage.QuestsTab_mc");
}
bool isQuestTabObjectiveListEnabledOnDataPage(const GFx::Movie* root)
{
GFx::Value var;
return root->GetVariable(&var, "root.Menu_mc.CurrentPage.QuestsTab_mc.ObjectivesList_mc.selectedIndex") && var.GetType() == GFx::Value::ValueType::kInt &&
var.GetInt() > -1;
}
bool isWorkshopsTabVisibleOnDataPage(const GFx::Movie* root)
{
return f4vr::isElementVisible(root, "root.Menu_mc.CurrentPage.WorkshopsTab_mc");
}
}
namespace frik
{
GFx::Movie* PipboyOperationHandler::getPipboyMenuRoot()
{
const auto menu = RE::UI::GetSingleton()->GetMenu("PipboyMenu");
return menu ? menu->uiMovie.get() : nullptr;
}
/**
* Is context menu message box popup is visible or not. Only one can be visible at a time.
*/
bool PipboyOperationHandler::isMessageHolderVisible(const GFx::Movie* root)
{
return root &&
(f4vr::isElementVisible(root, "root.Menu_mc.CurrentPage.MessageHolder_mc") || f4vr::isElementVisible(root, "root.Menu_mc.CurrentPage.QuestsTab_mc.MessageHolder_mc"));
}
/**
* Get the current open Pipboy page or null-opt if not open.
*/
std::optional<PipboyPage> PipboyOperationHandler::getCurrentPipboyPage(const GFx::Movie* root)
{
if (!root) {
return std::nullopt;
}
GFx::Value PBCurrentPage;
const bool getVariableSuccessful = root->GetVariable(&PBCurrentPage, "root.Menu_mc.DataObj.CurrentPage");
if (getVariableSuccessful && PBCurrentPage.GetType() != GFx::Value::ValueType::kUndefined) {
return static_cast<PipboyPage>(PBCurrentPage.GetUInt());
}
logger::sample("Failed to get current Pipboy page! getVariableSuccessful?({}) Type?({})",
getVariableSuccessful,
getVariableSuccessful ? static_cast<int>(PBCurrentPage.GetType()) : -1);
return std::nullopt;
}
/**
* Execute the given operation on the current Pipboy page.
*/
void PipboyOperationHandler::exec(const PipboyOperation operation)
{
const auto root = getPipboyMenuRoot();
if (!root) {
logger::warn<>("Pipboy operation failed, root is null");
return;
}
switch (operation) {
case PipboyOperation::GOTO_PREV_PAGE:
gotoPrevPage(root);
break;
case PipboyOperation::GOTO_NEXT_PAGE:
gotoNextPage(root);
break;
case PipboyOperation::GOTO_PREV_TAB:
gotoPrevTab(root);
break;
case PipboyOperation::GOTO_NEXT_TAB:
gotoNextTab(root);
break;
case PipboyOperation::MOVE_LIST_SELECTION_UP:
moveListSelectionUpDown(root, true);
break;
case PipboyOperation::MOVE_LIST_SELECTION_DOWN:
moveListSelectionUpDown(root, false);
break;
case PipboyOperation::PRIMARY_PRESS:
handlePrimaryControllerButtonsOperation(root, true);
break;
}
}
/**
* Operate Pipboy using primary hand controller.
*/
void PipboyOperationHandler::operate()
{
if (!g_config.enablePrimaryControllerPipboyUse || g_frik.isPipboyConfigurationModeAdjusting()) {
return;
}
// Use primary hand controller to operate Pipboy
if (const auto pipboyRoot = getPipboyMenuRoot()) {
handlePrimaryControllerThumbstickOperation(pipboyRoot);
handlePrimaryControllerButtonsOperation(pipboyRoot, false);
}
}
/**
* Execute operation on the currently active Pipboy UI by primary thumbstick input.
* On map page the map is moved.
* On other pages the list selection is moved up/down or tabs are changed left/right.
*/
void PipboyOperationHandler::handlePrimaryControllerThumbstickOperation(GFx::Movie* const root)
{
if (isPrimaryGripPressHeldDown()) {
return;
}
const auto doinantHandStick = vrcf::VRControllers.getThumbstickValue(vrcf::Hand::Primary);
if (fEqual(doinantHandStick.x, 0, 0.1f) && fEqual(doinantHandStick.y, 0, 0.1f)) {
return; // No movement, no operation
}
const auto currentPipboyPage = getCurrentPipboyPage(root);
if (currentPipboyPage == PipboyPage::MAP && !isMessageHolderVisible(root)) {
// Map Tab
GFx::Value akArgs[2];
akArgs[0] = doinantHandStick.x * -1;
akArgs[1] = doinantHandStick.y;
// Move Map
root->Invoke("root.Menu_mc.CurrentPage.WorldMapHolder_mc.PanMap", nullptr, akArgs, 2);
root->Invoke("root.Menu_mc.CurrentPage.LocalMapHolder_mc.PanMap", nullptr, akArgs, 2);
} else {
const auto direction = vrcf::VRControllers.getThumbstickPressedDirection(vrcf::Hand::Primary);
if (direction.has_value()) {
switch (direction.value()) {
case vrcf::Direction::Right:
if (!isMessageHolderVisible(root)) {
gotoNextTab(root);
}
break;
case vrcf::Direction::Left:
if (!isMessageHolderVisible(root)) {
gotoPrevTab(root);
}
break;
case vrcf::Direction::Up:
moveListSelectionUpDown(root, true);
break;
case vrcf::Direction::Down:
moveListSelectionUpDown(root, false);
break;
default:;
}
}
}
}
/**
* Execute operation on the currently active Pipboy UI by primary controller buttons.
* First thing is to detect is a message box is visible (context menu options) as message box and main lists are active at the
* same time. So, if the message box is visible we will only operate on the message box list and not the main list.
* See documentation: https://github.com/rollingrock/Fallout-4-VR-Body/wiki/Development-%E2%80%90-Pipboy-Controls
* @param root - Pipboy Scaleform UI root
* @param triggerPressed - true if operate as trigger is pressed regardless of controller input (used for physical handler)
*/
void PipboyOperationHandler::handlePrimaryControllerButtonsOperation(GFx::Movie* root, bool triggerPressed)
{
// page level navigation
const bool gripPressHeldDown = isPrimaryGripPressHeldDown();
if (!gripPressHeldDown && isAButtonPressed()) {
gotoPrevPage(root);
return;
}
if (!gripPressHeldDown && isBButtonPressed()) {
gotoNextPage(root);
return;
}
// include actual controller check
triggerPressed = triggerPressed || isPrimaryTriggerPressed();
// Context menu message box handling
if (triggerPressed && isMessageHolderVisible(root)) {
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
f4vr::doOperationOnScaleformMessageHolderList(root, "root.Menu_mc.CurrentPage.MessageHolder_mc", f4vr::ScaleformListOp::Select);
f4vr::doOperationOnScaleformMessageHolderList(root, "root.Menu_mc.CurrentPage.QuestsTab_mc.MessageHolder_mc", f4vr::ScaleformListOp::Select);
// prevent affecting the main list if message box is visible
return;
}
// Specific handling by current page
const auto pipboyPage = getCurrentPipboyPage(root);
if (pipboyPage.has_value()) {
switch (pipboyPage.value()) {
case PipboyPage::STATUS:
handlePrimaryControllerOperationOnStatusPage(root, triggerPressed);
break;
case PipboyPage::INVENTORY:
handlePrimaryControllerOperationOnInventoryPage(root, triggerPressed);
break;
case PipboyPage::DATA:
handlePrimaryControllerOperationOnDataPage(root, triggerPressed);
break;
case PipboyPage::MAP:
handlePrimaryControllerOperationOnMapPage(root, triggerPressed);
break;
case PipboyPage::RADIO:
handlePrimaryControllerOperationOnRadioPage(root, triggerPressed);
break;
default:;
}
}
if (vrcf::VRControllers.isPressed(vrcf::Hand::Primary, vr::EVRButtonId::k_EButton_Axis0)) {
root->Invoke("root.Menu_mc.CurrentPage.onMessageButtonPress()", nullptr, nullptr, 0);
}
}
void PipboyOperationHandler::gotoPrevPage(GFx::Movie* root)
{
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Tick);
root->Invoke("root.Menu_mc.gotoPrevPage", nullptr, nullptr, 0);
}
void PipboyOperationHandler::gotoNextPage(GFx::Movie* root)
{
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Tick);
root->Invoke("root.Menu_mc.gotoNextPage", nullptr, nullptr, 0);
}
void PipboyOperationHandler::gotoPrevTab(GFx::Movie* root)
{
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Tick);
root->Invoke("root.Menu_mc.gotoPrevTab", nullptr, nullptr, 0);
}
void PipboyOperationHandler::gotoNextTab(GFx::Movie* root)
{
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Tick);
root->Invoke("root.Menu_mc.gotoNextTab", nullptr, nullptr, 0);
}
/**
* Execute moving selection on the currently active list up or down.
* Whatever the list found to exist it will be moved, mostly we can "try" to move any of the lists and only the one that exists will be moved.
* On DATA page all 3 tabs can exist at the same time, so we need to check which one is visible to prevent working on a hidden one.
* First thing is to detect is a message box is visible (context menu options) as message box and main lists are active at the
* same time. So, if the message box is visible we will only operate on the message box list and not the main list.
*/
void PipboyOperationHandler::moveListSelectionUpDown(GFx::Movie* root, const bool moveUp)
{
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Tick);
const auto listOp = moveUp ? f4vr::ScaleformListOp::MoveUp : f4vr::ScaleformListOp::MoveDown;
if (isMessageHolderVisible(root)) {
f4vr::doOperationOnScaleformMessageHolderList(root, "root.Menu_mc.CurrentPage.MessageHolder_mc", listOp);
f4vr::doOperationOnScaleformMessageHolderList(root, "root.Menu_mc.CurrentPage.QuestsTab_mc.MessageHolder_mc", listOp);
// prevent affecting the main list if message box is visible
return;
}
// Inventory, Radio, Special, and Perks tabs
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.List_mc", listOp);
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.SPECIALTab_mc.List_mc", listOp);
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.PerksTab_mc.List_mc", listOp);
// Quest, Workshop, and Stats tabs exist at the same time, need to check which one is visible
if (isQuestTabVisibleOnDataPage(root)) {
// Quests tab has 2 lists for the main quests and quest objectives
const char* listPath =
isQuestTabObjectiveListEnabledOnDataPage(root) ? "root.Menu_mc.CurrentPage.QuestsTab_mc.ObjectivesList_mc" : "root.Menu_mc.CurrentPage.QuestsTab_mc.QuestsList_mc";
f4vr::doOperationOnScaleformList(root, listPath, listOp);
} else if (isWorkshopsTabVisibleOnDataPage(root)) {
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.WorkshopsTab_mc.List_mc", listOp);
} else {
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.StatsTab_mc.CategoryList_mc", listOp);
}
}
void PipboyOperationHandler::handlePrimaryControllerOperationOnStatusPage(GFx::Movie* root, const bool triggerPressed)
{
if (triggerPressed) {
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.SPECIALTab_mc.List_mc", f4vr::ScaleformListOp::Select);
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.PerksTab_mc.List_mc", f4vr::ScaleformListOp::Select);
}
}
void PipboyOperationHandler::handlePrimaryControllerOperationOnInventoryPage(GFx::Movie* root, const bool triggerPressed)
{
if (triggerPressed) {
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.List_mc", f4vr::ScaleformListOp::Select);
} else if (isPrimaryThumbstickPressed()) {
GFx::Value currentTab;
if (root->GetVariable(¤tTab, "root.Menu_mc.DataObj.CurrentTab")) {
// open context submenu
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
GFx::Value args[1];
args[0] = currentTab.GetUInt();
root->Invoke("root.Menu_mc.CurrentPage.CloseMessage", nullptr, nullptr, 0);
root->Invoke("root.Menu_mc.CurrentPage.OnOpenSubmenu", nullptr, args, 1);
}
}
}
/**
* On DATA page all 3 tabs can exist at the same time, so we need to check which one is visible to prevent working on a hidden one.
*/
void PipboyOperationHandler::handlePrimaryControllerOperationOnDataPage(GFx::Movie* root, const bool triggerPressed)
{
if (triggerPressed) {
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
if (isQuestTabVisibleOnDataPage(root)) {
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.QuestsTab_mc.QuestsList_mc", f4vr::ScaleformListOp::Select);
} else {
// open quest in map
f4vr::invokeScaleformProcessUserEvent(root, "root.Menu_mc.CurrentPage.WorkshopsTab_mc", "XButton");
}
} else if (isPrimaryThumbstickPressed()) {
// open context submenu
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
if (isQuestTabVisibleOnDataPage(root)) {
root->Invoke("root.Menu_mc.CurrentPage.QuestsTab_mc.OnOpenSubmenu", nullptr, nullptr, 0);
} else {
root->Invoke("root.Menu_mc.CurrentPage.WorkshopsTab_mc.OnOpenSubmenu", nullptr, nullptr, 0);
}
}
}
/**
* For handling map faster travel or marker setting we need to know if fast travel can be done using "bCanFastTravel"
* and then let the Pipboy code handle the rest by sending the right event to the currently visible map (world/local).
*/
void PipboyOperationHandler::handlePrimaryControllerOperationOnMapPage(GFx::Movie* root, const bool triggerPressed)
{
if (isPrimaryGripPressHeldDown()) {
if (triggerPressed) {
// switch world/local maps
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
f4vr::invokeScaleformProcessUserEvent(root, "root.Menu_mc.CurrentPage", "XButton");
} else {
// zoom map
const auto [_, primAxisY] = vrcf::VRControllers.getThumbstickValue(vrcf::Hand::Primary);
if (common::fNotEqual(primAxisY, 0, 0.5f)) {
GFx::Value args[1];
args[0] = primAxisY / 100.f;
root->Invoke(getCurrentMapPath(root, ".ZoomMap").c_str(), nullptr, args, 1);
}
}
} else if (triggerPressed) {
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
// handle fast travel, custom marker
const char* eventName = f4vr::getScaleformBool(root, getCurrentMapPath(root, ".bCanFastTravel").c_str()) ? "MapHolder:activate_marker" : "MapHolder:set_custom_marker";
f4vr::invokeScaleformDispatchEvent(root, getCurrentMapPath(root), eventName);
} else if (isPrimaryThumbstickPressed()) {
// open context submenu
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
root->Invoke("root.Menu_mc.CurrentPage.OnOpenSubmenu", nullptr, nullptr, 0);
}
}
void PipboyOperationHandler::handlePrimaryControllerOperationOnRadioPage(GFx::Movie* root, const bool triggerPressed)
{
if (triggerPressed) {
vrcf::VRHaptics.trigger(vrcf::Hand::Primary, vrcf::HapticPattern::Click);
f4vr::doOperationOnScaleformList(root, "root.Menu_mc.CurrentPage.List_mc", f4vr::ScaleformListOp::Select);
}
}
}