- added command groups and unit selection to save / load game info

This commit is contained in:
Mark Vejvoda 2012-03-15 07:09:36 +00:00
parent d1dd79047e
commit fc125bec37
8 changed files with 177 additions and 7 deletions

View File

@ -886,6 +886,9 @@ void Game::init(bool initForPreviewOnly) {
gameCamera.setPos(Vec2f(v.x, v.y));
}
}
else {
gui.loadGame(loadGameNode,&world);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);

View File

@ -153,6 +153,32 @@ void Display::saveGame(XmlNode *rootNode) const {
// int upCellSideCount;
// int upImageSize;
// int maxUpIndex;
}
void Display::loadGame(const XmlNode *rootNode) {
const XmlNode *displayNode = rootNode->getChild("Display");
// string title;
title = displayNode->getAttribute("title")->getValue();
// string text;
text = displayNode->getAttribute("text")->getValue();
// string infoText;
infoText = displayNode->getAttribute("infoText")->getValue();
// const Texture2D *upImages[upCellCount];
// const Texture2D *downImages[downCellCount];
// bool downLighted[downCellCount];
// const CommandType *commandTypes[downCellCount];
// CommandClass commandClasses[downCellCount];
// int progressBar;
progressBar = displayNode->getAttribute("progressBar")->getIntValue();
// int downSelectedPos;
//displayNode->addAttribute("downSelectedPos",intToStr(downSelectedPos), mapTagReplacements);
// Vec4f colors[colorCount];
// int currentColor;
//currentColor = displayNode->getAttribute("progressBar")->getIntValue();
// int upCellSideCount;
// int upImageSize;
// int maxUpIndex;
}
}}//end namespace

View File

@ -104,6 +104,7 @@ public:
int computeUpY(int index) const;
void saveGame(XmlNode *rootNode) const;
void loadGame(const XmlNode *rootNode);
private:
void calculateUpDimensions(int index);

View File

