1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-12-18 10:37:53 +01:00

Player controls: added mouse and game controller remapping.

Fixed duplicate button id.
This commit is contained in:
Muzychenko Andrey 2021-10-17 18:18:29 +03:00
parent d06aa1c736
commit 06b760e8dd
5 changed files with 302 additions and 217 deletions

View file

@ -13,7 +13,7 @@ optionsStruct options::Options{};
std::map<std::string, std::string> options::settings{}; std::map<std::string, std::string> options::settings{};
ControlsStruct options::RebindControls{}; ControlsStruct options::RebindControls{};
bool options::ShowDialog = false; bool options::ShowDialog = false;
const ControlRef* options::ControlWaitingForKey = nullptr; GameInput* options::ControlWaitingForInput = nullptr;
const ControlRef options::Controls[6] const ControlRef options::Controls[6]
{ {
{"Left Flipper", RebindControls.LeftFlipper}, {"Left Flipper", RebindControls.LeftFlipper},
@ -43,24 +43,50 @@ void options::init()
ImGui::EndFrame(); ImGui::EndFrame();
} }
Options.KeyDft.LeftFlipper = SDLK_z; Options.Key = Options.KeyDft =
Options.KeyDft.RightFlipper = SDLK_SLASH; {
Options.KeyDft.Plunger = SDLK_SPACE; {
Options.KeyDft.LeftTableBump = SDLK_x; {InputTypes::Keyboard, SDLK_z},
Options.KeyDft.RightTableBump = SDLK_PERIOD; {InputTypes::Mouse, SDL_BUTTON_LEFT},
Options.KeyDft.BottomTableBump = SDLK_UP; {InputTypes::GameController, SDL_CONTROLLER_BUTTON_LEFTSHOULDER},
Options.Key = Options.KeyDft; },
{
{InputTypes::Keyboard, SDLK_SLASH},
{InputTypes::Mouse, SDL_BUTTON_RIGHT},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
},
{
{InputTypes::Keyboard, SDLK_SPACE},
{InputTypes::Mouse, SDL_BUTTON_MIDDLE},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_A},
},
{
{InputTypes::Keyboard, SDLK_x},
{InputTypes::Mouse, SDL_BUTTON_X1},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_DPAD_LEFT},
},
{
{InputTypes::Keyboard, SDLK_PERIOD},
{InputTypes::Mouse, SDL_BUTTON_X2},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_DPAD_RIGHT},
},
{
{InputTypes::Keyboard, SDLK_UP},
{InputTypes::Mouse, SDL_BUTTON_X2 + 1},
{InputTypes::GameController, SDL_CONTROLLER_BUTTON_DPAD_UP},
},
};
GetInput("Left Flipper key", Options.Key.LeftFlipper);
GetInput("Right Flipper key", Options.Key.RightFlipper);
GetInput("Plunger key", Options.Key.Plunger);
GetInput("Left Table Bump key", Options.Key.LeftTableBump);
GetInput("Right Table Bump key", Options.Key.RightTableBump);
GetInput("Bottom Table Bump key", Options.Key.BottomTableBump);
Options.Sounds = get_int("Sounds", true); Options.Sounds = get_int("Sounds", true);
Options.Music = get_int("Music", false); Options.Music = get_int("Music", false);
Options.FullScreen = get_int("FullScreen", false); Options.FullScreen = get_int("FullScreen", false);
Options.Players = get_int("Players", 1); Options.Players = get_int("Players", 1);
Options.Key.LeftFlipper = get_int("Left Flipper key", Options.Key.LeftFlipper);
Options.Key.RightFlipper = get_int("Right Flipper key", Options.Key.RightFlipper);
Options.Key.Plunger = get_int("Plunger key", Options.Key.Plunger);
Options.Key.LeftTableBump = get_int("Left Table Bump key", Options.Key.LeftTableBump);
Options.Key.RightTableBump = get_int("Right Table Bump key", Options.Key.RightTableBump);
Options.Key.BottomTableBump = get_int("Bottom Table Bump key", Options.Key.BottomTableBump);
Options.UniformScaling = get_int("Uniform scaling", true); Options.UniformScaling = get_int("Uniform scaling", true);
ImGui::GetIO().FontGlobalScale = get_float("UI Scale", 1.0f); ImGui::GetIO().FontGlobalScale = get_float("UI Scale", 1.0f);
Options.Resolution = get_int("Screen Resolution", -1); Options.Resolution = get_int("Screen Resolution", -1);
@ -83,16 +109,17 @@ void options::init()
void options::uninit() void options::uninit()
{ {
SetInput("Left Flipper key", Options.Key.LeftFlipper);
SetInput("Right Flipper key", Options.Key.RightFlipper);
SetInput("Plunger key", Options.Key.Plunger);
SetInput("Left Table Bump key", Options.Key.LeftTableBump);
SetInput("Right Table Bump key", Options.Key.RightTableBump);
SetInput("Bottom Table Bump key", Options.Key.BottomTableBump);
set_int("Sounds", Options.Sounds); set_int("Sounds", Options.Sounds);
set_int("Music", Options.Music); set_int("Music", Options.Music);
set_int("FullScreen", Options.FullScreen); set_int("FullScreen", Options.FullScreen);
set_int("Players", Options.Players); set_int("Players", Options.Players);
set_int("Left Flipper key", Options.Key.LeftFlipper);
set_int("Right Flipper key", Options.Key.RightFlipper);
set_int("Plunger key", Options.Key.Plunger);
set_int("Left Table Bump key", Options.Key.LeftTableBump);
set_int("Right Table Bump key", Options.Key.RightTableBump);
set_int("Bottom Table Bump key", Options.Key.BottomTableBump);
set_int("Screen Resolution", Options.Resolution); set_int("Screen Resolution", Options.Resolution);
set_int("Uniform scaling", Options.UniformScaling); set_int("Uniform scaling", Options.UniformScaling);
set_float("UI Scale", ImGui::GetIO().FontGlobalScale); set_float("UI Scale", ImGui::GetIO().FontGlobalScale);
@ -137,6 +164,28 @@ void options::set_float(LPCSTR lpValueName, float data)
SetSetting(lpValueName, std::to_string(data)); SetSetting(lpValueName, std::to_string(data));
} }
void options::GetInput(const std::string& rowName, GameInput (&defaultValues)[3])
{
for (auto i = 0u; i <= 2; i++)
{
auto name = rowName + " " + std::to_string(i);
auto inputType = static_cast<InputTypes>(get_int((name + " type").c_str(), -1));
auto input = get_int((name + " input").c_str(), -1);
if (inputType <= InputTypes::GameController && input != -1)
defaultValues[i] = {inputType, input};
}
}
void options::SetInput(const std::string& rowName, GameInput (&values)[3])
{
for (auto i = 0u; i <= 2; i++)
{
auto input = values[i];
auto name = rowName + " " + std::to_string(i);
set_int((name + " type").c_str(), static_cast<int>(input.Type));
set_int((name + " input").c_str(), input.Value);
}
}
void options::toggle(Menu1 uIDCheckItem) void options::toggle(Menu1 uIDCheckItem)
{ {
@ -203,16 +252,20 @@ void options::toggle(Menu1 uIDCheckItem)
} }
} }
void options::KeyDown(int key) void options::InputDown(GameInput input)
{ {
if (ControlWaitingForKey) if (ControlWaitingForInput)
{ {
// Skip function keys, just in case. // Skip function keys, just in case.
if (key < SDLK_F1 || key > SDLK_F12) if (input.Type == InputTypes::Keyboard && input.Value >= SDLK_F1 && input.Value <= SDLK_F12)
{ return;
ControlWaitingForKey->Option = key;
ControlWaitingForKey = nullptr; // Start is reserved for pause
} if (input.Type == InputTypes::GameController && input.Value == SDL_CONTROLLER_BUTTON_START)
return;
*ControlWaitingForInput = input;
ControlWaitingForInput = nullptr;
} }
} }
@ -220,7 +273,7 @@ void options::ShowControlDialog()
{ {
if (!ShowDialog) if (!ShowDialog)
{ {
ControlWaitingForKey = nullptr; ControlWaitingForInput = nullptr;
RebindControls = Options.Key; RebindControls = Options.Key;
ShowDialog = true; ShowDialog = true;
} }
@ -228,10 +281,20 @@ void options::ShowControlDialog()
void options::RenderControlDialog() void options::RenderControlDialog()
{ {
static const char* mouseButtons[]
{
nullptr,
"Mouse Left",
"Mouse Middle",
"Mouse Right",
"Mouse X1",
"Mouse X2",
};
if (!ShowDialog) if (!ShowDialog)
return; return;
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2{500, 400}); ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2{550, 450});
if (ImGui::Begin("3D Pinball: Player Controls", &ShowDialog)) if (ImGui::Begin("3D Pinball: Player Controls", &ShowDialog))
{ {
ImGui::TextUnformatted("Instructions"); ImGui::TextUnformatted("Instructions");
@ -241,39 +304,70 @@ void options::RenderControlDialog()
"To change game controls, click the control button, press the new key, and then choose OK."); "To change game controls, click the control button, press the new key, and then choose OK.");
ImGui::TextWrapped( ImGui::TextWrapped(
"To restore 3D Pinball to its original settings, choose Default, and then choose OK."); "To restore 3D Pinball to its original settings, choose Default, and then choose OK.");
ImGui::TextWrapped("Original warns against binding the same key to multiple controls, but does not forbid it.");
ImGui::Spacing(); ImGui::Spacing();
ImGui::TextUnformatted("Control Options"); ImGui::TextUnformatted("Control Options");
ImGui::Separator();
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{5, 10}); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{5, 10});
if (ImGui::BeginTable("Controls", 2, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders)) if (ImGui::BeginTable("Controls", 4, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders))
{ {
for (auto& ctrl : Controls) ImGui::TableSetupColumn("Control");
{ ImGui::TableSetupColumn("Binding 1");
ImGui::TableNextColumn(); ImGui::TableSetupColumn("Binding 2");
if (ImGui::BeginTable("Control", 2, ImGuiTableFlags_NoSavedSettings)) ImGui::TableSetupColumn("Binding 3");
{ ImGui::TableHeadersRow();
ImGui::TableNextColumn();
ImGui::TextWrapped("%s", ctrl.Name);
int index = 0;
for (auto& row : Controls)
{
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ControlWaitingForKey == &ctrl) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{0.5, 0, 0, 1});
if (ImGui::Button(row.Name))
{
for (auto i = 0u; i <= 2; i++)
row.Option[i] = {};
}
ImGui::PopStyleColor(1);
for (auto i = 0u; i <= 2; i++)
{
auto& ctrl = row.Option[i];
ImGui::TableNextColumn();
if (ControlWaitingForInput == &ctrl)
{ {
ImGui::Button("Press the key", ImVec2(-1, 0)); ImGui::Button("Press the key", ImVec2(-1, 0));
} }
else else
{ {
auto keyName = SDL_GetKeyName(ctrl.Option); std::string tmp;
if (!keyName[0]) const char* keyName;
keyName = "Unknown key"; switch (ctrl.Type)
if (ImGui::Button(keyName, ImVec2(-1, 0)))
{ {
ControlWaitingForKey = &ctrl; case InputTypes::Keyboard:
keyName = SDL_GetKeyName(ctrl.Value);
break;
case InputTypes::Mouse:
if (ctrl.Value >= SDL_BUTTON_LEFT && ctrl.Value <= SDL_BUTTON_X2)
keyName = mouseButtons[ctrl.Value];
else
keyName = (tmp += "Mouse " + std::to_string(ctrl.Value)).c_str();
break;
case InputTypes::GameController:
keyName = SDL_GameControllerGetStringForButton(
static_cast<SDL_GameControllerButton>(ctrl.Value));
break;
case InputTypes::None:
default:
keyName = "Unused";
}
if (!keyName || !keyName[0])
keyName = "Unknown key";
if (ImGui::Button((std::string{keyName} + "##" + std::to_string(index++)).c_str(),
ImVec2(-1, 0)))
{
ControlWaitingForInput = &ctrl;
} }
} }
ImGui::EndTable();
} }
} }
ImGui::EndTable(); ImGui::EndTable();
@ -297,14 +391,14 @@ void options::RenderControlDialog()
if (ImGui::Button("Default")) if (ImGui::Button("Default"))
{ {
RebindControls = Options.KeyDft; RebindControls = Options.KeyDft;
ControlWaitingForKey = nullptr; ControlWaitingForInput = nullptr;
} }
} }
ImGui::End(); ImGui::End();
ImGui::PopStyleVar(); ImGui::PopStyleVar();
if (!ShowDialog) if (!ShowDialog)
ControlWaitingForKey = nullptr; ControlWaitingForInput = nullptr;
} }
void options::MyUserData_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line) void options::MyUserData_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line)

