1. minirop
  2. KVNS

Source

KVNS / GameWidget.h

#ifndef GAMEWIDGET_H
#define GAMEWIDGET_H

#include <QLabel>
#include <QDomElement>
#include <QHash>
#include <QDomNodeList>
#include <QCloseEvent>

#include "PluginInterfaces.h"
#include "PushButton.h"

class Character;
class Textbox;
class Music;
class GameWidget : public QLabel
{
	Q_OBJECT

public:
	GameWidget();
	~GameWidget();
	
	void setVariable(const QString& name, const QString& value);
	QString getVariable(const QString& name) const;
	
	void loadStyle(QDomElement elem);
	void loadCharacters(QDomElement elem);
	void initTextBox(QDomElement elem);
	QStringList getCharacters() const;
	
	void clean();
	void start();
	
	void setFirstArc(const QString& name);
	void setArcsDir(const QString& dir);
	void manageCloseEvent();

private slots:
	void saveGame(const QString& savefile = "1");
	void loadGame(const QString& savefile);
	
	void evaluate();
	void setTempValue(const QString& value);

signals:
	void gameFinished();

protected:
	void mousePressEvent(QMouseEvent* ev);

private:
	void loadArc();
	void loadPlugins();
	bool loadArcs(QDomElement elem);
	
	// evaluators
	// return true if the value of the variable named "name" is the content of "equals"
	bool evaluateIf(QDomElement elem);
	
	void evaluateList(QDomNodeList list, int nested = 0);
	void evaluateBackground(QDomElement elem);
	void evaluateShow(QDomElement elem);
	void evaluateSpeak(QDomElement elem);
	void evaluatePause(QDomElement elem);
	void evaluateMove(QDomElement elem);
	void evaluateChoices(QDomElement elem);
	void evaluateHidetextbox(QDomElement elem);
	void evaluateHide(QDomElement elem);
	void evaluateHideall(QDomElement elem);
	void evaluateGoto(QDomElement elem);
	//void evaluateGosub(QDomElement elem);
	void evaluateImage(QDomElement elem);
	void evaluateMusic(QDomElement elem);
	void evaluateVideo(QDomElement elem);
	void evaluateSetv(QDomElement elem);
	void evaluateSlide(QDomElement elem);
	void evaluateTransition(QDomElement elem);
	
	//
	QString parseVariable(QString text);
	int getPosFromName(QString name, Character * c, bool * ok);
	
	// buttons
	PushButton * saveBtn;
	
	// variables
	QHash<QString, QString> m_variables;
	QHash<QString, Character*> m_characters;
	QString currentArc;
	QString firstArc;
	QString arcsDir;
	//int gosubDepth;
	QDomNodeList nodesArc;
	Textbox* m_textbox;
	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;
	QString m_globalStyle;
};

#endif