Skip to content

Commit

Permalink
Add workaround for iOS+Qt bug
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanSavenko committed Dec 21, 2024
1 parent 69eac2f commit aa77547
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 40 deletions.
84 changes: 45 additions & 39 deletions launcher/startGame/StartGameTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/VCMIDirs.h"
#include "../../vcmiqt/MessageBox.h"

void StartGameTab::changeEvent(QEvent *event)
{
Expand Down Expand Up @@ -269,7 +270,7 @@ void StartGameTab::on_buttonHelpImportFiles_clicked()
" - VCMI configuration files (.json)\n"
);

QMessageBox::information(this, ui->buttonImportFiles->text(), message);
MessageBox::information(this, ui->buttonImportFiles->text(), message);
}

void StartGameTab::on_buttonInstallTranslationHelp_clicked()
Expand All @@ -279,7 +280,7 @@ void StartGameTab::on_buttonInstallTranslationHelp_clicked()
"VCMI provides translations of the game into various languages that you can use. "
"Use this option to automatically install such translation to your language."
);
QMessageBox::information(this, ui->buttonInstallTranslation->text(), message);
MessageBox::information(this, ui->buttonInstallTranslation->text(), message);
}

void StartGameTab::on_buttonActivateTranslationHelp_clicked()
Expand All @@ -289,7 +290,7 @@ void StartGameTab::on_buttonActivateTranslationHelp_clicked()
"Use this option to enable it."
);

QMessageBox::information(this, ui->buttonActivateTranslation->text(), message);
MessageBox::information(this, ui->buttonActivateTranslation->text(), message);
}

void StartGameTab::on_buttonUpdateModsHelp_clicked()
Expand All @@ -301,7 +302,7 @@ void StartGameTab::on_buttonUpdateModsHelp_clicked()
"You many want to postpone mod update until you finish any of your ongoing games."
);

QMessageBox::information(this, ui->buttonUpdateMods->text(), message);
MessageBox::information(this, ui->buttonUpdateMods->text(), message);
}

void StartGameTab::on_buttonChroniclesHelp_clicked()
Expand All @@ -314,7 +315,7 @@ void StartGameTab::on_buttonChroniclesHelp_clicked()
"This will generate and install mod for VCMI that contains imported chronicles"
);

QMessageBox::information(this, ui->labelChronicles->text(), message);
MessageBox::information(this, ui->labelChronicles->text(), message);
}

void StartGameTab::on_buttonMissingSoundtrackHelp_clicked()
Expand All @@ -325,7 +326,7 @@ void StartGameTab::on_buttonMissingSoundtrackHelp_clicked()
"To resolve this problem, please copy missing mp3 files from Heroes III to VCMI data files directory manually "
"or reinstall VCMI and re-import Heroes III data files"
);
QMessageBox::information(this, ui->labelMissingSoundtrack->text(), message);
MessageBox::information(this, ui->labelMissingSoundtrack->text(), message);
}

void StartGameTab::on_buttonMissingVideoHelp_clicked()
Expand All @@ -336,7 +337,7 @@ void StartGameTab::on_buttonMissingVideoHelp_clicked()
"To resolve this problem, please copy VIDEO.VID file from Heroes III to VCMI data files directory manually "
"or reinstall VCMI and re-import Heroes III data files"
);
QMessageBox::information(this, ui->labelMissingVideo->text(), message);
MessageBox::information(this, ui->labelMissingVideo->text(), message);
}

void StartGameTab::on_buttonMissingFilesHelp_clicked()
Expand All @@ -347,7 +348,7 @@ void StartGameTab::on_buttonMissingFilesHelp_clicked()
"To resolve this problem, please reinstall game and reimport data files using supported version of Heroes III. "
"VCMI requires Heroes III: Shadow of Death or Complete Edition to run, which you can get (for example) from gog.com"
);
QMessageBox::information(this, ui->labelMissingFiles->text(), message);
MessageBox::information(this, ui->labelMissingFiles->text(), message);
}

void StartGameTab::on_buttonMissingCampaignsHelp_clicked()
Expand All @@ -358,7 +359,7 @@ void StartGameTab::on_buttonMissingCampaignsHelp_clicked()
"To resolve this problem, please copy missing data files from Heroes III to VCMI data files directory manually "
"or reinstall VCMI and re-import Heroes III data files"
);
QMessageBox::information(this, ui->labelMissingCampaigns->text(), message);
MessageBox::information(this, ui->labelMissingCampaigns->text(), message);
}

void StartGameTab::on_buttonPresetExport_clicked()
Expand All @@ -373,21 +374,24 @@ void StartGameTab::on_buttonPresetImport_clicked()

void StartGameTab::on_buttonPresetNew_clicked()
{
bool ok;
QString presetName = QInputDialog::getText(
this,
ui->buttonPresetNew->text(),
tr("Enter preset name:"),
QLineEdit::Normal,
QString(),
&ok);

if (ok && !presetName.isEmpty())
{
getMainWindow()->getModView()->createNewPreset(presetName);
getMainWindow()->getModView()->activatePreset(presetName);
refreshPresets();
}
const auto & functor = [this](){
bool ok;
QString presetName = QInputDialog::getText(
this,
ui->buttonPresetNew->text(),
tr("Enter preset name:"),
QLineEdit::Normal,
QString(),
&ok);

if (ok && !presetName.isEmpty())
{
getMainWindow()->getModView()->createNewPreset(presetName);
getMainWindow()->getModView()->activatePreset(presetName);
refreshPresets();
}
};
MessageBox::showDialog(functor);
}

void StartGameTab::on_buttonPresetDelete_clicked()
Expand All @@ -411,21 +415,23 @@ void StartGameTab::on_comboBoxModPresets_currentTextChanged(const QString &prese

void StartGameTab::on_buttonPresetRename_clicked()
{
QString currentName = getMainWindow()->getModView()->getActivePreset();
const auto & functor = [this](){
QString currentName = getMainWindow()->getModView()->getActivePreset();

bool ok;
QString newName = QInputDialog::getText(
this,
ui->buttonPresetNew->text(),
tr("Rename preset '%1' to:").arg(currentName),
QLineEdit::Normal,
currentName,
&ok);
bool ok;
QString newName = QInputDialog::getText(
this,
ui->buttonPresetNew->text(),
tr("Rename preset '%1' to:").arg(currentName),
QLineEdit::Normal,
currentName,
&ok);

if (ok && !newName.isEmpty())
{
getMainWindow()->getModView()->renamePreset(currentName, newName);
refreshPresets();
}
if (ok && !newName.isEmpty())
{
getMainWindow()->getModView()->renamePreset(currentName, newName);
refreshPresets();
}
};
MessageBox::showDialog(functor);
}

3 changes: 2 additions & 1 deletion vcmiqt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(vcmiqt_SRCS
set(vcmiqt_HEADERS
StdInc.h

MessageBox.h
jsonutils.h
launcherdirs.h
convpathqstring.h
Expand All @@ -32,7 +33,7 @@ if(WIN32)
)
endif()

target_link_libraries(vcmiqt vcmi Qt${QT_VERSION_MAJOR}::Core)
target_link_libraries(vcmiqt vcmi Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets)

target_include_directories(vcmiqt PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
50 changes: 50 additions & 0 deletions vcmiqt/MessageBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* MessageBox.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/

#pragma once

#include "vcmiqt.h"

#include <QMessageBox>
#include <QTimer>

namespace MessageBox
{
#ifdef VCMI_IOS
// iOS can't display modal dialogs when called directly on button press
// https://bugreports.qt.io/browse/QTBUG-98651

template<typename Functor>
void showDialog(const Functor & f)
{
QTimer::singleShot(0, this, f);
}

void information(QWidget *parent, const QString &title, const QString& text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton)
{
QTimer::singleShot(0, this, [=](){
QMessageBox::information(parent, title, text, buttons, defaultButton);
});
}

#else

template<typename Functor>
void showDialog(const Functor & f)
{
f();
}

void information(QWidget *parent, const QString &title, const QString& text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton)
{
QMessageBox::information(parent, title, text, buttons, defaultButton);
}
#endif
}

0 comments on commit aa77547

Please sign in to comment.