View file

@ -28,14 +28,33 @@ enum class Menu1:int
WindowLinearFilter = 601, WindowLinearFilter = 601,
}; };
enum class InputTypes: unsigned
{
None = 0,
Keyboard = 1,
Mouse = 2,
GameController = 3,
};
struct GameInput
{
InputTypes Type;
int Value;
bool operator==(const GameInput& other) const
{
return Type == other.Type && Value == other.Value;
}
};
struct ControlsStruct struct ControlsStruct
{ {
int LeftFlipper; GameInput LeftFlipper[3];
int RightFlipper; GameInput RightFlipper[3];
int Plunger; GameInput Plunger[3];
int LeftTableBump; GameInput LeftTableBump[3];
int RightTableBump; GameInput RightTableBump[3];
int BottomTableBump; GameInput BottomTableBump[3];
}; };
struct optionsStruct struct optionsStruct
@ -59,7 +78,7 @@ struct optionsStruct
struct ControlRef struct ControlRef
{ {
const char* Name; const char* Name;
int& Option; GameInput (&Option)[3];
}; };
@ -81,16 +100,19 @@ public:
static void set_string(LPCSTR lpValueName, LPCSTR value); static void set_string(LPCSTR lpValueName, LPCSTR value);
static float get_float(LPCSTR lpValueName, float defaultValue); static float get_float(LPCSTR lpValueName, float defaultValue);
static void set_float(LPCSTR lpValueName, float data); static void set_float(LPCSTR lpValueName, float data);
static void GetInput(const std::string& rowName, GameInput (&defaultValues)[3]);
static void SetInput(const std::string& rowName, GameInput (&values)[3]);
static void toggle(Menu1 uIDCheckItem); static void toggle(Menu1 uIDCheckItem);
static void KeyDown(int key); static void InputDown(GameInput input);
static void ShowControlDialog(); static void ShowControlDialog();
static void RenderControlDialog(); static void RenderControlDialog();
static bool WaitingForInput() { return ControlWaitingForInput != nullptr; }
private: private:
static std::map<std::string, std::string> settings; static std::map<std::string, std::string> settings;
static ControlsStruct RebindControls; static ControlsStruct RebindControls;
static bool ShowDialog; static bool ShowDialog;
static const ControlRef Controls[6]; static const ControlRef Controls[6];
static const ControlRef* ControlWaitingForKey; static GameInput* ControlWaitingForInput;
static void MyUserData_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); static void MyUserData_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line);
static void* MyUserData_ReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name); static void* MyUserData_ReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name);

