mirror of
https://github.com/glest/glest-source.git
synced 2025-09-03 04:52:34 +02:00
mapeditor from GAE ( removed macro stuff and so on )
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>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
|
||||
// ==============================================================
|
||||
|
||||
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include <ctime>
|
||||
@@ -5,12 +18,11 @@
|
||||
#include "conversion.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
namespace MapEditor {
|
||||
|
||||
const string MainWindow::versionString= "v1.3.1";
|
||||
const string MainWindow::versionString = "v1.5.0-beta3";
|
||||
const string MainWindow::winHeader = "Glest Map Editor " + versionString + " - Built: " + __DATE__;
|
||||
|
||||
// ===============================================
|
||||
@@ -29,20 +41,20 @@ wxString ToUnicode(const string& str){
|
||||
// class MainWindow
|
||||
// ===============================================
|
||||
|
||||
MainWindow::MainWindow():
|
||||
wxFrame(NULL, -1, ToUnicode(winHeader), wxDefaultPosition, wxSize(800, 600))
|
||||
{
|
||||
MainWindow::MainWindow()
|
||||
: wxFrame(NULL, -1, ToUnicode(winHeader), wxDefaultPosition, wxSize(800, 600)) {
|
||||
|
||||
fileModified=false;
|
||||
lastX=0;
|
||||
lastY=0;
|
||||
|
||||
radius=1;
|
||||
height= 5;
|
||||
height=0;
|
||||
surface=1;
|
||||
object=0;
|
||||
resource=0;
|
||||
startLocation=1;
|
||||
enabledGroup= 0;
|
||||
|
||||
enabledGroup=ctHeight;
|
||||
currentBrush=btHeight;
|
||||
|
||||
//gl canvas
|
||||
int args[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER };
|
||||
@@ -53,111 +65,152 @@ MainWindow::MainWindow():
|
||||
|
||||
//file
|
||||
menuFile = new wxMenu();
|
||||
menuFile->Append(miFileLoad, wxT("Load"));
|
||||
menuFile->Append(wxID_OPEN);
|
||||
menuFile->AppendSeparator();
|
||||
menuFile->Append(miFileSave, wxT("Save"));
|
||||
menuFile->Append(miFileSaveAs, wxT("Save As"));
|
||||
menuFile->Append(wxID_SAVE);
|
||||
menuFile->Append(wxID_SAVEAS);
|
||||
menuFile->AppendSeparator();
|
||||
menuFile->Append(miFileExit, wxT("Exit"));
|
||||
menuBar->Append(menuFile, wxT("File"));
|
||||
menuFile->Append(wxID_EXIT);
|
||||
menuBar->Append(menuFile, wxT("&File"));
|
||||
|
||||
//edit
|
||||
menuEdit = new wxMenu();
|
||||
menuEdit->Append(miEditReset, wxT("Reset"));
|
||||
menuEdit->Append(miEditResetPlayers, wxT("Reset Players"));
|
||||
menuEdit->Append(miEditResize, wxT("Resize"));
|
||||
menuEdit->Append(miEditFlipX, wxT("Flip X"));
|
||||
menuEdit->Append(miEditFlipY, wxT("Flip Y"));
|
||||
menuEdit->Append(miEditRandomizeHeights, wxT("Randomize Heights"));
|
||||
menuEdit->Append(miEditRandomize, wxT("Randomize"));
|
||||
menuEdit->Append(miEditSwitchSurfaces, wxT("Switch Surfaces"));
|
||||
menuEdit->Append(miEditInfo, wxT("Info"));
|
||||
menuEdit->Append(miEditAdvanced, wxT("Advanced"));
|
||||
menuBar->Append(menuEdit, wxT("Edit"));
|
||||
menuEdit->Append(miEditUndo, wxT("&Undo\tCTRL+z"));
|
||||
menuEdit->Append(miEditRedo, wxT("&Redo\tCTRL+y"));
|
||||
menuEdit->Append(miEditReset, wxT("Rese&t"));
|
||||
menuEdit->Append(miEditResetPlayers, wxT("Reset &Players"));
|
||||
menuEdit->Append(miEditResize, wxT("Re&size"));
|
||||
menuEdit->Append(miEditFlipX, wxT("Flip &X"));
|
||||
menuEdit->Append(miEditFlipY, wxT("Flip &Y"));
|
||||
menuEdit->Append(miEditRandomizeHeights, wxT("Randomize &Heights"));
|
||||
menuEdit->Append(miEditRandomize, wxT("Randomi&ze"));
|
||||
menuEdit->Append(miEditSwitchSurfaces, wxT("Switch Su&rfaces"));
|
||||
menuEdit->Append(miEditInfo, wxT("&Info"));
|
||||
menuEdit->Append(miEditAdvanced, wxT("&Advanced"));
|
||||
menuBar->Append(menuEdit, wxT("&Edit"));
|
||||
|
||||
//misc
|
||||
menuMisc = new wxMenu();
|
||||
menuMisc->Append(miMiscResetZoomAndPos, wxT("Reset zoom and pos"));
|
||||
menuMisc->Append(miMiscAbout, wxT("About"));
|
||||
menuMisc->Append(miMiscHelp, wxT("Help"));
|
||||
menuBar->Append(menuMisc, wxT("Misc"));
|
||||
menuMisc->Append(miMiscResetZoomAndPos, wxT("&Reset zoom and pos"));
|
||||
menuMisc->Append(miMiscAbout, wxT("&About"));
|
||||
menuMisc->Append(miMiscHelp, wxT("&Help"));
|
||||
menuBar->Append(menuMisc, wxT("&Misc"));
|
||||
|
||||
//brush
|
||||
menuBrush = new wxMenu();
|
||||
|
||||
//height
|
||||
// Glest height brush
|
||||
menuBrushHeight = new wxMenu();
|
||||
for (int i = 0; i < heightCount; ++i) {
|
||||
menuBrushHeight->AppendCheckItem(miBrushHeight + i + 1, ToUnicode(intToStr(i - heightCount / 2)));
|
||||
}
|
||||
menuBrushHeight->Check(miBrushHeight + 1 + heightCount/2, true);
|
||||
menuBrush->Append(miBrushHeight, wxT("Height"), menuBrushHeight);
|
||||
menuBrushHeight->Check(miBrushHeight + (heightCount + 1) / 2, true);
|
||||
menuBrush->Append(miBrushHeight, wxT("&Height"), menuBrushHeight);
|
||||
|
||||
enabledGroup = ctHeight;
|
||||
|
||||
// ZombiePirate height brush
|
||||
menuBrushGradient = new wxMenu();
|
||||
for (int i = 0; i < heightCount; ++i) {
|
||||
menuBrushGradient->AppendCheckItem(miBrushGradient + i + 1, ToUnicode(intToStr(i - heightCount / 2)));
|
||||
}
|
||||
menuBrush->Append(miBrushGradient, wxT("&Gradient"), menuBrushGradient);
|
||||
|
||||
//surface
|
||||
menuBrushSurface = new wxMenu();
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface+1, wxT("1 - Grass"));
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface+2, wxT("2 - Secondary Grass"));
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface+3, wxT("3 - Road"));
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface+4, wxT("4 - Stone"));
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface+5, wxT("5 - Custom"));
|
||||
menuBrush->Append(miBrushSurface, wxT("Surface"), menuBrushSurface);
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface + 1, wxT("&1 - Grass"));
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface + 2, wxT("&2 - Secondary Grass"));
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface + 3, wxT("&3 - Road"));
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface + 4, wxT("&4 - Stone"));
|
||||
menuBrushSurface->AppendCheckItem(miBrushSurface + 5, wxT("&5 - Ground"));
|
||||
menuBrush->Append(miBrushSurface, wxT("&Surface"), menuBrushSurface);
|
||||
|
||||
//objects
|
||||
menuBrushObject = new wxMenu();
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+1, wxT("0 - None"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+2, wxT("1 - Tree (unwalkable/harvestable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+3, wxT("2 - DeadTree/Cactuses/Thornbush (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+4, wxT("3 - Stone (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+5, wxT("4 - Bush/Grass/Fern (walkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+6, wxT("5 - Water Object/Reed/Papyrus (walkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+7, wxT("6 - C1 BigTree/DeadTree/OldPalm (unwalkable/not harvestable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+8, wxT("7 - C2 Hanged/Impaled (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+9, wxT("8 - C3, Statues (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+10, wxT("9 - Big Rock (Mountain) (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+11, wxT("10 - Invisible Blocking Object (unwalkable)"));
|
||||
menuBrush->Append(miBrushObject, wxT("Object"), menuBrushObject);
|
||||
menuBrushObject->AppendCheckItem(miBrushObject + 1, wxT("&0 - None (erase)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+2, wxT("&1 - Tree (unwalkable/harvestable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+3, wxT("&2 - DeadTree/Cactuses/Thornbush (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+4, wxT("&3 - Stone (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+5, wxT("&4 - Bush/Grass/Fern (walkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+6, wxT("&5 - Water Object/Reed/Papyrus (walkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+7, wxT("&6 - C1 BigTree/DeadTree/OldPalm (unwalkable/not harvestable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+8, wxT("&7 - C2 Hanged/Impaled (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+9, wxT("&8 - C3 Statues (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+10, wxT("&9 - C4 Big Rock (Mountain) (unwalkable)"));
|
||||
menuBrushObject->AppendCheckItem(miBrushObject+11, wxT("10 &- C5 Invisible Blocking Object (unwalkable)"));
|
||||
menuBrush->Append(miBrushObject, wxT("&Object"), menuBrushObject);
|
||||
|
||||
//resources
|
||||
menuBrushResource = new wxMenu();
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+1, wxT("0 - None"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+2, wxT("1 - gold (unwalkable)"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+3, wxT("2 - stone (unwalkable)"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+4, wxT("3 - (not used yet)"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+5, wxT("4 - (not used yet)"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+6, wxT("5 - (not used yet)"));
|
||||
menuBrush->Append(miBrushResource, wxT("Resource"), menuBrushResource);
|
||||
menuBrushResource->AppendCheckItem(miBrushResource + 1, wxT("&0 - None"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+2, wxT("&1 - gold (unwalkable)"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+3, wxT("&2 - stone (unwalkable)"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+4, wxT("&3 - custom"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+5, wxT("&4 - custom"));
|
||||
menuBrushResource->AppendCheckItem(miBrushResource+6, wxT("&5 - custom"));
|
||||
menuBrush->Append(miBrushResource, wxT("&Resource"), menuBrushResource);
|
||||
|
||||
//players
|
||||
menuBrushStartLocation = new wxMenu();
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation+1, wxT("1 - Player 1 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation+2, wxT("2 - Player 2 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation+3, wxT("3 - Player 3 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation+4, wxT("4 - Player 4 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation+5, wxT("5 - Player 5 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation+6, wxT("6 - Player 6 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation+7, wxT("7 - Player 7 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation+8, wxT("8 - Player 8 "));
|
||||
menuBrush->Append(miBrushStartLocation, wxT("Player"), menuBrushStartLocation);
|
||||
|
||||
menuBar->Append(menuBrush, wxT("Brush"));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation + 1, wxT("&1 - Player 1"));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation + 2, wxT("&2 - Player 2"));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation + 3, wxT("&3 - Player 3"));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation + 4, wxT("&4 - Player 4"));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation + 5, wxT("&5 - Player 5 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation + 6, wxT("&6 - Player 6 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation + 7, wxT("&7 - Player 7 "));
|
||||
menuBrushStartLocation->AppendCheckItem(miBrushStartLocation + 8, wxT("&8 - Player 8 "));
|
||||
menuBrush->Append(miBrushStartLocation, wxT("&Player"), menuBrushStartLocation);
|
||||
menuBar->Append(menuBrush, wxT("&Brush"));
|
||||
|
||||
//radius
|
||||
menuRadius = new wxMenu();
|
||||
for(int i=0; i<radiusCount; ++i){
|
||||
menuRadius->AppendCheckItem(miRadius+i, ToUnicode(intToStr(i+1)));
|
||||
for (int i = 1; i <= radiusCount; ++i) {
|
||||
menuRadius->AppendCheckItem(miRadius + i, ToUnicode("&" + intToStr(i) + "\tALT+" + intToStr(i)));
|
||||
}
|
||||
menuRadius->Check(miRadius, true);
|
||||
menuBar->Append(menuRadius, wxT("Radius"));
|
||||
menuRadius->Check(miRadius + 1, true);
|
||||
menuBar->Append(menuRadius, wxT("&Radius"));
|
||||
|
||||
SetMenuBar(menuBar);
|
||||
|
||||
fileName = "New (unsaved) map";
|
||||
int status_widths[siCOUNT] = {
|
||||
10, // empty
|
||||
-2, // File name
|
||||
-2, // File type
|
||||
-2, // Brush Type
|
||||
-2, // Brush 'Value'
|
||||
-1, // Brush Radius
|
||||
};
|
||||
CreateStatusBar(siCOUNT);
|
||||
GetStatusBar()->SetStatusWidths(siCOUNT, status_widths);
|
||||
|
||||
SetStatusText(wxT("File: ") + ToUnicode(fileName), siFILE_NAME);
|
||||
SetStatusText(wxT("Type: Glest Map (gbm)"), siFILE_TYPE);
|
||||
SetStatusText(wxT("Brush: Height"), siBRUSH_TYPE);
|
||||
SetStatusText(wxT("Value: 0"), siBRUSH_VALUE);
|
||||
SetStatusText(wxT("Radius: 1"), siBRUSH_RADIUS);
|
||||
|
||||
#ifndef WIN32
|
||||
timer = new wxTimer(this);
|
||||
timer->Start(50);
|
||||
timer->Start(100);
|
||||
#endif
|
||||
glCanvas->SetFocus();
|
||||
}
|
||||
|
||||
void MainWindow::init(){
|
||||
void MainWindow::init(string fname) {
|
||||
glCanvas->SetCurrent();
|
||||
program = new Program(GetClientSize().x, GetClientSize().y);
|
||||
|
||||
fileName = "New (unsaved) Map";
|
||||
if (!fname.empty() && fileExists(fname)) {
|
||||
program->loadMap(fname);
|
||||
currentFile = fname;
|
||||
fileName = cutLastExt(lastFile(fname));
|
||||
}
|
||||
SetTitle(ToUnicode(winHeader + "; " + currentFile));
|
||||
setDirty(false);
|
||||
setExtension();
|
||||
}
|
||||
|
||||
void MainWindow::onClose(wxCloseEvent &event) {
|
||||
@@ -169,14 +222,53 @@ MainWindow::~MainWindow(){
|
||||
delete glCanvas;
|
||||
}
|
||||
|
||||
void MainWindow::setDirty(bool val) {
|
||||
if (fileModified && val) {
|
||||
return;
|
||||
}
|
||||
fileModified = val;
|
||||
if (fileModified) {
|
||||
SetStatusText(wxT("File: ") + ToUnicode(fileName) + wxT("*"), siFILE_NAME);
|
||||
} else {
|
||||
SetStatusText(wxT("File: ") + ToUnicode(fileName), siFILE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setExtension() {
|
||||
if (currentFile.empty()) {
|
||||
return;
|
||||
}
|
||||
string extnsn = ext(currentFile);
|
||||
if (extnsn == "gbm" || extnsn == "mgm") {
|
||||
currentFile = cutLastExt(currentFile);
|
||||
}
|
||||
if (Program::getMap()->getMaxFactions() <= 4) {
|
||||
SetStatusText(wxT("Type: Glest Map (gbm)"), siFILE_TYPE);
|
||||
currentFile += ".gbm";
|
||||
} else {
|
||||
SetStatusText(wxT("Type: Mega Map (mgm)"), siFILE_TYPE);
|
||||
currentFile += ".mgm";
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onTimer(wxTimerEvent &event) {
|
||||
wxPaintEvent paintEvent;
|
||||
onPaint(paintEvent);
|
||||
}
|
||||
|
||||
void MainWindow::onMouseDown(wxMouseEvent &event) {
|
||||
if (event.LeftIsDown()) {
|
||||
program->setUndoPoint(enabledGroup);
|
||||
program->setRefAlt(event.GetX(), event.GetY());
|
||||
change(event.GetX(), event.GetY());
|
||||
if (!isDirty()) {
|
||||
setDirty(true);
|
||||
}
|
||||
wxPaintEvent ev;
|
||||
onPaint(ev);
|
||||
}
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void MainWindow::onMouseMove(wxMouseEvent &event) {
|
||||
int dif;
|
||||
@@ -184,23 +276,27 @@ void MainWindow::onMouseMove(wxMouseEvent &event){
|
||||
int x = event.GetX();
|
||||
int y = event.GetY();
|
||||
|
||||
bool doPaint = true;
|
||||
if (event.LeftIsDown()) {
|
||||
change(x, y);
|
||||
}
|
||||
else if(event.MiddleIsDown()){
|
||||
} else if (event.MiddleIsDown()) {
|
||||
dif = (y - lastY);
|
||||
if (dif != 0) {
|
||||
program->incCellSize(dif / abs(dif));
|
||||
}
|
||||
}
|
||||
else if(event.RightIsDown()){
|
||||
} else if (event.RightIsDown()) {
|
||||
program->setOfset(x - lastX, y - lastY);
|
||||
} else {
|
||||
doPaint = false;
|
||||
}
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
if (doPaint) {
|
||||
wxPaintEvent ev;
|
||||
onPaint(ev);
|
||||
}
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void MainWindow::onPaint(wxPaintEvent &event) {
|
||||
program->renderMap(GetClientSize().x, GetClientSize().y);
|
||||
@@ -208,40 +304,39 @@ void MainWindow::onPaint(wxPaintEvent &event){
|
||||
}
|
||||
|
||||
void MainWindow::onMenuFileLoad(wxCommandEvent &event) {
|
||||
string fileName;
|
||||
|
||||
wxFileDialog fileDialog(this);
|
||||
fileDialog.SetWildcard(wxT("Glest Binary Map (*.gbm)|*.gbm"));
|
||||
fileDialog.SetWildcard(wxT("Glest Map (*.gbm)|*.gbm|Mega Map (*.mgm)|*.mgm"));
|
||||
if (fileDialog.ShowModal() == wxID_OK) {
|
||||
fileName= fileDialog.GetPath().ToAscii();
|
||||
program->loadMap(fileName);
|
||||
}
|
||||
|
||||
currentFile= fileName;
|
||||
currentFile = fileDialog.GetPath().ToAscii();
|
||||
program->loadMap(currentFile);
|
||||
fileName = cutLastExt(lastFile(currentFile));
|
||||
setDirty(false);
|
||||
setExtension();
|
||||
SetTitle(ToUnicode(winHeader + "; " + currentFile));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onMenuFileSave(wxCommandEvent &event) {
|
||||
if (currentFile.empty()) {
|
||||
wxCommandEvent ev;
|
||||
onMenuFileSaveAs(ev);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
setExtension();
|
||||
program->saveMap(currentFile);
|
||||
setDirty(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onMenuFileSaveAs(wxCommandEvent &event) {
|
||||
string fileName;
|
||||
|
||||
wxFileDialog fileDialog(this, wxT("Select file"), wxT(""), wxT(""), wxT("*.gbm"), wxSAVE);
|
||||
fileDialog.SetWildcard(wxT("Glest Binary Map (*.gbm)|*.gbm"));
|
||||
wxFileDialog fileDialog(this, wxT("Select file"), wxT(""), wxT(""), wxT("*.gbm|*.mgm"), wxSAVE);
|
||||
fileDialog.SetWildcard(wxT("Glest Map (*.gbm)|*.gbm|Mega Map (*.mgm)|*.mgm"));
|
||||
if (fileDialog.ShowModal() == wxID_OK) {
|
||||
fileName= fileDialog.GetPath().ToAscii();
|
||||
program->saveMap(fileName);
|
||||
currentFile = fileDialog.GetPath().ToAscii();
|
||||
setExtension();
|
||||
program->saveMap(currentFile);
|
||||
fileName = cutLastExt(lastFile(currentFile));
|
||||
setDirty(false);
|
||||
}
|
||||
|
||||
currentFile= fileName;
|
||||
SetTitle(ToUnicode(winHeader + "; " + currentFile));
|
||||
}
|
||||
|
||||
@@ -249,38 +344,56 @@ void MainWindow::onMenuFileExit(wxCommandEvent &event){
|
||||
Close();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditUndo(wxCommandEvent &event) {
|
||||
std::cout << "Undo Pressed" << std::endl;
|
||||
if (program->undo()) {
|
||||
Refresh();
|
||||
setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditRedo(wxCommandEvent &event) {
|
||||
std::cout << "Redo Pressed" << std::endl;
|
||||
if (program->redo()) {
|
||||
Refresh();
|
||||
setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditReset(wxCommandEvent &event) {
|
||||
program->setUndoPoint(ctAll);
|
||||
SimpleDialog simpleDialog;
|
||||
simpleDialog.addValue("Altitude", "10");
|
||||
simpleDialog.addValue("Surface", "1");
|
||||
simpleDialog.addValue("Height", "64");
|
||||
simpleDialog.addValue("Width", "64");
|
||||
simpleDialog.addValue("Height", "64");
|
||||
simpleDialog.show();
|
||||
|
||||
try {
|
||||
program->reset(
|
||||
strToInt(simpleDialog.getValue("Height")),
|
||||
strToInt(simpleDialog.getValue("Width")),
|
||||
strToInt(simpleDialog.getValue("Height")),
|
||||
strToInt(simpleDialog.getValue("Altitude")),
|
||||
strToInt(simpleDialog.getValue("Surface")));
|
||||
}
|
||||
catch(const exception &e){
|
||||
} catch (const exception &e) {
|
||||
wxMessageDialog(NULL, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
|
||||
}
|
||||
|
||||
currentFile = "";
|
||||
fileName = "New (unsaved) map";
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditResetPlayers(wxCommandEvent &event) {
|
||||
SimpleDialog simpleDialog;
|
||||
simpleDialog.addValue("Players", intToStr(program->getMap()->getMaxPlayers()));
|
||||
simpleDialog.addValue("Factions", intToStr(program->getMap()->getMaxFactions()));
|
||||
simpleDialog.show();
|
||||
|
||||
try {
|
||||
program->resetPlayers(strToInt(simpleDialog.getValue("Players")));
|
||||
}
|
||||
catch(const exception &e){
|
||||
program->resetFactions(strToInt(simpleDialog.getValue("Factions")));
|
||||
} catch (const exception &e) {
|
||||
wxMessageDialog(NULL, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
|
||||
}
|
||||
setDirty();
|
||||
setExtension();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditResize(wxCommandEvent &event) {
|
||||
@@ -297,26 +410,30 @@ void MainWindow::onMenuEditResize(wxCommandEvent &event){
|
||||
strToInt(simpleDialog.getValue("Width")),
|
||||
strToInt(simpleDialog.getValue("Altitude")),
|
||||
strToInt(simpleDialog.getValue("Surface")));
|
||||
}
|
||||
catch(const exception &e){
|
||||
} catch (const exception &e) {
|
||||
wxMessageDialog(NULL, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
|
||||
}
|
||||
setDirty();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditFlipX(wxCommandEvent &event) {
|
||||
program->flipX();
|
||||
setDirty();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditFlipY(wxCommandEvent &event) {
|
||||
program->flipY();
|
||||
setDirty();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditRandomizeHeights(wxCommandEvent &event) {
|
||||
program->randomizeMapHeights();
|
||||
setDirty();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditRandomize(wxCommandEvent &event) {
|
||||
program->randomizeMap();
|
||||
setDirty();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditSwitchSurfaces(wxCommandEvent &event) {
|
||||
@@ -329,10 +446,10 @@ void MainWindow::onMenuEditSwitchSurfaces(wxCommandEvent &event){
|
||||
program->switchMapSurfaces(
|
||||
strToInt(simpleDialog.getValue("Surface1")),
|
||||
strToInt(simpleDialog.getValue("Surface2")));
|
||||
}
|
||||
catch(const exception &e){
|
||||
} catch (const exception &e) {
|
||||
wxMessageDialog(NULL, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
|
||||
}
|
||||
setDirty();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditInfo(wxCommandEvent &event) {
|
||||
@@ -343,9 +460,13 @@ void MainWindow::onMenuEditInfo(wxCommandEvent &event){
|
||||
|
||||
simpleDialog.show();
|
||||
|
||||
program->setMapTitle(simpleDialog.getValue("Title"));
|
||||
program->setMapDesc(simpleDialog.getValue("Desc"));
|
||||
program->setMapAuthor(simpleDialog.getValue("Author"));
|
||||
if (program->setMapTitle(simpleDialog.getValue("Title"))
|
||||
|| program->setMapDesc(simpleDialog.getValue("Desc"))
|
||||
|| program->setMapAuthor(simpleDialog.getValue("Author"))) {
|
||||
if (!isDirty()) {
|
||||
setDirty(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onMenuEditAdvanced(wxCommandEvent &event) {
|
||||
@@ -359,10 +480,10 @@ void MainWindow::onMenuEditAdvanced(wxCommandEvent &event){
|
||||
program->setMapAdvanced(
|
||||
strToInt(simpleDialog.getValue("Height Factor")),
|
||||
strToInt(simpleDialog.getValue("Water Level")));
|
||||
}
|
||||
catch(const exception &e){
|
||||
} catch (const exception &e) {
|
||||
wxMessageDialog(NULL, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
|
||||
}
|
||||
setDirty();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuMiscResetZoomAndPos(wxCommandEvent &event) {
|
||||
@@ -370,7 +491,10 @@ void MainWindow::onMenuMiscResetZoomAndPos(wxCommandEvent &event){
|
||||
}
|
||||
|
||||
void MainWindow::onMenuMiscAbout(wxCommandEvent &event) {
|
||||
wxMessageDialog(NULL, wxT("Glest Map Editor - Copyright 2004 The Glest Team ( improved by titi )"), wxT("About")).ShowModal();
|
||||
wxMessageDialog(
|
||||
NULL,
|
||||
wxT("Glest Map Editor - Copyright 2004 The Glest Team\n(with improvements by others, 2010)."),
|
||||
wxT("About")).ShowModal();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuMiscHelp(wxCommandEvent &event) {
|
||||
@@ -380,68 +504,99 @@ void MainWindow::onMenuMiscHelp(wxCommandEvent &event){
|
||||
wxT("Help")).ShowModal();
|
||||
}
|
||||
|
||||
void MainWindow::onMenuBrushHeight(wxCommandEvent &event){
|
||||
void MainWindow::onMenuBrushHeight(wxCommandEvent &e) {
|
||||
uncheckBrush();
|
||||
menuBrushHeight->Check(event.GetId(), true);
|
||||
height= event.GetId() - miBrushHeight - heightCount/2 - 1;
|
||||
enabledGroup= 0;
|
||||
menuBrushHeight->Check(e.GetId(), true);
|
||||
height = e.GetId() - miBrushHeight - heightCount / 2 - 1;
|
||||
enabledGroup = ctHeight;
|
||||
currentBrush = btHeight;
|
||||
SetStatusText(wxT("Brush: Height"), siBRUSH_TYPE);
|
||||
SetStatusText(wxT("Value: ") + ToUnicode(intToStr(height)), siBRUSH_VALUE);
|
||||
}
|
||||
|
||||
void MainWindow::onMenuBrushSurface(wxCommandEvent &event){
|
||||
void MainWindow::onMenuBrushGradient(wxCommandEvent &e) {
|
||||
uncheckBrush();
|
||||
menuBrushSurface->Check(event.GetId(), true);
|
||||
surface= event.GetId() - miBrushSurface;
|
||||
enabledGroup= 1;
|
||||
menuBrushGradient->Check(e.GetId(), true);
|
||||
height = e.GetId() - miBrushGradient - heightCount / 2 - 1;
|
||||
enabledGroup = ctGradient;
|
||||
currentBrush = btGradient;
|
||||
SetStatusText(wxT("Brush: Gradient"), siBRUSH_TYPE);
|
||||
SetStatusText(wxT("Value: ") + ToUnicode(intToStr(height)), siBRUSH_VALUE);
|
||||
}
|
||||
|
||||
void MainWindow::onMenuBrushObject(wxCommandEvent &event){
|
||||
|
||||
void MainWindow::onMenuBrushSurface(wxCommandEvent &e) {
|
||||
uncheckBrush();
|
||||
menuBrushObject->Check(event.GetId(), true);
|
||||
object= event.GetId() - miBrushObject - 1;
|
||||
enabledGroup= 2;
|
||||
menuBrushSurface->Check(e.GetId(), true);
|
||||
surface = e.GetId() - miBrushSurface;
|
||||
enabledGroup = ctSurface;
|
||||
currentBrush = btSurface;
|
||||
SetStatusText(wxT("Brush: Surface"), siBRUSH_TYPE);
|
||||
SetStatusText(
|
||||
wxT("Value: ") + ToUnicode(intToStr(surface)) + wxT(" ")
|
||||
+ ToUnicode(surface_descs[surface - 1]), siBRUSH_VALUE);
|
||||
}
|
||||
|
||||
void MainWindow::onMenuBrushResource(wxCommandEvent &event){
|
||||
void MainWindow::onMenuBrushObject(wxCommandEvent &e) {
|
||||
uncheckBrush();
|
||||
menuBrushResource->Check(event.GetId(), true);
|
||||
resource= event.GetId() - miBrushResource - 1;
|
||||
enabledGroup= 3;
|
||||
menuBrushObject->Check(e.GetId(), true);
|
||||
object = e.GetId() - miBrushObject - 1;
|
||||
enabledGroup = ctObject;
|
||||
currentBrush = btObject;
|
||||
SetStatusText(wxT("Brush: Object"), siBRUSH_TYPE);
|
||||
SetStatusText(
|
||||
wxT("Value: ") + ToUnicode(intToStr(object)) + wxT(" ")
|
||||
+ ToUnicode(object_descs[object]), siBRUSH_VALUE);
|
||||
}
|
||||
|
||||
void MainWindow::onMenuBrushStartLocation(wxCommandEvent &event){
|
||||
void MainWindow::onMenuBrushResource(wxCommandEvent &e) {
|
||||
uncheckBrush();
|
||||
menuBrushStartLocation->Check(event.GetId(), true);
|
||||
startLocation= event.GetId() - miBrushStartLocation - 1;
|
||||
enabledGroup= 4;
|
||||
menuBrushResource->Check(e.GetId(), true);
|
||||
resource = e.GetId() - miBrushResource - 1;
|
||||
enabledGroup = ctResource;
|
||||
currentBrush = btResource;
|
||||
SetStatusText(wxT("Brush: Resource"), siBRUSH_TYPE);
|
||||
SetStatusText(
|
||||
wxT("Value: ") + ToUnicode(intToStr(resource)) + wxT(" ")
|
||||
+ ToUnicode(resource_descs[resource]), siBRUSH_VALUE);
|
||||
}
|
||||
|
||||
void MainWindow::onMenuRadius(wxCommandEvent &event){
|
||||
void MainWindow::onMenuBrushStartLocation(wxCommandEvent &e) {
|
||||
uncheckBrush();
|
||||
menuBrushStartLocation->Check(e.GetId(), true);
|
||||
startLocation = e.GetId() - miBrushStartLocation;
|
||||
enabledGroup = ctLocation;
|
||||
currentBrush = btStartLocation;
|
||||
SetStatusText(wxT("Brush: Start Locations"), siBRUSH_TYPE);
|
||||
SetStatusText(wxT("Value: ") + ToUnicode(intToStr(startLocation)), siBRUSH_VALUE);
|
||||
}
|
||||
|
||||
void MainWindow::onMenuRadius(wxCommandEvent &e) {
|
||||
uncheckRadius();
|
||||
menuRadius->Check(event.GetId(), true);
|
||||
radius= event.GetId() - miRadius + 1;
|
||||
}
|
||||
|
||||
void MainWindow::onTimer(wxTimerEvent &event) {
|
||||
wxPaintEvent paintEvent;
|
||||
onPaint(paintEvent);
|
||||
menuRadius->Check(e.GetId(), true);
|
||||
radius = e.GetId() - miRadius;
|
||||
SetStatusText(wxT("Radius: ") + ToUnicode(intToStr(radius)), siBRUSH_RADIUS);
|
||||
}
|
||||
|
||||
void MainWindow::change(int x, int y) {
|
||||
switch (enabledGroup) {
|
||||
case 0:
|
||||
program->changeMapHeight(x, y, height, radius);
|
||||
case ctHeight:
|
||||
program->glestChangeMapHeight(x, y, height, radius);
|
||||
break;
|
||||
case 1:
|
||||
case ctSurface:
|
||||
program->changeMapSurface(x, y, surface, radius);
|
||||
break;
|
||||
case 2:
|
||||
case ctObject:
|
||||
program->changeMapObject(x, y, object, radius);
|
||||
break;
|
||||
case 3:
|
||||
case ctResource:
|
||||
program->changeMapResource(x, y, resource, radius);
|
||||
break;
|
||||
case 4:
|
||||
program->changeStartLocation(x, y, startLocation);
|
||||
case ctLocation:
|
||||
program->changeStartLocation(x, y, startLocation - 1);
|
||||
break;
|
||||
case ctGradient:
|
||||
program->pirateChangeMapHeight(x, y, height, radius);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -450,6 +605,9 @@ void MainWindow::uncheckBrush(){
|
||||
for (int i = 0; i < heightCount; ++i) {
|
||||
menuBrushHeight->Check(miBrushHeight + i + 1, false);
|
||||
}
|
||||
for (int i = 0; i < heightCount; ++i) {
|
||||
menuBrushGradient->Check(miBrushGradient + i + 1, false);
|
||||
}
|
||||
for (int i = 0; i < surfaceCount; ++i) {
|
||||
menuBrushSurface->Check(miBrushSurface + i + 1, false);
|
||||
}
|
||||
@@ -465,22 +623,111 @@ void MainWindow::uncheckBrush(){
|
||||
}
|
||||
|
||||
void MainWindow::uncheckRadius() {
|
||||
for(int i=0; i<radiusCount; ++i){
|
||||
for (int i = 1; i <= radiusCount; ++i) {
|
||||
menuRadius->Check(miRadius + i, false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onKeyDown(wxKeyEvent &e) {
|
||||
if (currentBrush == btHeight || currentBrush == btGradient) { // 'height' brush
|
||||
if (e.GetKeyCode() >= '0' && e.GetKeyCode() <= '5') {
|
||||
height = e.GetKeyCode() - 48; // '0'-'5' == 0-5
|
||||
if (e.GetModifiers() == wxMOD_CONTROL) { // Ctrl means negative
|
||||
height = -height ;
|
||||
}
|
||||
int id_offset = heightCount / 2 + height + 1;
|
||||
if (currentBrush == btHeight) {
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushHeight + id_offset);
|
||||
onMenuBrushHeight(evt);
|
||||
} else {
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushGradient + id_offset);
|
||||
onMenuBrushGradient(evt);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (currentBrush == btSurface) { // surface texture
|
||||
if (e.GetKeyCode() >= '1' && e.GetKeyCode() <= '5') {
|
||||
surface = e.GetKeyCode() - 48; // '1'-'5' == 1-5
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushSurface + surface);
|
||||
onMenuBrushSurface(evt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (currentBrush == btObject) {
|
||||
bool valid = true;
|
||||
if (e.GetKeyCode() >= '1' && e.GetKeyCode() <= '9') {
|
||||
object = e.GetKeyCode() - 48; // '1'-'9' == 1-9
|
||||
} else if (e.GetKeyCode() == '0') { // '0' == 10
|
||||
object = 10;
|
||||
} else if (e.GetKeyCode() == '-') { // '-' == 0
|
||||
object = 0;
|
||||
} else {
|
||||
valid = false;
|
||||
}
|
||||
if (valid) {
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushObject + object + 1);
|
||||
onMenuBrushObject(evt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (currentBrush == btResource) {
|
||||
if (e.GetKeyCode() >= '0' && e.GetKeyCode() <= '5') {
|
||||
resource = e.GetKeyCode() - 48; // '0'-'5' == 0-5
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushResource + resource + 1);
|
||||
onMenuBrushResource(evt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (currentBrush == btStartLocation) {
|
||||
if (e.GetKeyCode() >= '1' && e.GetKeyCode() <= '8') {
|
||||
startLocation = e.GetKeyCode() - 48; // '1'-'8' == 0-7
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushStartLocation + startLocation);
|
||||
onMenuBrushStartLocation(evt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.GetKeyCode() == 'H') {
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushHeight + height + heightCount / 2 + 1);
|
||||
onMenuBrushHeight(evt);
|
||||
} else if (e.GetKeyCode() == 'G') {
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushGradient + height + heightCount / 2 + 1);
|
||||
onMenuBrushGradient(evt);
|
||||
} else if (e.GetKeyCode() == 'S') {
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushSurface + surface);
|
||||
onMenuBrushSurface(evt);
|
||||
} else if (e.GetKeyCode() == 'O') {
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushObject + object + 1);
|
||||
onMenuBrushObject(evt);
|
||||
} else if (e.GetKeyCode() == 'R') {
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushResource + resource + 1);
|
||||
onMenuBrushResource(evt);
|
||||
} else if (e.GetKeyCode() == 'L') {
|
||||
wxCommandEvent evt(wxEVT_NULL, miBrushStartLocation + startLocation + 1);
|
||||
onMenuBrushStartLocation(evt);
|
||||
} else {
|
||||
e.Skip();
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(MainWindow, wxFrame)
|
||||
|
||||
EVT_TIMER(-1, MainWindow::onTimer)
|
||||
|
||||
EVT_CLOSE(MainWindow::onClose)
|
||||
EVT_LEFT_DOWN(MainWindow::onMouseDown)
|
||||
EVT_MOTION(MainWindow::onMouseMove)
|
||||
|
||||
EVT_MENU(miFileLoad, MainWindow::onMenuFileLoad)
|
||||
EVT_MENU(miFileSave, MainWindow::onMenuFileSave)
|
||||
EVT_MENU(miFileSaveAs, MainWindow::onMenuFileSaveAs)
|
||||
EVT_MENU(miFileExit, MainWindow::onMenuFileExit)
|
||||
// these are 'handled' by GlCanvas and funneled to these handlers
|
||||
//EVT_LEFT_DOWN(MainWindow::onMouseDown)
|
||||
//EVT_MOTION(MainWindow::onMouseMove)
|
||||
//EVT_KEY_DOWN(MainWindow::onKeyDown)
|
||||
|
||||
EVT_MENU(wxID_OPEN, MainWindow::onMenuFileLoad)
|
||||
EVT_MENU(wxID_SAVE, MainWindow::onMenuFileSave)
|
||||
EVT_MENU(wxID_SAVEAS, MainWindow::onMenuFileSaveAs)
|
||||
EVT_MENU(wxID_EXIT, MainWindow::onMenuFileExit)
|
||||
|
||||
EVT_MENU(miEditUndo, MainWindow::onMenuEditUndo)
|
||||
EVT_MENU(miEditRedo, MainWindow::onMenuEditRedo)
|
||||
EVT_MENU(miEditReset, MainWindow::onMenuEditReset)
|
||||
EVT_MENU(miEditResetPlayers, MainWindow::onMenuEditResetPlayers)
|
||||
EVT_MENU(miEditResize, MainWindow::onMenuEditResize)
|
||||
@@ -497,6 +744,7 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame)
|
||||
EVT_MENU(miMiscHelp, MainWindow::onMenuMiscHelp)
|
||||
|
||||
EVT_MENU_RANGE(miBrushHeight + 1, miBrushHeight + heightCount, MainWindow::onMenuBrushHeight)
|
||||
EVT_MENU_RANGE(miBrushGradient + 1, miBrushGradient + heightCount, MainWindow::onMenuBrushGradient)
|
||||
EVT_MENU_RANGE(miBrushSurface + 1, miBrushSurface + surfaceCount, MainWindow::onMenuBrushSurface)
|
||||
EVT_MENU_RANGE(miBrushObject + 1, miBrushObject + objectCount, MainWindow::onMenuBrushObject)
|
||||
EVT_MENU_RANGE(miBrushResource + 1, miBrushResource + resourceCount, MainWindow::onMenuBrushResource)
|
||||
@@ -508,9 +756,8 @@ END_EVENT_TABLE()
|
||||
// class GlCanvas
|
||||
// =====================================================
|
||||
|
||||
GlCanvas::GlCanvas(MainWindow * mainWindow, int* args):
|
||||
wxGLCanvas(mainWindow, -1, wxDefaultPosition,wxDefaultSize,0,wxT("GLCanvas"),args)
|
||||
{
|
||||
GlCanvas::GlCanvas(MainWindow * mainWindow, int* args)
|
||||
: wxGLCanvas(mainWindow, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("GLCanvas"), args) {
|
||||
this->mainWindow = mainWindow;
|
||||
}
|
||||
|
||||
@@ -522,7 +769,13 @@ void GlCanvas::onMouseMove(wxMouseEvent &event){
|
||||
mainWindow->onMouseMove(event);
|
||||
}
|
||||
|
||||
void GlCanvas::onKeyDown(wxKeyEvent &event) {
|
||||
mainWindow->onKeyDown(event);
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(GlCanvas, wxGLCanvas)
|
||||
EVT_KEY_DOWN(GlCanvas::onKeyDown)
|
||||
|
||||
EVT_LEFT_DOWN(GlCanvas::onMouseDown)
|
||||
EVT_MOTION(GlCanvas::onMouseMove)
|
||||
END_EVENT_TABLE()
|
||||
@@ -572,17 +825,21 @@ void SimpleDialog::show(){
|
||||
// ===============================================
|
||||
|
||||
bool App::OnInit() {
|
||||
string fileparam;
|
||||
if(argc==2){
|
||||
fileparam = wxFNCONV(argv[1]);
|
||||
}
|
||||
|
||||
mainWindow = new MainWindow();
|
||||
mainWindow->Show();
|
||||
mainWindow->init();
|
||||
mainWindow->init(fileparam);
|
||||
return true;
|
||||
}
|
||||
|
||||
int App::MainLoop() {
|
||||
try {
|
||||
return wxApp::MainLoop();
|
||||
}
|
||||
catch(const exception &e){
|
||||
} catch (const exception &e) {
|
||||
wxMessageDialog(NULL, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();
|
||||
}
|
||||
return 0;
|
||||
@@ -592,6 +849,6 @@ int App::OnExit(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
||||
IMPLEMENT_APP(Glest::MapEditor::App)
|
||||
IMPLEMENT_APP(MapEditor::App)
|
||||
|
@@ -1,5 +1,16 @@
|
||||
#ifndef _GLEST_MAPEDITOR_MAIN_H_
|
||||
#define _GLEST_MAPEDITOR_MAIN_H_
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>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 _MAPEDITOR_MAIN_H_
|
||||
#define _MAPEDITOR_MAIN_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -9,14 +20,59 @@
|
||||
|
||||
#include "program.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::pair;
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
namespace MapEditor {
|
||||
|
||||
class GlCanvas;
|
||||
|
||||
enum BrushType {
|
||||
btHeight,
|
||||
btGradient,
|
||||
btSurface,
|
||||
btObject,
|
||||
btResource,
|
||||
btStartLocation
|
||||
};
|
||||
|
||||
enum StatusItems {
|
||||
siNULL_ENTRY,
|
||||
siFILE_NAME,
|
||||
siFILE_TYPE,
|
||||
siBRUSH_TYPE,
|
||||
siBRUSH_VALUE,
|
||||
siBRUSH_RADIUS,
|
||||
siCOUNT
|
||||
};
|
||||
|
||||
|
||||
const char *object_descs[] = {
|
||||
"None (Erase)",
|
||||
"Tree",
|
||||
"Dead Tree",
|
||||
"Stone",
|
||||
"Bush",
|
||||
"Water Object",
|
||||
"Big/Dead Tree",
|
||||
"Trophy Corpse",
|
||||
"Statues",
|
||||
"Big Rock",
|
||||
"Invisible Blocking"
|
||||
};
|
||||
|
||||
const char *resource_descs[] = {
|
||||
"None (Erase)", "Gold", "Stone", "Custom", "Custom", "Custom"
|
||||
};
|
||||
|
||||
|
||||
const char *surface_descs[] = {
|
||||
"Grass", "Alt. Grass", "Road", "Stone", "Ground"
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class MainWindow
|
||||
// =====================================================
|
||||
@@ -42,6 +98,8 @@ private:
|
||||
miFileSaveAs,
|
||||
miFileExit,
|
||||
|
||||
miEditUndo,
|
||||
miEditRedo,
|
||||
miEditReset,
|
||||
miEditResetPlayers,
|
||||
miEditResize,
|
||||
@@ -58,7 +116,8 @@ private:
|
||||
miMiscHelp,
|
||||
|
||||
miBrushHeight,
|
||||
miBrushSurface= miBrushHeight + heightCount + 1,
|
||||
miBrushGradient = miBrushHeight + heightCount + 1,
|
||||
miBrushSurface = miBrushGradient + heightCount + 1,
|
||||
miBrushObject = miBrushSurface + surfaceCount + 1,
|
||||
miBrushResource = miBrushObject + objectCount + 1,
|
||||
miBrushStartLocation = miBrushResource + resourceCount + 1,
|
||||
@@ -79,6 +138,8 @@ private:
|
||||
wxMenu *menuMisc;
|
||||
wxMenu *menuBrush;
|
||||
wxMenu *menuBrushHeight;
|
||||
wxMenu *menuBrushGradient;
|
||||
|
||||
wxMenu *menuBrushSurface;
|
||||
wxMenu *menuBrushObject;
|
||||
wxMenu *menuBrushResource;
|
||||
@@ -87,30 +148,37 @@ private:
|
||||
|
||||
string currentFile;
|
||||
|
||||
BrushType currentBrush;
|
||||
int height;
|
||||
int surface;
|
||||
int radius;
|
||||
int object;
|
||||
int resource;
|
||||
int startLocation;
|
||||
int enabledGroup;
|
||||
ChangeType enabledGroup;
|
||||
|
||||
string fileName;
|
||||
bool fileModified;
|
||||
|
||||
public:
|
||||
MainWindow();
|
||||
~MainWindow();
|
||||
|
||||
void init();
|
||||
void init(string fname);
|
||||
|
||||
void onClose(wxCloseEvent &event);
|
||||
void onMouseDown(wxMouseEvent &event);
|
||||
void onMouseMove(wxMouseEvent &event);
|
||||
void onPaint(wxPaintEvent &event);
|
||||
void onKeyDown(wxKeyEvent &e);
|
||||
|
||||
void onMenuFileLoad(wxCommandEvent &event);
|
||||
void onMenuFileSave(wxCommandEvent &event);
|
||||
void onMenuFileSaveAs(wxCommandEvent &event);
|
||||
void onMenuFileExit(wxCommandEvent &event);
|
||||
|
||||
void onMenuEditUndo(wxCommandEvent &event);
|
||||
void onMenuEditRedo(wxCommandEvent &event);
|
||||
void onMenuEditReset(wxCommandEvent &event);
|
||||
void onMenuEditResetPlayers(wxCommandEvent &event);
|
||||
void onMenuEditResize(wxCommandEvent &event);
|
||||
@@ -127,6 +195,7 @@ public:
|
||||
void onMenuMiscHelp(wxCommandEvent &event);
|
||||
|
||||
void onMenuBrushHeight(wxCommandEvent &event);
|
||||
void onMenuBrushGradient(wxCommandEvent &event);
|
||||
void onMenuBrushSurface(wxCommandEvent &event);
|
||||
void onMenuBrushObject(wxCommandEvent &event);
|
||||
void onMenuBrushResource(wxCommandEvent &event);
|
||||
@@ -139,6 +208,11 @@ public:
|
||||
|
||||
void uncheckBrush();
|
||||
void uncheckRadius();
|
||||
|
||||
private:
|
||||
bool isDirty() const { return fileModified; }
|
||||
void setDirty(bool val=true);
|
||||
void setExtension();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@@ -154,6 +228,7 @@ public:
|
||||
|
||||
void onMouseDown(wxMouseEvent &event);
|
||||
void onMouseMove(wxMouseEvent &event);
|
||||
void onKeyDown(wxKeyEvent &event);
|
||||
|
||||
private:
|
||||
MainWindow *mainWindow;
|
||||
@@ -195,8 +270,8 @@ public:
|
||||
virtual int OnExit();
|
||||
};
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
||||
DECLARE_APP(Glest::MapEditor::App)
|
||||
DECLARE_APP(MapEditor::App)
|
||||
|
||||
#endif
|
||||
|
@@ -1,3 +1,15 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>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
|
||||
// ==============================================================
|
||||
|
||||
|
||||
#include "map.h"
|
||||
|
||||
#include <cmath>
|
||||
@@ -6,7 +18,7 @@
|
||||
using namespace Shared::Util;
|
||||
using namespace std;
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
namespace MapEditor {
|
||||
|
||||
// ===============================================
|
||||
// class Map
|
||||
@@ -20,7 +32,7 @@ Map::Map(){
|
||||
cells = NULL;
|
||||
startLocations = NULL;
|
||||
reset(64, 64, 10.f, 1);
|
||||
resetPlayers(4);
|
||||
resetFactions(8);
|
||||
title = "";
|
||||
desc = "";
|
||||
author = "";
|
||||
@@ -60,14 +72,13 @@ int Map::getStartLocationY(int index) const{
|
||||
return startLocations[index].y;
|
||||
}
|
||||
|
||||
static int get_dist(int delta_x, int delta_y)
|
||||
{
|
||||
double dx = delta_x;
|
||||
double dy = delta_y;
|
||||
return static_cast<int> (sqrt(dx * dx + dy * dy));
|
||||
static int get_dist(int delta_x, int delta_y) {
|
||||
float dx = delta_x;
|
||||
float dy = delta_y;
|
||||
return static_cast<int>(sqrtf(dx * dx + dy * dy));
|
||||
}
|
||||
|
||||
void Map::changeHeight(int x, int y, int height, int radius){
|
||||
void Map::glestChangeHeight(int x, int y, int height, int radius) {
|
||||
|
||||
for (int i = x - radius + 1; i < x + radius; i++) {
|
||||
for (int j = y - radius + 1; j < y + radius; j++) {
|
||||
@@ -94,6 +105,157 @@ void Map::changeHeight(int x, int y, int height, int radius){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Map::pirateChangeHeight(int x, int y, int height, int radius) {
|
||||
// Make sure not to try and blanket change the height over the bounds
|
||||
// Find our goal height for the centre of the brush
|
||||
int goalAlt;
|
||||
int overBounds = refAlt + height;
|
||||
if (overBounds > 20) {
|
||||
goalAlt = 20;
|
||||
}
|
||||
else if (overBounds < 0) {
|
||||
goalAlt = 0;
|
||||
} else {
|
||||
goalAlt = overBounds;
|
||||
}
|
||||
|
||||
// If the radius is 1 don't bother doing any calculations
|
||||
if (radius == 1) {
|
||||
cells[x][y].height = goalAlt;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get Old height reference points and compute gradients
|
||||
// from the heights of the sides and corners of the brush to the centre goal height
|
||||
float gradient[3][3]; // [i][j]
|
||||
int indexI = 0;
|
||||
for (int i = x - radius; i <= x + radius; i += radius) {
|
||||
int indexJ = 0;
|
||||
for (int j = y - radius; j <= y + radius; j += radius) {
|
||||
// round off the corners
|
||||
int ti, tj;
|
||||
if (abs(i - x) == abs(j - y)) {
|
||||
ti = (i - x) * 0.707 + x + 0.5;
|
||||
tj = (j - y) * 0.707 + y + 0.5;
|
||||
} else {
|
||||
ti = i;
|
||||
tj = j;
|
||||
}
|
||||
if (inside(ti, tj)) {
|
||||
gradient[indexI][indexJ] = (cells[ti][tj].height - goalAlt) / radius;
|
||||
//} else if (dist == 0) {
|
||||
//gradient[indexI][indexJ] = 0;
|
||||
} else {
|
||||
// assume outside the map bounds is height 10
|
||||
gradient[indexI][indexJ] = (10.0 - goalAlt) / radius;
|
||||
}
|
||||
//std::cout << "gradient[" << indexI << "][" << indexJ << "] = " << gradient[indexI][indexJ] << std::endl;
|
||||
//std::cout << "derived from height " << cells[ti][tj].height << " at " << ti << " " << tj << std::endl;
|
||||
indexJ++;
|
||||
}
|
||||
indexI++;
|
||||
}
|
||||
//std::cout << endl;
|
||||
|
||||
// A brush with radius n cells should have a true radius of n-1 distance
|
||||
radius -= 1;
|
||||
for (int i = x - radius; i <= x + radius; i++) {
|
||||
for (int j = y - radius; j <= y + radius; j++) {
|
||||
int dist = get_dist(i - x, j - y);
|
||||
if (inside(i, j) && dist < radius) {
|
||||
// Normalize di and dj and round them to an int so they can be used as indicies
|
||||
float normIf = (float(i - x)/ radius);
|
||||
float normJf = (float(j - y)/ radius);
|
||||
int normI[2];
|
||||
int normJ[2];
|
||||
float usedGrad;
|
||||
|
||||
// Build a search box to find the gradients we are concerned about
|
||||
// Find the nearest i indices
|
||||
if (normIf < -0.33) {
|
||||
normI[0] = 0;
|
||||
if (normIf == 0) {
|
||||
normI[1] = 0;
|
||||
} else {
|
||||
normI[1] = 1;
|
||||
}
|
||||
} else if (normIf < 0.33) {
|
||||
normI[0] = 1;
|
||||
if (normIf > 0) {
|
||||
normI[1] = 2;
|
||||
} else if (normIf < 0) {
|
||||
normI[1] = 0;
|
||||
} else /*(normIf == 0)*/ {
|
||||
normI[1] = 1;
|
||||
}
|
||||
} else {
|
||||
normI[0] = 2;
|
||||
if (normIf == 1) {
|
||||
normI[1] = 2;
|
||||
} else {
|
||||
normI[1] = 1;
|
||||
}
|
||||
}
|
||||
// find nearest j indices
|
||||
if (normJf < -0.33) {
|
||||
normJ[0] = 0;
|
||||
if (normJf == 0) {
|
||||
normJ[1] = 0;
|
||||
} else {
|
||||
normJ[1] = 1;
|
||||
}
|
||||
} else if (normJf < 0.33) {
|
||||
normJ[0] = 1;
|
||||
if (normJf > 0) {
|
||||
normJ[1] = 2;
|
||||
} else if (normJf < 0) {
|
||||
normJ[1] = 0;
|
||||
} else /*(normJf == 0)*/ {
|
||||
normJ[1] = 1;
|
||||
}
|
||||
} else {
|
||||
normJ[0] = 2;
|
||||
if (normJf == 1) {
|
||||
normJ[1] = 2;
|
||||
} else {
|
||||
normJ[1] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which gradients to use and take a weighted average
|
||||
if (abs(normIf) > abs(normJf)) {
|
||||
usedGrad =
|
||||
gradient[normI[0]] [normJ[0]] * abs(normJf) +
|
||||
gradient[normI[0]] [normJ[1]] * (1 - abs(normJf));
|
||||
} else if (abs(normIf) < abs(normJf)) {
|
||||
usedGrad =
|
||||
gradient[normI[0]] [normJ[0]] * abs(normIf) +
|
||||
gradient[normI[1]] [normJ[0]] * (1 - abs(normIf));
|
||||
} else {
|
||||
usedGrad =
|
||||
gradient[normI[0]] [normJ[0]];
|
||||
}
|
||||
|
||||
|
||||
float newAlt = usedGrad * dist + goalAlt;
|
||||
|
||||
// if the change in height and what is supposed to be the change in height
|
||||
// are the same sign then we can change the height
|
||||
if ( ((newAlt - cells[i][j].height) > 0 && height > 0) ||
|
||||
((newAlt - cells[i][j].height) < 0 && height < 0) ||
|
||||
height == 0) {
|
||||
cells[i][j].height = newAlt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map::setHeight(int x, int y, float height) {
|
||||
cells[x][y].height = height;
|
||||
}
|
||||
|
||||
void Map::setRefAlt(int x, int y) {
|
||||
if (inside(x, y)) {
|
||||
refAlt = static_cast<int>(cells[x][y].height);
|
||||
@@ -114,7 +276,7 @@ void Map::flipX(){
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<maxPlayers; ++i){
|
||||
for (int i = 0; i < maxFactions; ++i) {
|
||||
startLocations[i].x = w - startLocations[i].x - 1;
|
||||
}
|
||||
|
||||
@@ -138,7 +300,7 @@ void Map::flipY(){
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<maxPlayers; ++i){
|
||||
for (int i = 0; i < maxFactions; ++i) {
|
||||
startLocations[i].y = h - startLocations[i].y - 1;
|
||||
}
|
||||
|
||||
@@ -164,6 +326,10 @@ void Map::changeSurface(int x, int y, int surface, int radius){
|
||||
}
|
||||
}
|
||||
|
||||
void Map::setSurface(int x, int y, int surface) {
|
||||
cells[x][y].surface = surface;
|
||||
}
|
||||
|
||||
void Map::changeObject(int x, int y, int object, int radius) {
|
||||
int i, j;
|
||||
int dist;
|
||||
@@ -181,6 +347,11 @@ void Map::changeObject(int x, int y, int object, int radius){
|
||||
}
|
||||
}
|
||||
|
||||
void Map::setObject(int x, int y, int object) {
|
||||
cells[x][y].object = object;
|
||||
if (object != 0) cells[x][y].resource = 0;
|
||||
}
|
||||
|
||||
void Map::changeResource(int x, int y, int resource, int radius) {
|
||||
int i, j;
|
||||
int dist;
|
||||
@@ -198,10 +369,15 @@ void Map::changeResource(int x, int y, int resource, int radius){
|
||||
}
|
||||
}
|
||||
|
||||
void Map::changeStartLocation(int x, int y, int player){
|
||||
if ((player-1)<maxPlayers && inside(x, y)){
|
||||
startLocations[player].x= x;
|
||||
startLocations[player].y= y;
|
||||
void Map::setResource(int x, int y, int resource) {
|
||||
cells[x][y].resource = resource;
|
||||
if (resource != 0) cells[x][y].object = 0;
|
||||
}
|
||||
|
||||
void Map::changeStartLocation(int x, int y, int faction) {
|
||||
if ((faction - 1) < maxFactions && inside(x, y)) {
|
||||
startLocations[faction].x = x;
|
||||
startLocations[faction].y = y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +415,7 @@ void Map::reset(int w, int h, float alt, int surf){
|
||||
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
this->maxPlayers= maxPlayers;
|
||||
this->maxFactions = maxFactions;
|
||||
|
||||
cells = new Cell*[w];
|
||||
for (int i = 0; i < w; i++) {
|
||||
@@ -278,7 +454,7 @@ void Map::resize(int w, int h, float alt, int surf){
|
||||
int oldH = this->h;
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
this->maxPlayers= maxPlayers;
|
||||
this->maxFactions = maxFactions;
|
||||
|
||||
//create new cells
|
||||
Cell **oldCells = cells;
|
||||
@@ -306,7 +482,7 @@ void Map::resize(int w, int h, float alt, int surf){
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=0; i<maxPlayers; ++i){
|
||||
for (int i = 0; i < maxFactions; ++i) {
|
||||
startLocations[i].x += wOffset;
|
||||
startLocations[i].y += hOffset;
|
||||
}
|
||||
@@ -319,19 +495,18 @@ void Map::resize(int w, int h, float alt, int surf){
|
||||
}
|
||||
}
|
||||
|
||||
void Map::resetPlayers(int maxPlayers){
|
||||
void Map::resetFactions(int maxPlayers) {
|
||||
if (maxPlayers<1 || maxPlayers>8){
|
||||
throw runtime_error("Max Players must be in the range 1-8");
|
||||
return;
|
||||
}
|
||||
|
||||
if (startLocations != NULL)
|
||||
delete startLocations;
|
||||
|
||||
this->maxPlayers= maxPlayers;
|
||||
maxFactions = maxPlayers;
|
||||
|
||||
startLocations= new StartLocation[maxPlayers];
|
||||
for (int i=0; i<maxPlayers; i++){
|
||||
startLocations = new StartLocation[maxFactions];
|
||||
for (int i = 0; i < maxFactions; i++) {
|
||||
startLocations[i].x = 0;
|
||||
startLocations[i].y = 0;
|
||||
}
|
||||
@@ -375,7 +550,7 @@ void Map::randomize(){
|
||||
int slPlaceFactorX = random.randRange(0, 1);
|
||||
int slPlaceFactorY = random.randRange(0, 1) * 2;
|
||||
|
||||
for(int i=0; i<maxPlayers; ++i){
|
||||
for (int i = 0; i < maxFactions; ++i) {
|
||||
StartLocation sl;
|
||||
float slNoiseFactor = random.randRange(0.5f, 0.8f);
|
||||
|
||||
@@ -391,14 +566,12 @@ void Map::switchSurfaces(int surf1, int surf2){
|
||||
for (int j = 0; j < h; ++j) {
|
||||
if (cells[i][j].surface == surf1) {
|
||||
cells[i][j].surface = surf2;
|
||||
}
|
||||
else if(cells[i][j].surface==surf2){
|
||||
} else if (cells[i][j].surface == surf2) {
|
||||
cells[i][j].surface = surf1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
throw runtime_error("Incorrect surfaces");
|
||||
}
|
||||
}
|
||||
@@ -419,8 +592,8 @@ void Map::loadFromFile(const string &path){
|
||||
desc = header.description;
|
||||
|
||||
//read start locations
|
||||
resetPlayers(header.maxPlayers);
|
||||
for(int i=0; i<maxPlayers; ++i){
|
||||
resetFactions(header.maxFactions);
|
||||
for (int i = 0; i < maxFactions; ++i) {
|
||||
fread(&startLocations[i].x, sizeof(int32), 1, f1);
|
||||
fread(&startLocations[i].y, sizeof(int32), 1, f1);
|
||||
}
|
||||
@@ -447,16 +620,14 @@ void Map::loadFromFile(const string &path){
|
||||
fread(&obj, sizeof(int8), 1, f1);
|
||||
if (obj <= 10) {
|
||||
cells[i][j].object = obj;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
cells[i][j].resource = obj - 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f1);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
throw runtime_error("error opening map file: " + path);
|
||||
}
|
||||
}
|
||||
@@ -471,7 +642,7 @@ void Map::saveToFile(const string &path){
|
||||
MapFileHeader header;
|
||||
|
||||
header.version = 1;
|
||||
header.maxPlayers= maxPlayers;
|
||||
header.maxFactions = maxFactions;
|
||||
header.width = w;
|
||||
header.height = h;
|
||||
header.altFactor = altFactor;
|
||||
@@ -483,7 +654,7 @@ void Map::saveToFile(const string &path){
|
||||
fwrite(&header, sizeof(MapFileHeader), 1, f1);
|
||||
|
||||
//write start locations
|
||||
for(int i=0; i<maxPlayers; ++i){
|
||||
for (int i = 0; i < maxFactions; ++i) {
|
||||
fwrite(&startLocations[i].x, sizeof(int32), 1, f1);
|
||||
fwrite(&startLocations[i].y, sizeof(int32), 1, f1);
|
||||
}
|
||||
@@ -516,8 +687,7 @@ void Map::saveToFile(const string &path){
|
||||
|
||||
fclose(f1);
|
||||
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
throw runtime_error("Error opening map file: " + path);
|
||||
}
|
||||
|
||||
@@ -549,8 +719,8 @@ void Map::sinRandomize(int strenght){
|
||||
float normH = static_cast<float>(i) / w;
|
||||
float normV = static_cast<float>(j) / h;
|
||||
|
||||
float sh= (sin(normH*sinH1) + sin(normH*sinH2))/2.f;
|
||||
float sv= (sin(normV*sinV1) + sin(normV*sinV2))/2.f;
|
||||
float sh = (sinf(normH * sinH1) + sin(normH * sinH2)) / 2.f;
|
||||
float sv = (sinf(normV * sinV1) + sin(normV * sinV2)) / 2.f;
|
||||
|
||||
float newHeight = (ah + bh * sh + av + bv * sv) / 2.f;
|
||||
applyNewHeight(newHeight, i, j, strenght);
|
||||
@@ -583,4 +753,4 @@ void Map::applyNewHeight(float newHeight, int x, int y, int strenght){
|
||||
cells[x][y].height = static_cast<float>(((cells[x][y].height * strenght) + newHeight) / (strenght + 1));
|
||||
}
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
@@ -1,5 +1,16 @@
|
||||
#ifndef _GLEST_MAPEDITOR_MAP_H_
|
||||
#define _GLEST_MAPEDITOR_MAP_H_
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>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 _MAPEDITOR_MAP_H_
|
||||
#define _MAPEDITOR_MAP_H_
|
||||
|
||||
#include "util.h"
|
||||
#include "types.h"
|
||||
@@ -10,9 +21,11 @@ using Shared::Platform::int32;
|
||||
using Shared::Platform::float32;
|
||||
using Shared::Util::Random;
|
||||
|
||||
namespace MapEditor {
|
||||
|
||||
struct MapFileHeader {
|
||||
int32 version;
|
||||
int32 maxPlayers;
|
||||
int32 maxFactions;
|
||||
int32 width;
|
||||
int32 height;
|
||||
int32 altFactor;
|
||||
@@ -22,8 +35,6 @@ struct MapFileHeader{
|
||||
int8 description[256];
|
||||
};
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
|
||||
// ===============================================
|
||||
// class Map
|
||||
// ===============================================
|
||||
@@ -57,7 +68,7 @@ private:
|
||||
int altFactor;
|
||||
int waterLevel;
|
||||
Cell **cells;
|
||||
int maxPlayers;
|
||||
int maxFactions;
|
||||
StartLocation *startLocations;
|
||||
int refAlt;
|
||||
|
||||
@@ -82,22 +93,28 @@ public:
|
||||
|
||||
int getH() const {return h;}
|
||||
int getW() const {return w;}
|
||||
int getMaxPlayers() const {return maxPlayers;}
|
||||
int getMaxFactions() const {return maxFactions;}
|
||||
string getTitle() const {return title;}
|
||||
string getDesc() const {return desc;}
|
||||
string getAuthor() const {return author;}
|
||||
|
||||
void changeHeight(int x, int y, int height, int radius);
|
||||
void glestChangeHeight(int x, int y, int height, int radius);
|
||||
void pirateChangeHeight(int x, int y, int height, int radius);
|
||||
void changeSurface(int x, int y, int surface, int radius);
|
||||
void changeObject(int x, int y, int object, int radius);
|
||||
void changeResource(int x, int y, int resource, int radius);
|
||||
void changeStartLocation(int x, int y, int player);
|
||||
|
||||
void setHeight(int x, int y, float height);
|
||||
void setSurface(int x, int y, int surface);
|
||||
void setObject(int x, int y, int object);
|
||||
void setResource(int x, int y, int resource);
|
||||
|
||||
void flipX();
|
||||
void flipY();
|
||||
void reset(int w, int h, float alt, int surf);
|
||||
void resize(int w, int h, float alt, int surf);
|
||||
void resetPlayers(int maxPlayers);
|
||||
void resetFactions(int maxFactions);
|
||||
void randomizeHeights();
|
||||
void randomize();
|
||||
void switchSurfaces(int surf1, int surf2);
|
||||
@@ -112,6 +129,6 @@ public:
|
||||
void applyNewHeight(float newHeight, int x, int y, int strenght);
|
||||
};
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
||||
#endif
|
||||
|
@@ -1,15 +1,148 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>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
|
||||
// ==============================================================
|
||||
|
||||
|
||||
#include "program.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
namespace MapEditor {
|
||||
|
||||
////////////////////////////
|
||||
// class UndoPoint
|
||||
////////////////////////////
|
||||
int UndoPoint::w = 0;
|
||||
int UndoPoint::h = 0;
|
||||
|
||||
UndoPoint::UndoPoint()
|
||||
: height(0)
|
||||
, surface(0)
|
||||
, object(0)
|
||||
, resource(0)
|
||||
, change(ctNone) {
|
||||
w = Program::map->getW();
|
||||
h = Program::map->getH();
|
||||
}
|
||||
/*
|
||||
UndoPoint::UndoPoint(ChangeType change) {
|
||||
w = Program::map->getW();
|
||||
h = Program::map->getH();
|
||||
|
||||
init(change);
|
||||
}*/
|
||||
|
||||
void UndoPoint::init(ChangeType change) {
|
||||
this->change = change;
|
||||
switch (change) {
|
||||
// Back up everything
|
||||
case ctAll:
|
||||
// Back up heights
|
||||
case ctHeight:
|
||||
case ctGradient:
|
||||
// Build an array of heights from the map
|
||||
//std::cout << "Building an array of heights to use for our UndoPoint" << std::endl;
|
||||
height = new float[w * h];
|
||||
for (int i = 0; i < w; ++i) {
|
||||
for (int j = 0; j < h; ++j) {
|
||||
height[j * w + i] = Program::map->getHeight(i, j);
|
||||
}
|
||||
}
|
||||
//std::cout << "Built the array" << std::endl;
|
||||
if (change != ctAll) break;
|
||||
// Back up surfaces
|
||||
case ctSurface:
|
||||
surface = new int[w * h];
|
||||
for (int i = 0; i < w; ++i) {
|
||||
for (int j = 0; j < h; ++j) {
|
||||
surface[j * w + i] = Program::map->getSurface(i, j);
|
||||
}
|
||||
}
|
||||
if (change != ctAll) break;
|
||||
// Back up both objects and resources if either changes
|
||||
case ctObject:
|
||||
case ctResource:
|
||||
object = new int[w * h];
|
||||
for (int i = 0; i < w; ++i) {
|
||||
for (int j = 0; j < h; ++j) {
|
||||
object[j * w + i] = Program::map->getObject(i, j);
|
||||
}
|
||||
}
|
||||
resource = new int[w * h];
|
||||
for (int i = 0; i < w; ++i) {
|
||||
for (int j = 0; j < h; ++j) {
|
||||
resource[j * w + i] = Program::map->getResource(i, j);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UndoPoint::~UndoPoint() {
|
||||
delete [] height;
|
||||
delete [] resource;
|
||||
delete [] object;
|
||||
delete [] surface;
|
||||
}
|
||||
|
||||
void UndoPoint::revert() {
|
||||
//std::cout << "attempting to revert last changes to " << undoID << std::endl;
|
||||
switch (change) {
|
||||
// Revert Everything
|
||||
case ctAll:
|
||||
// Revert Heights
|
||||
case ctHeight:
|
||||
case ctGradient:
|
||||
// Restore the array of heights to the map
|
||||
//std::cout << "attempting to restore the height array" << std::endl;
|
||||
for (int i = 0; i < w; i++) {
|
||||
for (int j = 0; j < h; j++) {
|
||||
Program::map->setHeight(i, j, height[j * w + i]);
|
||||
}
|
||||
}
|
||||
if (change != ctAll) break;
|
||||
// Revert surfaces
|
||||
case ctSurface:
|
||||
//std::cout << "attempting to restore the surface array" << std::endl;
|
||||
for (int i = 0; i < w; i++) {
|
||||
for (int j = 0; j < h; j++) {
|
||||
Program::map->setSurface(i, j, surface[j * w + i]);
|
||||
}
|
||||
}
|
||||
if (change != ctAll) break;
|
||||
// Revert objects and resources
|
||||
case ctObject:
|
||||
case ctResource:
|
||||
for (int i = 0; i < w; i++) {
|
||||
for (int j = 0; j < h; j++) {
|
||||
Program::map->setObject(i, j, object[j * w + i]);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < w; i++) {
|
||||
for (int j = 0; j < h; j++) {
|
||||
Program::map->setResource(i, j, resource[j * w + i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
//std::cout << "reverted changes (we hope)" << std::endl;
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// class Program
|
||||
// ===============================================
|
||||
|
||||
Map *Program::map = NULL;
|
||||
|
||||
Program::Program(int w, int h) {
|
||||
cellSize = 6;
|
||||
ofsetX = 0;
|
||||
@@ -22,8 +155,12 @@ Program::~Program(){
|
||||
delete map;
|
||||
}
|
||||
|
||||
void Program::changeMapHeight(int x, int y, int Height, int radius){
|
||||
map->changeHeight((x-ofsetX)/cellSize, (y+ofsetY)/cellSize, Height, radius);
|
||||
void Program::glestChangeMapHeight(int x, int y, int Height, int radius) {
|
||||
map->glestChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius);
|
||||
}
|
||||
|
||||
void Program::pirateChangeMapHeight(int x, int y, int Height, int radius) {
|
||||
map->pirateChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius);
|
||||
}
|
||||
|
||||
void Program::changeMapSurface(int x, int y, int surface, int radius) {
|
||||
@@ -42,6 +179,41 @@ void Program::changeStartLocation(int x, int y, int player){
|
||||
map->changeStartLocation((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, player);
|
||||
}
|
||||
|
||||
void Program::setUndoPoint(ChangeType change) {
|
||||
if (change == ctLocation) return;
|
||||
|
||||
undoStack.push(UndoPoint());
|
||||
undoStack.top().init(change);
|
||||
|
||||
redoStack.clear();
|
||||
}
|
||||
|
||||
bool Program::undo() {
|
||||
if (undoStack.empty()) {
|
||||
return false;
|
||||
}
|
||||
// push current state onto redo stack
|
||||
redoStack.push(UndoPoint());
|
||||
redoStack.top().init(undoStack.top().getChange());
|
||||
|
||||
undoStack.top().revert();
|
||||
undoStack.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Program::redo() {
|
||||
if (redoStack.empty()) {
|
||||
return false;
|
||||
}
|
||||
// push current state onto undo stack
|
||||
undoStack.push(UndoPoint());
|
||||
undoStack.top().init(redoStack.top().getChange());
|
||||
|
||||
redoStack.top().revert();
|
||||
redoStack.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Program::renderMap(int w, int h) {
|
||||
renderer.renderMap(map, ofsetX, ofsetY, w, h, cellSize);
|
||||
}
|
||||
@@ -71,6 +243,8 @@ void Program::switchMapSurfaces(int surf1, int surf2){
|
||||
}
|
||||
|
||||
void Program::reset(int w, int h, int alt, int surf) {
|
||||
undoStack.clear();
|
||||
redoStack.clear();
|
||||
map->reset(w, h, (float) alt, surf);
|
||||
}
|
||||
|
||||
@@ -78,20 +252,32 @@ void Program::resize(int w, int h, int alt, int surf){
|
||||
map->resize(w, h, (float) alt, surf);
|
||||
}
|
||||
|
||||
void Program::resetPlayers(int maxPlayers){
|
||||
map->resetPlayers(maxPlayers);
|
||||
void Program::resetFactions(int maxFactions) {
|
||||
map->resetFactions(maxFactions);
|
||||
}
|
||||
|
||||
void Program::setMapTitle(const string &title){
|
||||
bool Program::setMapTitle(const string &title) {
|
||||
if (map->getTitle() != title) {
|
||||
map->setTitle(title);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Program::setMapDesc(const string &desc){
|
||||
bool Program::setMapDesc(const string &desc) {
|
||||
if (map->getDesc() != desc) {
|
||||
map->setDesc(desc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Program::setMapAuthor(const string &author){
|
||||
bool Program::setMapAuthor(const string &author) {
|
||||
if (map->getAuthor() != author) {
|
||||
map->setAuthor(author);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Program::setOfset(int x, int y) {
|
||||
@@ -122,6 +308,8 @@ void Program::setMapAdvanced(int altFactor, int waterLevel){
|
||||
}
|
||||
|
||||
void Program::loadMap(const string &path) {
|
||||
undoStack.clear();
|
||||
redoStack.clear();
|
||||
map->loadFromFile(path);
|
||||
}
|
||||
|
||||
@@ -129,4 +317,4 @@ void Program::saveMap(const string &path){
|
||||
map->saveToFile(path);
|
||||
}
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
@@ -1,13 +1,87 @@
|
||||
#ifndef _GLEST_MAPEDITOR_PROGRAM_H_
|
||||
#define _GLEST_MAPEDITOR_PROGRAM_H_
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>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 _MAPEDITOR_PROGRAM_H_
|
||||
#define _MAPEDITOR_PROGRAM_H_
|
||||
|
||||
#include "map.h"
|
||||
#include "renderer.h"
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
#include <stack>
|
||||
|
||||
using std::stack;
|
||||
|
||||
namespace MapEditor {
|
||||
|
||||
class MainWindow;
|
||||
|
||||
enum ChangeType {
|
||||
ctNone = -1,
|
||||
ctHeight,
|
||||
ctSurface,
|
||||
ctObject,
|
||||
ctResource,
|
||||
ctLocation,
|
||||
ctGradient,
|
||||
ctAll
|
||||
};
|
||||
|
||||
// =============================================
|
||||
// class Undo Point
|
||||
// A linked list class that is more of an extension / modification on
|
||||
// the already existing Cell struct in map.h
|
||||
// Provides the ability to only specify a certain property of the map to change
|
||||
// =============================================
|
||||
class UndoPoint {
|
||||
private:
|
||||
// Only keep a certain number of undo points in memory otherwise
|
||||
// Big projects could hog a lot of memory
|
||||
const static int MAX_UNDO_LIST_SIZE = 100; // TODO get feedback on this value
|
||||
static int undoCount;
|
||||
|
||||
ChangeType change;
|
||||
|
||||
// Pointers to arrays of each property
|
||||
int *surface;
|
||||
int *object;
|
||||
int *resource;
|
||||
float *height;
|
||||
|
||||
// Map width and height
|
||||
static int w;
|
||||
static int h;
|
||||
|
||||
public:
|
||||
UndoPoint();
|
||||
~UndoPoint();
|
||||
void init(ChangeType change);
|
||||
void revert();
|
||||
|
||||
inline ChangeType getChange() const { return change; }
|
||||
};
|
||||
|
||||
class ChangeStack : public std::stack<UndoPoint> {
|
||||
public:
|
||||
static const int maxSize = 100;
|
||||
|
||||
void clear() { c.clear(); }
|
||||
|
||||
void push(UndoPoint p) {
|
||||
if (c.size() >= maxSize) {
|
||||
c.pop_front();
|
||||
}
|
||||
stack<UndoPoint>::push(p);
|
||||
}
|
||||
};
|
||||
|
||||
// ===============================================
|
||||
// class Program
|
||||
// ===============================================
|
||||
@@ -17,23 +91,31 @@ private:
|
||||
Renderer renderer;
|
||||
int ofsetX, ofsetY;
|
||||
int cellSize;
|
||||
Map *map;
|
||||
static Map *map;
|
||||
friend class UndoPoint;
|
||||
|
||||
ChangeStack undoStack, redoStack;
|
||||
|
||||
public:
|
||||
Program(int w, int h);
|
||||
~Program();
|
||||
|
||||
//map cell change
|
||||
void changeMapHeight(int x, int y, int Height, int radius);
|
||||
void glestChangeMapHeight(int x, int y, int Height, int radius);
|
||||
void pirateChangeMapHeight(int x, int y, int Height, int radius);
|
||||
void changeMapSurface(int x, int y, int surface, int radius);
|
||||
void changeMapObject(int x, int y, int object, int radius);
|
||||
void changeMapResource(int x, int y, int resource, int radius);
|
||||
void changeStartLocation(int x, int y, int player);
|
||||
|
||||
void setUndoPoint(ChangeType change);
|
||||
bool undo();
|
||||
bool redo();
|
||||
|
||||
//map ops
|
||||
void reset(int w, int h, int alt, int surf);
|
||||
void resize(int w, int h, int alt, int surf);
|
||||
void resetPlayers(int maxPlayers);
|
||||
void resetFactions(int maxFactions);
|
||||
void setRefAlt(int x, int y);
|
||||
void flipX();
|
||||
void flipY();
|
||||
@@ -44,9 +126,9 @@ public:
|
||||
void saveMap(const string &path);
|
||||
|
||||
//map misc
|
||||
void setMapTitle(const string &title);
|
||||
void setMapDesc(const string &desc);
|
||||
void setMapAuthor(const string &author);
|
||||
bool setMapTitle(const string &title);
|
||||
bool setMapDesc(const string &desc);
|
||||
bool setMapAuthor(const string &author);
|
||||
void setMapAdvanced(int altFactor, int waterLevel);
|
||||
|
||||
//misc
|
||||
@@ -55,9 +137,9 @@ public:
|
||||
void incCellSize(int i);
|
||||
void resetOfset();
|
||||
|
||||
const Map *getMap() {return map;}
|
||||
static const Map *getMap() {return map;}
|
||||
};
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
||||
#endif
|
||||
|
@@ -1,15 +1,26 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>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
|
||||
// ==============================================================
|
||||
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "opengl.h"
|
||||
|
||||
#include "vec.h"
|
||||
|
||||
using namespace Shared::Graphics;
|
||||
using namespace Shared::Graphics::Gl;
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
namespace MapEditor {
|
||||
|
||||
// ===============================================
|
||||
// class Renderer
|
||||
@@ -28,6 +39,7 @@ void Renderer::init(int clientW, int clientH){
|
||||
|
||||
void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int cellSize) {
|
||||
float alt;
|
||||
float showWater;
|
||||
|
||||
assertGl();
|
||||
|
||||
@@ -46,17 +58,22 @@ void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int c
|
||||
|
||||
for (int j = 0; j < map->getH(); j++) {
|
||||
for (int i = 0; i < map->getW(); i++) {
|
||||
if (i*cellSize+x>-cellSize && i*cellSize+x<clientW && clientH-cellSize-j*cellSize+y>-cellSize && clientH-cellSize-j*cellSize+y<clientH){
|
||||
if (i * cellSize + x > -cellSize
|
||||
&& i * cellSize + x < clientW
|
||||
&& clientH - cellSize - j * cellSize + y > -cellSize
|
||||
&& clientH - cellSize - j * cellSize + y < clientH) {
|
||||
|
||||
//surface
|
||||
alt = map->getHeight(i, j) / 20.f;
|
||||
showWater = map->getWaterLevel()/ 20.f - alt;
|
||||
showWater = (showWater > 0)? showWater:0;
|
||||
Vec3f surfColor;
|
||||
switch (map->getSurface(i, j)) {
|
||||
case 1: surfColor= Vec3f(0.0, 0.8f*alt, 0.f); break;
|
||||
case 2: surfColor= Vec3f(0.4f*alt, 0.6f*alt, 0.f); break;
|
||||
case 3: surfColor= Vec3f(0.6f*alt, 0.3f*alt, 0.f); break;
|
||||
case 4: surfColor= Vec3f(0.7f*alt, 0.7f*alt, 0.7f*alt); break;
|
||||
case 5: surfColor= Vec3f(1.0f*alt, 0.f, 0.f); break;
|
||||
case 1: surfColor = Vec3f(0.0, 0.8f * alt, 0.f + showWater); break;
|
||||
case 2: surfColor = Vec3f(0.4f * alt, 0.6f * alt, 0.f + showWater); break;
|
||||
case 3: surfColor = Vec3f(0.6f * alt, 0.3f * alt, 0.f + showWater); break;
|
||||
case 4: surfColor = Vec3f(0.7f * alt, 0.7f * alt, 0.7f * alt + showWater); break;
|
||||
case 5: surfColor = Vec3f(0.7f * alt, 0.5f * alt, 0.3f * alt + showWater); break;
|
||||
}
|
||||
|
||||
glColor3fv(surfColor.ptr());
|
||||
@@ -90,10 +107,10 @@ void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int c
|
||||
glEnd();
|
||||
}
|
||||
|
||||
bool found= false;
|
||||
// bool found = false;
|
||||
|
||||
//height lines
|
||||
if(!found){
|
||||
// if (!found) {
|
||||
glColor3fv((surfColor*0.5f).ptr());
|
||||
//left
|
||||
if (i > 0 && map->getHeight(i - 1, j) > map->getHeight(i, j)) {
|
||||
@@ -124,7 +141,7 @@ void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int c
|
||||
glVertex2i((i + 1) * cellSize, clientH - j * cellSize);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
//resources
|
||||
switch (map->getResource(i, j)) {
|
||||
@@ -149,7 +166,7 @@ void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int c
|
||||
|
||||
//start locations
|
||||
glLineWidth(3);
|
||||
for (int i=0; i<map->getMaxPlayers(); i++){
|
||||
for (int i = 0; i < map->getMaxFactions(); i++) {
|
||||
switch (i) {
|
||||
case 0: glColor3f(1.f, 0.f, 0.f); break;
|
||||
case 1: glColor3f(0.f, 0.f, 1.f); break;
|
||||
@@ -174,4 +191,4 @@ void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int c
|
||||
assertGl();
|
||||
}
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
@@ -1,9 +1,20 @@
|
||||
#ifndef _GLEST_MAPEDITOR_RENDERER_H_
|
||||
#define _GLEST_MAPEDITOR_RENDERER_H_
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>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 _MAPEDITOR_RENDERER_H_
|
||||
#define _MAPEDITOR_RENDERER_H_
|
||||
|
||||
#include "map.h"
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
namespace MapEditor {
|
||||
|
||||
// ===============================================
|
||||
// class Renderer
|
||||
@@ -15,6 +26,6 @@ public:
|
||||
void renderMap(Map *map, int x, int y, int clientW, int clientH, int cellSize);
|
||||
};
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user