File: dialog-mapgenerator.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (377 lines) | stat: -rw-r--r-- 13,503 bytes parent folder | download | duplicates (2)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "common/config-manager.h"
#include "common/translation.h"

#include "scumm/he/moonbase/map_main.h"
#include "scumm/he/moonbase/dialog-mapgenerator.h"

namespace Scumm {

enum {
	kAlgorCmd = 'ALGR',
	kAlgorRandCmd = 'ALRM',

	kSizeCmd = 'SIZE',
	kSizeRandCmd = 'SZRM',

	kTileCmd = 'TILE',
	kTileRandCmd = 'TLRM',

	kEnergyCmd = 'ENGY',
	kEnergyRandCmd = 'EGRM',

	kTerrainCmd = 'TRIN',
	kTerrainRandCmd = 'TRRM',

	kWaterCmd = 'WTER',
	kWaterRandCmd = 'WTRM',

	kCancelCmd = 'CNCL',
	kGenerateCmd = 'GNRT'
};

MapGeneratorDialog::MapGeneratorDialog(bool demo) : Dialog("MapGenerator"), _refreshing(false) {
	// I18N: Random map generator for Moonbase Commander
	_dialogTitle = new GUI::StaticTextWidget(this, "MapGenerator.Title", _("Random Map Options"));
	_dialogTitle->setAlign(Graphics::kTextAlignCenter);

	// I18N: Map generator algorithms
	_algorDesc = new GUI::StaticTextWidget(this, "MapGenerator.Algorithm", _("Algorithm"));
	_algorDesc->setAlign(Graphics::kTextAlignLeft);
	_algorGroup = new GUI::RadiobuttonGroup(this, kAlgorCmd);
	// I18N: Spiff algorithm
	_algorSpiff = new GUI::RadiobuttonWidget(this, "MapGenerator.AlgorithmSpiff", _algorGroup, SPIFF_GEN, _("Spiff"));
	// I18N: Katton algorithm
	_algorSpiff = new GUI::RadiobuttonWidget(this, "MapGenerator.AlgorithmKatton", _algorGroup, KATTON_GEN, _("Katton"));
	// I18N: Random algorithm
	_algorRandom = new GUI::CheckboxWidget(this, "MapGenerator.AlgorithmRandom", _("Random"), _("Picks the map algorithm randomly."), kAlgorRandCmd);

	// I18N: Map sizes
	_sizeDesc = new GUI::StaticTextWidget(this, "MapGenerator.Size", _("Size"));
	_sizeDesc->setAlign(Graphics::kTextAlignCenter);

	_sizeGroup = new GUI::RadiobuttonGroup(this, kSizeCmd);
	_sizeSmall = new GUI::RadiobuttonWidget(this, "MapGenerator.SizeSmall", _sizeGroup, 4, _("Small"));
	_sizeMedium = new GUI::RadiobuttonWidget(this, "MapGenerator.SizeMedium", _sizeGroup, 5, _("Medium"));
	_sizeLarge = new GUI::RadiobuttonWidget(this, "MapGenerator.SizeLarge", _sizeGroup, 6, _("Large"));
	_sizeHuge = new GUI::RadiobuttonWidget(this, "MapGenerator.SizeHuge", _sizeGroup, 7, _("Huge"));
	_sizeSAI = new GUI::RadiobuttonWidget(this, "MapGenerator.SizeSAI", _sizeGroup, 8, _("SAI"));
	_sizeRidiculous = new GUI::RadiobuttonWidget(this, "MapGenerator.SizeRidiculous", _sizeGroup, 9, _("Ridiculous"));
	_sizeMax = new GUI::RadiobuttonWidget(this, "MapGenerator.SizeMax", _sizeGroup, 10, _("Max"));
	// I18N: Random map size
	_sizeRandom = new GUI::CheckboxWidget(this, "MapGenerator.SizeRandom", _("Random"), _("Picks the map size randomly."), kSizeRandCmd);

	// I18N: Map tilesets
	_tileDesc = new GUI::StaticTextWidget(this, "MapGenerator.Tileset", _("Tileset"));
	_tileDesc->setAlign(Graphics::kTextAlignCenter);
	_tileGroup = new GUI::RadiobuttonGroup(this, kTileCmd);
	_tileTerrandra = new GUI::RadiobuttonWidget(this, "MapGenerator.TilesetTerrandra", _tileGroup, 1, Common::U32String("Terrandra"));
	_tileZanateros = new GUI::RadiobuttonWidget(this, "MapGenerator.TilesetZanateros", _tileGroup, 2, Common::U32String("Zanateros"));
	// Demo version of the game only has tilesets 1, 2, 4 and 6.  Don't create buttons for
	// missing tiles.
	if (!demo)
		_tileDrijim = new GUI::RadiobuttonWidget(this, "MapGenerator.TilesetDaijim", _tileGroup, 3, Common::U32String("Daijim 3"));
	_tileKyanite = new GUI::RadiobuttonWidget(this, "MapGenerator.TilesetKyanite", _tileGroup, 4, Common::U32String("Kyanite"));
	if (!demo)
		_tileEmerau = new GUI::RadiobuttonWidget(this, "MapGenerator.TilesetEmerau", _tileGroup, 5, Common::U32String("Emerau Glyph"));
	_tileAblation = new GUI::RadiobuttonWidget(this, "MapGenerator.TilesetAblation", _tileGroup, 6, Common::U32String("Ablation Land"));
	// I18N: Random tileset
	_tileRandom = new GUI::CheckboxWidget(this, "MapGenerator.TilesetRandom", _("Random"), _("Picks the map tileset randomly."), kTileRandCmd);

	// I18N: Percentage of energy pools
	_energyDesc = new GUI::StaticTextWidget(this, "MapGenerator.Energy", _("Energy"));
	_energyDesc->setAlign(Graphics::kTextAlignCenter);
	_energySlider = new GUI::SliderWidget(this, "MapGenerator.EnergySlider", Common::U32String(), kEnergyCmd);
	_energySlider->setMinValue(0); _energySlider->setMaxValue(6);
	// I18N: Energy slider label
	_energyLabel = new GUI::StaticTextWidget(this, "MapGenerator.EnergySliderLabel", _("Scarce - Lots"), Common::U32String());
	_energyLabel->setAlign(Graphics::kTextAlignCenter);


	// I18N: Random percentage of energy pools
	_energyRandom = new GUI::CheckboxWidget(this, "MapGenerator.EnergyRandom", _("Random"), _("Picks the random amount of energy pools."), kEnergyRandCmd);

	// I18N: Percentage of terrain
	_terrainDesc = new GUI::StaticTextWidget(this, "MapGenerator.Terrain", _("Terrain"));
	_terrainDesc->setAlign(Graphics::kTextAlignCenter);
	_terrainSlider = new GUI::SliderWidget(this, "MapGenerator.TerrainSlider", Common::U32String(), kTerrainCmd);
	_terrainSlider->setMinValue(0); _terrainSlider->setMaxValue(6);
	// I18N: Terrain slider label
	_terrainLabel = new GUI::StaticTextWidget(this, "MapGenerator.TerrainSliderLabel", _("Barren - Rough"), Common::U32String());
	_terrainLabel->setAlign(Graphics::kTextAlignCenter);

	// I18N: Random percentage of terrain
	_terrainRandom = new GUI::CheckboxWidget(this, "MapGenerator.TerrainRandom", _("Random"), _("Picks the random amount of terrain level."), kTerrainRandCmd);

	// I18N: Percentage of water
	_waterDesc = new GUI::StaticTextWidget(this, "MapGenerator.Water", _("Water"));
	_waterDesc->setAlign(Graphics::kTextAlignCenter);
	_waterSlider = new GUI::SliderWidget(this, "MapGenerator.WaterSlider", Common::U32String(), kWaterCmd);
	_waterSlider->setMinValue(0); _waterSlider->setMaxValue(6);
	// I18N: Water slider label
	_waterLabel = new GUI::StaticTextWidget(this, "MapGenerator.WaterSliderLabel", _("Driest - Wettest"), Common::U32String());
	_waterLabel->setAlign(Graphics::kTextAlignCenter);

	// I18N: Random percentage of water
	_waterRandom = new GUI::CheckboxWidget(this, "MapGenerator.WaterRandom", _("Random"), _("Picks the random amount of water."), kWaterRandCmd);

	_cancelButton = new GUI::ButtonWidget(this, "MapGenerator.Cancel", _("Cancel"), Common::U32String(), kCancelCmd);
	// I18N: Generate new map
	_generateButton = new GUI::ButtonWidget(this, "MapGenerator.Generate", _("Generate"), Common::U32String(), kGenerateCmd);
	refresh();
}

void MapGeneratorDialog::refresh() {
	_refreshing = true;

	//  ALGORITHM
	bool randomAlgorithm = true;
	if (ConfMan.hasKey("map_algorithm"))
		randomAlgorithm = ConfMan.getInt("map_algorithm") == 0;

	_algorGroup->setEnabled(!randomAlgorithm);
	_algorRandom->setState(randomAlgorithm);

	if (!randomAlgorithm)
		_algorGroup->setValue(ConfMan.getInt("map_algorithm"));

	// SIZE
	bool randomSize = true;
	if (ConfMan.hasKey("map_size"))
		randomSize = ConfMan.getInt("map_size") == 0;

	_sizeGroup->setEnabled(!randomSize);
	_sizeRandom->setState(randomSize);

	if (!randomSize)
		_sizeGroup->setValue(ConfMan.getInt("map_size"));

	// TILESET
	bool randomTileset = true;
	if (ConfMan.hasKey("map_tileset"))
		randomTileset = ConfMan.getInt("map_tileset") == 0;

	_tileGroup->setEnabled(!randomTileset);
	_tileRandom->setState(randomTileset);

	if (!randomTileset)
		_tileGroup->setValue(ConfMan.getInt("map_tileset"));

	// ENERGY
	bool randomEnergy = true;
	if (ConfMan.hasKey("map_energy"))
		randomEnergy = ConfMan.getInt("map_energy") == -1;

	_energySlider->setEnabled(!randomEnergy);
	_energyRandom->setState(randomEnergy);

	if (!randomEnergy)
		_energySlider->setValue(ConfMan.getInt("map_energy"));
	else if (ConfMan.hasKey("prev_map_energy"))
		_energySlider->setValue(ConfMan.getInt("prev_map_energy"));
	else
		_energySlider->setValue(3);

	// TERRAIN
	bool randomTerrain = true;
	if (ConfMan.hasKey("map_terrain"))
		randomTerrain = ConfMan.getInt("map_terrain") == -1;

	_terrainSlider->setEnabled(!randomTerrain);
	_terrainRandom->setState(randomTerrain);

	if (!randomTerrain)
		_terrainSlider->setValue(ConfMan.getInt("map_terrain"));
	else if (ConfMan.hasKey("prev_map_terrain"))
		_terrainSlider->setValue(ConfMan.getInt("prev_map_terrain"));
	else
		_terrainSlider->setValue(3);


	// WATER
	bool randomWater = true;
	if (ConfMan.hasKey("map_water"))
		randomWater = ConfMan.getInt("map_water") == -1;

	_waterSlider->setEnabled(!randomWater);
	_waterRandom->setState(randomWater);

	if (!randomWater)
		_waterSlider->setValue(ConfMan.getInt("map_water"));
	else if (ConfMan.hasKey("prev_map_water"))
		_waterSlider->setValue(ConfMan.getInt("prev_map_water"));
	else
		_waterSlider->setValue(3);

	drawDialog(GUI::kDrawLayerForeground);

	_refreshing = false;
}

void MapGeneratorDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
	if (_refreshing)
		return;

