Skip to content

Commit

Permalink
Fix: make delete map button function better (#6789)
Browse files Browse the repository at this point in the history
#### Motivation for adding to Mudlet
In the referred to issue it was pointed out that the delete map button
was not accessible until a mapper has been created - which is not an
optimum situation.

#### Other info (issues closed, discussion etc)
Moves the handling of the `(bool) mShowDefaultArea` flag from the
`dlgMapper` class to the `TMap` one so it can be controlled even when
there is not a map widget loaded.

#### Brief overview of PR changes/additions
This will close #6549.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
  • Loading branch information
SlySven committed Apr 24, 2023
1 parent 096396d commit fb04f6f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/T2DMap.cpp
Expand Up @@ -1555,8 +1555,8 @@ void T2DMap::paintEvent(QPaintEvent* e)
static bool isAreaWidgetValid = true; // Remember between uses
QFont _f = mpMap->mpMapper->comboBox_showArea->font();
if (isAreaWidgetValid) {
if (mAreaID == -1 // the map being shown is the "default" area
&& !mpMap->mpMapper->getDefaultAreaShown()) { // the area widget is not showing the "default" area
if (mAreaID == -1 // the map being shown is the "default" area
&& !mpMap->getDefaultAreaShown()) { // the area widget is not showing the "default" area

isAreaWidgetValid = false; // So the widget CANNOT indicate the correct area
// Set the area widget to indicate the area widget is NOT
Expand All @@ -1567,7 +1567,7 @@ void T2DMap::paintEvent(QPaintEvent* e)
_f.setOverline(true);
}
} else {
if (!(mAreaID == -1 && !mpMap->mpMapper->getDefaultAreaShown())) {
if (!(mAreaID == -1 && !mpMap->getDefaultAreaShown())) {
isAreaWidgetValid = true; // So the widget CAN now indicate the correct area
// Reset to normal
_f.setItalic(false);
Expand Down
4 changes: 2 additions & 2 deletions src/TLuaInterpreter.cpp
Expand Up @@ -12258,11 +12258,11 @@ int TLuaInterpreter::setDefaultAreaVisible(lua_State* L)
// AND the mapper was showing the default area
// the area widget will NOT be showing the correct area name afterwards
bool isAreaWidgetInNeedOfResetting = false;
if ((!host.mpMap->mpMapper->getDefaultAreaShown()) && (isToShowDefaultArea) && (host.mpMap->mpMapper->mp2dMap->mAreaID == -1)) {
if ((!host.mpMap->getDefaultAreaShown()) && (isToShowDefaultArea) && (host.mpMap->mpMapper->mp2dMap->mAreaID == -1)) {
isAreaWidgetInNeedOfResetting = true;
}

host.mpMap->mpMapper->setDefaultAreaShown(isToShowDefaultArea);
host.mpMap->setDefaultAreaShown(isToShowDefaultArea);
if (isAreaWidgetInNeedOfResetting) {
// Corner case fixup:
host.mpMap->mpMapper->comboBox_showArea->setCurrentText(host.mpMap->getDefaultAreaName());
Expand Down
10 changes: 10 additions & 0 deletions src/TMap.cpp
Expand Up @@ -3484,3 +3484,13 @@ void TMap::setUnsaved(const char* fromWhere)
#endif
mUnsavedMap = true;
}

void TMap::setDefaultAreaShown(bool state)
{
if (mShowDefaultArea != state) {
mShowDefaultArea = state;
if (!mpMapper.isNull()) {
mpMapper->updateAreaComboBox();
}
}
}
5 changes: 5 additions & 0 deletions src/TMap.h
Expand Up @@ -196,6 +196,8 @@ class TMap : public QObject
void setUnsaved(const char*);
void resetUnsaved() { mUnsavedMap = false; }
bool isUnsaved() const { return mUnsavedMap; }
void setDefaultAreaShown(bool);
bool getDefaultAreaShown() { return mShowDefaultArea; }


TRoomDB* mpRoomDB = nullptr;
Expand Down Expand Up @@ -381,6 +383,9 @@ public slots:

// Used to flag whether the map auto-save needs to be done after the next interval:
bool mUnsavedMap = false;
// Used to hide the default area from casual viewing for those MUDs that
// want to script a "fog-of-war" system by hiding rooms in the -1 area:
bool mShowDefaultArea = true;
};

#endif // MUDLET_TMAP_H
14 changes: 3 additions & 11 deletions src/dlgMapper.cpp
Expand Up @@ -150,7 +150,7 @@ void dlgMapper::updateAreaComboBox()
QMap<QString, QString> areaNames;
while (itAreaNamesA.hasNext()) {
itAreaNamesA.next();
if (itAreaNamesA.key() == -1 && !mShowDefaultArea) {
if (itAreaNamesA.key() == -1 && !mpMap->getDefaultAreaShown()) {
continue; // Skip the default area from the listing if so directed
}

Expand All @@ -166,7 +166,7 @@ void dlgMapper::updateAreaComboBox()

comboBox_showArea->clear();

if (areaNames.isEmpty() || (mpMap && areaNames.count() == 1 && (*areaNames.constBegin() == mpMap->getDefaultAreaName()) && !mShowDefaultArea)) {
if (areaNames.isEmpty() || (mpMap && areaNames.count() == 1 && (*areaNames.constBegin() == mpMap->getDefaultAreaName()) && !mpMap->getDefaultAreaShown())) {
// IF there are no area names to show - should be impossible as there
// should always be the "Default Area" one
// OR there is only one sorted name
Expand All @@ -179,7 +179,7 @@ void dlgMapper::updateAreaComboBox()
return;
}

if (areaNames.count() == ((areaNames.contains(mpMap->getDefaultAreaName()) && !mShowDefaultArea) ? 2 : 1)) {
if (areaNames.count() == ((areaNames.contains(mpMap->getDefaultAreaName()) && !mpMap->getDefaultAreaShown()) ? 2 : 1)) {
// IF we have exactly 2 (if we are NOT showing the default area AND the names include it)
// OR exactly 1 otherwise
// THEN
Expand Down Expand Up @@ -332,14 +332,6 @@ void dlgMapper::slot_toggleRoundRooms(const bool state)
}
}

void dlgMapper::setDefaultAreaShown(bool state)
{
if (mShowDefaultArea != state) {
mShowDefaultArea = state;
updateAreaComboBox();
}
}

void dlgMapper::resetAreaComboBoxToPlayerRoomArea()
{
Host* pHost = mpHost;
Expand Down
3 changes: 0 additions & 3 deletions src/dlgMapper.h
Expand Up @@ -49,8 +49,6 @@ class dlgMapper : public QWidget, public Ui::mapper
GLWidget* glWidget = nullptr;
#endif
void updateAreaComboBox();
void setDefaultAreaShown(bool);
bool getDefaultAreaShown() { return mShowDefaultArea; }
void resetAreaComboBoxToPlayerRoomArea();
// The button is the goto source for this bit of information:
bool isIn3DMode() const { return pushButton_3D->isDown(); }
Expand Down Expand Up @@ -78,7 +76,6 @@ public slots:
private:
TMap* mpMap = nullptr;
QPointer<Host> mpHost;
bool mShowDefaultArea = true;
};

#endif // MUDLET_DLGMAPPER_H
66 changes: 35 additions & 31 deletions src/dlgProfilePreferences.cpp
Expand Up @@ -939,25 +939,26 @@ void dlgProfilePreferences::initWithHost(Host* pHost)
comboBox_mapFileSaveFormatVersion->addItem(tr("%1 {Default, recommended}").arg(pHost->mpMap->mDefaultVersion), QVariant(pHost->mpMap->mDefaultVersion));
comboBox_mapFileSaveFormatVersion->setEnabled(false);
label_mapFileSaveFormatVersion->setEnabled(false);
if (pHost->mpMap->mMaxVersion > pHost->mpMap->mDefaultVersion || pHost->mpMap->mMinVersion < pHost->mpMap->mDefaultVersion) {
for (int i = pHost->mpMap->mMinVersion; i <= pHost->mpMap->mMaxVersion; ++i) {
if (i == pHost->mpMap->mDefaultVersion) {
continue;
if (pHost->mpMap) {
if (pHost->mpMap->mMaxVersion > pHost->mpMap->mDefaultVersion || pHost->mpMap->mMinVersion < pHost->mpMap->mDefaultVersion) {
for (int i = pHost->mpMap->mMinVersion; i <= pHost->mpMap->mMaxVersion; ++i) {
if (i == pHost->mpMap->mDefaultVersion) {
continue;
}
comboBox_mapFileSaveFormatVersion->setEnabled(true);
label_mapFileSaveFormatVersion->setEnabled(true);
if (i > pHost->mpMap->mDefaultVersion) {
comboBox_mapFileSaveFormatVersion->addItem(tr("%1 {Upgraded, experimental/testing, NOT recommended}").arg(i), QVariant(i));
} else {
comboBox_mapFileSaveFormatVersion->addItem(tr("%1 {Downgraded, for sharing with older version users, NOT recommended}").arg(i), QVariant(i));
}
}
comboBox_mapFileSaveFormatVersion->setEnabled(true);
label_mapFileSaveFormatVersion->setEnabled(true);
if (i > pHost->mpMap->mDefaultVersion) {
comboBox_mapFileSaveFormatVersion->addItem(tr("%1 {Upgraded, experimental/testing, NOT recommended}").arg(i), QVariant(i));
} else {
comboBox_mapFileSaveFormatVersion->addItem(tr("%1 {Downgraded, for sharing with older version users, NOT recommended}").arg(i), QVariant(i));
int _indexForCurrentSaveFormat = comboBox_mapFileSaveFormatVersion->findData(pHost->mpMap->mSaveVersion, Qt::UserRole);
if (_indexForCurrentSaveFormat >= 0) {
comboBox_mapFileSaveFormatVersion->setCurrentIndex(_indexForCurrentSaveFormat);
}
}
int _indexForCurrentSaveFormat = comboBox_mapFileSaveFormatVersion->findData(pHost->mpMap->mSaveVersion, Qt::UserRole);
if (_indexForCurrentSaveFormat >= 0) {
comboBox_mapFileSaveFormatVersion->setCurrentIndex(_indexForCurrentSaveFormat);
}
}
if (pHost->mpMap->mpMapper) {

QLabel* pLabel_mapSymbolFontFudge = new QLabel(tr("2D Map Room Symbol scaling factor:"), groupBox_mapViewOptions);
mpDoubleSpinBox_mapSymbolFontFudge = new QDoubleSpinBox(groupBox_mapViewOptions);
mpDoubleSpinBox_mapSymbolFontFudge->setValue(pHost->mpMap->mMapSymbolFontFudgeFactor);
Expand All @@ -979,7 +980,7 @@ void dlgProfilePreferences::initWithHost(Host* pHost)

checkBox_showDefaultArea->show();
checkBox_showDefaultArea->setText(tr(R"(Show "%1" in the map area selection)").arg(pHost->mpMap->getDefaultAreaName()));
checkBox_showDefaultArea->setChecked(pHost->mpMap->mpMapper->getDefaultAreaShown());
checkBox_showDefaultArea->setChecked(pHost->mpMap->getDefaultAreaShown());

pushButton_showGlyphUsage->setEnabled(true);
fontComboBox_mapSymbols->setCurrentFont(pHost->mpMap->mMapSymbolFont);
Expand Down Expand Up @@ -2794,26 +2795,29 @@ void dlgProfilePreferences::slot_saveAndClose()
pHost->mEnableMSDP = mEnableMSDP->isChecked();
pHost->mMapperUseAntiAlias = mMapperUseAntiAlias->isChecked();
pHost->mMapperShowRoomBorders = checkbox_mMapperShowRoomBorders->isChecked();
if (pHost->mpMap && pHost->mpMap->mpMapper) {
pHost->mpMap->mpMapper->mp2dMap->mMapperUseAntiAlias = mMapperUseAntiAlias->isChecked();
bool isAreaWidgetInNeedOfResetting = false;
if ((!pHost->mpMap->mpMapper->getDefaultAreaShown()) && (checkBox_showDefaultArea->isChecked()) && (pHost->mpMap->mpMapper->mp2dMap->mAreaID == -1)) {
isAreaWidgetInNeedOfResetting = true;
}

pHost->mpMap->mpMapper->setDefaultAreaShown(checkBox_showDefaultArea->isChecked());
if (isAreaWidgetInNeedOfResetting) {
// Corner case fixup:
pHost->mpMap->mpMapper->comboBox_showArea->setCurrentText(pHost->mpMap->getDefaultAreaName());
if (pHost->mpMap) {
// Need to save the original value in case we change it in the line
// following this one:
bool defaultAreaWasNotShown = pHost->mpMap->getDefaultAreaShown();
pHost->mpMap->setDefaultAreaShown(checkBox_showDefaultArea->isChecked());
if (pHost->mpMap->mpMapper) {
pHost->mpMap->mpMapper->mp2dMap->mMapperUseAntiAlias = mMapperUseAntiAlias->isChecked();

if (!defaultAreaWasNotShown && checkBox_showDefaultArea->isChecked() && pHost->mpMap->mpMapper->mp2dMap->mAreaID == -1) {
// Corner case fixup, user has asked for the default area
// to be shown and it wasn't - so it can now be:
pHost->mpMap->mpMapper->comboBox_showArea->setCurrentText(pHost->mpMap->getDefaultAreaName());
}
}

// If a map was loaded
if (mpDoubleSpinBox_mapSymbolFontFudge) {
pHost->mpMap->mMapSymbolFontFudgeFactor = mpDoubleSpinBox_mapSymbolFontFudge->value();
}

pHost->mpMap->mpMapper->mp2dMap->repaint(); // Forceably redraw it as we ARE currently showing default area
pHost->mpMap->mpMapper->update();
if (pHost->mpMap->mpMapper) {
pHost->mpMap->mpMapper->mp2dMap->repaint(); // Forceably redraw it as we ARE currently showing default area
pHost->mpMap->mpMapper->update();
}
}
QMargins newBorders{leftBorderWidth->value(), topBorderHeight->value(), rightBorderWidth->value(), bottomBorderHeight->value()};
pHost->setBorders(newBorders);
Expand Down

0 comments on commit fb04f6f

Please sign in to comment.