mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:57:59 +02:00
Merge pull request #8974 from huffman/feat/help-select-xbox-tab
Update help window to auto select xbox or vive controller tab on availability of device
This commit is contained in:
commit
00a94bdd6d
12 changed files with 88 additions and 10 deletions
|
@ -50,21 +50,33 @@
|
||||||
function showKbm() {
|
function showKbm() {
|
||||||
document.getElementById("main_image").setAttribute("src", "img/controls-help-keyboard.png");
|
document.getElementById("main_image").setAttribute("src", "img/controls-help-keyboard.png");
|
||||||
}
|
}
|
||||||
function showHandControllers() {
|
function showViveControllers() {
|
||||||
document.getElementById("main_image").setAttribute("src", "img/controls-help-vive.png");
|
document.getElementById("main_image").setAttribute("src", "img/controls-help-vive.png");
|
||||||
}
|
}
|
||||||
function showGameController() {
|
function showXboxController() {
|
||||||
document.getElementById("main_image").setAttribute("src", "img/controls-help-gamepad.png");
|
document.getElementById("main_image").setAttribute("src", "img/controls-help-gamepad.png");
|
||||||
}
|
}
|
||||||
|
function load() {
|
||||||
|
console.log("In help.html: ", window.location.href);
|
||||||
|
parts = window.location.href.split("?");
|
||||||
|
if (parts.length > 0) {
|
||||||
|
var defaultTab = parts[1];
|
||||||
|
if (defaultTab == "xbox") {
|
||||||
|
showXboxController();
|
||||||
|
} else if (defaultTab == "vive") {
|
||||||
|
showViveControllers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body onload="load()">
|
||||||
<div id="image_area">
|
<div id="image_area">
|
||||||
<img id="main_image" src="img/controls-help-keyboard.png" width="1024px" height="720px"></img>
|
<img id="main_image" src="img/controls-help-keyboard.png" width="1024px" height="720px"></img>
|
||||||
<a href="#" id="kbm_button" onmousedown="showKbm()"></a>
|
<a href="#" id="kbm_button" onmousedown="showKbm()"></a>
|
||||||
<a href="#" id="hand_controllers_button" onmousedown="showHandControllers()"></a>
|
<a href="#" id="hand_controllers_button" onmousedown="showViveControllers()"></a>
|
||||||
<a href="#" id="game_controller_button" onmousedown="showGameController()"></a>
|
<a href="#" id="game_controller_button" onmousedown="showXboxController()"></a>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
@ -2161,7 +2161,17 @@ void Application::aboutApp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::showHelp() {
|
void Application::showHelp() {
|
||||||
InfoView::show(INFO_HELP_PATH);
|
static const QString QUERY_STRING_XBOX = "xbox";
|
||||||
|
static const QString QUERY_STRING_VIVE = "vive";
|
||||||
|
|
||||||
|
QString queryString = "";
|
||||||
|
if (PluginUtils::isViveControllerAvailable()) {
|
||||||
|
queryString = QUERY_STRING_VIVE;
|
||||||
|
} else if (PluginUtils::isXboxControllerAvailable()) {
|
||||||
|
queryString = QUERY_STRING_XBOX;
|
||||||
|
}
|
||||||
|
|
||||||
|
InfoView::show(INFO_HELP_PATH, false, queryString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::resizeEvent(QResizeEvent* event) {
|
void Application::resizeEvent(QResizeEvent* event) {
|
||||||
|
|
|
@ -21,6 +21,9 @@ public:
|
||||||
virtual void pluginFocusOutEvent() = 0;
|
virtual void pluginFocusOutEvent() = 0;
|
||||||
virtual void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) = 0;
|
virtual void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) = 0;
|
||||||
|
|
||||||
|
// Some input plugins are comprised of multiple subdevices (SDL2, for instance).
|
||||||
|
// If an input plugin is only a single device, it will only return it's primary name.
|
||||||
|
virtual QStringList getSubdeviceNames() { return { getName() }; };
|
||||||
virtual bool isHandController() const = 0;
|
virtual bool isHandController() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,3 +32,26 @@ bool PluginUtils::isHandControllerAvailable() {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool isSubdeviceContainingNameAvailable(QString name) {
|
||||||
|
for (auto& inputPlugin : PluginManager::getInstance()->getInputPlugins()) {
|
||||||
|
if (inputPlugin->isActive()) {
|
||||||
|
auto subdeviceNames = inputPlugin->getSubdeviceNames();
|
||||||
|
for (auto& subdeviceName : subdeviceNames) {
|
||||||
|
if (subdeviceName.contains(name)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool PluginUtils::isViveControllerAvailable() {
|
||||||
|
return isSubdeviceContainingNameAvailable("OpenVR");
|
||||||
|
};
|
||||||
|
|
||||||
|
bool PluginUtils::isXboxControllerAvailable() {
|
||||||
|
return isSubdeviceContainingNameAvailable("X360 Controller");
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,4 +16,6 @@ class PluginUtils {
|
||||||
public:
|
public:
|
||||||
static bool isHMDAvailable(const QString& pluginName = "");
|
static bool isHMDAvailable(const QString& pluginName = "");
|
||||||
static bool isHandControllerAvailable();
|
static bool isHandControllerAvailable();
|
||||||
|
static bool isViveControllerAvailable();
|
||||||
|
static bool isXboxControllerAvailable();
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,7 +37,7 @@ QString fetchVersion(const QUrl& url) {
|
||||||
return r.trimmed();
|
return r.trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoView::show(const QString& path, bool firstOrChangedOnly) {
|
void InfoView::show(const QString& path, bool firstOrChangedOnly, QString urlQuery) {
|
||||||
static bool registered{ false };
|
static bool registered{ false };
|
||||||
if (!registered) {
|
if (!registered) {
|
||||||
registerType();
|
registerType();
|
||||||
|
@ -49,6 +49,8 @@ void InfoView::show(const QString& path, bool firstOrChangedOnly) {
|
||||||
} else {
|
} else {
|
||||||
url = QUrl::fromLocalFile(path);
|
url = QUrl::fromLocalFile(path);
|
||||||
}
|
}
|
||||||
|
url.setQuery(urlQuery);
|
||||||
|
|
||||||
if (firstOrChangedOnly) {
|
if (firstOrChangedOnly) {
|
||||||
const QString lastVersion = infoVersion.get();
|
const QString lastVersion = infoVersion.get();
|
||||||
const QString version = fetchVersion(url);
|
const QString version = fetchVersion(url);
|
||||||
|
|
|
@ -22,7 +22,7 @@ class InfoView : public QQuickItem {
|
||||||
static const QString NAME;
|
static const QString NAME;
|
||||||
public:
|
public:
|
||||||
static void registerType();
|
static void registerType();
|
||||||
static void show(const QString& path, bool firstOrChangedOnly = false);
|
static void show(const QString& path, bool firstOrChangedOnly = false, QString urlQuery = "");
|
||||||
|
|
||||||
InfoView(QQuickItem* parent = nullptr);
|
InfoView(QQuickItem* parent = nullptr);
|
||||||
QUrl url();
|
QUrl url();
|
||||||
|
|
|
@ -31,6 +31,8 @@ public:
|
||||||
|
|
||||||
const QString& getName() const { return _name; }
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
|
SDL_GameController* getGameController() { return _sdlGameController; }
|
||||||
|
|
||||||
// Device functions
|
// Device functions
|
||||||
virtual controller::Input::NamedVector getAvailableInputs() const override;
|
virtual controller::Input::NamedVector getAvailableInputs() const override;
|
||||||
virtual QString getDefaultMappingConfig() const override;
|
virtual QString getDefaultMappingConfig() const override;
|
||||||
|
|
|
@ -65,8 +65,10 @@ void SDL2Manager::init() {
|
||||||
_openJoysticks[id] = joystick;
|
_openJoysticks[id] = joystick;
|
||||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||||
userInputMapper->registerDevice(joystick);
|
userInputMapper->registerDevice(joystick);
|
||||||
|
auto name = SDL_GameControllerName(controller);
|
||||||
|
_subdeviceNames << name;
|
||||||
emit joystickAdded(joystick.get());
|
emit joystickAdded(joystick.get());
|
||||||
emit subdeviceConnected(getName(), SDL_GameControllerName(controller));
|
emit subdeviceConnected(getName(), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +80,10 @@ void SDL2Manager::init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList SDL2Manager::getSubdeviceNames() {
|
||||||
|
return _subdeviceNames;
|
||||||
|
}
|
||||||
|
|
||||||
void SDL2Manager::deinit() {
|
void SDL2Manager::deinit() {
|
||||||
_openJoysticks.clear();
|
_openJoysticks.clear();
|
||||||
|
|
||||||
|
@ -157,15 +163,19 @@ void SDL2Manager::pluginUpdate(float deltaTime, const controller::InputCalibrati
|
||||||
Joystick::Pointer joystick = std::make_shared<Joystick>(id, controller);
|
Joystick::Pointer joystick = std::make_shared<Joystick>(id, controller);
|
||||||
_openJoysticks[id] = joystick;
|
_openJoysticks[id] = joystick;
|
||||||
userInputMapper->registerDevice(joystick);
|
userInputMapper->registerDevice(joystick);
|
||||||
|
QString name = SDL_GameControllerName(controller);
|
||||||
emit joystickAdded(joystick.get());
|
emit joystickAdded(joystick.get());
|
||||||
emit subdeviceConnected(getName(), SDL_GameControllerName(controller));
|
emit subdeviceConnected(getName(), name);
|
||||||
|
_subdeviceNames << name;
|
||||||
}
|
}
|
||||||
} else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
|
} else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
|
||||||
if (_openJoysticks.contains(event.cdevice.which)) {
|
if (_openJoysticks.contains(event.cdevice.which)) {
|
||||||
Joystick::Pointer joystick = _openJoysticks[event.cdevice.which];
|
Joystick::Pointer joystick = _openJoysticks[event.cdevice.which];
|
||||||
_openJoysticks.remove(event.cdevice.which);
|
_openJoysticks.remove(event.cdevice.which);
|
||||||
userInputMapper->removeDevice(joystick->getDeviceID());
|
userInputMapper->removeDevice(joystick->getDeviceID());
|
||||||
|
QString name = SDL_GameControllerName(joystick->getGameController());
|
||||||
emit joystickRemoved(joystick.get());
|
emit joystickRemoved(joystick.get());
|
||||||
|
_subdeviceNames.removeOne(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
bool isSupported() const override;
|
bool isSupported() const override;
|
||||||
const QString& getName() const override { return NAME; }
|
const QString& getName() const override { return NAME; }
|
||||||
|
|
||||||
|
QStringList getSubdeviceNames() override;
|
||||||
bool isHandController() const override { return false; }
|
bool isHandController() const override { return false; }
|
||||||
|
|
||||||
void init() override;
|
void init() override;
|
||||||
|
@ -79,6 +80,7 @@ private:
|
||||||
QMap<SDL_JoystickID, Joystick::Pointer> _openJoysticks;
|
QMap<SDL_JoystickID, Joystick::Pointer> _openJoysticks;
|
||||||
bool _isInitialized { false } ;
|
bool _isInitialized { false } ;
|
||||||
static const QString NAME;
|
static const QString NAME;
|
||||||
|
QStringList _subdeviceNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi__SDL2Manager_h
|
#endif // hifi__SDL2Manager_h
|
||||||
|
|
|
@ -117,6 +117,17 @@ void OculusControllerManager::stopHapticPulse(bool leftHand) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList OculusControllerManager::getSubdeviceNames() {
|
||||||
|
QStringList devices;
|
||||||
|
if (_touch) {
|
||||||
|
devices << _touch->getName();
|
||||||
|
}
|
||||||
|
if (_remote) {
|
||||||
|
devices << _remote->getName();
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
|
|
||||||
static const std::vector<std::pair<ovrButton, StandardButtonChannel>> BUTTON_MAP { {
|
static const std::vector<std::pair<ovrButton, StandardButtonChannel>> BUTTON_MAP { {
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
const QString& getName() const override { return NAME; }
|
const QString& getName() const override { return NAME; }
|
||||||
|
|
||||||
bool isHandController() const override { return _touch != nullptr; }
|
bool isHandController() const override { return _touch != nullptr; }
|
||||||
|
QStringList getSubdeviceNames() override;
|
||||||
|
|
||||||
bool activate() override;
|
bool activate() override;
|
||||||
void deactivate() override;
|
void deactivate() override;
|
||||||
|
|
Loading…
Reference in a new issue