File: display.h

package info (click to toggle)
megaglest 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,904 kB
  • ctags: 18,215
  • sloc: cpp: 144,232; ansic: 11,860; sh: 2,949; perl: 1,899; python: 1,751; objc: 142; asm: 42; makefile: 24
file content (119 lines) | stat: -rw-r--r-- 3,707 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// ==============================================================
//	This file is part of Glest (www.glest.org)
//
//	Copyright (C) 2001-2008 MartiƱo Figueroa
//
//	You can redistribute this code and/or modify it under 
//	the terms of the GNU General Public License as published 
//	by the Free Software Foundation; either version 2 of the 
//	License, or (at your option) any later version
// ==============================================================

#ifndef _GLEST_GAME_DISPLAY_H_
#define _GLEST_GAME_DISPLAY_H_

#ifdef WIN32
    #include <winsock2.h>
    #include <winsock.h>
#endif

#include <string>
#include "texture.h"
#include "util.h"
#include "command_type.h"
#include "game_util.h"
#include "leak_dumper.h"

using std::string;

using Shared::Graphics::Texture2D;
using Shared::Graphics::Vec4f;
using Shared::Util::replaceBy;

namespace Glest{ namespace Game{

// =====================================================
// 	class Display
//
///	Display for unit commands, and unit selection
// =====================================================

class Display{
public:
	static const int cellSideCount= 4;
	static const int upCellCount= 36;
	static const int downCellCount= cellSideCount*cellSideCount;
	static const int colorCount= 9;
	static const int imageSize= 32;
	static const int invalidPos= -1;
	static const int downY = imageSize*9;
	static const int infoStringY= imageSize*4;

private:
	string title;
	string text;
	string infoText;
	const Texture2D *upImages[upCellCount];
	const Texture2D *downImages[downCellCount];
	bool downLighted[downCellCount];
	const CommandType *commandTypes[downCellCount];
	CommandClass commandClasses[downCellCount];
	int progressBar;
	int downSelectedPos;
	Vec4f colors[colorCount];
	int currentColor;

	int upCellSideCount;
	int upImageSize;
	int maxUpIndex;
	

public:
	Display();

	//get
	string getTitle() const							{return title;}
	string getText() const							{return text;}
	string getInfoText() const						{return infoText;}
	const Texture2D *getUpImage(int index) const	{return upImages[index];}
	const Texture2D *getDownImage(int index) const	{return downImages[index];}
	bool getDownLighted(int index) const			{return downLighted[index];}
	const CommandType *getCommandType(int i) const	{return commandTypes[i];}
	CommandClass getCommandClass(int i)	const		{return commandClasses[i];}
	Vec4f getColor() const;
	int getProgressBar() const						{return progressBar;}
	int getDownSelectedPos() const					{return downSelectedPos;}
	int getUpCellSideCount() const					{return upCellSideCount;}
	int getUpImageSize() const						{return upImageSize;}
	
	//set
	void setTitle(const string title)					{this->title= formatString(title);}
	void setText(const string &text)					{this->text= formatString(text);}
	void setInfoText(const string infoText)				{this->infoText= formatString(infoText);}
	void setUpImage(int i, const Texture2D *image);
	void setDownImage(int i, const Texture2D *image)	{downImages[i]= image;}
	void setCommandType(int i, const CommandType *ct)	{commandTypes[i]= ct;}
	void setCommandClass(int i, const CommandClass cc)	{commandClasses[i]= cc;}
	void setDownLighted(int i, bool lighted)			{downLighted[i]= lighted;}
	void setProgressBar(int i)							{progressBar= i;}
	void setDownSelectedPos(int i)						{downSelectedPos= i;}
	
	//misc
	void clear();
	void switchColor();
	int computeDownIndex(int x, int y) const;
	int computeDownX(int index) const;
	int computeDownY(int index) const;
	int computeUpX(int index) const;
	int computeUpY(int index) const;

	void saveGame(XmlNode *rootNode) const;
	void loadGame(const XmlNode *rootNode);

private:
	void calculateUpDimensions(int index);
};

}}//end namespace 

#endif