mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
First version that works in lobby
This commit is contained in:
@@ -156,6 +156,12 @@ void CLobbyScreen::startCampaign()
|
|||||||
|
|
||||||
void CLobbyScreen::startScenario(bool allowOnlyAI)
|
void CLobbyScreen::startScenario(bool allowOnlyAI)
|
||||||
{
|
{
|
||||||
|
if (tabRand && CSH->si->mapGenOptions)
|
||||||
|
{
|
||||||
|
// Save RMG settings at game start
|
||||||
|
tabRand->saveOptions(*CSH->si->mapGenOptions);
|
||||||
|
}
|
||||||
|
|
||||||
if (CSH->validateGameStart(allowOnlyAI))
|
if (CSH->validateGameStart(allowOnlyAI))
|
||||||
{
|
{
|
||||||
CSH->sendStartGame(allowOnlyAI);
|
CSH->sendStartGame(allowOnlyAI);
|
||||||
|
|||||||
@@ -38,6 +38,11 @@
|
|||||||
#include "../../lib/filesystem/Filesystem.h"
|
#include "../../lib/filesystem/Filesystem.h"
|
||||||
#include "../../lib/RoadHandler.h"
|
#include "../../lib/RoadHandler.h"
|
||||||
|
|
||||||
|
//#include "../../lib/GameSettings.h"
|
||||||
|
#include "../../lib/CConfigHandler.h"
|
||||||
|
#include "../../lib/serializer/JsonSerializer.h"
|
||||||
|
#include "../../lib/serializer/JsonDeserializer.h"
|
||||||
|
|
||||||
RandomMapTab::RandomMapTab():
|
RandomMapTab::RandomMapTab():
|
||||||
InterfaceObjectConfigurable()
|
InterfaceObjectConfigurable()
|
||||||
{
|
{
|
||||||
@@ -162,7 +167,8 @@ RandomMapTab::RandomMapTab():
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMapInfoByHost();
|
loadOptions();
|
||||||
|
//updateMapInfoByHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RandomMapTab::updateMapInfoByHost()
|
void RandomMapTab::updateMapInfoByHost()
|
||||||
@@ -569,3 +575,48 @@ TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab):
|
|||||||
buttonOk = widget<CButton>("buttonOK");
|
buttonOk = widget<CButton>("buttonOK");
|
||||||
buttonCancel = widget<CButton>("buttonCancel");
|
buttonCancel = widget<CButton>("buttonCancel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RandomMapTab::saveOptions(const CMapGenOptions & options)
|
||||||
|
{
|
||||||
|
JsonNode data;
|
||||||
|
JsonSerializer ser(nullptr, data);
|
||||||
|
|
||||||
|
ser.serializeStruct("lastSettings", const_cast<CMapGenOptions & >(options));
|
||||||
|
|
||||||
|
// FIXME: Do not nest fields
|
||||||
|
Settings rmgSettings = persistentStorage.write["rmg"];
|
||||||
|
rmgSettings["rmg"] = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RandomMapTab::loadOptions()
|
||||||
|
{
|
||||||
|
// FIXME: Potential leak?
|
||||||
|
auto options = new CMapGenOptions();
|
||||||
|
|
||||||
|
|
||||||
|
auto rmgSettings = persistentStorage["rmg"]["rmg"];
|
||||||
|
if (!rmgSettings.Struct().empty())
|
||||||
|
{
|
||||||
|
JsonDeserializer handler(nullptr, rmgSettings);
|
||||||
|
handler.serializeStruct("lastSettings", *options);
|
||||||
|
|
||||||
|
// FIXME: Regenerate players, who are not saved
|
||||||
|
mapGenOptions.reset(options);
|
||||||
|
// Will check template and set other options as well
|
||||||
|
setTemplate(mapGenOptions->getMapTemplate());
|
||||||
|
if(auto w = widget<ComboBox>("templateList"))
|
||||||
|
{
|
||||||
|
// FIXME: Private function, need id
|
||||||
|
w->setItem(mapGenOptions->getMapTemplate());
|
||||||
|
logGlobal->warn("Set RMG template on drop-down list");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Else? Set default
|
||||||
|
logGlobal->warn("Loaded previous RMG settings");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logGlobal->warn("Did not load previous RMG settings");
|
||||||
|
}
|
||||||
|
updateMapInfoByHost();
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "../../lib/GameConstants.h"
|
#include "../../lib/GameConstants.h"
|
||||||
#include "../../lib/rmg/CRmgTemplate.h"
|
#include "../../lib/rmg/CRmgTemplate.h"
|
||||||
#include "../gui/InterfaceObjectConfigurable.h"
|
#include "../gui/InterfaceObjectConfigurable.h"
|
||||||
|
#include "../lib/rmg/MapGenOptionsSaver.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ class CLabelGroup;
|
|||||||
class CSlider;
|
class CSlider;
|
||||||
class CPicture;
|
class CPicture;
|
||||||
|
|
||||||
class RandomMapTab : public InterfaceObjectConfigurable
|
class RandomMapTab : public InterfaceObjectConfigurable, public MapGenOptionsSaver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RandomMapTab();
|
RandomMapTab();
|
||||||
@@ -36,6 +37,9 @@ public:
|
|||||||
void updateMapInfoByHost();
|
void updateMapInfoByHost();
|
||||||
void setMapGenOptions(std::shared_ptr<CMapGenOptions> opts);
|
void setMapGenOptions(std::shared_ptr<CMapGenOptions> opts);
|
||||||
void setTemplate(const CRmgTemplate *);
|
void setTemplate(const CRmgTemplate *);
|
||||||
|
|
||||||
|
void saveOptions(const CMapGenOptions & options) override;
|
||||||
|
void loadOptions() override;
|
||||||
CMapGenOptions & obtainMapGenOptions() {return *mapGenOptions;}
|
CMapGenOptions & obtainMapGenOptions() {return *mapGenOptions;}
|
||||||
|
|
||||||
CFunctionList<void(std::shared_ptr<CMapInfo>, std::shared_ptr<CMapGenOptions>)> mapInfoChanged;
|
CFunctionList<void(std::shared_ptr<CMapInfo>, std::shared_ptr<CMapGenOptions>)> mapInfoChanged;
|
||||||
@@ -44,8 +48,8 @@ private:
|
|||||||
void deactivateButtonsFrom(CToggleGroup & group, const std::set<int> & allowed);
|
void deactivateButtonsFrom(CToggleGroup & group, const std::set<int> & allowed);
|
||||||
std::vector<int> getPossibleMapSizes();
|
std::vector<int> getPossibleMapSizes();
|
||||||
|
|
||||||
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
|
||||||
std::shared_ptr<CMapInfo> mapInfo;
|
std::shared_ptr<CMapInfo> mapInfo;
|
||||||
|
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
||||||
|
|
||||||
//options allowed - need to store as impact each other
|
//options allowed - need to store as impact each other
|
||||||
std::set<int> playerCountAllowed;
|
std::set<int> playerCountAllowed;
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ SelectionTab::SelectionTab(ESelectionScreen Type)
|
|||||||
inputName->filters += CTextInput::filenameFilter;
|
inputName->filters += CTextInput::filenameFilter;
|
||||||
labelMapSizes = std::make_shared<CLabel>(87, 62, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[510]);
|
labelMapSizes = std::make_shared<CLabel>(87, 62, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[510]);
|
||||||
|
|
||||||
|
// TODO: Global constants?
|
||||||
int sizes[] = {36, 72, 108, 144, 0};
|
int sizes[] = {36, 72, 108, 144, 0};
|
||||||
const char * filterIconNmes[] = {"SCSMBUT.DEF", "SCMDBUT.DEF", "SCLGBUT.DEF", "SCXLBUT.DEF", "SCALBUT.DEF"};
|
const char * filterIconNmes[] = {"SCSMBUT.DEF", "SCMDBUT.DEF", "SCLGBUT.DEF", "SCXLBUT.DEF", "SCALBUT.DEF"};
|
||||||
for(int i = 0; i < 5; i++)
|
for(int i = 0; i < 5; i++)
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ class ComboBox : public CButton
|
|||||||
|
|
||||||
friend class DropDown;
|
friend class DropDown;
|
||||||
|
|
||||||
void setItem(const void *);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ComboBox(Point position, const AnimationPath & defName, const std::pair<std::string, std::string> & help, const JsonNode & dropDownDescriptor, Point dropDownPosition, EShortcut key = {}, bool playerColoredButton = false);
|
ComboBox(Point position, const AnimationPath & defName, const std::pair<std::string, std::string> & help, const JsonNode & dropDownDescriptor, Point dropDownPosition, EShortcut key = {}, bool playerColoredButton = false);
|
||||||
|
|
||||||
@@ -67,6 +65,7 @@ public:
|
|||||||
std::function<std::string(int, const void *)> getItemText;
|
std::function<std::string(int, const void *)> getItemText;
|
||||||
|
|
||||||
void setItem(int id);
|
void setItem(int id);
|
||||||
|
void setItem(const void *);
|
||||||
|
|
||||||
void updateListItems();
|
void updateListItems();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -534,6 +534,7 @@ set(lib_HEADERS
|
|||||||
rmg/RmgPath.h
|
rmg/RmgPath.h
|
||||||
rmg/CMapGenerator.h
|
rmg/CMapGenerator.h
|
||||||
rmg/CMapGenOptions.h
|
rmg/CMapGenOptions.h
|
||||||
|
rmg/MapGenOptionsSaver.h
|
||||||
rmg/CRmgTemplate.h
|
rmg/CRmgTemplate.h
|
||||||
rmg/CRmgTemplateStorage.h
|
rmg/CRmgTemplateStorage.h
|
||||||
rmg/CZonePlacer.h
|
rmg/CZonePlacer.h
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "CRandomGenerator.h"
|
#include "CRandomGenerator.h"
|
||||||
#include "../VCMI_Lib.h"
|
#include "../VCMI_Lib.h"
|
||||||
#include "../CTownHandler.h"
|
#include "../CTownHandler.h"
|
||||||
|
#include "serializer/JsonSerializeFormat.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@@ -816,4 +817,45 @@ void CMapGenOptions::CPlayerSettings::setTeam(const TeamID & value)
|
|||||||
team = value;
|
team = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMapGenOptions::serializeJson(JsonSerializeFormat & handler)
|
||||||
|
{
|
||||||
|
handler.serializeInt("width", width);
|
||||||
|
handler.serializeInt("height", height);
|
||||||
|
handler.serializeBool("haswoLevels", hasTwoLevels);
|
||||||
|
handler.serializeInt("humanOrCpuPlayerCount", humanOrCpuPlayerCount);
|
||||||
|
handler.serializeInt("teamCount", teamCount);
|
||||||
|
handler.serializeInt("compOnlyPlayerCount", compOnlyPlayerCount);
|
||||||
|
handler.serializeInt("compOnlyTeamCount", compOnlyTeamCount);
|
||||||
|
handler.serializeInt("waterContent", waterContent);
|
||||||
|
handler.serializeInt("monsterStrength", monsterStrength);
|
||||||
|
|
||||||
|
std::string templateName;
|
||||||
|
if(mapTemplate && handler.saving)
|
||||||
|
{
|
||||||
|
templateName = mapTemplate->getId();
|
||||||
|
}
|
||||||
|
handler.serializeString("templateName", templateName);
|
||||||
|
if(!handler.saving)
|
||||||
|
{
|
||||||
|
// FIXME: doesn't load correctly? Name is "Jebus Cross"
|
||||||
|
setMapTemplate(templateName);
|
||||||
|
if (mapTemplate)
|
||||||
|
{
|
||||||
|
logGlobal->warn("Loaded previous RMG template");
|
||||||
|
// FIXME: Update dropdown menu
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logGlobal->warn("Failed to deserialize previous map template");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handler.serializeIdArray("roads", enabledRoads);
|
||||||
|
//TODO: Serialize CMapGenOptions::CPlayerSettings ? This won't b saved between sessions
|
||||||
|
if (!handler.saving)
|
||||||
|
{
|
||||||
|
resetPlayersMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|||||||
@@ -210,6 +210,8 @@ public:
|
|||||||
|
|
||||||
h & enabledRoads;
|
h & enabledRoads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serializeJson(JsonSerializeFormat & handler);
|
||||||
};
|
};
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|||||||
@@ -841,20 +841,20 @@ void CRmgTemplate::serializeSize(JsonSerializeFormat & handler, int3 & value, co
|
|||||||
{
|
{
|
||||||
static const std::map<std::string, int3> sizeMapping =
|
static const std::map<std::string, int3> sizeMapping =
|
||||||
{
|
{
|
||||||
{"s", { 36, 36, 1}},
|
{"s", {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_SMALL, 1}},
|
||||||
{"s+u", { 36, 36, 2}},
|
{"s+u", {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_SMALL, 2}},
|
||||||
{"m", { 72, 72, 1}},
|
{"m", {CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_MIDDLE, 1}},
|
||||||
{"m+u", { 72, 72, 2}},
|
{"m+u", {CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_MIDDLE, 2}},
|
||||||
{"l", {108, 108, 1}},
|
{"l", {CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_LARGE, 1}},
|
||||||
{"l+u", {108, 108, 2}},
|
{"l+u", {CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_LARGE, 2}},
|
||||||
{"xl", {144, 144, 1}},
|
{"xl", {CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_XLARGE, 1}} ,
|
||||||
{"xl+u", {144, 144, 2}},
|
{"xl+u", {CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_XLARGE, 2}} ,
|
||||||
{"h", {180, 180, 1}},
|
{"h", {CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_HUGE, 1}},
|
||||||
{"h+u", {180, 180, 2}},
|
{"h+u", {CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_HUGE, 2}},
|
||||||
{"xh", {216, 216, 1}},
|
{"xh", {CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_XHUGE, 1}},
|
||||||
{"xh+u", {216, 216, 2}},
|
{"xh+u", {CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_XHUGE, 2}},
|
||||||
{"g", {252, 252, 1}},
|
{"g", {CMapHeader::MAP_SIZE_GIANT, CMapHeader::MAP_SIZE_GIANT, 1}},
|
||||||
{"g+u", {252, 252, 2}}
|
{"g+u", {CMapHeader::MAP_SIZE_GIANT, CMapHeader::MAP_SIZE_GIANT, 2}}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::map<int3, std::string> sizeReverseMapping = vstd::invertMap(sizeMapping);
|
static const std::map<int3, std::string> sizeReverseMapping = vstd::invertMap(sizeMapping);
|
||||||
|
|||||||
@@ -219,6 +219,17 @@ void WindowNewMap::saveUserSettings()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowNewMap::saveOptions(const CMapGenOptions & options)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowNewMap::loadOptions()
|
||||||
|
{
|
||||||
|
mapGenOptions = CMapGenOptions();
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
void WindowNewMap::on_cancelButton_clicked()
|
void WindowNewMap::on_cancelButton_clicked()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
|
|||||||
@@ -12,13 +12,14 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "../lib/rmg/CMapGenOptions.h"
|
#include "../lib/rmg/CMapGenOptions.h"
|
||||||
|
#include "../lib/rmg/MapGenOptionsSaver.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class WindowNewMap;
|
class WindowNewMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
class WindowNewMap : public QDialog
|
class WindowNewMap : public QDialog, public MapGenOptionsSaver
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -64,10 +65,13 @@ class WindowNewMap : public QDialog
|
|||||||
|
|
||||||
const std::map<int, std::pair<int, int>> mapSizes
|
const std::map<int, std::pair<int, int>> mapSizes
|
||||||
{
|
{
|
||||||
{0, {36, 36}},
|
{0, {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_SMALL}},
|
||||||
{1, {72, 72}},
|
{1, {CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_MIDDLE}},
|
||||||
{2, {108, 108}},
|
{2, {CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_LARGE}},
|
||||||
{3, {144, 144}},
|
{3, {CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_XLARGE}},
|
||||||
|
{4, {CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_HUGE}},
|
||||||
|
{5, {CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_XHUGE}},
|
||||||
|
{6, {CMapHeader::MAP_SIZE_GIANT, CMapHeader::MAP_SIZE_GIANT}},
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -108,6 +112,9 @@ private:
|
|||||||
void loadUserSettings();
|
void loadUserSettings();
|
||||||
void saveUserSettings();
|
void saveUserSettings();
|
||||||
|
|
||||||
|
void saveOptions(const CMapGenOptions & options) override;
|
||||||
|
void loadOptions() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::WindowNewMap *ui;
|
Ui::WindowNewMap *ui;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user