mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-09 08:25:16 +00:00
implement mouse handler config
This commit is contained in:
parent
3ba4c8a1c7
commit
eb8ab8ef15
29 changed files with 850 additions and 105 deletions
73
rpcs3/Input/raw_mouse_config.cpp
Normal file
73
rpcs3/Input/raw_mouse_config.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include "stdafx.h"
|
||||
#include "raw_mouse_config.h"
|
||||
#include "Emu/Io/MouseHandler.h"
|
||||
|
||||
cfg::string& raw_mouse_config::get_button(int code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case CELL_MOUSE_BUTTON_1: return mouse_button_1;
|
||||
case CELL_MOUSE_BUTTON_2: return mouse_button_2;
|
||||
case CELL_MOUSE_BUTTON_3: return mouse_button_3;
|
||||
case CELL_MOUSE_BUTTON_4: return mouse_button_4;
|
||||
case CELL_MOUSE_BUTTON_5: return mouse_button_5;
|
||||
case CELL_MOUSE_BUTTON_6: return mouse_button_6;
|
||||
case CELL_MOUSE_BUTTON_7: return mouse_button_7;
|
||||
case CELL_MOUSE_BUTTON_8: return mouse_button_8;
|
||||
default: fmt::throw_exception("Invalid code %d", code);
|
||||
}
|
||||
}
|
||||
|
||||
raw_mice_config::raw_mice_config()
|
||||
{
|
||||
for (u32 i = 0; i < ::size32(players); i++)
|
||||
{
|
||||
players.at(i) = std::make_shared<raw_mouse_config>(this, fmt::format("Player %d", i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
bool raw_mice_config::load()
|
||||
{
|
||||
m_mutex.lock();
|
||||
|
||||
bool result = false;
|
||||
const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id);
|
||||
cfg_log.notice("Loading %s config: %s", cfg_id, cfg_name);
|
||||
|
||||
from_default();
|
||||
|
||||
if (fs::file cfg_file{ cfg_name, fs::read })
|
||||
{
|
||||
if (std::string content = cfg_file.to_string(); !content.empty())
|
||||
{
|
||||
result = from_string(content);
|
||||
}
|
||||
|
||||
m_mutex.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mutex.unlock();
|
||||
save();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void raw_mice_config::save()
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id);
|
||||
cfg_log.notice("Saving %s config to '%s'", cfg_id, cfg_name);
|
||||
|
||||
if (!fs::create_path(fs::get_parent_dir(cfg_name)))
|
||||
{
|
||||
cfg_log.fatal("Failed to create path: %s (%s)", cfg_name, fs::g_tls_error);
|
||||
}
|
||||
|
||||
if (!cfg::node::save(cfg_name))
|
||||
{
|
||||
cfg_log.error("Failed to save %s config to '%s' (error=%s)", cfg_id, cfg_name, fs::g_tls_error);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue