File: CommandColors.h

package info (click to toggle)
spring 106.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 55,316 kB
  • sloc: cpp: 543,954; ansic: 44,800; python: 12,575; java: 12,201; awk: 5,889; sh: 1,796; asm: 1,546; xml: 655; perl: 405; php: 211; objc: 194; makefile: 76; sed: 2
file content (202 lines) | stat: -rw-r--r-- 5,420 bytes parent folder | download | duplicates (3)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef _COMMAND_COLORS_H
#define _COMMAND_COLORS_H

#include <string>
#include "System/UnorderedMap.hpp"

class CCommandColors {
public:
	CCommandColors();

	bool LoadConfigFromFile(const std::string& filename);
	bool LoadConfigFromString(const std::string& cfg);

	// for command queue lines
	bool         AlwaysDrawQueue()   const { return alwaysDrawQueue;   }
	bool         UseQueueIcons()     const { return useQueueIcons;     }
	float        QueueIconAlpha()    const { return queueIconAlpha;    }
	float        QueueIconScale()    const { return queueIconScale;    }
	bool         UseColorRestarts()  const { return useColorRestarts;  }
	bool         UseRestartColor()   const { return useRestartColor;   }
	float        RestartAlpha()      const { return restartAlpha;      }

	float        QueuedLineWidth()   const { return queuedLineWidth;   }
	unsigned int QueuedBlendSrc()    const { return queuedBlendSrc;    }
	unsigned int QueuedBlendDst()    const { return queuedBlendDst;    }
	unsigned int StipplePattern()    const { return stipplePattern;    }
	unsigned int StippleFactor()     const { return stippleFactor;     }
	float        StippleSpeed()      const { return stippleSpeed;      }

	float        SelectedLineWidth() const { return selectedLineWidth; }
	unsigned int SelectedBlendSrc()  const { return selectedBlendSrc;  }
	unsigned int SelectedBlendDst()  const { return selectedBlendDst;  }
	bool         BuildBoxesOnShift() const { return buildBoxesOnShift; }

	float        MouseBoxLineWidth() const { return mouseBoxLineWidth; }
	unsigned int MouseBoxBlendSrc()  const { return mouseBoxBlendSrc;  }
	unsigned int MouseBoxBlendDst()  const { return mouseBoxBlendDst;  }

	float        UnitBoxLineWidth()  const { return unitBoxLineWidth;  }

	// custom command queue rendering
	struct DrawData {
		int cmdIconID = 0;
		float color[4];
		bool showArea = false;

		DrawData()
		{
			for (int i = 0; i < 4; ++i) { color[i] = 1.0f; }
		}

		DrawData(int cii, const float c[4], bool area) : cmdIconID(cii), showArea(area)
		{
			for (int i = 0; i < 4; ++i) { color[i] = c[i]; }
		}
	};

	void SetCustomCmdData(int cmdID, int cmdIconID, const float color[4], bool showArea) { customCmds[cmdID] = DrawData(cmdIconID, color, showArea); }
	void ClearCustomCmdData(int cmdID) { customCmds.erase(cmdID); }

	/// get custom command line parameters
	/// @return NULL if no line defined, a pointer to a DrawData otherwise
	/// NB: do not call {Set,Clear}CustomCmdData while holding this pointer
	const DrawData* GetCustomCmdData(int cmdID) const {
		const auto it = customCmds.find(cmdID);

		if (it == customCmds.end())
			return nullptr;

		return &(it->second);
	}

	// the colors
	const float* unitBox;
	const float* buildBox;
	const float* allyBuildBox;
	const float* mouseBox;

	// for command queue rendering
	const float* start;
	const float* restart;
	const float* stop;
	const float* wait;
	const float* build;
	const float* move;
	const float* attack;
	const float* fight;
	const float* guard;
	const float* patrol;
	const float* capture;
	const float* repair;
	const float* reclaim;
	const float* restore;
	const float* resurrect;
	const float* load;
	const float* unload;
	const float* deathWait;
	const float* customArea;

	// for selected unit range rendering
	const float* rangeAttack;
	const float* rangeBuild;
	const float* rangeRadar;
	const float* rangeSonar;
	const float* rangeSeismic;
	const float* rangeJammer;
	const float* rangeSonarJammer;
	const float* rangeShield;
	const float* rangeDecloak;
	const float* rangeExtract;
	const float* rangeKamikaze;
	const float* rangeSelfDestruct;
	const float* rangeInterceptorOn;
	const float* rangeInterceptorOff;

private:
	enum ColorIndices {
		startIndex = 0,
		restartIndex,
		stopIndex,
		waitIndex,
		buildIndex,
		moveIndex,
		attackIndex,
		fightIndex,
		guardIndex,
		patrolIndex,
		captureIndex,
		repairIndex,
		reclaimIndex,
		restoreIndex,
		resurrectIndex,
		loadIndex,
		unloadIndex,
		deathWaitIndex,
		customAreaIndex,

		rangeAttackIndex,
		rangeBuildIndex,
		rangeRadarIndex,
		rangeSonarIndex,
		rangeSeismicIndex,
		rangeJammerIndex,
		rangeSonarJammerIndex,
		rangeShieldIndex,
		rangeDecloakIndex,
		rangeExtractIndex,
		rangeKamikazeIndex,
		rangeSelfDestructIndex,
		rangeInterceptorOnIndex,
		rangeInterceptorOffIndex,

		unitBoxIndex,
		buildBoxIndex,
		allyBuildBoxIndex,
		mouseBoxIndex,

		ColorCount
	};

	float colors[ColorCount][4];

	// for command queue lines
	bool alwaysDrawQueue   = false;
	bool  useQueueIcons    = true;
	bool  useColorRestarts = true;
	bool  useRestartColor  = true;
	bool buildBoxesOnShift = true;

	float queueIconAlpha = 0.5f;
	float queueIconScale = 1.0f;
	float   restartAlpha = 0.25f;

	float   queuedLineWidth = 1.49f;
	float selectedLineWidth = 1.49f;
	float mouseBoxLineWidth = 1.49f;
	float  unitBoxLineWidth = 1.49f;
	float      stippleSpeed = 1.0f;

	unsigned int stipplePattern = 0xffffffff;
	unsigned int stippleFactor = 1;

	unsigned int queuedBlendSrc;
	unsigned int queuedBlendDst;

	unsigned int selectedBlendSrc;
	unsigned int selectedBlendDst;

	unsigned int mouseBoxBlendSrc;
	unsigned int mouseBoxBlendDst;

	spring::unordered_map<std::string, int> colorNames;
	spring::unordered_map<int, DrawData> customCmds;
};


extern CCommandColors cmdColors;


#endif // _COMMAND_COLORS_H