@ -1189,7 +1189,9 @@ void Gui::saveGame(XmlNode *rootNode) const {
// //display
// const UnitType *choosenBuildingType;
if(choosenBuildingType != NULL) {
const Faction* thisFaction= world->getThisFaction();
guiNode->addAttribute("choosenBuildingType",choosenBuildingType->getName(), mapTagReplacements);
guiNode->addAttribute("choosenBuildingTypeFactionIndex",intToStr(thisFaction->getIndex()), mapTagReplacements);
}
// const CommandType *activeCommandType;
if(activeCommandType != NULL) {
@ -1231,6 +1233,76 @@ void Gui::saveGame(XmlNode *rootNode) const {
// const Object *selectedResourceObject;
//
// Texture2D* hudTexture;
}
void Gui::loadGame(const XmlNode *rootNode, World *world) {
const XmlNode *guiNode = rootNode->getChild("Gui");
//External objects
// RandomGen random;
random.setLastNumber(guiNode->getAttribute("random")->getIntValue());
// const Commander *commander;
// const World *world;
// const Game *game;
// GameCamera *gameCamera;
// Console *console;
//
// //Positions
// Vec2i posObjWorld; //world coords
//guiNode->addAttribute("posObjWorld",posObjWorld.getString(), mapTagReplacements);
posObjWorld = Vec2i::strToVec2(guiNode->getAttribute("posObjWorld")->getValue());
// bool validPosObjWorld;
validPosObjWorld = guiNode->getAttribute("validPosObjWorld")->getIntValue();
// //display
// const UnitType *choosenBuildingType;
// if(choosenBuildingType != NULL) {
// guiNode->addAttribute("choosenBuildingType",choosenBuildingType->getName(), mapTagReplacements);
// }
if(guiNode->hasAttribute("choosenBuildingType") == true) {
string unitType = guiNode->getAttribute("choosenBuildingType")->getValue();
int factionIndex = guiNode->getAttribute("choosenBuildingTypeFactionIndex")->getIntValue();
choosenBuildingType = world->getFaction(factionIndex)->getType()->getUnitType(unitType);
}
// const CommandType *activeCommandType;
//if(activeCommandType != NULL) {
// guiNode->addAttribute("activeCommandType",activeCommandType->getName(), mapTagReplacements);
//}
// CommandClass activeCommandClass;
//guiNode->addAttribute("activeCommandClass",intToStr(activeCommandClass), mapTagReplacements);
// int activePos;
activePos = guiNode->getAttribute("activePos")->getIntValue();
// int lastPosDisplay;
lastPosDisplay = guiNode->getAttribute("lastPosDisplay")->getIntValue();
// //composite
// Display display;
display.loadGame(guiNode);
// Mouse3d mouse3d;
// Selection selection;
selection.loadGame(guiNode,world);
// SelectionQuad selectionQuad;
// int lastQuadCalcFrame;
lastQuadCalcFrame = guiNode->getAttribute("lastQuadCalcFrame")->getIntValue();
// int selectionCalculationFrameSkip;
selectionCalculationFrameSkip = guiNode->getAttribute("selectionCalculationFrameSkip")->getIntValue();
// int minQuadSize;
minQuadSize = guiNode->getAttribute("minQuadSize")->getIntValue();
// Chrono lastGroupRecallTime;
//guiNode->addAttribute("lastGroupRecallTime",intToStr(lastGroupRecallTime.getMillis()), mapTagReplacements);
// int lastGroupRecall;
lastGroupRecall = guiNode->getAttribute("lastGroupRecall")->getIntValue();
// //states
// bool selectingBuilding;
//selectingBuilding = guiNode->getAttribute("selectingBuilding")->getIntValue();
// bool selectingPos;
//guiNode->addAttribute("selectingPos",intToStr(selectingPos), mapTagReplacements);
// bool selectingMeetingPoint;
//guiNode->addAttribute("selectingMeetingPoint",intToStr(selectingMeetingPoint), mapTagReplacements);
// CardinalDir selectedBuildingFacing;
//guiNode->addAttribute("selectedBuildingFacing",intToStr(selectedBuildingFacing), mapTagReplacements);
// const Object *selectedResourceObject;
//
// Texture2D* hudTexture;
}
}}//end namespace

View File

@ -200,6 +200,7 @@ public:
void onSelectionChanged();
void saveGame(XmlNode *rootNode) const;
void loadGame(const XmlNode *rootNode, World *world);
private:

View File

