X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fleveleditor.cpp;h=42f0fd8250bf2380ff9c1fe70234a73d8cc9c35e;hb=2d97548e5cded4b201bbc10d6cec6232df03e9a4;hp=0578d3703bd735eedf29833e0c3493245efcef66;hpb=00fb759c2385ff08caf38e916c2d0ba8cafc8a41;p=supertux.git diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 0578d3703..42f0fd825 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -31,13 +31,13 @@ #include "leveleditor.h" #include "resources.h" #include "tile.h" -#include "tilemap.h" #include "tile_manager.h" #include "sector.h" -#include "background.h" #include "gameloop.h" -#include "gameobjs.h" -#include "camera.h" +#include "object/gameobjs.h" +#include "object/camera.h" +#include "object/tilemap.h" +#include "object/background.h" LevelEditor::LevelEditor() { @@ -110,12 +110,8 @@ LevelEditor::LevelEditor() if(!tile) continue; - Surface* surface; - if(tile->editor_images.size()) - surface = tile->editor_images[0]; - else if(tile->images.size()) - surface = tile->images[0]; - else + Surface* surface = tile->get_editor_image(); + if(!surface) continue; Button button = Button(surface, "", SDLKey(0)); @@ -288,7 +284,9 @@ while(SDL_PollEvent(&event)) level_subset->description = create_subset_menu->get_item_by_id(MN_ID_DESCRIPTION_SUBSET).input; //FIXME: generate better level filenames level_subset->add_level(subset_name+'/'+"new_level.stl"); - Level::create(level_subset->get_level_filename(0)); + Level* newlevel = new Level(); + newlevel->add_sector(create_sector("main", 25, 19)); + newlevel->save(level_subset->get_level_filename(0)); level_subset->save(); load_level(0); @@ -368,7 +366,9 @@ while(SDL_PollEvent(&event)) if(confirm_dialog(NULL, str)) { level_subset->add_level("new_level.stl"); - Level::create(level_subset->get_level_filename(level_nb + 1)); + Level* newlevel = new Level(); + newlevel->add_sector(create_sector("main", 25, 19)); + newlevel->save(level_subset->get_level_filename(level_nb + 1)); level_subset->save(); load_level(level_nb + 1); } @@ -455,7 +455,7 @@ std::cerr << "previous sector.\n"; { vector.push_back(tilemap->get_tile(x + (int)(((selection_ini.x+scroll.x)*zoom)/32), - y + (int)(((selection_ini.y+scroll.y)*zoom)/32))->id); + y + (int)(((selection_ini.y+scroll.y)*zoom)/32))->getID()); } selection.push_back(vector); } @@ -780,7 +780,7 @@ if(sector_ == NULL) { if(!confirm_dialog(NULL, _("No more sectors exist. Create another?"))) return; - sector_ = Sector::create("new_sector",25,19); + sector_ = create_sector("new_sector",25,19); level->add_sector(sector_); } @@ -855,6 +855,7 @@ void LevelEditor::test_level() void LevelEditor::change(int x, int y, int newtile, int layer) { + (void) layer; // find the tilemap of the current layer, and then change the tile if(x < 0 || (unsigned int)x >= sector->solids->get_width()*32 || y < 0 || (unsigned int)y >= sector->solids->get_height()*32) @@ -934,7 +935,7 @@ mouse_cursor->set_state(MC_HIDE); char str[1024]; -char *text1[] = { +const char *text1[] = { _("This is the built-in level editor. Its aim is to be intuitive\n" "and simple to use, so it should be pretty straightforward.\n" "\n" @@ -970,7 +971,7 @@ char *text1[] = { "enemies and game objects in the bottom.\n") }; -char *text2[] = { +const char *text2[] = { _("The Foreground/Interactive/Background buttons may be used to\n" "see and edit the respective layer. Levels have three tiles layers:\n" "Foreground - tiles are drawn on top of everything and have no contact\n" @@ -1003,7 +1004,7 @@ char *text2[] = { "Webpage: http://pingus.seul.org/~grumbel/flexlay/") }; -char **text[] = { text1, text2 }; +const char **text[] = { text1, text2 }; bool done; @@ -1032,3 +1033,19 @@ for(unsigned int i = 0; i < sizeof(text) / sizeof(text[0]); i++) show_grid = show_grid_t; mouse_cursor->set_state(MC_NORMAL); } + +Sector* +LevelEditor::create_sector(const std::string& name, size_t width, size_t height) +{ + Sector* sector = new Sector; + sector->set_name(name); + + sector->add_object(new TileMap(LAYER_BACKGROUNDTILES, false, width, height)); + sector->add_object(new TileMap(LAYER_TILES, true, width, height)); + sector->add_object(new TileMap(LAYER_FOREGROUNDTILES, false, width, height)); + sector->add_object(new Camera(sector)); + sector->update_game_objects(); + + return sector; +} +