- added null checks for map editor
This commit is contained in:
parent
f2467faebe
commit
d4370675be
|
@ -489,8 +489,10 @@ void MainWindow::onPaint(wxPaintEvent &event) {
|
|||
if(panel) panel->Update();
|
||||
if(menuBar) menuBar->Update();
|
||||
|
||||
if(program && glCanvas) {
|
||||
program->renderMap(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y);
|
||||
glCanvas->SwapBuffers();
|
||||
}
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
|
|
|
@ -155,12 +155,13 @@ Program::Program(int w, int h) {
|
|||
|
||||
Program::~Program() {
|
||||
delete map;
|
||||
map = NULL;
|
||||
}
|
||||
|
||||
int Program::getObject(int x, int y) {
|
||||
int i=(x - ofsetX) / cellSize;
|
||||
int j= (y + ofsetY) / cellSize;
|
||||
if (map->inside(i, j)) {
|
||||
if (map && map->inside(i, j)) {
|
||||
return map->getObject(i,j);
|
||||
}
|
||||
else {
|
||||
|
@ -171,7 +172,7 @@ int Program::getObject(int x, int y) {
|
|||
int Program::getResource(int x, int y) {
|
||||
int i=(x - ofsetX) / cellSize;
|
||||
int j= (y + ofsetY) / cellSize;
|
||||
if (map->inside(i, j)) {
|
||||
if (map && map->inside(i, j)) {
|
||||
return map->getResource(i,j);
|
||||
}
|
||||
else {
|
||||
|
@ -181,27 +182,27 @@ int Program::getResource(int x, int y) {
|
|||
|
||||
// TODO: move editor-specific code from shared_lib to here.
|
||||
void Program::glestChangeMapHeight(int x, int y, int Height, int radius) {
|
||||
map->glestChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius);
|
||||
if(map) 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);
|
||||
if(map) map->pirateChangeHeight((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, static_cast<MapSurfaceType>(surface), radius);
|
||||
if(map) map->changeSurface((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, static_cast<MapSurfaceType>(surface), radius);
|
||||
}
|
||||
|
||||
void Program::changeMapObject(int x, int y, int object, int radius) {
|
||||
map->changeObject((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, object, radius);
|
||||
if(map) map->changeObject((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, object, radius);
|
||||
}
|
||||
|
||||
void Program::changeMapResource(int x, int y, int resource, int radius) {
|
||||
map->changeResource((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, resource, radius);
|
||||
if(map) map->changeResource((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, resource, radius);
|
||||
}
|
||||
|
||||
void Program::changeStartLocation(int x, int y, int player) {
|
||||
map->changeStartLocation((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, player);
|
||||
if(map) map->changeStartLocation((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, player);
|
||||
}
|
||||
|
||||
void Program::setUndoPoint(ChangeType change) {
|
||||
|
@ -240,22 +241,23 @@ bool Program::redo() {
|
|||
}
|
||||
|
||||
void Program::renderMap(int w, int h) {
|
||||
renderer.renderMap(map, ofsetX, ofsetY, w, h, cellSize, grid);
|
||||
if(map) renderer.renderMap(map, ofsetX, ofsetY, w, h, cellSize, grid);
|
||||
}
|
||||
|
||||
void Program::setRefAlt(int x, int y) {
|
||||
map->setRefAlt((x - ofsetX) / cellSize, (y + ofsetY) / cellSize);
|
||||
if(map) map->setRefAlt((x - ofsetX) / cellSize, (y + ofsetY) / cellSize);
|
||||
}
|
||||
|
||||
void Program::flipX() {
|
||||
map->flipX();
|
||||
if(map) map->flipX();
|
||||
}
|
||||
|
||||
void Program::flipY() {
|
||||
map->flipY();
|
||||
if(map) map->flipY();
|
||||
}
|
||||
|
||||
void Program::mirrorX() { // copy left to right
|
||||
if(map) {
|
||||
int w=map->getW();
|
||||
int h=map->getH();
|
||||
for (int i = 0; i < w/2; i++) {
|
||||
|
@ -276,8 +278,10 @@ void Program::mirrorX() { // copy left to right
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Program::mirrorY() { // copy top to bottom
|
||||
if(map) {
|
||||
int w=map->getW();
|
||||
int h=map->getH();
|
||||
for (int i = 0; i < w; i++) {
|
||||
|
@ -298,8 +302,10 @@ void Program::mirrorY() { // copy top to bottom
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Program::mirrorXY() { // copy leftbottom to topright, can handle non-sqaure maps
|
||||
if(map) {
|
||||
int w=map->getW();
|
||||
int h=map->getH();
|
||||
if (h==w) {
|
||||
|
@ -339,8 +345,10 @@ void Program::mirrorXY() { // copy leftbottom to topright, can handle non-sqaure
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Program::rotatecopyX() {
|
||||
if(map) {
|
||||
int w=map->getW();
|
||||
int h=map->getH();
|
||||
for (int i = 0; i < w/2; i++) {
|
||||
|
@ -361,8 +369,10 @@ void Program::rotatecopyX() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Program::rotatecopyY() {
|
||||
if(map) {
|
||||
int w=map->getW();
|
||||
int h=map->getH();
|
||||
for (int i = 0; i < w; i++) {
|
||||
|
@ -383,8 +393,10 @@ void Program::rotatecopyY() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Program::rotatecopyXY() {
|
||||
if(map) {
|
||||
int w=map->getW();
|
||||
int h=map->getH();
|
||||
int sw=w/h; if(sw<1) sw=1; // x-squares per y
|
||||
|
@ -414,8 +426,10 @@ void Program::rotatecopyXY() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Program::rotatecopyCorner() { // rotate top left 1/4 to top right 1/4
|
||||
if(map) {
|
||||
int w=map->getW();
|
||||
int h=map->getH();
|
||||
if (h==w) {
|
||||
|
@ -455,9 +469,11 @@ void Program::rotatecopyCorner() { // rotate top left 1/4 to top right 1/4
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Program::shiftLeft() {
|
||||
if(map) {
|
||||
int w=map->getW()-1;
|
||||
int h=map->getH();
|
||||
for (int i=0; i<w; i++)
|
||||
|
@ -466,7 +482,9 @@ void Program::shiftLeft() {
|
|||
for (int i = 0; i < map->getMaxFactions(); ++i) // move players
|
||||
map->changeStartLocation(map->getStartLocationX(i)-1, map->getStartLocationY(i), i); // it allready check limits
|
||||
}
|
||||
}
|
||||
void Program::shiftRight() {
|
||||
if(map) {
|
||||
int w=map->getW()-1;
|
||||
int h=map->getH();
|
||||
for (int i=w; i>0; i--)
|
||||
|
@ -476,7 +494,9 @@ void Program::shiftRight() {
|
|||
if (map->getStartLocationX(i) != 0 || map->getStartLocationY(i) != 0) // don't move the unset ones
|
||||
map->changeStartLocation(map->getStartLocationX(i)+1, map->getStartLocationY(i), i); // it allready check limits
|
||||
}
|
||||
}
|
||||
void Program::shiftUp() {
|
||||
if(map) {
|
||||
int w=map->getW();
|
||||
int h=map->getH()-1;
|
||||
for (int i=0; i<w; i++)
|
||||
|
@ -485,7 +505,9 @@ void Program::shiftUp() {
|
|||
for (int i = 0; i < map->getMaxFactions(); ++i) // move players
|
||||
map->changeStartLocation(map->getStartLocationX(i), map->getStartLocationY(i)-1, i); // it allready check limits
|
||||
}
|
||||
}
|
||||
void Program::shiftDown() {
|
||||
if(map) {
|
||||
int w=map->getW();
|
||||
int h=map->getH()-1;
|
||||
for (int i=0; i<w; i++)
|
||||
|
@ -495,55 +517,62 @@ void Program::shiftDown() {
|
|||
if (map->getStartLocationX(i) != 0 || map->getStartLocationY(i) != 0) // don't move the unset ones
|
||||
map->changeStartLocation(map->getStartLocationX(i), map->getStartLocationY(i)+1, i); // it allready check limits
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Program::randomizeMapHeights() {
|
||||
map->randomizeHeights();
|
||||
if(map) map->randomizeHeights();
|
||||
}
|
||||
|
||||
void Program::randomizeMap() {
|
||||
map->randomize();
|
||||
if(map) map->randomize();
|
||||
}
|
||||
|
||||
void Program::switchMapSurfaces(int surf1, int surf2) {
|
||||
map->switchSurfaces(static_cast<MapSurfaceType>(surf1), static_cast<MapSurfaceType>(surf2));
|
||||
if(map) map->switchSurfaces(static_cast<MapSurfaceType>(surf1), static_cast<MapSurfaceType>(surf2));
|
||||
}
|
||||
|
||||
void Program::reset(int w, int h, int alt, int surf) {
|
||||
undoStack.clear();
|
||||
redoStack.clear();
|
||||
map->reset(w, h, (float) alt, static_cast<MapSurfaceType>(surf));
|
||||
if(map) map->reset(w, h, (float) alt, static_cast<MapSurfaceType>(surf));
|
||||
}
|
||||
|
||||
void Program::resize(int w, int h, int alt, int surf) {
|
||||
map->resize(w, h, (float) alt, static_cast<MapSurfaceType>(surf));
|
||||
if(map) map->resize(w, h, (float) alt, static_cast<MapSurfaceType>(surf));
|
||||
}
|
||||
|
||||
void Program::resetFactions(int maxFactions) {
|
||||
map->resetFactions(maxFactions);
|
||||
if(map) map->resetFactions(maxFactions);
|
||||
}
|
||||
|
||||
bool Program::setMapTitle(const string &title) {
|
||||
if(map) {
|
||||
if (map->getTitle() != title) {
|
||||
map->setTitle(title);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Program::setMapDesc(const string &desc) {
|
||||
if(map) {
|
||||
if (map->getDesc() != desc) {
|
||||
map->setDesc(desc);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Program::setMapAuthor(const string &author) {
|
||||
if(map) {
|
||||
if (map->getAuthor() != author) {
|
||||
map->setAuthor(author);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -553,7 +582,7 @@ void Program::setOfset(int x, int y) {
|
|||
}
|
||||
|
||||
void Program::incCellSize(int i) {
|
||||
|
||||
if(map) {
|
||||
int minInc = 2 - cellSize;
|
||||
|
||||
if (i < minInc) {
|
||||
|
@ -563,6 +592,7 @@ void Program::incCellSize(int i) {
|
|||
ofsetX -= (map->getW() * i) / 2;
|
||||
ofsetY += (map->getH() * i) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
void Program::resetOfset() {
|
||||
ofsetX = 0;
|
||||
|
@ -576,7 +606,7 @@ bool Program::setGridOnOff() {
|
|||
}
|
||||
|
||||
void Program::setMapAdvanced(int altFactor, int waterLevel) {
|
||||
map->setAdvanced(altFactor, waterLevel);
|
||||
if(map) map->setAdvanced(altFactor, waterLevel);
|
||||
}
|
||||
|
||||
void Program::loadMap(const string &path) {
|
||||
|
@ -586,7 +616,7 @@ void Program::loadMap(const string &path) {
|
|||
}
|
||||
|
||||
void Program::saveMap(const string &path) {
|
||||
map->saveToFile(path);
|
||||
if(map) map->saveToFile(path);
|
||||
}
|
||||
|
||||
}// end namespace
|
||||
|
|
Loading…
Reference in New Issue
Block a user