|
@@ -851,21 +851,51 @@ void MainWindow::on_pushButton_clicked()
|
851
|
851
|
|
852
|
852
|
QSpinBox *widthSpinBox = new QSpinBox();
|
853
|
853
|
QSpinBox *heightSpinBox = new QSpinBox();
|
854
|
|
- widthSpinBox->setValue(editor->map->getWidth());
|
855
|
|
- heightSpinBox->setValue(editor->map->getHeight());
|
856
|
854
|
widthSpinBox->setMinimum(1);
|
857
|
855
|
heightSpinBox->setMinimum(1);
|
858
|
|
- widthSpinBox->setMaximum(255);
|
859
|
|
- heightSpinBox->setMaximum(255);
|
|
856
|
+ // See below for explanation of maximum map dimensions
|
|
857
|
+ widthSpinBox->setMaximum(0x1E7);
|
|
858
|
+ heightSpinBox->setMaximum(0x1D1);
|
|
859
|
+ widthSpinBox->setValue(editor->map->getWidth());
|
|
860
|
+ heightSpinBox->setValue(editor->map->getHeight());
|
860
|
861
|
form.addRow(new QLabel("Width"), widthSpinBox);
|
861
|
862
|
form.addRow(new QLabel("Height"), heightSpinBox);
|
862
|
863
|
|
|
864
|
+ QLabel *errorLabel = new QLabel();
|
|
865
|
+ QPalette errorPalette;
|
|
866
|
+ errorPalette.setColor(QPalette::WindowText, Qt::red);
|
|
867
|
+ errorLabel->setPalette(errorPalette);
|
|
868
|
+ errorLabel->setVisible(false);
|
|
869
|
+
|
863
|
870
|
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
|
864
|
871
|
form.addRow(&buttonBox);
|
865
|
|
- connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
|
872
|
+ connect(&buttonBox, &QDialogButtonBox::accepted, [&dialog, &widthSpinBox, &heightSpinBox, &errorLabel](){
|
|
873
|
+ // Ensure width and height are an acceptable size.
|
|
874
|
+ // The maximum number of metatiles in a map is the following:
|
|
875
|
+ // max = (width + 15) * (height + 14)
|
|
876
|
+ // This limit can be found in fieldmap.c in pokeruby/pokeemerald.
|
|
877
|
+ int realWidth = widthSpinBox->value() + 15;
|
|
878
|
+ int realHeight = heightSpinBox->value() + 14;
|
|
879
|
+ int numMetatiles = realWidth * realHeight;
|
|
880
|
+ if (numMetatiles <= 0x2800) {
|
|
881
|
+ dialog.accept();
|
|
882
|
+ } else {
|
|
883
|
+ QString errorText = QString("Error: The specified width and height are too large.\n"
|
|
884
|
+ "The maximum width and height is the following: (width + 15) * (height + 14) <= 10240\n"
|
|
885
|
+ "The specified width and height was: (%1 + 15) * (%2 + 14) = %3")
|
|
886
|
+ .arg(widthSpinBox->value())
|
|
887
|
+ .arg(heightSpinBox->value())
|
|
888
|
+ .arg(numMetatiles);
|
|
889
|
+ errorLabel->setText(errorText);
|
|
890
|
+ errorLabel->setVisible(true);
|
|
891
|
+ }
|
|
892
|
+ });
|
866
|
893
|
connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
867
|
894
|
|
|
895
|
+ form.addRow(errorLabel);
|
|
896
|
+
|
868
|
897
|
if (dialog.exec() == QDialog::Accepted) {
|
869
|
|
- qDebug() << "Change width";
|
|
898
|
+ editor->map->setDimensions(widthSpinBox->value(), heightSpinBox->value());
|
|
899
|
+ setMap(editor->map->name);
|
870
|
900
|
}
|
871
|
901
|
}
|