	switch(cmd) {
	case kAlgorCmd:
		ConfMan.setInt("map_algorithm", data);
		break;
	case kAlgorRandCmd:
		if (data == 1) {
			if (ConfMan.hasKey("map_algorithm") && ConfMan.getInt("map_algorithm") != 0)
				// Store previous value
				ConfMan.setInt("prev_map_algorithm", ConfMan.getInt("map_algorithm"));
			ConfMan.setInt("map_algorithm", 0);
		} else {
			// Restore previous value
			int previousValue = SPIFF_GEN;
			if (ConfMan.hasKey("prev_map_algorithm"))
				previousValue = ConfMan.getInt("prev_map_algorithm");
			ConfMan.setInt("map_algorithm", previousValue);
		}

		refresh();
		break;
	case kSizeCmd:
		ConfMan.setInt("map_size", data);
		break;
	case kSizeRandCmd:
		if (data == 1) {
			if (ConfMan.hasKey("map_size") && ConfMan.getInt("map_size") != 0)
				// Store previous value
				ConfMan.setInt("prev_map_size", ConfMan.getInt("map_size"));
			ConfMan.setInt("map_size", 0);
		} else {
			// Restore previous value
			int previousValue = 4;
			if (ConfMan.hasKey("prev_map_size"))
				previousValue = ConfMan.getInt("prev_map_size");
			ConfMan.setInt("map_size", previousValue);
		}

		refresh();
		break;
	case kTileCmd:
		ConfMan.setInt("map_tileset", data);
		break;
	case kTileRandCmd:
		if (data == 1) {
			if (ConfMan.hasKey("map_tileset") && ConfMan.getInt("map_tileset") != 0)
				// Store previous value
				ConfMan.setInt("prev_map_tileset", ConfMan.getInt("map_tileset"));
			ConfMan.setInt("map_tileset", 0);
		} else {
			// Restore previous value
			int previousValue = 5;
			if (ConfMan.hasKey("prev_map_tileset"))
				previousValue = ConfMan.getInt("prev_map_tileset");
			ConfMan.setInt("map_tileset", previousValue);
		}

		refresh();
		break;
	case kEnergyCmd:
		ConfMan.setInt("map_energy", data);
		break;
	case kEnergyRandCmd:
		if (data == 1) {
			if (ConfMan.hasKey("map_energy") && ConfMan.getInt("map_energy") != -1)
				// Store previous value
				ConfMan.setInt("prev_map_energy", ConfMan.getInt("map_energy"));
			ConfMan.setInt("map_energy", -1);
		} else {
			// Restore previous value
			int previousValue = 3;
			if (ConfMan.hasKey("prev_map_energy"))
				previousValue = ConfMan.getInt("prev_map_energy");
			ConfMan.setInt("map_energy", previousValue);
		}

		refresh();
		break;
	case kTerrainCmd:
		ConfMan.setInt("map_terrain", data);
		break;
	case kTerrainRandCmd:
		if (data == 1) {
			if (ConfMan.hasKey("map_terrain") && ConfMan.getInt("map_terrain") != -1)
				// Store previous value
				ConfMan.setInt("prev_map_terrain", ConfMan.getInt("map_terrain"));
			ConfMan.setInt("map_terrain", -1);
		} else {
			// Restore previous value
			int previousValue = 3;
			if (ConfMan.hasKey("prev_map_terrain"))
				previousValue = ConfMan.getInt("prev_map_terrain");
			ConfMan.setInt("map_terrain", previousValue);
		}

		refresh();
		break;
	case kWaterCmd:
		ConfMan.setInt("map_water", data);
		break;
	case kWaterRandCmd:
		if (data == 1) {
			if (ConfMan.hasKey("map_water") && ConfMan.getInt("map_water") != -1)
				// Store previous value
				ConfMan.setInt("prev_map_water", ConfMan.getInt("map_water"));
			ConfMan.setInt("map_water", -1);
		} else {
			// Restore previous value
			int previousValue = 3;
			if (ConfMan.hasKey("prev_map_water"))
				previousValue = ConfMan.getInt("prev_map_water");
			ConfMan.setInt("map_water", previousValue);
		}

		refresh();
		break;
	case kCancelCmd:
		setResult(0);
		close();
		break;
	case kGenerateCmd:
		ConfMan.flushToDisk();
		setResult(1);
		close();
		break;
	default:
		Dialog::handleCommand(sender, cmd, data);
	}
}

void MapGeneratorDialog::handleKeyDown(Common::KeyState state) {
	switch (state.keycode) {
	case Common::KEYCODE_RETURN:
	case Common::KEYCODE_KP_ENTER:
		ConfMan.flushToDisk();
		setResult(1);
		close();
		break;
	default:
		Dialog::handleKeyDown(state);
	}
}

} // End of namespace Scumm