mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-09 13:14:02 +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:
commit
7669f6524b
@ -196,6 +196,7 @@ endif()
|
|||||||
target_sources(vcmieditor PRIVATE
|
target_sources(vcmieditor PRIVATE
|
||||||
${editor_SRCS}
|
${editor_SRCS}
|
||||||
${editor_HEADERS}
|
${editor_HEADERS}
|
||||||
|
${editor_FORMS}
|
||||||
${editor_RESOURCES}
|
${editor_RESOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ static QVariantMap JsonToMap(const JsonMap & json)
|
|||||||
QVariantMap map;
|
QVariantMap map;
|
||||||
for(auto & entry : json)
|
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;
|
return map;
|
||||||
}
|
}
|
||||||
@ -61,23 +61,18 @@ QVariant toVariant(const JsonNode & node)
|
|||||||
{
|
{
|
||||||
switch(node.getType())
|
switch(node.getType())
|
||||||
{
|
{
|
||||||
break;
|
|
||||||
case JsonNode::JsonType::DATA_NULL:
|
case JsonNode::JsonType::DATA_NULL:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
break;
|
|
||||||
case JsonNode::JsonType::DATA_BOOL:
|
case JsonNode::JsonType::DATA_BOOL:
|
||||||
return QVariant(node.Bool());
|
return QVariant(node.Bool());
|
||||||
break;
|
|
||||||
case JsonNode::JsonType::DATA_FLOAT:
|
case JsonNode::JsonType::DATA_FLOAT:
|
||||||
case JsonNode::JsonType::DATA_INTEGER:
|
|
||||||
return QVariant(node.Float());
|
return QVariant(node.Float());
|
||||||
break;
|
case JsonNode::JsonType::DATA_INTEGER:
|
||||||
|
return QVariant{static_cast<qlonglong>(node.Integer())};
|
||||||
case JsonNode::JsonType::DATA_STRING:
|
case JsonNode::JsonType::DATA_STRING:
|
||||||
return QVariant(QString::fromUtf8(node.String().c_str()));
|
return QVariant(QString::fromStdString(node.String()));
|
||||||
break;
|
|
||||||
case JsonNode::JsonType::DATA_VECTOR:
|
case JsonNode::JsonType::DATA_VECTOR:
|
||||||
return JsonToList(node.Vector());
|
return JsonToList(node.Vector());
|
||||||
break;
|
|
||||||
case JsonNode::JsonType::DATA_STRUCT:
|
case JsonNode::JsonType::DATA_STRUCT:
|
||||||
return JsonToMap(node.Struct());
|
return JsonToMap(node.Struct());
|
||||||
}
|
}
|
||||||
@ -87,33 +82,31 @@ QVariant toVariant(const JsonNode & node)
|
|||||||
QVariant JsonFromFile(QString filename)
|
QVariant JsonFromFile(QString filename)
|
||||||
{
|
{
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
file.open(QFile::ReadOnly);
|
if(!file.open(QFile::ReadOnly))
|
||||||
auto data = file.readAll();
|
{
|
||||||
|
logGlobal->error("Failed to open file %s. Reason: %s", qUtf8Printable(filename), qUtf8Printable(file.errorString()));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
if(data.size() == 0)
|
const auto data = file.readAll();
|
||||||
{
|
JsonNode node(reinterpret_cast<const std::byte*>(data.data()), data.size(), filename.toStdString());
|
||||||
logGlobal->error("Failed to open file %s", filename.toUtf8().data());
|
return toVariant(node);
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JsonNode node(reinterpret_cast<const std::byte*>(data.data()), data.size(), filename.toStdString());
|
|
||||||
return toVariant(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode toJson(QVariant object)
|
JsonNode toJson(QVariant object)
|
||||||
{
|
{
|
||||||
JsonNode ret;
|
JsonNode ret;
|
||||||
|
|
||||||
if(object.canConvert<QVariantMap>())
|
if(object.userType() == QMetaType::QString)
|
||||||
ret.Struct() = VariantToMap(object.toMap());
|
|
||||||
else if(object.canConvert<QVariantList>())
|
|
||||||
ret.Vector() = VariantToList(object.toList());
|
|
||||||
else if(object.userType() == QMetaType::QString)
|
|
||||||
ret.String() = object.toString().toUtf8().data();
|
ret.String() = object.toString().toUtf8().data();
|
||||||
else if(object.userType() == QMetaType::Bool)
|
else if(object.userType() == QMetaType::Bool)
|
||||||
ret.Bool() = object.toBool();
|
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>())
|
else if(object.canConvert<double>())
|
||||||
ret.Float() = object.toFloat();
|
ret.Float() = object.toFloat();
|
||||||
|
|
||||||
|
@ -150,6 +150,10 @@ bool WindowNewMap::loadUserSettings()
|
|||||||
ui->monsterOpt4->setChecked(true); break;
|
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;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,6 +240,10 @@ void WindowNewMap::on_okButton_clicked()
|
|||||||
|
|
||||||
mapGenOptions.setWaterContent(water);
|
mapGenOptions.setWaterContent(water);
|
||||||
mapGenOptions.setMonsterStrength(monster);
|
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();
|
saveUserSettings();
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>444</width>
|
<width>444</width>
|
||||||
<height>445</height>
|
<height>506</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -52,7 +52,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>20</y>
|
<y>20</y>
|
||||||
<width>281</width>
|
<width>281</width>
|
||||||
<height>68</height>
|
<height>73</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2" columnstretch="3,0,1">
|
<layout class="QGridLayout" name="gridLayout_2" columnstretch="3,0,1">
|
||||||
@ -72,7 +72,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="inputMethodHints">
|
<property name="inputMethodHints">
|
||||||
<set>Qt::ImhDigitsOnly</set>
|
<set>Qt::InputMethodHint::ImhDigitsOnly</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">36</string>
|
<string notr="true">36</string>
|
||||||
@ -98,7 +98,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="inputMethodHints">
|
<property name="inputMethodHints">
|
||||||
<set>Qt::ImhDigitsOnly</set>
|
<set>Qt::InputMethodHint::ImhDigitsOnly</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">36</string>
|
<string notr="true">36</string>
|
||||||
@ -132,10 +132,10 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer_5">
|
<spacer name="horizontalSpacer_5">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeType">
|
<property name="sizeType">
|
||||||
<enum>QSizePolicy::Fixed</enum>
|
<enum>QSizePolicy::Policy::Fixed</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@ -207,7 +207,7 @@
|
|||||||
<x>10</x>
|
<x>10</x>
|
||||||
<y>140</y>
|
<y>140</y>
|
||||||
<width>431</width>
|
<width>431</width>
|
||||||
<height>301</height>
|
<height>361</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -237,7 +237,7 @@
|
|||||||
<x>10</x>
|
<x>10</x>
|
||||||
<y>20</y>
|
<y>20</y>
|
||||||
<width>391</width>
|
<width>391</width>
|
||||||
<height>68</height>
|
<height>72</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
|
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
|
||||||
@ -546,7 +546,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@ -675,7 +675,104 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<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>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@ -692,9 +789,9 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>10</x>
|
<x>10</x>
|
||||||
<y>230</y>
|
<y>280</y>
|
||||||
<width>411</width>
|
<width>411</width>
|
||||||
<height>32</height>
|
<height>34</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
@ -732,37 +829,37 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QLineEdit" name="lineSeed">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>280</x>
|
<x>80</x>
|
||||||
<y>270</y>
|
<y>320</y>
|
||||||
<width>131</width>
|
<width>283</width>
|
||||||
<height>21</height>
|
<height>33</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="inputMethodHints">
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
<set>Qt::ImhDigitsOnly</set>
|
<item>
|
||||||
</property>
|
<widget class="QCheckBox" name="checkSeed">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>0</string>
|
<string>Custom seed</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QCheckBox" name="checkSeed">
|
</item>
|
||||||
<property name="geometry">
|
<item>
|
||||||
<rect>
|
<widget class="QLineEdit" name="lineSeed">
|
||||||
<x>110</x>
|
<property name="enabled">
|
||||||
<y>270</y>
|
<bool>false</bool>
|
||||||
<width>161</width>
|
</property>
|
||||||
<height>20</height>
|
<property name="inputMethodHints">
|
||||||
</rect>
|
<set>Qt::InputMethodHint::ImhDigitsOnly</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Custom seed</string>
|
<string>0</string>
|
||||||
</property>
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QCheckBox" name="randomMapCheck">
|
<widget class="QCheckBox" name="randomMapCheck">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user