@ -16,6 +16,7 @@
#include "unit_type.h"
#include "gui.h"
#include "config.h"
#include "world.h"
#include "leak_dumper.h"
using namespace std;
@ -229,20 +230,84 @@ void Selection::saveGame(XmlNode *rootNode) const {
Unit *unit = selectedUnits[i];
XmlNode *selectedUnitsNode = selectionNode->addChild("selectedUnits");
selectedUnitsNode->addAttribute("id",intToStr(unit->getId()), mapTagReplacements);
selectedUnitsNode->addAttribute("unitId",intToStr(unit->getId()), mapTagReplacements);
}
// UnitContainer groups[maxGroups];
for(unsigned int x = 0; x < maxGroups; ++x) {
XmlNode *groupsNode = selectionNode->addChild("groups");
for(unsigned int i = 0; i < selectedUnits.size(); i++) {
Unit *unit = selectedUnits[i];
for(unsigned int i = 0; i < groups[x].size(); ++i) {
Unit *unit = groups[x][i];
XmlNode *selectedUnitsNode = groupsNode->addChild("selectedUnits");
selectedUnitsNode->addAttribute("id",intToStr(unit->getId()), mapTagReplacements);
selectedUnitsNode->addAttribute("unitId",intToStr(unit->getId()), mapTagReplacements);
}
}
// Gui *gui;
}
void Selection::loadGame(const XmlNode *rootNode, World *world) {
const XmlNode *selectionNode = rootNode->getChild("Selection");
// vector<XmlNode *> fowPixmap1NodeList = minimapNode->getChildList("fowPixmap1");
// for(unsigned int i = 0; i < fowPixmap1NodeList.size(); ++i) {
// XmlNode *fowPixmap1Node = fowPixmap1NodeList[i];
//
// int pixelIndex = fowPixmap1Node->getAttribute("index")->getIntValue();
// fowPixmap1->getPixels()[pixelIndex] = fowPixmap1Node->getAttribute("pixel")->getIntValue();
// }
// int factionIndex;
factionIndex = selectionNode->getAttribute("factionIndex")->getIntValue();
// int teamIndex;
teamIndex = selectionNode->getAttribute("teamIndex")->getIntValue();
// UnitContainer selectedUnits;
// for(unsigned int i = 0; i < selectedUnits.size(); i++) {
// Unit *unit = selectedUnits[i];
//
// XmlNode *selectedUnitsNode = selectionNode->addChild("selectedUnits");
// selectedUnitsNode->addAttribute("id",intToStr(unit->getId()), mapTagReplacements);
// }
vector<XmlNode *> selectedUnitsNodeList = selectionNode->getChildList("selectedUnits");
for(unsigned int i = 0; i < selectedUnitsNodeList.size(); ++i) {
XmlNode *selectedUnitsNode = selectedUnitsNodeList[i];
int unitId = selectedUnitsNode->getAttribute("unitId")->getIntValue();
Unit *unit = world->findUnitById(unitId);
//assert(unit != NULL);
//printf("#1 Unit [%s], group: %d\n",unit->getType()->getName().c_str(),i);
selectedUnits.push_back(unit);
}
// UnitContainer groups[maxGroups];
// for(unsigned int x = 0; x < maxGroups; ++x) {
// XmlNode *groupsNode = selectionNode->addChild("groups");
// for(unsigned int i = 0; i < groups[x].size(); ++i) {
// Unit *unit = groups[x][i];
//
// XmlNode *selectedUnitsNode = groupsNode->addChild("selectedUnits");
// selectedUnitsNode->addAttribute("unitId",intToStr(unit->getId()), mapTagReplacements);
// }
// }
vector<XmlNode *> groupsNodeList = selectionNode->getChildList("groups");
for(unsigned int i = 0; i < groupsNodeList.size(); ++i) {
XmlNode *groupsNode = groupsNodeList[i];
vector<XmlNode *> selectedGroupsUnitsNodeList = groupsNode->getChildList("selectedUnits");
for(unsigned int j = 0; j < selectedGroupsUnitsNodeList.size(); ++j) {
XmlNode *selectedGroupsUnitsNode = selectedGroupsUnitsNodeList[j];
int unitId = selectedGroupsUnitsNode->getAttribute("unitId")->getIntValue();
Unit *unit = world->findUnitById(unitId);
//assert(unit != NULL);
//printf("Unit #2 [%s], group: %d\n",unit->getType()->getName().c_str(),i);
groups[i].push_back(unit);
}
}
// Gui *gui;
}
}}//end namespace

View File

@ -21,6 +21,7 @@ using std::vector;
namespace Glest{ namespace Game{
class Gui;
class World;
// =====================================================
// class Selection
@ -81,6 +82,7 @@ public:
virtual void unitEvent(UnitObserver::Event event, const Unit *unit);
virtual void saveGame(XmlNode *rootNode) const;
void loadGame(const XmlNode *rootNode, World *world);
};
}}//end namespace

View File

@ -367,7 +367,7 @@ void XmlIoRapid::save(const string &path, const XmlNode *node){
//xmlFile << xml_no_indent;
// xmlFile << xml_as_string << '\0';
xmlFile << doc << '\0';
xmlFile << doc;
#if defined(WIN32) && !defined(__MINGW32__)
if(fp) {