Allow to set custom button mapping and combo keys for each game

This commit is contained in:
rock88 2020-06-12 21:33:08 +03:00
parent dc26386d8e
commit 96c61cd3f3
3 changed files with 24 additions and 2 deletions

View file

@ -2,7 +2,9 @@
#include "Application.hpp" #include "Application.hpp"
#include "GameStreamClient.hpp" #include "GameStreamClient.hpp"
#include "BoxArtManager.hpp" #include "BoxArtManager.hpp"
#include "InputSettingsWindow.hpp"
#include "nanovg.h" #include "nanovg.h"
#include <nanogui/opengl.h>
using namespace nanogui; using namespace nanogui;
@ -32,6 +34,16 @@ AppButton::AppButton(Widget* parent, const std::string &address, APP_LIST app, i
} }
} }
bool AppButton::gamepad_button_event(int jid, int button, int action) {
if (action && button == NANOGUI_GAMEPAD_BUTTON_Y) {
if (auto application = dynamic_cast<Application *>(screen())) {
application->push_window<InputSettingsWindow>(m_app.id, m_app.name);
}
return true;
}
return Button::gamepad_button_event(jid, button, action);
}
void AppButton::draw(NVGcontext *ctx) { void AppButton::draw(NVGcontext *ctx) {
int handle = BoxArtManager::manager()->texture_id(m_app.id); int handle = BoxArtManager::manager()->texture_id(m_app.id);

View file

@ -6,6 +6,8 @@ class AppButton: public nanogui::Button {
public: public:
AppButton(Widget* parent, const std::string &address, APP_LIST app, int current_game); AppButton(Widget* parent, const std::string &address, APP_LIST app, int current_game);
bool gamepad_button_event(int jid, int button, int action) override;
void draw(NVGcontext *ctx) override; void draw(NVGcontext *ctx) override;
private: private:

View file

@ -2,13 +2,14 @@
#include "LoadingOverlay.hpp" #include "LoadingOverlay.hpp"
#include "AppButton.hpp" #include "AppButton.hpp"
#include "StreamWindow.hpp" #include "StreamWindow.hpp"
#include "GamepadMapper.hpp"
using namespace nanogui; using namespace nanogui;
AppListWindow::AppListWindow(Widget *parent, const std::string &address): ContentWindow(parent, "Applications"), m_address(address) { AppListWindow::AppListWindow(Widget *parent, const std::string &address): ContentWindow(parent, "Applications"), m_address(address) {
set_left_pop_button(); set_left_pop_button();
container()->set_layout(new GridLayout(Orientation::Horizontal, 5, Alignment::Minimum, 30, 18)); set_box_layout(Orientation::Vertical, Alignment::Minimum, 30, 10);
} }
void AppListWindow::window_appear() { void AppListWindow::window_appear() {
@ -35,10 +36,16 @@ void AppListWindow::reload() {
loader->dispose(); loader->dispose();
if (result.isSuccess()) { if (result.isSuccess()) {
container()->add<Label>("* For adjust Gamepad buttons and Combo keys for a specific game, select this game by a Dpad and press Y");
container()->add<Widget>()->set_fixed_height(6);
auto button_container = container()->add<Widget>();
button_container->set_layout(new GridLayout(Orientation::Horizontal, 5, Alignment::Minimum, 0, 18));
PAPP_LIST app = result.value(); PAPP_LIST app = result.value();
while (app != NULL) { while (app != NULL) {
auto button = container()->add<AppButton>(m_address, *app, currentGame); auto button = button_container->add<AppButton>(m_address, *app, currentGame);
button->set_callback([this, app] { button->set_callback([this, app] {
run_game(app->id); run_game(app->id);
}); });
@ -57,6 +64,7 @@ void AppListWindow::reload() {
} }
void AppListWindow::run_game(int app_id) { void AppListWindow::run_game(int app_id) {
GamepadMapper::mapper()->load_gamepad_map(app_id);
push<StreamWindow>(m_address, app_id); push<StreamWindow>(m_address, app_id);
} }