View file

@ -360,86 +360,83 @@ void pb::loose_focus()
MainTable->Message(1010, time_now); MainTable->Message(1010, time_now);
} }
void pb::keyup(int key) void pb::InputUp(GameInput input)
{ {
if (game_mode == 1 && !winmain::single_step && !demo_mode) if (game_mode != 1 || winmain::single_step || demo_mode)
{ return;
if (key == options::Options.Key.LeftFlipper)
if (AnyBindingMatchesInput(options::Options.Key.LeftFlipper, input))
{ {
MainTable->Message(1001, time_now); MainTable->Message(1001, time_now);
} }
else if (key == options::Options.Key.RightFlipper) if (AnyBindingMatchesInput(options::Options.Key.RightFlipper, input))
{ {
MainTable->Message(1003, time_now); MainTable->Message(1003, time_now);
} }
else if (key == options::Options.Key.Plunger) if (AnyBindingMatchesInput(options::Options.Key.Plunger, input))
{ {
MainTable->Message(1005, time_now); MainTable->Message(1005, time_now);
} }
else if (key == options::Options.Key.LeftTableBump) if (AnyBindingMatchesInput(options::Options.Key.LeftTableBump, input))
{ {
nudge::un_nudge_right(0, nullptr); nudge::un_nudge_right(0, nullptr);
} }
else if (key == options::Options.Key.RightTableBump) if (AnyBindingMatchesInput(options::Options.Key.RightTableBump, input))
{ {
nudge::un_nudge_left(0, nullptr); nudge::un_nudge_left(0, nullptr);
} }
else if (key == options::Options.Key.BottomTableBump) if (AnyBindingMatchesInput(options::Options.Key.BottomTableBump, input))
{ {
nudge::un_nudge_up(0, nullptr); nudge::un_nudge_up(0, nullptr);
} }
} }
}
void pb::keydown(int key) void pb::InputDown(GameInput input)
{ {
options::KeyDown(key); options::InputDown(input);
if (winmain::single_step || demo_mode) if (winmain::single_step || demo_mode)
return; return;
if (game_mode != 1) if (game_mode != 1)
{ {
mode_countdown(-1); mode_countdown(-1);
return; return;
} }
control::pbctrl_bdoor_controller(static_cast<char>(key));
if (key == options::Options.Key.LeftFlipper) if (input.Type == InputTypes::Keyboard)
control::pbctrl_bdoor_controller(static_cast<char>(input.Value));
if (AnyBindingMatchesInput(options::Options.Key.LeftFlipper, input))
{ {
MainTable->Message(1000, time_now); MainTable->Message(1000, time_now);
return;
} }
if (key == options::Options.Key.RightFlipper) if (AnyBindingMatchesInput(options::Options.Key.RightFlipper, input))
{ {
MainTable->Message(1002, time_now); MainTable->Message(1002, time_now);
} }
else if (AnyBindingMatchesInput(options::Options.Key.Plunger, input))
{
if (key == options::Options.Key.Plunger)
{ {
MainTable->Message(1004, time_now); MainTable->Message(1004, time_now);
return;
} }
if (key == options::Options.Key.LeftTableBump) if (AnyBindingMatchesInput(options::Options.Key.LeftTableBump, input))
{ {
if (!MainTable->TiltLockFlag) if (!MainTable->TiltLockFlag)
nudge::nudge_right(); nudge::nudge_right();
return;
} }
if (key == options::Options.Key.RightTableBump) if (AnyBindingMatchesInput(options::Options.Key.RightTableBump, input))
{ {
if (!MainTable->TiltLockFlag) if (!MainTable->TiltLockFlag)
nudge::nudge_left(); nudge::nudge_left();
return;
} }
if (key == options::Options.Key.BottomTableBump) if (AnyBindingMatchesInput(options::Options.Key.BottomTableBump, input))
{ {
if (!MainTable->TiltLockFlag) if (!MainTable->TiltLockFlag)
nudge::nudge_up(); nudge::nudge_up();
return;
} }
}
if (cheat_mode) if (cheat_mode && input.Type == InputTypes::Keyboard)
{ {
switch (key) switch (input.Value)
{ {
case 'b': case 'b':
TBall* ball; TBall* ball;
@ -648,3 +645,11 @@ void pb::PushCheat(const std::string& cheat)
for (auto ch : cheat) for (auto ch : cheat)
control::pbctrl_bdoor_controller(ch); control::pbctrl_bdoor_controller(ch);
} }
bool pb::AnyBindingMatchesInput(GameInput (&options)[3], GameInput key)
{
for (auto& option : options)
if (key == option)
return true;
return false;
}

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "high_score.h" #include "high_score.h"
struct GameInput;
class TPinballTable; class TPinballTable;
class DatFile; class DatFile;
class TBall; class TBall;
@ -54,8 +55,8 @@ public:
static void window_size(int* width, int* height); static void window_size(int* width, int* height);
static void pause_continue(); static void pause_continue();
static void loose_focus(); static void loose_focus();
static void keyup(int key); static void InputUp(GameInput input);
static void keydown(int key); static void InputDown(GameInput input);
static int mode_countdown(int time); static int mode_countdown(int time);
static void launch_ball(); static void launch_ball();
static void end_game(); static void end_game();
@ -66,4 +67,6 @@ public:
static void PushCheat(const std::string& cheat); static void PushCheat(const std::string& cheat);
private: private:
static int demo_mode, mode_countdown_; static int demo_mode, mode_countdown_;
static bool AnyBindingMatchesInput(GameInput (&options)[3], GameInput key);
}; };

View file

@ -563,7 +563,7 @@ int winmain::event_handler(const SDL_Event* event)
{ {
ImGui_ImplSDL2_ProcessEvent(event); ImGui_ImplSDL2_ProcessEvent(event);
if (ImIO->WantCaptureMouse) if (ImIO->WantCaptureMouse && !options::WaitingForInput())
{ {
if (mouse_down) if (mouse_down)
{ {
@ -600,11 +600,11 @@ int winmain::event_handler(const SDL_Event* event)
return_value = 0; return_value = 0;
return 0; return 0;
case SDL_KEYUP: case SDL_KEYUP:
pb::keyup(event->key.keysym.sym); pb::InputUp({InputTypes::Keyboard, event->key.keysym.sym});
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (!event->key.repeat) if (!event->key.repeat)
pb::keydown(event->key.keysym.sym); pb::InputDown({InputTypes::Keyboard, event->key.keysym.sym});
switch (event->key.keysym.sym) switch (event->key.keysym.sym)
{ {
case SDLK_ESCAPE: case SDLK_ESCAPE:
@ -664,6 +664,8 @@ int winmain::event_handler(const SDL_Event* event)
} }
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
{
bool noInput = false;
switch (event->button.button) switch (event->button.button)
{ {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
@ -673,22 +675,20 @@ int winmain::event_handler(const SDL_Event* event)
last_mouse_x = event->button.x; last_mouse_x = event->button.x;
last_mouse_y = event->button.y; last_mouse_y = event->button.y;
SDL_SetWindowGrab(MainWindow, SDL_TRUE); SDL_SetWindowGrab(MainWindow, SDL_TRUE);
noInput = true;
} }
else
pb::keydown(Options.Key.LeftFlipper);
break;
case SDL_BUTTON_RIGHT:
if (!pb::cheat_mode)
pb::keydown(Options.Key.RightFlipper);
break;
case SDL_BUTTON_MIDDLE:
pb::keydown(Options.Key.Plunger);
break; break;
default: default:
break; break;
} }
if (!noInput)
pb::InputDown({InputTypes::Mouse, event->button.button});
}
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
{
bool noInput = false;
switch (event->button.button) switch (event->button.button)
{ {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
@ -696,20 +696,16 @@ int winmain::event_handler(const SDL_Event* event)
{ {
mouse_down = 0; mouse_down = 0;
SDL_SetWindowGrab(MainWindow, SDL_FALSE); SDL_SetWindowGrab(MainWindow, SDL_FALSE);
noInput = true;
} }
if (!pb::cheat_mode)
pb::keyup(Options.Key.LeftFlipper);
break;
case SDL_BUTTON_RIGHT:
if (!pb::cheat_mode)
pb::keyup(Options.Key.RightFlipper);
break;
case SDL_BUTTON_MIDDLE:
pb::keyup(Options.Key.Plunger);
break; break;
default: default:
break; break;
} }
if (!noInput)
pb::InputUp({InputTypes::Mouse, event->button.button});
}
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
switch (event->window.event) switch (event->window.event)
@ -757,52 +753,17 @@ int winmain::event_handler(const SDL_Event* event)
} }
break; break;
case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONDOWN:
pb::InputDown({InputTypes::GameController, event->cbutton.button});
switch (event->cbutton.button) switch (event->cbutton.button)
{ {
case SDL_CONTROLLER_BUTTON_A: case SDL_CONTROLLER_BUTTON_START:
pb::keydown(Options.Key.Plunger); pause();
break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
pb::keydown(Options.Key.LeftFlipper);
break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
pb::keydown(Options.Key.RightFlipper);
break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
pb::keydown(Options.Key.LeftTableBump);
break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
pb::keydown(Options.Key.RightTableBump);
break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
pb::keydown(Options.Key.BottomTableBump);
break; break;
default: ; default: ;
} }
break; break;
case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERBUTTONUP:
switch (event->cbutton.button) pb::InputUp({InputTypes::GameController, event->cbutton.button});
{
case SDL_CONTROLLER_BUTTON_A:
pb::keyup(Options.Key.Plunger);
break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
pb::keyup(Options.Key.LeftFlipper);
break;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
pb::keyup(Options.Key.RightFlipper);
break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
pb::keyup(Options.Key.LeftTableBump);
break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
pb::keyup(Options.Key.RightTableBump);
break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
pb::keyup(Options.Key.BottomTableBump);
break;
default: ;
}
break; break;
default: ; default: ;
} }