1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Merge pull request #4606 from wb180/mapeditor_fix

Added ability to choose road types in editor RMG options
This commit is contained in:
Ivan Savenko 2024-09-18 15:07:55 +03:00 committed by GitHub
commit 7669f6524b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 164 additions and 65 deletions

View File

@ -196,6 +196,7 @@ endif()
target_sources(vcmieditor PRIVATE
${editor_SRCS}
${editor_HEADERS}
${editor_FORMS}
${editor_RESOURCES}
)

View File

@ -17,7 +17,7 @@ static QVariantMap JsonToMap(const JsonMap & json)
QVariantMap map;
for(auto & entry : json)
{
map.insert(QString::fromUtf8(entry.first.c_str()), JsonUtils::toVariant(entry.second));
map.insert(QString::fromStdString(entry.first), JsonUtils::toVariant(entry.second));
}
return map;
}
@ -61,23 +61,18 @@ QVariant toVariant(const JsonNode & node)
{
switch(node.getType())
{
break;
case JsonNode::JsonType::DATA_NULL:
return QVariant();
break;
case JsonNode::JsonType::DATA_BOOL:
return QVariant(node.Bool());
break;
case JsonNode::JsonType::DATA_FLOAT:
case JsonNode::JsonType::DATA_INTEGER:
return QVariant(node.Float());
break;
case JsonNode::JsonType::DATA_INTEGER:
return QVariant{static_cast<qlonglong>(node.Integer())};
case JsonNode::JsonType::DATA_STRING:
return QVariant(QString::fromUtf8(node.String().c_str()));
break;
return QVariant(QString::fromStdString(node.String()));
case JsonNode::JsonType::DATA_VECTOR:
return JsonToList(node.Vector());
break;
case JsonNode::JsonType::DATA_STRUCT:
return JsonToMap(node.Struct());
}
@ -87,33 +82,31 @@ QVariant toVariant(const JsonNode & node)
QVariant JsonFromFile(QString filename)
{
QFile file(filename);
file.open(QFile::ReadOnly);
auto data = file.readAll();
if(!file.open(QFile::ReadOnly))
{
logGlobal->error("Failed to open file %s. Reason: %s", qUtf8Printable(filename), qUtf8Printable(file.errorString()));
return {};
}
if(data.size() == 0)
{
logGlobal->error("Failed to open file %s", filename.toUtf8().data());
return QVariant();
}
else
{
JsonNode node(reinterpret_cast<const std::byte*>(data.data()), data.size(), filename.toStdString());
return toVariant(node);
}
const auto data = file.readAll();
JsonNode node(reinterpret_cast<const std::byte*>(data.data()), data.size(), filename.toStdString());
return toVariant(node);
}
JsonNode toJson(QVariant object)
{
JsonNode ret;
if(object.canConvert<QVariantMap>())
ret.Struct() = VariantToMap(object.toMap());
else if(object.canConvert<QVariantList>())
ret.Vector() = VariantToList(object.toList());
else if(object.userType() == QMetaType::QString)
if(object.userType() == QMetaType::QString)
ret.String() = object.toString().toUtf8().data();
else if(object.userType() == QMetaType::Bool)
ret.Bool() = object.toBool();
else if(object.canConvert<QVariantMap>())
ret.Struct() = VariantToMap(object.toMap());
else if(object.canConvert<QVariantList>())
ret.Vector() = VariantToList(object.toList());
else if(object.canConvert<int>())
ret.Integer() = object.toInt();
else if(object.canConvert<double>())
ret.Float() = object.toFloat();

View File

@ -150,6 +150,10 @@ bool WindowNewMap::loadUserSettings()
ui->monsterOpt4->setChecked(true); break;
}
ui->roadDirt->setChecked(mapGenOptions.isRoadEnabled(Road::DIRT_ROAD));
ui->roadGravel->setChecked(mapGenOptions.isRoadEnabled(Road::GRAVEL_ROAD));
ui->roadCobblestone->setChecked(mapGenOptions.isRoadEnabled(Road::COBBLESTONE_ROAD));
ret = true;
}
@ -236,6 +240,10 @@ void WindowNewMap::on_okButton_clicked()
mapGenOptions.setWaterContent(water);
mapGenOptions.setMonsterStrength(monster);
mapGenOptions.setRoadEnabled(Road::DIRT_ROAD, ui->roadDirt->isChecked());
mapGenOptions.setRoadEnabled(Road::GRAVEL_ROAD, ui->roadGravel->isChecked());
mapGenOptions.setRoadEnabled(Road::COBBLESTONE_ROAD, ui->roadCobblestone->isChecked());
saveUserSettings();

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>444</width>
<height>445</height>
<height>506</height>
</rect>
</property>
<property name="sizePolicy">
@ -52,7 +52,7 @@
<x>0</x>
<y>20</y>
<width>281</width>
<height>68</height>
<height>73</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="3,0,1">
@ -72,7 +72,7 @@
</size>
</property>
<property name="inputMethodHints">
<set>Qt::ImhDigitsOnly</set>
<set>Qt::InputMethodHint::ImhDigitsOnly</set>
</property>
<property name="text">
<string notr="true">36</string>
@ -98,7 +98,7 @@
</size>
</property>
<property name="inputMethodHints">
<set>Qt::ImhDigitsOnly</set>
<set>Qt::InputMethodHint::ImhDigitsOnly</set>
</property>
<property name="text">
<string notr="true">36</string>
@ -132,10 +132,10 @@
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -207,7 +207,7 @@
<x>10</x>
<y>140</y>
<width>431</width>
<height>301</height>
<height>361</height>
</rect>
</property>
<property name="sizePolicy">
@ -237,7 +237,7 @@
<x>10</x>
<y>20</y>
<width>391</width>
<height>68</height>
<height>72</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
@ -546,7 +546,7 @@
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -675,7 +675,104 @@
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_6">
<property name="geometry">
<rect>
<x>10</x>
<y>230</y>
<width>411</width>
<height>51</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>480</width>
<height>96</height>
</size>
</property>
<property name="title">
<string>Roads</string>
</property>
<widget class="QWidget" name="layoutWidget4_2">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>411</width>
<height>26</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5" stretch="0,0,0,0,0,1">
<item>
<widget class="QCheckBox" name="roadDirt">
<property name="text">
<string>Dirt</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="roadGravel">
<property name="text">
<string>Gravel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="roadCobblestone">
<property name="text">
<string>Cobblestone</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -692,9 +789,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>230</y>
<y>280</y>
<width>411</width>
<height>32</height>
<height>34</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
@ -732,37 +829,37 @@
</item>
</layout>
</widget>
<widget class="QLineEdit" name="lineSeed">
<property name="enabled">
<bool>false</bool>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>280</x>
<y>270</y>
<width>131</width>
<height>21</height>
<x>80</x>
<y>320</y>
<width>283</width>
<height>33</height>
</rect>
</property>
<property name="inputMethodHints">
<set>Qt::ImhDigitsOnly</set>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
<widget class="QCheckBox" name="checkSeed">
<property name="geometry">
<rect>
<x>110</x>
<y>270</y>
<width>161</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Custom seed</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QCheckBox" name="checkSeed">
<property name="text">
<string>Custom seed</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineSeed">
<property name="enabled">
<bool>false</bool>
</property>
<property name="inputMethodHints">
<set>Qt::InputMethodHint::ImhDigitsOnly</set>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QCheckBox" name="randomMapCheck">