mapeditor from GAE ( removed macro stuff and so on )
This commit is contained in:
parent
06012e4804
commit
983d8475c9
File diff suppressed because it is too large
Load Diff
|
@ -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>
|
||||
|
@ -7,41 +18,88 @@
|
|||
#include <wx/wx.h>
|
||||
#include <wx/glcanvas.h>
|
||||
|
||||
#include "program.h"
|
||||
#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
|
||||
// =====================================================
|
||||
|
||||
class MainWindow: public wxFrame{
|
||||
class MainWindow: public wxFrame {
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
private:
|
||||
static const string versionString;
|
||||
static const string winHeader;
|
||||
static const int heightCount= 11;
|
||||
static const int surfaceCount= 5;
|
||||
static const int objectCount= 11;
|
||||
static const int resourceCount= 6;
|
||||
static const int startLocationCount= 8;
|
||||
static const int radiusCount= 9;
|
||||
static const int heightCount = 11;
|
||||
static const int surfaceCount = 5;
|
||||
static const int objectCount = 11;
|
||||
static const int resourceCount = 6;
|
||||
static const int startLocationCount = 8;
|
||||
static const int radiusCount = 9;
|
||||
|
||||
private:
|
||||
enum MenuId{
|
||||
enum MenuId {
|
||||
miFileLoad,
|
||||
miFileSave,
|
||||
miFileSaveAs,
|
||||
miFileExit,
|
||||
|
||||
miEditUndo,
|
||||
miEditRedo,
|
||||
miEditReset,
|
||||
miEditResetPlayers,
|
||||
miEditResize,
|
||||
|
@ -58,12 +116,13 @@ private:
|
|||
miMiscHelp,
|
||||
|
||||
miBrushHeight,
|
||||
miBrushSurface= miBrushHeight + heightCount + 1,
|
||||
miBrushObject= miBrushSurface + surfaceCount + 1,
|
||||
miBrushResource= miBrushObject + objectCount + 1,
|
||||
miBrushStartLocation= miBrushResource + resourceCount + 1,
|
||||
miBrushGradient = miBrushHeight + heightCount + 1,
|
||||
miBrushSurface = miBrushGradient + heightCount + 1,
|
||||
miBrushObject = miBrushSurface + surfaceCount + 1,
|
||||
miBrushResource = miBrushObject + objectCount + 1,
|
||||
miBrushStartLocation = miBrushResource + resourceCount + 1,
|
||||
|
||||
miRadius= miBrushStartLocation + startLocationCount + 1
|
||||
miRadius = miBrushStartLocation + startLocationCount + 1
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -79,38 +138,47 @@ private:
|
|||
wxMenu *menuMisc;
|
||||
wxMenu *menuBrush;
|
||||
wxMenu *menuBrushHeight;
|
||||
wxMenu *menuBrushGradient;
|
||||
|
||||
wxMenu *menuBrushSurface;
|
||||
wxMenu *menuBrushObject;
|
||||
wxMenu *menuBrushResource;
|
||||
wxMenu *menuBrushStartLocation;
|
||||
wxMenu *menuRadius;
|
||||
|
||||
string currentFile;
|
||||
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,21 +208,27 @@ public:
|
|||
|
||||
void uncheckBrush();
|
||||
void uncheckRadius();
|
||||
|
||||
private:
|
||||
bool isDirty() const { return fileModified; }
|
||||
void setDirty(bool val=true);
|
||||
void setExtension();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class GlCanvas
|
||||
// =====================================================
|
||||
|
||||
class GlCanvas: public wxGLCanvas{
|
||||
class GlCanvas: public wxGLCanvas {
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
public:
|
||||
GlCanvas(MainWindow *mainWindow,int* args);
|
||||
GlCanvas(MainWindow *mainWindow, int *args);
|
||||
|
||||
void onMouseDown(wxMouseEvent &event);
|
||||
void onMouseMove(wxMouseEvent &event);
|
||||
void onKeyDown(wxKeyEvent &event);
|
||||
|
||||
private:
|
||||
MainWindow *mainWindow;
|
||||
|
@ -163,7 +238,7 @@ private:
|
|||
// class SimpleDialog
|
||||
// =====================================================
|
||||
|
||||
class SimpleDialog: public wxDialog{
|
||||
class SimpleDialog: public wxDialog {
|
||||
private:
|
||||
typedef vector<pair<string, string> > Values;
|
||||
|
||||
|
@ -185,7 +260,7 @@ public:
|
|||
// class App
|
||||
// =====================================================
|
||||
|
||||
class App: public wxApp{
|
||||
class App: public wxApp {
|
||||
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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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ñ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;
|
||||
|
||||
struct MapFileHeader{
|
||||
namespace MapEditor {
|
||||
|
||||
struct MapFileHeader {
|
||||
int32 version;
|
||||
int32 maxPlayers;
|
||||
int32 maxFactions;
|
||||
int32 width;
|
||||
int32 height;
|
||||
int32 altFactor;
|
||||
|
@ -22,88 +35,92 @@ struct MapFileHeader{
|
|||
int8 description[256];
|
||||
};
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
|
||||
// ===============================================
|
||||
// class Map
|
||||
// ===============================================
|
||||
|
||||
class Map{
|
||||
class Map {
|
||||
public:
|
||||
static const int maxHeight= 20;
|
||||
static const int minHeight= 0;
|
||||
static const int maxHeight = 20;
|
||||
static const int minHeight = 0;
|
||||
|
||||
private:
|
||||
struct Cell{
|
||||
int surface;
|
||||
int object;
|
||||
int resource;
|
||||
float height;
|
||||
};
|
||||
|
||||
struct StartLocation{
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
struct Cell {
|
||||
int surface;
|
||||
int object;
|
||||
int resource;
|
||||
float height;
|
||||
};
|
||||
|
||||
struct StartLocation {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
Random random;
|
||||
string title;
|
||||
string author;
|
||||
string desc;
|
||||
string recScn;
|
||||
int type;
|
||||
int h;
|
||||
string title;
|
||||
string author;
|
||||
string desc;
|
||||
string recScn;
|
||||
int type;
|
||||
int h;
|
||||
int w;
|
||||
int altFactor;
|
||||
int waterLevel;
|
||||
Cell **cells;
|
||||
int maxPlayers;
|
||||
StartLocation *startLocations;
|
||||
int altFactor;
|
||||
int waterLevel;
|
||||
Cell **cells;
|
||||
int maxFactions;
|
||||
StartLocation *startLocations;
|
||||
int refAlt;
|
||||
|
||||
public:
|
||||
Map();
|
||||
~Map();
|
||||
float getHeight(int x, int y) const;
|
||||
int getSurface(int x, int y) const;
|
||||
int getObject(int x, int y) const;
|
||||
int getResource(int x, int y) const;
|
||||
int getStartLocationX(int index) const;
|
||||
int getStartLocationY(int index) const;
|
||||
int getHeightFactor() const;
|
||||
int getWaterLevel() const;
|
||||
bool inside(int x, int y);
|
||||
Map();
|
||||
~Map();
|
||||
float getHeight(int x, int y) const;
|
||||
int getSurface(int x, int y) const;
|
||||
int getObject(int x, int y) const;
|
||||
int getResource(int x, int y) const;
|
||||
int getStartLocationX(int index) const;
|
||||
int getStartLocationY(int index) const;
|
||||
int getHeightFactor() const;
|
||||
int getWaterLevel() const;
|
||||
bool inside(int x, int y);
|
||||
|
||||
void setRefAlt(int x, int y);
|
||||
void setRefAlt(int x, int y);
|
||||
void setAdvanced(int altFactor, int waterLevel);
|
||||
void setTitle(const string &title);
|
||||
void setDesc(const string &desc);
|
||||
void setAuthor(const string &author);
|
||||
|
||||
void setTitle(const string &title);
|
||||
void setDesc(const string &desc);
|
||||
void setAuthor(const string &author);
|
||||
|
||||
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 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 resize(int w, int h, float alt, int surf);
|
||||
void resetFactions(int maxFactions);
|
||||
void randomizeHeights();
|
||||
void randomize();
|
||||
void switchSurfaces(int surf1, int surf2);
|
||||
|
||||
void loadFromFile(const string &path);
|
||||
void saveToFile(const string &path);
|
||||
void loadFromFile(const string &path);
|
||||
void saveToFile(const string &path);
|
||||
|
||||
public:
|
||||
void resetHeights(int height);
|
||||
|
@ -112,6 +129,6 @@ public:
|
|||
void applyNewHeight(float newHeight, int x, int y, int strenght);
|
||||
};
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,132 +1,320 @@
|
|||
// ==============================================================
|
||||
// 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"
|
||||
#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
|
||||
// ===============================================
|
||||
|
||||
Program::Program(int w, int h){
|
||||
cellSize=6;
|
||||
ofsetX= 0;
|
||||
ofsetY= 0;
|
||||
map= new Map();
|
||||
renderer.init(w, h);
|
||||
Map *Program::map = NULL;
|
||||
|
||||
Program::Program(int w, int h) {
|
||||
cellSize = 6;
|
||||
ofsetX = 0;
|
||||
ofsetY = 0;
|
||||
map = new Map();
|
||||
renderer.init(w, h);
|
||||
}
|
||||
|
||||
Program::~Program(){
|
||||
delete map;
|
||||
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::changeMapSurface(int x, int y, int surface, int radius){
|
||||
map->changeSurface((x-ofsetX)/cellSize, (y+ofsetY)/cellSize, surface, radius);
|
||||
void Program::pirateChangeMapHeight(int x, int y, int Height, int radius) {
|
||||
map->pirateChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius);
|
||||
}
|
||||
|
||||
void Program::changeMapObject(int x, int y, int object, int radius){
|
||||
map->changeObject((x-ofsetX)/cellSize, (y+ofsetY)/cellSize, object, radius);
|
||||
void Program::changeMapSurface(int x, int y, int surface, int radius) {
|
||||
map->changeSurface((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, surface, radius);
|
||||
}
|
||||
|
||||
void Program::changeMapResource(int x, int y, int resource, int radius){
|
||||
map->changeResource((x-ofsetX)/cellSize, (y+ofsetY)/cellSize, resource, radius);
|
||||
void Program::changeMapObject(int x, int y, int object, int radius) {
|
||||
map->changeObject((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, object, radius);
|
||||
}
|
||||
|
||||
void Program::changeStartLocation(int x, int y, int player){
|
||||
map->changeStartLocation((x-ofsetX)/cellSize, (y+ofsetY)/cellSize, player);
|
||||
void Program::changeMapResource(int x, int y, int resource, int radius) {
|
||||
map->changeResource((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, resource, radius);
|
||||
}
|
||||
|
||||
void Program::renderMap(int w, int h){
|
||||
renderer.renderMap(map, ofsetX, ofsetY, w, h, cellSize);
|
||||
void Program::changeStartLocation(int x, int y, int player) {
|
||||
map->changeStartLocation((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, player);
|
||||
}
|
||||
|
||||
void Program::setRefAlt(int x, int y){
|
||||
map->setRefAlt((x-ofsetX)/cellSize, (y+ofsetY)/cellSize);
|
||||
void Program::setUndoPoint(ChangeType change) {
|
||||
if (change == ctLocation) return;
|
||||
|
||||
undoStack.push(UndoPoint());
|
||||
undoStack.top().init(change);
|
||||
|
||||
redoStack.clear();
|
||||
}
|
||||
|
||||
void Program::flipX(){
|
||||
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);
|
||||
}
|
||||
|
||||
void Program::setRefAlt(int x, int y) {
|
||||
map->setRefAlt((x - ofsetX) / cellSize, (y + ofsetY) / cellSize);
|
||||
}
|
||||
|
||||
void Program::flipX() {
|
||||
map->flipX();
|
||||
}
|
||||
|
||||
void Program::flipY(){
|
||||
void Program::flipY() {
|
||||
map->flipY();
|
||||
}
|
||||
|
||||
void Program::randomizeMapHeights(){
|
||||
void Program::randomizeMapHeights() {
|
||||
map->randomizeHeights();
|
||||
}
|
||||
|
||||
void Program::randomizeMap(){
|
||||
void Program::randomizeMap() {
|
||||
map->randomize();
|
||||
}
|
||||
|
||||
void Program::switchMapSurfaces(int surf1, int surf2){
|
||||
void Program::switchMapSurfaces(int surf1, int surf2) {
|
||||
map->switchSurfaces(surf1, surf2);
|
||||
}
|
||||
|
||||
void Program::reset(int w, int h, int alt, int surf){
|
||||
map->reset(w, h, (float) alt, surf);
|
||||
void Program::reset(int w, int h, int alt, int surf) {
|
||||
undoStack.clear();
|
||||
redoStack.clear();
|
||||
map->reset(w, h, (float) alt, surf);
|
||||
}
|
||||
|
||||
void Program::resize(int w, int h, int alt, int surf){
|
||||
map->resize(w, h, (float) alt, surf);
|
||||
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){
|
||||
map->setTitle(title);
|
||||
}
|
||||
|
||||
void Program::setMapDesc(const string &desc){
|
||||
map->setDesc(desc);
|
||||
}
|
||||
|
||||
void Program::setMapAuthor(const string &author){
|
||||
map->setAuthor(author);
|
||||
}
|
||||
|
||||
void Program::setOfset(int x, int y){
|
||||
ofsetX+= x;
|
||||
ofsetY-= y;
|
||||
}
|
||||
|
||||
void Program::incCellSize(int i){
|
||||
|
||||
int minInc= 2-cellSize;
|
||||
|
||||
if(i<minInc){
|
||||
i= minInc;
|
||||
bool Program::setMapTitle(const string &title) {
|
||||
if (map->getTitle() != title) {
|
||||
map->setTitle(title);
|
||||
return true;
|
||||
}
|
||||
cellSize+= i;
|
||||
ofsetX-= (map->getW()*i)/2;
|
||||
ofsetY+= (map->getH()*i)/2;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Program::resetOfset(){
|
||||
ofsetX= 0;
|
||||
ofsetY= 0;
|
||||
cellSize= 6;
|
||||
bool Program::setMapDesc(const string &desc) {
|
||||
if (map->getDesc() != desc) {
|
||||
map->setDesc(desc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Program::setMapAdvanced(int altFactor, int waterLevel){
|
||||
map->setAdvanced(altFactor, waterLevel);
|
||||
bool Program::setMapAuthor(const string &author) {
|
||||
if (map->getAuthor() != author) {
|
||||
map->setAuthor(author);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Program::loadMap(const string &path){
|
||||
map->loadFromFile(path);
|
||||
void Program::setOfset(int x, int y) {
|
||||
ofsetX += x;
|
||||
ofsetY -= y;
|
||||
}
|
||||
|
||||
void Program::saveMap(const string &path){
|
||||
map->saveToFile(path);
|
||||
void Program::incCellSize(int i) {
|
||||
|
||||
int minInc = 2 - cellSize;
|
||||
|
||||
if (i < minInc) {
|
||||
i = minInc;
|
||||
}
|
||||
cellSize += i;
|
||||
ofsetX -= (map->getW() * i) / 2;
|
||||
ofsetY += (map->getH() * i) / 2;
|
||||
}
|
||||
|
||||
}}// end namespace
|
||||
void Program::resetOfset() {
|
||||
ofsetX = 0;
|
||||
ofsetY = 0;
|
||||
cellSize = 6;
|
||||
}
|
||||
|
||||
void Program::setMapAdvanced(int altFactor, int waterLevel) {
|
||||
map->setAdvanced(altFactor, waterLevel);
|
||||
}
|
||||
|
||||
void Program::loadMap(const string &path) {
|
||||
undoStack.clear();
|
||||
redoStack.clear();
|
||||
map->loadFromFile(path);
|
||||
}
|
||||
|
||||
void Program::saveMap(const string &path) {
|
||||
map->saveToFile(path);
|
||||
}
|
||||
|
||||
}// end namespace
|
||||
|
|
|
@ -1,63 +1,145 @@
|
|||
#ifndef _GLEST_MAPEDITOR_PROGRAM_H_
|
||||
#define _GLEST_MAPEDITOR_PROGRAM_H_
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _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
|
||||
// class Program
|
||||
// ===============================================
|
||||
|
||||
class Program{
|
||||
class Program {
|
||||
private:
|
||||
Renderer renderer;
|
||||
int ofsetX, ofsetY;
|
||||
int cellSize;
|
||||
Map *map;
|
||||
int ofsetX, ofsetY;
|
||||
int cellSize;
|
||||
static Map *map;
|
||||
friend class UndoPoint;
|
||||
|
||||
ChangeStack undoStack, redoStack;
|
||||
|
||||
public:
|
||||
Program(int w, int h);
|
||||
~Program();
|
||||
Program(int w, int h);
|
||||
~Program();
|
||||
|
||||
//map cell change
|
||||
void changeMapHeight(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 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 reset(int w, int h, int alt, int surf);
|
||||
void resize(int w, int h, int alt, int surf);
|
||||
void resetFactions(int maxFactions);
|
||||
void setRefAlt(int x, int y);
|
||||
void flipX();
|
||||
void flipY();
|
||||
void randomizeMapHeights();
|
||||
void randomizeMap();
|
||||
void switchMapSurfaces(int surf1, int surf2);
|
||||
void loadMap(const string &path);
|
||||
void saveMap(const string &path);
|
||||
void loadMap(const string &path);
|
||||
void saveMap(const string &path);
|
||||
|
||||
//map misc
|
||||
void setMapTitle(const string &title);
|
||||
void setMapDesc(const string &desc);
|
||||
void setMapAuthor(const string &author);
|
||||
void setMapAdvanced(int altFactor, int waterLevel);
|
||||
bool setMapTitle(const string &title);
|
||||
bool setMapDesc(const string &desc);
|
||||
bool setMapAuthor(const string &author);
|
||||
void setMapAdvanced(int altFactor, int waterLevel);
|
||||
|
||||
//misc
|
||||
void renderMap(int w, int h);
|
||||
void setOfset(int x, int y);
|
||||
void incCellSize(int i);
|
||||
void resetOfset();
|
||||
void incCellSize(int i);
|
||||
void resetOfset();
|
||||
|
||||
const Map *getMap() {return map;}
|
||||
static const Map *getMap() {return map;}
|
||||
};
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,41 +1,53 @@
|
|||
// ==============================================================
|
||||
// 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
|
||||
// class Renderer
|
||||
// ===============================================
|
||||
|
||||
void Renderer::init(int clientW, int clientH){
|
||||
void Renderer::init(int clientW, int clientH) {
|
||||
assertGl();
|
||||
|
||||
glFrontFace(GL_CW);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glPolygonMode(GL_FRONT, GL_FILL);
|
||||
glClearColor(0.5, 0.5, 0.5, 1.0);
|
||||
|
||||
|
||||
assertGl();
|
||||
}
|
||||
|
||||
void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int cellSize){
|
||||
float alt;
|
||||
void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int cellSize) {
|
||||
float alt;
|
||||
float showWater;
|
||||
|
||||
assertGl();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, clientW,0, clientH,1,-1);
|
||||
glOrtho(0, clientW, 0, clientH, 1, -1);
|
||||
glViewport(0, 0, clientW, clientH);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glPushAttrib(GL_CURRENT_BIT);
|
||||
|
||||
|
@ -44,33 +56,38 @@ void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int c
|
|||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glColor3f(0, 0, 0);
|
||||
|
||||
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){
|
||||
|
||||
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) {
|
||||
|
||||
//surface
|
||||
alt= map->getHeight(i, j)/20.f;
|
||||
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;
|
||||
switch (map->getSurface(i, j)) {
|
||||
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());
|
||||
|
||||
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glVertex2i(i*cellSize, clientH-j*cellSize-cellSize);
|
||||
glVertex2i(i*cellSize, clientH-j*cellSize);
|
||||
glVertex2i(i*cellSize+cellSize, clientH-j*cellSize-cellSize);
|
||||
glVertex2i(i*cellSize+cellSize, clientH-j*cellSize);
|
||||
glVertex2i(i * cellSize, clientH - j * cellSize - cellSize);
|
||||
glVertex2i(i * cellSize, clientH - j * cellSize);
|
||||
glVertex2i(i * cellSize + cellSize, clientH - j * cellSize - cellSize);
|
||||
glVertex2i(i * cellSize + cellSize, clientH - j * cellSize);
|
||||
glEnd();
|
||||
|
||||
//objects
|
||||
switch(map->getObject(i,j)){
|
||||
case 0: glColor3f(0.f, 0.f, 0.f); break;
|
||||
switch (map->getObject(i, j)) {
|
||||
case 0: glColor3f(0.f, 0.f, 0.f); break;
|
||||
case 1: glColor3f(1.f, 0.f, 0.f); break;
|
||||
case 2: glColor3f(1.f, 1.f, 1.f); break;
|
||||
case 3: glColor3f(0.5f, 0.5f, 1.f); break;
|
||||
|
@ -80,54 +97,54 @@ void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int c
|
|||
case 7: glColor3f(0.f, 1.f, 1.f); break;
|
||||
case 8: glColor3f(0.7f, 0.1f, 0.3f); break;
|
||||
case 9: glColor3f(0.5f, 1.f, 0.1f); break;
|
||||
case 10:glColor3f(1.f, 0.2f, 0.8f); break;
|
||||
case 10: glColor3f(1.f, 0.2f, 0.8f); break;
|
||||
}
|
||||
|
||||
if(map->getObject(i, j)!=0){
|
||||
glPointSize(cellSize/2.f);
|
||||
if (map->getObject(i, j) != 0) {
|
||||
glPointSize(cellSize / 2.f);
|
||||
glBegin(GL_POINTS);
|
||||
glVertex2i(i*cellSize+cellSize/2, clientH-j*cellSize-cellSize/2);
|
||||
glVertex2i(i * cellSize + cellSize / 2, clientH - j * cellSize - cellSize / 2);
|
||||
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)){
|
||||
if (i > 0 && map->getHeight(i - 1, j) > map->getHeight(i, j)) {
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(i*cellSize, clientH-(j+1)*cellSize);
|
||||
glVertex2i(i*cellSize, clientH-j*cellSize);
|
||||
glVertex2i(i * cellSize, clientH - (j + 1) * cellSize);
|
||||
glVertex2i(i * cellSize, clientH - j * cellSize);
|
||||
glEnd();
|
||||
}
|
||||
//down
|
||||
if(j>0 && map->getHeight(i, j-1)>map->getHeight(i, j)){
|
||||
if (j > 0 && map->getHeight(i, j - 1) > map->getHeight(i, j)) {
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(i*cellSize, clientH-j*cellSize);
|
||||
glVertex2i((i+1)*cellSize, clientH-j*cellSize);
|
||||
glVertex2i(i * cellSize, clientH - j * cellSize);
|
||||
glVertex2i((i + 1) * cellSize, clientH - j * cellSize);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
glColor3fv((surfColor*2.f).ptr());
|
||||
//left
|
||||
if(i>0 && map->getHeight(i-1, j)<map->getHeight(i, j)){
|
||||
if (i > 0 && map->getHeight(i - 1, j) < map->getHeight(i, j)) {
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(i*cellSize, clientH-(j+1)*cellSize);
|
||||
glVertex2i(i*cellSize, clientH-j*cellSize);
|
||||
glEnd();
|
||||
}
|
||||
if(j>0 && map->getHeight(i, j-1)<map->getHeight(i, j)){
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(i*cellSize, clientH-j*cellSize);
|
||||
glVertex2i((i+1)*cellSize, clientH-j*cellSize);
|
||||
glVertex2i(i * cellSize, clientH - (j + 1) * cellSize);
|
||||
glVertex2i(i * cellSize, clientH - j * cellSize);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
if (j > 0 && map->getHeight(i, j - 1) < map->getHeight(i, j)) {
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(i * cellSize, clientH - j * cellSize);
|
||||
glVertex2i((i + 1) * cellSize, clientH - j * cellSize);
|
||||
glEnd();
|
||||
}
|
||||
// }
|
||||
|
||||
//resources
|
||||
switch(map->getResource(i,j)){
|
||||
switch (map->getResource(i, j)) {
|
||||
case 1: glColor3f(1.f, 1.f, 0.f); break;
|
||||
case 2: glColor3f(0.5f, 0.5f, 0.5f); break;
|
||||
case 3: glColor3f(1.f, 0.f, 0.f); break;
|
||||
|
@ -135,13 +152,13 @@ void Renderer::renderMap(Map *map, int x, int y, int clientW, int clientH, int c
|
|||
case 5: glColor3f(0.5f, 0.5f, 1.f); break;
|
||||
}
|
||||
|
||||
if (map->getResource(i,j)!=0){
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(i*cellSize, clientH-j*cellSize-cellSize);
|
||||
glVertex2i(i*cellSize+cellSize, clientH-j*cellSize);
|
||||
glVertex2i(i*cellSize, clientH-j*cellSize);
|
||||
glVertex2i(i*cellSize+cellSize, clientH-j*cellSize-cellSize);
|
||||
glEnd();
|
||||
if (map->getResource(i, j) != 0) {
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i(i * cellSize, clientH - j * cellSize - cellSize);
|
||||
glVertex2i(i * cellSize + cellSize, clientH - j * cellSize);
|
||||
glVertex2i(i * cellSize, clientH - j * cellSize);
|
||||
glVertex2i(i * cellSize + cellSize, clientH - j * cellSize - cellSize);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,23 +166,23 @@ 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++){
|
||||
switch(i){
|
||||
case 0: glColor3f(1.f, 0.f, 0.f); break;
|
||||
case 1: glColor3f(0.f, 0.f, 1.f); break;
|
||||
case 2: glColor3f(0.f, 1.f, 0.f); break;
|
||||
case 3: glColor3f(1.f, 1.f, 0.f); break;
|
||||
case 4: glColor3f(1.f, 1.f, 1.f); break;
|
||||
case 5: glColor3f(0.f, 1.f, 0.8f); break;
|
||||
case 6: glColor3f(1.f, 0.8f, 0.f); break;
|
||||
case 7: glColor3f(1.f, 0.8f, 1.f); break;
|
||||
}
|
||||
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;
|
||||
case 2: glColor3f(0.f, 1.f, 0.f); break;
|
||||
case 3: glColor3f(1.f, 1.f, 0.f); break;
|
||||
case 4: glColor3f(1.f, 1.f, 1.f); break;
|
||||
case 5: glColor3f(0.f, 1.f, 0.8f); break;
|
||||
case 6: glColor3f(1.f, 0.8f, 0.f); break;
|
||||
case 7: glColor3f(1.f, 0.8f, 1.f); break;
|
||||
}
|
||||
glBegin(GL_LINES);
|
||||
glVertex2i((map->getStartLocationX(i)-1)*cellSize, clientH- (map->getStartLocationY(i)-1)*cellSize);
|
||||
glVertex2i((map->getStartLocationX(i)+1)*cellSize+cellSize, clientH- (map->getStartLocationY(i)+1)*cellSize-cellSize);
|
||||
glVertex2i((map->getStartLocationX(i)-1)*cellSize, clientH- (map->getStartLocationY(i)+1)*cellSize-cellSize);
|
||||
glVertex2i((map->getStartLocationX(i)+1)*cellSize+cellSize, clientH- (map->getStartLocationY(i)-1)*cellSize);
|
||||
glEnd();
|
||||
glVertex2i((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
|
||||
glVertex2i((map->getStartLocationX(i) + 1) * cellSize + cellSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - cellSize);
|
||||
glVertex2i((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - cellSize);
|
||||
glVertex2i((map->getStartLocationX(i) + 1) * cellSize + cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
@ -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,20 +1,31 @@
|
|||
#ifndef _GLEST_MAPEDITOR_RENDERER_H_
|
||||
#define _GLEST_MAPEDITOR_RENDERER_H_
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _MAPEDITOR_RENDERER_H_
|
||||
#define _MAPEDITOR_RENDERER_H_
|
||||
|
||||
#include "map.h"
|
||||
|
||||
namespace Glest{ namespace MapEditor{
|
||||
namespace MapEditor {
|
||||
|
||||
// ===============================================
|
||||
// class Renderer
|
||||
// ===============================================
|
||||
|
||||
class Renderer{
|
||||
class Renderer {
|
||||
public:
|
||||
void init(int clientW, int clientH);
|
||||
void renderMap(Map *map, int x, int y, int clientW, int clientH, int cellSize);
|
||||
};
|
||||
|
||||
}}// end namespace
|
||||
}// end namespace
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue