[Super-tux-commit] supertux/src level_subset.h,1.4,1.5 level_subset.cpp,1.10,1.11 leveleditor.h,1.18
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-09-24 15:10:22
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28188/src Modified Files: level_subset.h level_subset.cpp leveleditor.h level.h level.cpp title.cpp leveleditor.cpp Log Message: Uploading the level editor I was working on - It isn't still usable, but it was only getting dust and getting obsolete due to changes on API. Also, made the necessary changes on other stuff. Some bugs were introduced (others were already there :)). Index: level_subset.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level_subset.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- level_subset.cpp 6 Aug 2004 11:43:09 -0000 1.10 +++ level_subset.cpp 24 Sep 2004 15:10:10 -0000 1.11 @@ -76,7 +76,7 @@ lisp_free(root_obj); } -void LevelSubset::load(const char* subset) +void LevelSubset::load(const std::string& subset) { name = subset; @@ -170,6 +170,7 @@ { assert(num < levels.size()); +std::cerr << "levels[" << num << "]: " << levels[num] << std::endl; return directory + levels[num]; } Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.63 retrieving revision 1.64 diff -u -d -r1.63 -r1.64 --- level.h 17 Sep 2004 12:22:40 -0000 1.63 +++ level.h 24 Sep 2004 15:10:10 -0000 1.64 @@ -61,6 +61,13 @@ Sector* get_sector(const std::string& name); + Sector* get_next_sector(const Sector* sector); + Sector* get_previous_sector(const Sector* sector); + + const std::string& get_sector_name(const Sector* sector); + + int get_total_sectors(); + int get_total_badguys(); int get_total_coins(); Index: level_subset.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level_subset.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- level_subset.h 21 Jul 2004 16:51:53 -0000 1.4 +++ level_subset.h 24 Sep 2004 15:10:10 -0000 1.5 @@ -48,7 +48,7 @@ ~LevelSubset(); static void create(const std::string& subset_name); - void load(const char* subset); + void load(const std::string& filename); void save(); void add_level(const std::string& name); Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.119 retrieving revision 1.120 diff -u -d -r1.119 -r1.120 --- title.cpp 18 Sep 2004 12:13:09 -0000 1.119 +++ title.cpp 24 Sep 2004 15:10:10 -0000 1.120 @@ -114,7 +114,7 @@ for (std::set<std::string>::iterator it = level_subsets.begin(); it != level_subsets.end(); ++it) { LevelSubset* subset = new LevelSubset(); - subset->load((*it).c_str()); + subset->load(*it); contrib_menu->additem(MN_GOTO, subset->title, 0, contrib_subset_menu, i); contrib_subsets.push_back(subset); ++i; Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.150 retrieving revision 1.151 diff -u -d -r1.150 -r1.151 --- leveleditor.cpp 16 Sep 2004 15:04:17 -0000 1.150 +++ leveleditor.cpp 24 Sep 2004 15:10:10 -0000 1.151 @@ -1,1808 +1,967 @@ -// $Id$ -// -// SuperTux -// Copyright (C) 2003 Ricardo Cruz <ri...@ae...> -// Copyright (C) 2003 Tobias Glaesser <tob...@gm...> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// [...2549 lines suppressed...] - - done_ = 0; - - while(done_ == 0) - { - done_ = wait_for_event(event); - SDL_Delay(50); - } + done = wait_for_event(event); + SDL_Delay(50); } + } - show_selections = true; - le_show_grid = tmp_show_grid; - le_selection_mode = temp_le_selection_mode; - le_help_shown = false; +show_grid = show_grid_t; +mouse_cursor->set_state(MC_NORMAL); } Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.102 retrieving revision 1.103 diff -u -d -r1.102 -r1.103 --- level.cpp 21 Sep 2004 22:03:32 -0000 1.102 +++ level.cpp 24 Sep 2004 15:10:10 -0000 1.103 @@ -158,6 +158,58 @@ return i->second; } +const std::string& +Level::get_sector_name(const Sector* sector) +{ + for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) + { + if(i->second == sector) + return i->first; + } + std::cerr << "Warning: Sector not found on level\n"; + return ""; +} + +Sector* +Level::get_next_sector(const Sector* sector) +{ + for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) + { + if(i->second == sector) + { + i++; + if(i == sectors.end()) + return NULL; + return i->second; + } + } + std::cerr << "Warning: Sector not found on level\n"; + return NULL; +} + +Sector* +Level::get_previous_sector(const Sector* sector) +{ + for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) + { + if(i->second == sector) + { + if(i == sectors.begin()) + return NULL; + i--; + return i->second; + } + } + std::cerr << "Warning: Sector not found on level\n"; + return NULL; +} + +int +Level::get_total_sectors() +{ +return sectors.size(); +} + int Level::get_total_badguys() { Index: leveleditor.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- leveleditor.h 27 Jul 2004 19:31:39 -0000 1.18 +++ leveleditor.h 24 Sep 2004 15:10:10 -0000 1.19 @@ -1,203 +1,149 @@ -// $Id$ -// -// SuperTux -// Copyright (C) 2003 Ricardo Cruz <ri...@ae...> -// Copyright (C) 2003 Tobias Glaesser <tob...@gm...> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/*************************************************************************** + leveleditor.h - built'in level editor + ------------------- + begin : June, 23 2004 + copyright : (C) 2004 by Ricardo Cruz + email : ri...@ae... + ***************************************************************************/ -/* leveleditor.h - A built-in level editor for SuperTux */ +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ #ifndef SUPERTUX_LEVELEDITOR_H #define SUPERTUX_LEVELEDITOR_H +#include "SDL.h" + +#include <set> +#include <string> + #include "video/drawing_context.h" -#include "special/game_object.h" -#include "video/surface.h" +#include "special/timer.h" #include "level.h" #include "level_subset.h" -#include "special/moving_object.h" -#include "gui/button.h" -#include "gui/menu.h" using namespace SuperTux; -enum LevelEditorMainMenuIDs { - MNID_RETURNLEVELEDITOR, - MNID_SUBSETSETTINGS, - MNID_QUITLEVELEDITOR - }; +namespace SuperTux { +class ButtonGroup; +class Menu; +class Surface; +} + +class Sector; +class TileMap; + +enum { + MN_ID_RETURN, + MN_ID_LOAD_SUBSET, + MN_ID_QUIT, + + // settings menu ids: + MN_ID_NAME, + MN_ID_AUTHOR, + MN_ID_WIDTH, + MN_ID_HEIGHT, + MN_ID_APPLY_SETTINGS, -enum LevelEditorSubsetSettingsIDs { - MNID_SUBSETTITLE, - MNID_SUBSETDESCRIPTION, - MNID_SUBSETSAVECHANGES + // creating subset menu ids: + MN_ID_FILENAME_SUBSET, + MN_ID_TITLE_SUBSET, + MN_ID_DESCRIPTION_SUBSET, + MN_ID_CREATE_SUBSET }; - -enum LevelEditorSubsetNewIDs { - MNID_SUBSETNAME, - MNID_CREATESUBSET -}; -enum LevelEditorSettingsMenuIDs { - MNID_NAME, - MNID_AUTHOR, - MNID_SONG, - MNID_BGIMG, - MNID_PARTICLE, - MNID_LENGTH, - MNID_HEIGHT, - MNID_TIME, - MNID_GRAVITY, - MNID_BGSPEED, - MNID_TopRed, - MNID_TopGreen, - MNID_TopBlue, - MNID_BottomRed, - MNID_BottomGreen, - MNID_BottomBlue, - MNID_APPLY +enum { + BT_LEVEL_SAVE, + BT_LEVEL_TEST, + BT_LEVEL_SETUP, + + BT_NEXT_LEVEL, + BT_PREVIOUS_LEVEL, + BT_NEXT_SECTOR, + BT_PREVIOUS_SECTOR + }; + +enum { + OBJ_TRAMPOLINE = -100, + OBJ_FLYING_PLATFORM = -101, + OBJ_DOOR = -102 }; - class LevelEditor { public: LevelEditor(); ~LevelEditor(); - int run(char* filename = NULL); + void run(const std::string filename = ""); private: + void events(); + void action(); + void draw(DrawingContext& context); -// Functions -void newlevel(void); -void selectlevel(void); -void savelevel(); -void editlevel(void); -void testlevel(void); -void checkevents(void); -void unload_level(); + void load_level_subset(std::string filename); + void load_level(std::string filename); + void load_level(int nb); + void load_sector(std::string name); + void load_sector(Sector* sector); -/* own declerations */ -/* crutial ones (main loop) */ -void init_menus(); -int load_level_subset(const char *filename); -void drawlevel(DrawingContext& context); -void drawinterface(DrawingContext& context); -void change(float x, float y, int tm, unsigned int c); -void showhelp(); -void set_defaults(void); -void activate_bad_guys(void); -void goto_level(int levelnb); -void highlight_selection(); + void save_level(); + void test_level(); + void setup_level(); -void drawminimap(); + void show_help(); -void apply_level_settings_menu(); -void update_subset_settings_menu(); -void save_subset_settings_menu(); -void update_level_settings_menu(); -void change_object_properties(GameObject *pobj); + void change(int x, int y, int newtile, int layer); -// structs -struct TileOrObject -{ - TileOrObject() : tile(0), obj(NULL) { is_tile = true; }; + void load_buttons_gfx(); + void free_buttons_gfx(); - void Tile(unsigned int set_to) { tile = set_to; is_tile = true; } - void Object(GameObject* pobj) { obj = pobj; is_tile = false; } - //Returns true for a tile - bool IsTile() { return is_tile; }; - //Returns true for a GameObject - bool IsObject() { return !is_tile; }; + Level level; + std::string level_filename; + Sector* sector; // current sector + TileMap *solids, *foregrounds, *backgrounds; + std::string sector_name; - void Init() { tile = 0; obj = NULL; is_tile = true; }; + std::set<std::string> level_subsets; + LevelSubset level_subset; + int level_nb; - bool is_tile; //true for tile (false for object) - unsigned int tile; - GameObject* obj; -}; + Menu* main_menu; + Menu* subset_menu; + Menu* create_subset_menu; + Menu* settings_menu; -struct square -{ - int x1, y1, x2, y2; -}; + bool left_button, middle_button; + bool done; + bool show_grid; -/* selection modes */ -enum SelectionMode { CURSOR, SQUARE, NONE }; + Vector scroll; + float zoom; -// variables -/* leveleditor internals */ -std::set<std::string> level_subsets; -bool le_level_changed; /* if changes, ask for saving, when quiting*/ -bool show_minimap; -bool show_selections; -bool le_help_shown; -int pos_x, pos_y, cursor_x, cursor_y; -int le_levelnb; -Level* le_level; -LevelSubset* le_level_subset; -int le_show_grid; -int le_frame; -Surface* le_selection; -int done; -TileOrObject le_current; -bool le_mouse_pressed[2]; -bool le_mouse_clicked[2]; -Button* le_save_level_bt; -Button* le_exit_bt; -Button* le_test_level_bt; -Button* le_next_level_bt; -Button* le_previous_level_bt; -Button* le_move_right_bt; -Button* le_move_left_bt; -Button* le_move_up_bt; -Button* le_move_down_bt; -Button* le_rubber_bt; -Button* le_select_mode_one_bt; -Button* le_select_mode_two_bt; -Button* le_settings_bt; -Button* le_tilegroup_bt; -Button* le_objects_bt; -Button* le_object_select_bt; -Button* le_object_properties_bt; -ButtonPanel* le_tilemap_panel; -int active_tm; -Menu* leveleditor_menu; -Menu* subset_load_menu; -Menu* subset_new_menu; -Menu* subset_settings_menu; -Menu* level_settings_menu; -Menu* select_tilegroup_menu; -Menu* select_objects_menu; -Timer select_tilegroup_menu_effect; -Timer select_objects_menu_effect; -Timer display_level_info; -typedef std::map<std::string, ButtonPanel*> ButtonPanelMap; -ButtonPanelMap tilegroups_map; -ButtonPanelMap objects_map; -std::string cur_tilegroup; -std::string cur_objects; -MouseCursor* mouse_select_object; -MovingObject* selected_game_object; + SDL_Event event; + Timer frame_timer; + Timer level_name_timer; -square selection; -SelectionMode le_selection_mode; -SDL_Event event; + Surface *img_background_bt, *img_foreground_bt, *img_interactive_bt; + Surface *img_save_level_bt, *img_setup_level_bt, *img_test_level_bt; + Surface *img_rubber_bt; + Surface *img_previous_level_bt, *img_next_level_bt, *img_previous_sector_bt, *img_next_sector_bt; + + ButtonGroup *tiles_board, *tiles_layer, *level_options; + int cur_layer; + + std::vector <std::vector <int> > selection; + Vector selection_ini, selection_end; + + bool level_changed; }; -#endif /*SUPERTUX_LEVELEDITOR_H*/ +#endif |