Skip to content

Commit

Permalink
Merge branch 'master' into wip-translator
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohlstand committed Feb 23, 2024
2 parents de2512d + 5ea493b commit c82e5bb
Show file tree
Hide file tree
Showing 33 changed files with 3,176 additions and 511 deletions.
197 changes: 181 additions & 16 deletions Editor/editing/_scenes/level/itemmsgbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
#include <QFontMetrics>
#include <QScrollBar>
#include <QStyle>
#include <QSettings>

#include "itemmsgbox.h"
#include <ui_itemmsgbox.h>

#include "main_window/global_settings.h"


ItemMsgBox::ItemMsgBox(Opened_By openedBy, QString text, bool isFriendly, QString label, QString title, QWidget *parent) :
QDialog(parent),
ui(new Ui::ItemMsgBox)
Expand All @@ -45,27 +49,77 @@ ItemMsgBox::ItemMsgBox(Opened_By openedBy, QString text, bool isFriendly, QStrin
if(!title.isEmpty())
this->setWindowTitle(title);

//#ifdef Q_OS_MACX
// QFont theFont("Press Start 2P", 11);
//#else
// QFont theFont("Press Start 2P", 11);
//#endif
QFont theFont("Press Start 2P");
theFont.setPixelSize(8);
theFont.setStyleHint(QFont::Monospace);
ui->msgTextBox->setFont(theFont);
ui->msgTextBox->clear();
QFontMetrics meter(ui->msgTextBox->font());
int w_width = meter.size(Qt::TextSingleLine, "XXXXXXXXXXXXXXXXXXXXXXXXXXX").width();
int scrW = ui->msgTextBox->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
ui->msgTextBox->setMaximumWidth(w_width + scrW + 18);
ui->msgTextBox->setMinimumWidth(w_width + scrW + 18);
ui->msgTextBox->appendPlainText(currentText);
// Set default preview font to 8
ui->previewBox->setFontSize(8);

ui->previewFont->setValue(ui->previewBox->fontSize());

QObject::connect(ui->previewShow, static_cast<void(QToolButton::*)(bool)>(&QToolButton::toggled),
this, &ItemMsgBox::updateDialogueSize);

qApp->processEvents(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers);
ui->previewArea->setVisible(ui->previewShow->isChecked());
ItemMsgBox::updateDialogueSize(ui->previewShow->isChecked());

QObject::connect(ui->msgTextBox, &QPlainTextEdit::textChanged, this,
[this]()->void
{
ui->previewBox->setText(ui->msgTextBox->toPlainText());
});

QObject::connect(ui->previewFont, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](int val)->void
{
ui->previewBox->setFontSize(val);
});

QObject::connect(ui->previewEngine, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
[this](int val)->void
{
ui->previewBox->setVanillaMode(val == 0);
ui->previewMacrosGroup->setVisible(val > 0);
ui->previewBox->setEnableMacros(val > 0 && ui->previewMacrosGroup->isChecked());
updateEngineDesc();
});

updateEngineDesc();

QObject::connect(ui->previewMacrosGroup, static_cast<void(QGroupBox::*)(bool)>(&QGroupBox::toggled), this,
[this](bool macros)->void
{
ui->previewBox->setEnableMacros(macros && ui->previewEngine->currentIndex() > 0);
ui->previewMacrosGroup->setVisible(ui->previewEngine->currentIndex() > 0);
});

QObject::connect(ui->previewMacroPlayer, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](int val)->void
{
ui->previewBox->setMacroPlayerNum(val);
});

QObject::connect(ui->previewMacroState, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](int val)->void
{
ui->previewBox->setMacroPlayerState(val);
});

ui->previewMacrosGroup->setChecked(false);
ui->previewMacrosGroup->setVisible(ui->previewEngine->currentIndex() > 0);

#if 1 // Hide experimental feature
ui->previewMacroState->setVisible(false);
ui->previewMacroStateLabel->setVisible(false);
#endif

ui->msgTextBox->setPlainText(currentText);
updateGeometry();

loadSetup();
}

ItemMsgBox::~ItemMsgBox()
{
saveSetup();
delete ui;
}

Expand All @@ -79,3 +133,114 @@ void ItemMsgBox::on_buttonBox_accepted()
currentText = ui->msgTextBox->toPlainText();
accept();
}

