Commits

minirop committed 23cea40

beginning of the save/load thing

Comments (0)

Files changed (2)

 	m_textbox->hide();
 	
 	loadPlugins();
+	
+	currentSavedPos = 0;
 }
 
 GameWidget::~GameWidget()
 	SoundSystem::release();
 }
 
+void GameWidget::load(const QString& savefile)
+{
+	Q_UNUSED(savefile);
+	
+	setPixmap(QPixmap(lastLoadedBackground));
+}
+
 void GameWidget::loadArc()
 {
 	if(MainWindow::isClosing)
 		return;
 	
-	if(currentArc.isEmpty()) currentArc = firstArc;
+	if(currentArc.isEmpty())
+	{
+		currentArc = firstArc;
+		lastLoadedArc = firstArc;
+	}
 	
 	QString cFile = QString("%1/%2.xml").arg(arcsDir).arg(currentArc);
 	
 
 void GameWidget::evaluateList(QDomNodeList list, int nested)
 {
-	for(uint i = 0;i < list.length();i++)
+	uint i = 0;
+	if(currentSavedPos < savedPositions.size())
+	{
+		i = savedPositions[ currentSavedPos ];
+		qDebug() << "loading evaluateList" << i;
+	}
+	else
+	{
+		savedPositions.push_back(0);
+	}
+	
+	for(;i < list.length();i++)
 	{
 		if(isClosing) return;
 		
+		savedPositions[ currentSavedPos ] = i;
+		
+		qDebug() << currentSavedPos << savedPositions;
+		
 		QDomNode node = list.item(i);
 		if(!node.isNull())
 		{
 				{
 					if(evaluateIf(e))
 					{
+						currentSavedPos++;
 						evaluateList(e.childNodes(), nested+1);
+						currentSavedPos--;
 					}
 				}
 				else if(name == "hide")
 					evaluateTransition(e);
 				else if(name == "goto")
 				{
+					currentSavedPos++;
 					evaluateGoto(e);
+					currentSavedPos--;
 					i = list.length();
 				}
 				else if(name == "gosub")
 				{
+					currentSavedPos++;
 					gosubDepth++;
 					evaluateGosub(e);
 					gosubDepth--;
+					currentSavedPos--;
 				}
 				else if(m_XmlPlugins.contains(name))
 					m_XmlPlugins[name]->evaluateNode(name, this, e);
 		}
 	}
 	
-	if(!currentArc.isEmpty())
+	savedPositions.pop_back();
+	
+	if(!currentArc.isEmpty()) // needed for <goto>
 	{
 		start();
 	}
 void GameWidget::evaluateGoto(QDomElement elem)
 {
 	currentArc = parseVariable(elem.attribute("name"));
+	lastLoadedArc = currentArc;
 }
 
 void GameWidget::evaluateTransition(QDomElement elem)
 
 void GameWidget::evaluateBackground(QDomElement elem)
 {
-	setPixmap(QPixmap(parseVariable(elem.attribute("src"))));
+	lastLoadedBackground = parseVariable(elem.attribute("src"));
+	setPixmap(QPixmap(lastLoadedBackground));
 }
 
 void GameWidget::evaluateShow(QDomElement elem)
 {
 	int duration = elem.attribute("duration", "0").toInt();
 	
-	if(!CTRL_IS_DOWN)
+	if(CTRL_IS_DOWN)
 	{
 		duration = 100;
 	}
 	GameWidget();
 	~GameWidget();
 	
+	void load(const QString& savefile);
+	
 	void setVariable(const QString& name, const QString& value);
 	QString getVariable(const QString& name) const;
 	
 	Music* m_music;
 	QHash<QString, XmlInterface*> m_XmlPlugins;
 	bool isClosing; // avoid evaluation of further nodes when closing has been asked
+	QVector<int> savedPositions; // save the position within the arc
+	int currentSavedPos; // depth in the stack
+	// last variables for the save
+	QString lastLoadedArc;
+	QString lastLoadedMusic;
+	QString lastLoadedBackground;
 	
 	//
 	QString m_tempValue;