Skip to content

Commit

Permalink
GmaeConfigWIdget: Always load game_id.ini tab in the editor and corre…
Browse files Browse the repository at this point in the history
…ctly update it.
  • Loading branch information
TryTwo committed Sep 25, 2024
1 parent b6b4e45 commit 0996c55
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions Source/Core/DolphinQt/Config/GameConfigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ GameConfigWidget::GameConfigWidget(const UICommon::GameFile& game) : m_game(game
false);

// Always give the user the opportunity to create a new INI
if (m_local_tab->count() == 0)
bool game_id_tab = false;
for (int i = 0; i < m_local_tab->count(); i++)
{
if (m_local_tab->tabText(i).toStdString() == m_game_id + ".ini")
game_id_tab = true;
}

if (game_id_tab == false)
{
auto* edit = new GameConfigEdit(
nullptr, QString::fromStdString(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini"),
Expand Down Expand Up @@ -206,17 +213,15 @@ void GameConfigWidget::CreateWidgets()
auto* layout = new QVBoxLayout;
auto* tab_widget = new QTabWidget;
tab_widget->addTab(general_widget, tr("General"));
tab_widget->addTab(advanced_widget, tr("Editor"));
const int editor_index = tab_widget->indexOf(advanced_widget);
const int editor_index = tab_widget->addTab(advanced_widget, tr("Editor"));

// GFX settings tabs. Placed in a QWidget for consistent margins.
auto* gfx_tab_holder = new QWidget;
auto* gfx_layout = new QVBoxLayout;
gfx_tab_holder->setLayout(gfx_layout);
tab_widget->addTab(gfx_tab_holder, tr("GFX"));
const int gfx_index = tab_widget->addTab(gfx_tab_holder, tr("GFX"));

auto* gfx_tabs = new QTabWidget;
const int gfx_index = tab_widget->indexOf(gfx_tabs);

gfx_tabs->addTab(GetWrappedWidget(new GeneralWidget(this, m_layer.get()), this, 125, 100),
tr("General"));
Expand All @@ -235,12 +240,25 @@ void GameConfigWidget::CreateWidgets()
{
// Layer only auto-saves when it is destroyed.
m_layer->Save();
m_local_tab->removeTab(0);
auto* edit = new GameConfigEdit(
nullptr,
QString::fromStdString(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini"),
false);
m_local_tab->addTab(edit, QString::fromStdString(m_game_id + ".ini"));

// There can be multiple ini loaded for a game, only replace the one related to the game
// ini being edited.
for (int i = 0; i < m_local_tab->count(); i++)
{
if (m_local_tab->tabText(i).toStdString() == m_game_id + ".ini")
{
m_local_tab->removeTab(i);

auto* edit =
new GameConfigEdit(nullptr,
QString::fromStdString(File::GetUserPath(D_GAMESETTINGS_IDX) +
m_game_id + ".ini"),
false);

m_local_tab->insertTab(i, edit, QString::fromStdString(m_game_id + ".ini"));
return;
}
}
}

// Update GFX tabs after using ini editor.
Expand All @@ -261,8 +279,8 @@ void GameConfigWidget::CreateWidgets()

GameConfigWidget::~GameConfigWidget()
{
// If a game is running and the game properties window is closed, update local game layer with any
// new changes. Not sure if doing it more frequently is safe.
// If a game is running and the game properties window is closed, update local game layer with
// any new changes. Not sure if doing it more frequently is safe.

auto local_layer = Config::GetLayer(Config::LayerType::LocalGame);
if (local_layer && SConfig::GetInstance().GetGameID() == m_game_id)
Expand Down

0 comments on commit 0996c55

Please sign in to comment.