void ItemMsgBox::updateDialogueSize(bool showPreview)
{
QRect self = this->geometry();
QRect selfL = ui->dialogueLayout->geometry();

QString buttonText = tr("Preview", "The text on the switch button");

if(showPreview)
{
ui->previewShow->setText(QString("%1 <<").arg(buttonText));

ui->previewArea->setVisible(showPreview);
qApp->processEvents(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers);
QSize area = ui->previewArea->size();
self.setWidth(self.width() + area.width());
selfL.setWidth(selfL.width() + area.width());
ui->dialogueLayout->setGeometry(selfL);
this->setGeometry(self);
}
else
{
ui->previewShow->setText(QString("%1 >>").arg(buttonText));

QSize area = ui->previewArea->size();
ui->previewArea->setVisible(showPreview);
this->update();
qApp->processEvents(QEventLoop::ExcludeUserInputEvents|QEventLoop::ExcludeSocketNotifiers);
self.setWidth(self.width() - area.width());
selfL.setWidth(selfL.width() - area.width());
ui->dialogueLayout->setGeometry(selfL);
this->setGeometry(self);
}
}

void ItemMsgBox::updateEngineDesc()
{
switch(ui->previewEngine->currentIndex())
{
case 0: // SMBX 1.3 / X2
ui->engineDesc->setText(
tr("The basic message box of <b>SMBX 1.3 / X2</b> has the next restrictions:\n"
"<ul>\n"
" <li>New line <b>CAN NOT be done via the \"Return\"/\"Enter\" key</b><br/>\n"
"(you should use spaces as a workaround).<li>\n"
" <li>Line breaks happen automatically after <b>27 characters</b>.</li>\n"
" <li>Very long words doesn't breaks and gets printed out of screen.<br/>\n"
"So, please break these words to avoid this.</li>\n"
" <li>You can't use any Unicode characters: <b>ASCII only</b> works.</li>\n"
"</ul>", "Message box behaviour explanation")
);
break;

case 1: // Moondust / TheXTech
ui->engineDesc->setText(
tr("The message box of <b>Moondust / TheXTech</b> has the next restrictions:\n"
"<ul>\n"
" <li>New line <b>CAN be done by \"Return\"/\"Enter\" key</b> easily.</li>\n"
" <li>Line breaks also happen automatically after <b>27 characters</b>.</li>\n"
" <li>Very long words gets broken forcibly.</li>\n"
" <li>You can use <b>any Unicode</b> characters.</li>\n"
" <li><b>Preprocessor's macros</b> can be used.</li>\n"
"</ul>", "Message box behaviour explanation")
);
break;
}
}

void ItemMsgBox::loadSetup()
{
QSettings settings(ConfStatus::configLocalSettingsFile, QSettings::IniFormat);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
settings.setIniCodec("UTF-8");
#endif

settings.beginGroup("MsgBoxEditor");
{
if(settings.contains("show-preview"))
ui->previewShow->setChecked(settings.value("show-preview", false).toBool());

ui->previewEngine->setCurrentIndex(settings.value("engine", 0).toInt());
if(settings.contains("font-size"))
ui->previewFont->setValue(settings.value("font-size").toInt());

ui->previewMacrosGroup->setChecked(settings.value("macros", false).toBool());
ui->previewMacroPlayer->setValue(settings.value("macros-player", 0).toInt());

restoreGeometry(settings.value("geometry").toByteArray());
}
settings.endGroup();
}

void ItemMsgBox::saveSetup()
{
QSettings settings(ConfStatus::configLocalSettingsFile, QSettings::IniFormat);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
settings.setIniCodec("UTF-8");
#endif

settings.beginGroup("MsgBoxEditor");
{
settings.setValue("show-preview", ui->previewShow->isChecked());
settings.setValue("engine", ui->previewEngine->currentIndex());
settings.setValue("font-size", ui->previewFont->value());
settings.setValue("macros", ui->previewMacrosGroup->isChecked());
settings.setValue("macros-player", ui->previewMacroPlayer->value());

settings.setValue("geometry", saveGeometry());
}
settings.endGroup();
}
5 changes: 5 additions & 0 deletions Editor/editing/_scenes/level/itemmsgbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ class ItemMsgBox : public QDialog

private slots:
void on_buttonBox_accepted();
void updateDialogueSize(bool showPreview);
void updateEngineDesc();

private:
Ui::ItemMsgBox *ui;

void loadSetup();
void saveSetup();
};

#endif // ITEMMSGBOX_H
Loading

0 comments on commit c82e5bb

Please sign in to comment.