Skip to content

Commit

Permalink
Make setting persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
zonkmachine committed Jul 16, 2023
1 parent f0206ff commit 2cce2c2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions data/lang/ui-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,10 @@
"description": "",
"message": "Invert Mouse Y"
},
"NO_MOUSE_MIDDLE_BUTTON": {
"description": "",
"message": "No middle mouse button available"
},
"IN_CARGO_HOLD": {
"description": "",
"message": "In cargo hold"
Expand Down
1 change: 1 addition & 0 deletions src/GameConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GameConfig::GameConfig(const map_string &override_)
map["SfxVolume"] = "0.8";
map["EnableJoystick"] = "1";
map["InvertMouseY"] = "0";
map["noMiddleMouseButton"] = "0";
map["FOVVertical"] = "65";
map["DisplayNavTunnel"] = "0";
map["CompactRadar"] = "1";
Expand Down
11 changes: 11 additions & 0 deletions src/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ Manager::Manager(IniConfig *config, SDL_Window *window) :
m_capturingMouse(false),
joystickEnabled(true),
mouseYInvert(false),
mouseMiddleButton(false),
m_enableBindings(true)
{
joystickEnabled = (m_config->Int("EnableJoystick")) ? true : false;
mouseYInvert = (m_config->Int("InvertMouseY")) ? true : false;
mouseMiddleButton = (m_config->Int("noMiddleMouseButton")) ? true : false;

Input::InitJoysticks(m_config);
}
Expand Down Expand Up @@ -500,6 +502,15 @@ void Manager::SetMouseYInvert(bool state)
}
}

void Manager::SetMouseMiddleButton(bool state)
{
mouseMiddleButton = state;
if (m_enableConfigSaving) {
m_config->SetInt("noMiddleMouseButton", mouseMiddleButton);
m_config->Save();
}
}

void Manager::GetMousePosition(int position[2])
{
SDL_GetMouseState(&position[0], &position[1]);
Expand Down
2 changes: 1 addition & 1 deletion src/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ class Input::Manager {
bool m_capturingMouse;

bool joystickEnabled;
bool mouseMiddleButton;
bool mouseYInvert;
bool mouseMiddleButton;

std::map<std::string, BindingPage> bindingPages;
std::map<std::string, InputBindings::Action> actionBindings;
Expand Down
7 changes: 6 additions & 1 deletion src/lua/LuaInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,12 @@ static int l_input_get_mouse_middle_button(lua_State *l)

static int l_input_set_mouse_middle_button(lua_State *l)
{
//lua_pushboolean(l, Pi::input->IsMouseYInvert());
if (lua_isnone(l, 1))
return luaL_error(l, "SetMouseMiddleButton takes one boolean argument");
const bool mousebutton = lua_toboolean(l, 1);
Pi::config->SetInt("noMiddleMouseButton", (mousebutton ? 1 : 0));
Pi::config->Save();
Pi::input->SetMouseMiddleButton(mousebutton);
return 0;
}

Expand Down

0 comments on commit 2cce2c2

Please sign in to comment.