1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Merge pull request #4597 from Laserlicht/simplify_ttf

simplify usage of ttf font
This commit is contained in:
Ivan Savenko 2024-09-20 11:49:58 +03:00 committed by GitHub
commit 2b4342f21d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 130 additions and 60 deletions

View File

@ -1080,6 +1080,12 @@ bool CModListView::isModEnabled(const QString & modName)
return mod.isEnabled();
}
bool CModListView::isModInstalled(const QString & modName)
{
auto mod = modModel->getMod(modName);
return mod.isInstalled();
}
QString CModListView::getTranslationModName(const QString & language)
{
for(const auto & modName : modModel->getModList())

View File

@ -95,6 +95,9 @@ public:
/// returns true if mod is currently enabled
bool isModEnabled(const QString & modName);
/// returns true if mod is currently installed
bool isModInstalled(const QString & modName);
public slots:
void enableModByName(QString modName);
void disableModByName(QString modName);

View File

@ -54,6 +54,14 @@ static constexpr std::array downscalingFilterTypes =
"best"
};
MainWindow * CSettingsView::getMainWindow()
{
foreach(QWidget *w, qApp->allWidgets())
if(QMainWindow* mainWin = qobject_cast<QMainWindow*>(w))
return dynamic_cast<MainWindow *>(mainWin);
return nullptr;
}
void CSettingsView::setDisplayList()
{
QStringList list;
@ -166,6 +174,17 @@ void CSettingsView::loadSettings()
ui->sliderControllerSticksAcceleration->setValue(settings["input"]["controllerAxisScale"].Float() * 100);
ui->lineEditGameLobbyHost->setText(QString::fromStdString(settings["lobby"]["hostname"].String()));
ui->spinBoxNetworkPortLobby->setValue(settings["lobby"]["port"].Integer());
auto mainWindow = getMainWindow();
if(mainWindow)
{
bool fontModAvailable = mainWindow->getModView()->isModInstalled("vcmi-extras.truetypefonts");
if(!fontModAvailable)
{
ui->labelTtfFont->hide();
ui->buttonTtfFont->hide();
}
}
loadToggleButtonSettings();
}
@ -190,6 +209,10 @@ void CSettingsView::loadToggleButtonSettings()
std::string cursorType = settings["video"]["cursor"].String();
int cursorTypeIndex = vstd::find_pos(cursorTypesList, cursorType);
setCheckbuttonState(ui->buttonCursorType, cursorTypeIndex);
auto mainWindow = getMainWindow();
if(mainWindow)
setCheckbuttonState(ui->buttonTtfFont, mainWindow->getModView()->isModEnabled("vcmi-extras.truetypefonts"));
}
void CSettingsView::fillValidResolutions()
@ -442,8 +465,7 @@ void CSettingsView::on_comboBoxLanguage_currentIndexChanged(int index)
QString selectedLanguage = ui->comboBoxLanguage->itemData(index).toString();
node->String() = selectedLanguage.toStdString();
if(auto * mainWindow = dynamic_cast<MainWindow *>(qApp->activeWindow()))
mainWindow->updateTranslation();
getMainWindow()->updateTranslation();
}
void CSettingsView::changeEvent(QEvent *event)
@ -475,7 +497,7 @@ void CSettingsView::loadTranslation()
{
QString baseLanguage = Languages::getHeroesDataLanguage();
auto * mainWindow = dynamic_cast<MainWindow *>(qApp->activeWindow());
auto * mainWindow = getMainWindow();
if (!mainWindow)
return;
@ -518,7 +540,7 @@ void CSettingsView::loadTranslation()
void CSettingsView::on_pushButtonTranslation_clicked()
{
auto * mainWindow = dynamic_cast<MainWindow *>(qApp->activeWindow());
auto * mainWindow = getMainWindow();
assert(mainWindow);
if (!mainWindow)
@ -582,7 +604,7 @@ void CSettingsView::on_spinBoxInterfaceScaling_valueChanged(int arg1)
void CSettingsView::on_refreshRepositoriesButton_clicked()
{
auto * mainWindow = dynamic_cast<MainWindow *>(qApp->activeWindow());
auto * mainWindow = getMainWindow();
assert(mainWindow);
if (!mainWindow)
@ -747,3 +769,13 @@ void CSettingsView::on_sliderControllerSticksSensitivity_valueChanged(int value)
Settings node = settings.write["input"]["controllerAxisSpeed"];
node->Integer() = value;
}
void CSettingsView::on_buttonTtfFont_toggled(bool value)
{
auto mainWindow = getMainWindow();
if(value)
mainWindow->getModView()->enableModByName("vcmi-extras.truetypefonts");
else
mainWindow->getModView()->disableModByName("vcmi-extras.truetypefonts");
updateCheckbuttonText(ui->buttonTtfFont);
}

View File

@ -14,10 +14,14 @@ namespace Ui
class CSettingsView;
}
class MainWindow;
class CSettingsView : public QWidget
{
Q_OBJECT
MainWindow * getMainWindow();
public:
explicit CSettingsView(QWidget * parent = nullptr);
~CSettingsView();
@ -84,6 +88,8 @@ private slots:
void on_sliderControllerSticksSensitivity_valueChanged(int value);
void on_buttonTtfFont_toggled(bool value);
private:
Ui::CSettingsView * ui;

View File

@ -68,7 +68,7 @@
</property>
</widget>
</item>
<item row="46" column="1" colspan="4">
<item row="47" column="1" colspan="4">
<widget class="QComboBox" name="comboBoxEnemyAI">
<property name="editable">
<bool>false</bool>
@ -88,14 +88,14 @@
</item>
</widget>
</item>
<item row="39" column="0">
<item row="40" column="0">
<widget class="QLabel" name="labelControllerSticksAcceleration">
<property name="text">
<string>Sticks Acceleration</string>
</property>
</widget>
</item>
<item row="49" column="2" colspan="3">
<item row="50" column="2" colspan="3">
<widget class="QPushButton" name="refreshRepositoriesButton">
<property name="text">
<string>Refresh now</string>
@ -132,14 +132,14 @@
</property>
</widget>
</item>
<item row="52" column="0">
<item row="53" column="0">
<widget class="QLabel" name="labelGameLobbyHost">
<property name="text">
<string>Online Lobby address</string>
</property>
</widget>
</item>
<item row="43" column="1" colspan="4">
<item row="44" column="1" colspan="4">
<widget class="QComboBox" name="comboBoxAlliedPlayerAI">
<property name="currentText">
<string notr="true">VCAI</string>
@ -172,7 +172,7 @@
</property>
</widget>
</item>
<item row="25" column="1" colspan="4">
<item row="26" column="1" colspan="4">
<widget class="QSlider" name="sliderMusicVolume">
<property name="maximum">
<number>100</number>
@ -243,7 +243,7 @@
</property>
</widget>
</item>
<item row="50" column="0">
<item row="51" column="0">
<widget class="QLabel" name="labelRepositoryDefault">
<property name="text">
<string>Default repository</string>
@ -270,7 +270,7 @@
</property>
</widget>
</item>
<item row="32" column="1" colspan="4">
<item row="33" column="1" colspan="4">
<widget class="QSlider" name="sliderRelativeCursorSpeed">
<property name="minimum">
<number>100</number>
@ -296,7 +296,7 @@
</property>
</widget>
</item>
<item row="41" column="0">
<item row="42" column="0">
<widget class="QLabel" name="labelArtificialIntelligence">
<property name="font">
<font>
@ -311,7 +311,7 @@
</property>
</widget>
</item>
<item row="31" column="0">
<item row="32" column="0">
<widget class="QLabel" name="labelRelativeCursorMode">
<property name="text">
<string>Use Relative Pointer Mode</string>
@ -325,7 +325,7 @@
</property>
</widget>
</item>
<item row="45" column="0">
<item row="46" column="0">
<widget class="QLabel" name="labelFriendlyAI">
<property name="text">
<string>Autocombat AI in battles</string>
@ -339,35 +339,35 @@
</property>
</widget>
</item>
<item row="34" column="0">
<item row="35" column="0">
<widget class="QLabel" name="labelLongTouchDuration">
<property name="text">
<string>Long Touch Duration</string>
</property>
</widget>
</item>
<item row="38" column="0">
<item row="39" column="0">
<widget class="QLabel" name="labelControllerSticksSensitivity">
<property name="text">
<string>Sticks Sensitivity</string>
</property>
</widget>
</item>
<item row="36" column="0">
<item row="37" column="0">
<widget class="QLabel" name="labelToleranceDistanceTouch">
<property name="text">
<string>Touch Tap Tolerance</string>
</property>
</widget>
</item>
<item row="51" column="2" colspan="3">
<item row="52" column="2" colspan="3">
<widget class="QLineEdit" name="lineEditRepositoryExtra">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="26" column="1" colspan="4">
<item row="27" column="1" colspan="4">
<widget class="QSlider" name="sliderSoundVolume">
<property name="maximum">
<number>100</number>
@ -414,7 +414,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</item>
</widget>
</item>
<item row="50" column="1">
<item row="51" column="1">
<widget class="QToolButton" name="buttonRepositoryDefault">
<property name="enabled">
<bool>true</bool>
@ -436,7 +436,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="50" column="2" colspan="3">
<item row="51" column="2" colspan="3">
<widget class="QLineEdit" name="lineEditRepositoryDefault">
<property name="text">
<string notr="true"/>
@ -456,7 +456,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
<item row="19" column="1" colspan="4">
<widget class="QComboBox" name="comboBoxDisplayIndex"/>
</item>
<item row="36" column="1" colspan="4">
<item row="37" column="1" colspan="4">
<widget class="QSlider" name="sliderToleranceDistanceTouch">
<property name="minimum">
<number>0</number>
@ -484,7 +484,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="53" column="0">
<item row="54" column="0">
<widget class="QLabel" name="labelNetworkPortLobby">
<property name="text">
<string>Online Lobby port</string>
@ -525,7 +525,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="24" column="0">
<item row="25" column="0">
<widget class="QLabel" name="labelAudio">
<property name="font">
<font>
@ -540,7 +540,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="51" column="1">
<item row="52" column="1">
<widget class="QToolButton" name="buttonRepositoryExtra">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@ -559,7 +559,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="38" column="1" colspan="4">
<item row="39" column="1" colspan="4">
<widget class="QSlider" name="sliderControllerSticksSensitivity">
<property name="minimum">
<number>500</number>
@ -620,7 +620,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</item>
</widget>
</item>
<item row="45" column="1" colspan="4">
<item row="46" column="1" colspan="4">
<widget class="QComboBox" name="comboBoxFriendlyAI">
<property name="editable">
<bool>false</bool>
@ -640,14 +640,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</item>
</widget>
</item>
<item row="49" column="0">
<item row="50" column="0">
<widget class="QLabel" name="labelAutoCheck">
<property name="text">
<string>Check on startup</string>
</property>
</widget>
</item>
<item row="28" column="1" colspan="4">
<item row="29" column="1" colspan="4">
<widget class="QSlider" name="slideToleranceDistanceMouse">
<property name="minimum">
<number>0</number>
@ -691,7 +691,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="34" column="1" colspan="4">
<item row="35" column="1" colspan="4">
<widget class="QSlider" name="sliderLongTouchDuration">
<property name="minimum">
<number>500</number>
@ -719,7 +719,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
<item row="1" column="1" colspan="4">
<widget class="QComboBox" name="comboBoxLanguage"/>
</item>
<item row="53" column="1" colspan="4">
<item row="54" column="1" colspan="4">
<widget class="QSpinBox" name="spinBoxNetworkPortLobby">
<property name="minimum">
<number>1024</number>
@ -732,14 +732,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="46" column="0">
<item row="47" column="0">
<widget class="QLabel" name="labelEnemyAI">
<property name="text">
<string>Enemy AI in battles</string>
</property>
</widget>
</item>
<item row="29" column="0">
<item row="30" column="0">
<widget class="QLabel" name="labelInputMouse_2">
<property name="font">
<font>
@ -761,7 +761,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="48" column="0">
<item row="49" column="0">
<widget class="QLabel" name="labelIgnoreSslErrors">
<property name="text">
<string>Ignore SSL errors</string>
@ -778,7 +778,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="52" column="1" colspan="4">
<item row="53" column="1" colspan="4">
<widget class="QLineEdit" name="lineEditGameLobbyHost">
<property name="text">
<string notr="true"/>
@ -792,14 +792,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="33" column="0">
<item row="34" column="0">
<widget class="QLabel" name="labelHapticFeedback">
<property name="text">
<string>Haptic Feedback</string>
</property>
</widget>
</item>
<item row="33" column="1" colspan="4">
<item row="34" column="1" colspan="4">
<widget class="QToolButton" name="buttonHapticFeedback">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@ -815,14 +815,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="51" column="0">
<item row="52" column="0">
<widget class="QLabel" name="labelRepositoryExtra">
<property name="text">
<string>Additional repository</string>
</property>
</widget>
</item>
<item row="28" column="0">
<item row="29" column="0">
<widget class="QLabel" name="labelToleranceDistanceMouse">
<property name="text">
<string>Mouse Click Tolerance</string>
@ -836,14 +836,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="32" column="0">
<item row="33" column="0">
<widget class="QLabel" name="labelRelativeCursorSpeed">
<property name="text">
<string>Relative Pointer Speed</string>
</property>
</widget>
</item>
<item row="47" column="0">
<item row="48" column="0">
<widget class="QLabel" name="labelNetwork">
<property name="font">
<font>
@ -865,7 +865,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="48" column="1" colspan="4">
<item row="49" column="1" colspan="4">
<widget class="QToolButton" name="buttonIgnoreSslErrors">
<property name="enabled">
<bool>true</bool>
@ -894,14 +894,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="42" column="0">
<item row="43" column="0">
<widget class="QLabel" name="labelEnemyPlayerAI">
<property name="text">
<string>Adventure Map Enemies</string>
</property>
</widget>
</item>
<item row="44" column="1" colspan="4">
<item row="45" column="1" colspan="4">
<widget class="QComboBox" name="comboBoxNeutralAI">
<property name="currentText">
<string notr="true">BattleAI</string>
@ -918,21 +918,21 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</item>
</widget>
</item>
<item row="44" column="0">
<item row="45" column="0">
<widget class="QLabel" name="labelNeutralAI">
<property name="text">
<string>Neutral AI in battles</string>
</property>
</widget>
</item>
<item row="43" column="0">
<item row="44" column="0">
<widget class="QLabel" name="labelAlliedPlayerAI">
<property name="text">
<string>Adventure Map Allies</string>
</property>
</widget>
</item>
<item row="27" column="0">
<item row="28" column="0">
<widget class="QLabel" name="labelInputMouse">
<property name="font">
<font>
@ -947,7 +947,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="49" column="1">
<item row="50" column="1">
<widget class="QToolButton" name="buttonAutoCheck">
<property name="enabled">
<bool>true</bool>
@ -985,7 +985,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="42" column="1" colspan="4">
<item row="43" column="1" colspan="4">
<widget class="QComboBox" name="comboBoxEnemyPlayerAI">
<property name="currentText">
<string notr="true">VCAI</string>
@ -1009,7 +1009,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="37" column="0">
<item row="38" column="0">
<widget class="QLabel" name="labelInputMouse_3">
<property name="font">
<font>
@ -1031,14 +1031,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="40" column="0">
<item row="41" column="0">
<widget class="QLabel" name="labelToleranceDistanceController">
<property name="text">
<string>Controller Click Tolerance</string>
</property>
</widget>
</item>
<item row="39" column="1" colspan="4">
<item row="40" column="1" colspan="4">
<widget class="QSlider" name="sliderControllerSticksAcceleration">
<property name="minimum">
<number>100</number>
@ -1080,14 +1080,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="26" column="0">
<item row="27" column="0">
<widget class="QLabel" name="labelSoundVolume">
<property name="text">
<string>Sound Volume</string>
</property>
</widget>
</item>
<item row="40" column="1" colspan="4">
<item row="41" column="1" colspan="4">
<widget class="QSlider" name="sliderToleranceDistanceController">
<property name="minimum">
<number>0</number>
@ -1115,7 +1115,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="31" column="1" colspan="4">
<item row="32" column="1" colspan="4">
<widget class="QToolButton" name="buttonRelativeCursorMode">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@ -1131,21 +1131,21 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</property>
</widget>
</item>
<item row="25" column="0">
<item row="26" column="0">
<widget class="QLabel" name="labelMusicVolume">
<property name="text">
<string>Music Volume</string>
</property>
</widget>
</item>
<item row="30" column="0">
<item row="31" column="0">
<widget class="QLabel" name="labelResetTutorialTouchscreen">
<property name="text">
<string>Show Tutorial again</string>
</property>
</widget>
</item>
<item row="30" column="1" colspan="4">
<item row="31" column="1" colspan="4">
<widget class="QPushButton" name="pushButtonResetTutorialTouchscreen">
<property name="text">
<string>Reset</string>
@ -1188,6 +1188,29 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use
</item>
</widget>
</item>
<item row="24" column="0">
<widget class="QLabel" name="labelTtfFont">
<property name="text">
<string>Use scalable fonts</string>
</property>
</widget>
</item>
<item row="24" column="1" colspan="4">
<widget class="QToolButton" name="buttonTtfFont">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>