From DONOTREPLY at icculus.org Tue Aug 30 12:48:54 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 30 Aug 2005 12:48:54 -0400 Subject: r124 - in trunk: . src Message-ID: <20050830164854.19410.qmail@icculus.org> Author: jonas Date: 2005-08-30 12:48:53 -0400 (Tue, 30 Aug 2005) New Revision: 124 Modified: trunk/TODO trunk/src/common.cpp trunk/src/common.h trunk/src/gfxeng.cpp trunk/src/gfxeng.h trunk/src/input.cpp trunk/src/lost_penguins.cpp trunk/src/menu.cpp trunk/src/menu.h trunk/src/objectpools.cpp Log: updated TODO, improved/added edit mode, added Box class for edit mode... Modified: trunk/TODO =================================================================== --- trunk/TODO 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/TODO 2005-08-30 16:48:53 UTC (rev 124) @@ -12,27 +12,26 @@ o pointers => references where possible o Describe everything using Doxygen styles, move the documentation from *.cpp to the headers... - o Idea: _all_ objects should have a "kore" like the players (curpos thing) + o Idea: _all_ objects should have a "core" like the players (curpos thing) This would help in many ways and should be a frame information and not an image as done for players atm! o Use Singletons - o Introduce abstract classes for all engines and load the corresponding + o IDEA: Introduce abstract classes for all engines and load the corresponding concrete class depending on the game_mode instead of using if... o Move/Fall/push/crash/collisions: o the character should have more information what he hits - o movements into dense objects should involve a push() - o I have no idea about how the push should look like, elevators can be pushed - up, even though you don't collide with them on top - o characters should be "pushable", eg. a stone that falls down pushes the - character down or better: an elevator should push the characters up + o IDEA: movements into dense objects should involve a push() + -> I have no idea about how the push should look like, elevators can be pushed + up, even though you don't collide with them on top + -> characters should be "pushable", eg. a stone that falls down pushes the + character down or better: an elevator should push the characters up o In case of the elevator, the players are somehow "bound" to the elevator (ie. it's not like: the elevator moves, the character falls, but they move together) Solution: The elevators move function checks all objects it would hit, if they are pushable (not dense) they are moved first if possible. If it's not possible, do sthg else (stop the elevator and hit the object/whatever)... - o the collision detection and the move/fall code is all a big mess o Animations/Events: o Allow as complex Images as possible: @@ -116,7 +115,7 @@ illegaly placed! - the placement should somehow involve checkPlace... - o Plugins: + o (Plugins): o move object creation code (addObjectByName) to the objects o create dynamical plugins for all objects (or compile all in) @@ -145,12 +144,10 @@ ============== o Make water movements possible (eric) - o Improve player bar management o Add better graphics o finnish the map editor o OpenGL o Simple AI - o Menu o Finnish the vikings: - weapons: run, jump2, fart, sword, arm, fire, claws @@ -182,6 +179,3 @@ o Items?: - special items - - o IDEA: add horizontal gravity that slows objects down?? - Modified: trunk/src/common.cpp =================================================================== --- trunk/src/common.cpp 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/src/common.cpp 2005-08-30 16:48:53 UTC (rev 124) @@ -12,6 +12,19 @@ Config config; Uint8 game_mode=NOTHING; Menu* menu=NULL; +Box* box=NULL; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN +const Uint32 rmask=0xff000000; +const Uint32 gmask=0x00ff0000; +const Uint32 bmask=0x0000ff00; +const Uint32 amask=0x000000ff; +#else +const Uint32 rmask=0x000000ff; +const Uint32 gmask=0x0000ff00; +const Uint32 bmask=0x00ff0000; +const Uint32 amask=0xff000000; +#endif +Uint32 vflags=SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF; string itos(int i) { std::stringstream s; Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/src/common.h 2005-08-30 16:48:53 UTC (rev 124) @@ -41,6 +41,7 @@ class Weapon; class Animation; class Menu; +class Box; typedef std::set::iterator object_iterator; typedef std::set::iterator character_iterator; @@ -147,10 +148,19 @@ Menu* closeMenu(); /// Close all menus (menu=NULL) void closeMenus(); +/// Set the current box +Box* setBox(Box* newbox); +/// Close the current box +void closeBox(); //@} //global variables //@{ +extern const Uint32 rmask; +extern const Uint32 gmask; +extern const Uint32 bmask; +extern const Uint32 amask; +extern Uint32 vflags; /// Game configuration extern Config config; /// Image Cache @@ -173,6 +183,8 @@ extern Uint8 game_mode; /// Currently used menu, NULL if not inside a menu extern Menu* menu; +/// Currently used box, NULL if there is no box +extern Box* box; //@} #endif Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/src/gfxeng.cpp 2005-08-30 16:48:53 UTC (rev 124) @@ -13,23 +13,11 @@ GraphicsEngine::GraphicsEngine(): -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask(0xff000000), - gmask(0x00ff0000), - bmask(0x0000ff00), - amask(0x000000ff), -#else - rmask(0x000000ff), - gmask(0x0000ff00), - bmask(0x00ff0000), - amask(0xff000000), -#endif screen(NULL), menubg(NULL), show_bar(true), show_fps(true), - fullscreen(config.full), - vflags(SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF) { + fullscreen(config.full) { shift.x=0; shift.y=0; resize(config.width, config.height); @@ -82,7 +70,8 @@ } else if (game_mode&GAME_EDIT) { if (show_fps) toggleFPS(); if (show_bar) togglePlayerBar(); - drawEditScene(); + drawScene(); + drawBox(); updatetype=UPDATE_ALL; } else return; //This is the most time consuming operation @@ -147,11 +136,15 @@ void GraphicsEngine::drawScene() { //We don't want to change pos! SDL_Rect tmprect,srcpos; - if (scenario->player!=NULL) { - shift=setShift(scenario->player->getCenter()); - } else { - shift.x=0; - shift.y=0; + if (game_mode&GAME_PLAY) { + if (scenario->player!=NULL) { + shift=setShift(scenario->player->getCenter()); + } else { + shift.x=0; + shift.y=0; + } + } else if (game_mode&GAME_EDIT) { + SDL_FillRect(screen,NULL,0); } tmprect=*scenario->area; @@ -168,7 +161,7 @@ ++obit; } - if (scenario->player!=NULL) { + if (game_mode&GAME_PLAY && scenario->player!=NULL) { tmprect=*(scenario->player->getPos()); srcpos=scenario->player->getFrame().pos; shiftMapArea(tmprect,*(scenario->player->getCurPos())); @@ -176,26 +169,6 @@ } } -void GraphicsEngine::drawEditScene() { - //We don't want to change pos! - SDL_Rect tmprect,srcpos; - - SDL_FillRect(screen,NULL,0); - tmprect=*scenario->area; - srcpos=scenario->background->getFrame().pos; - shiftMapArea(tmprect,*scenario->background->getCurPos()); - SDL_BlitSurface(scenario->background->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift)); - - object_iterator obit=scenario->pool->objectspool.begin(); - while (obit!=scenario->pool->objectspool.end()) { - tmprect=*((*obit)->getPos()); - srcpos=(*obit)->getFrame().pos; - shiftMapArea(tmprect,*((*obit)->getCurPos())); - SDL_BlitSurface((*obit)->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift)); - ++obit; - } -} - //TODO don't draw the whole screen, just till bar, just upgrade certain regions of the bar void GraphicsEngine::drawPlayerBar() { if (!show_bar) return; @@ -353,13 +326,21 @@ } } +void GraphicsEngine::drawBox() { + if (box && box->surface) { + SDL_Rect tmprect; + tmprect=box->area; + SDL_BlitSurface(box->surface,0,screen,&tmprect); + } +} + //this could probably be done much easier ;) inline void GraphicsEngine::setGameMenuBG() { if (menubg) SDL_FreeSurface(menubg); if (game_mode&GAME_PLAY) { drawScene(); drawPlayerBar(); - } else if (game_mode&GAME_EDIT) drawEditScene(); + } else if (game_mode&GAME_EDIT) drawScene(); SDL_Flip(screen); SDL_Surface* tmp = SDL_CreateRGBSurface ( Modified: trunk/src/gfxeng.h =================================================================== --- trunk/src/gfxeng.h 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/src/gfxeng.h 2005-08-30 16:48:53 UTC (rev 124) @@ -32,15 +32,14 @@ void setMenuBG(SDL_Surface* menu_background=NULL); const SDL_Rect& addShift(Sint16,Sint16); const SDL_Rect& setShift(Sint16,Sint16); + const SDL_Rect& getShift() { + return shift; + } protected: - const Uint32 rmask; - const Uint32 gmask; - const Uint32 bmask; - const Uint32 amask; - /// currently visible part of the map area - SDL_Rect vis_map; /// main screen SDL_Surface* screen; + /// currently visible part of the map area + SDL_Rect vis_map; /// menu background SDL_Surface* menubg; /// player bar @@ -53,17 +52,12 @@ bool fullscreen; //update state Uint8 updatetype; - //video flags - Uint32 vflags; // current shift SDL_Rect shift; protected: /// Draw the background and all objects in the pool. This is a very time /// consuming function... inline void drawScene(); - /// Draw the background and all objects in the pool in map editor mode. - /// This is a very time consuming function... - inline void drawEditScene(); /// Draw player bar inline void drawPlayerBar(); /// Draw the frames per second @@ -73,6 +67,7 @@ /// If no scenario is running or the scenario was interrupted this will /// draw the menu. inline void drawMenu(); + inline void drawBox(); inline void resetMenuBG(); inline SDL_Rect clipToBG(SDL_Rect dest) const; /// updates backpos and returns the new shift vector (ignore w,h) Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/src/input.cpp 2005-08-30 16:48:53 UTC (rev 124) @@ -46,11 +46,11 @@ } while(SDL_PollEvent(&event)) { switch(event.type) { - // special events - case SDL_VIDEORESIZE: { - gfxeng->resize(event.resize.w, event.resize.h); - break; - } + // special events + case SDL_VIDEORESIZE: { + gfxeng->resize(event.resize.w, event.resize.h); + break; + } // keyboard events case SDL_QUIT: { quitGame(0); @@ -94,11 +94,11 @@ } while(SDL_PollEvent(&event)) { switch(event.type) { - // special events - case SDL_VIDEORESIZE: { - gfxeng->resize(event.resize.w, event.resize.h); - break; - } + // special events + case SDL_VIDEORESIZE: { + gfxeng->resize(event.resize.w, event.resize.h); + break; + } // keyboard events case SDL_QUIT: { quitGame(0); @@ -136,11 +136,11 @@ } while(SDL_PollEvent(&event)) { switch(event.type) { - // special events - case SDL_VIDEORESIZE: { - gfxeng->resize(event.resize.w, event.resize.h); - break; - } + // special events + case SDL_VIDEORESIZE: { + gfxeng->resize(event.resize.w, event.resize.h); + break; + } // keyboard events case SDL_QUIT: { quitGame(0); @@ -183,15 +183,52 @@ } while(SDL_PollEvent(&event)) { switch(event.type) { - // special events - case SDL_VIDEORESIZE: { - gfxeng->resize(event.resize.w, event.resize.h); - break; - } + // special events + case SDL_VIDEORESIZE: { + gfxeng->resize(event.resize.w, event.resize.h); + break; + } // keyboard events case SDL_QUIT: { quitGame(0); } + case SDL_MOUSEBUTTONUP: { + switch (event.button.button) { + case SDL_BUTTON_LEFT: { + break; + } + case SDL_BUTTON_RIGHT: { + if (box) box->act(box->getCurrentEntry(event.button.x,event.button.y)); + break; + } + case SDL_BUTTON_MIDDLE: { + break; + } + default: { + break; + } + } + break; + } + case SDL_MOUSEBUTTONDOWN: { + switch (event.button.button) { + case SDL_BUTTON_LEFT: { + if (box) box->act(box->getCurrentEntry(event.button.x,event.button.y)); + break; + } + case SDL_BUTTON_RIGHT: { + setBox(new EditBox(event.button.x,event.button.y)); + break; + } + case SDL_BUTTON_MIDDLE: { + break; + } + default: { + break; + } + } + break; + } case SDL_KEYDOWN: { SDLKey key=event.key.keysym.sym; keypressed[key]=true; Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/src/lost_penguins.cpp 2005-08-30 16:48:53 UTC (rev 124) @@ -31,7 +31,7 @@ cout << "Couldn't initialize SDL!\n"; exit(-1); } - SDL_ShowCursor(SDL_DISABLE); + SDL_ShowCursor(SDL_ENABLE); //Change directory to datadir cout << "ImageCache...\n"; @@ -64,6 +64,7 @@ int quitGame(int errorcode=0) { cout << endl << "Quitting game (exit code: " << errorcode << ")...\n"; + closeBox(); closeMenus(); delete scenario; cout << "Scenario closed...\n"; Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/src/menu.cpp 2005-08-30 16:48:53 UTC (rev 124) @@ -3,6 +3,7 @@ #include "physics.h" #include "gfxeng.h" #include "sfxeng.h" +#include "font.h" #include "menu.h" Menu* setMenu(Menu* newmenu) { @@ -283,3 +284,122 @@ } */ } + +Box* setBox(Box* newbox) { + gfxeng->update(UPDATE_ALL); + return box=newbox; +} + +void closeBox() { + if (box) delete box; + box=NULL; + gfxeng->update(UPDATE_ALL); +} + +Box::Box(Sint16 x, Sint16 y): + title("MENU"), + //don't forget the "::" + font(::font), + font_title(font), + font_high(font2), + surface(NULL) { + area.x=x; + area.y=y; +} +Box::~Box() { +} + +void Box::act(Sint8) { + closeBox(); +} + +const SDL_Rect& Box::getArea() { + Uint16 tmp=0; + Uint16 maxwidth=font_title->getTextWidth(title); + for (Uint8 i=0; igetTextWidth(entries[i]),font_high->getTextWidth(entries[i])); + maxwidth=max(maxwidth,tmp); + } + area.w=maxwidth+2*WFONT; + area.h=entries.size()*(DFONT+font->getHeight())+2*WFONT+font_title->getHeight(); + return area; +} + +Sint8 Box::getCurrentEntry(Sint16 x, Sint16 y) { + getArea(); + if ( + (x>=(area.x+area.w)) || + (x<=area.x) || + (y>=(area.y+area.h)) || + (y<=(area.y+WFONT+font_title->getHeight()+(int)(DFONT/2)))) { + return -1; + } + Sint16 tmp=y-area.y-WFONT-font_title->getHeight()-(int)(DFONT/2); + Uint16 entrysize=DFONT+font->getHeight(); + Uint8 currententry=0; + while (tmp>entrysize) { + tmp-=entrysize; + ++currententry; + } + return currententry; +} + +void Box::update() { + if (surface==NULL) { + getArea(); + SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask); + surface=SDL_DisplayFormatAlpha(tmp); + SDL_FreeSurface(tmp); + SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180)); + + /* create a border */ + Sint16 tmph=0; + SDL_Rect line; + line.x=0; + line.y=0; + line.w=BORDERSIZE; + line.h=area.h; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.x=area.w-BORDERSIZE; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.x=0; + line.y=0; + line.w=area.w; + line.h=BORDERSIZE; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.y=area.h-BORDERSIZE; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + + /* write title */ + font_title->writeCenter(surface,title,WFONT); + line.y=font_title->getHeight()+(int)((DFONT-line.h)/2); + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.h=LINESIZE; + + /* write entries */ + for (Uint8 i=0; igetHeight()*i+WFONT+font_title->getHeight(); + font->writeCenter(surface,entries[i],tmph); + line.y=tmph+font->getHeight()+(int)((DFONT-line.h)/2); + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,180)); + } + } +} + +EditBox::EditBox(Sint16 x, Sint16 y): Box(x,y) { + title="PLACE"; + entries.resize(4); + entries[0]="Olaf"; + entries[1]="Water"; + entries[2]="Zombie"; + entries[3]="Exit"; + update(); +} + +void EditBox::act(Sint8 curentry) { + if (curentry==1) { + setBox(new EditBox(area.x+10,area.y+10)); + } else { + closeBox(); + } +} Modified: trunk/src/menu.h =================================================================== --- trunk/src/menu.h 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/src/menu.h 2005-08-30 16:48:53 UTC (rev 124) @@ -1,6 +1,11 @@ #ifndef DEF_MENU_H #define DEF_MENU_H 1 +#define WFONT 4 +#define DFONT 10 +#define BORDERSIZE 2 +#define LINESIZE 1 + /** \brief abstract menu base class Abstract base class for menus. The main part is in the constructor and in the @@ -105,4 +110,46 @@ void update(); }; + +/** \brief abstract selection box base class + +*/ +class Box { + friend class GraphicsEngine; + friend class InputHandler; + public: + Box(Sint16,Sint16); + virtual ~Box(); + /// Name of the menu + string title; + /// Main menu function, depends on currententry (changed by input), overload this. + virtual void act(Sint8) = 0; + Uint8 getSize() { + return entries.size(); + } + const SDL_Rect& getArea(); + Sint8 getCurrentEntry(Sint16,Sint16); + protected: + /// List of all Box entry names + std::vector entries; + /// Font for non highlighted menu entries + Font* font; + /// Font for the menu title + Font* font_title; + /// Font for the selected menu entry + Font* font_high; + /// Area occupied by the selection box + SDL_Rect area; + /// Menu surface to be drawn + SDL_Surface* surface; + /// Draw the box surface + void update(); +}; + +class EditBox : public Box { + public: + EditBox(Sint16,Sint16); + virtual void act(Sint8); +}; + #endif Modified: trunk/src/objectpools.cpp =================================================================== --- trunk/src/objectpools.cpp 2005-07-10 10:09:34 UTC (rev 123) +++ trunk/src/objectpools.cpp 2005-08-30 16:48:53 UTC (rev 124) @@ -1,5 +1,7 @@ #include "common.h" #include "scenario.h" +//HACK +#include "gfxeng.h" #include "sfxeng.h" #include "sndcache.h" #include "objectpools.h" @@ -37,6 +39,8 @@ } Object* ObjectsPool::addObjectbyName(const string& obj, const string& image, Sint16 x, Sint16 y, const string& arg1, const string& arg2, const string& arg3) { + x-=gfxeng->getShift().x; + y-=gfxeng->getShift().y; //Set names... string name=obj; if (arg1!="0") { From DONOTREPLY at icculus.org Wed Aug 31 05:42:45 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 31 Aug 2005 05:42:45 -0400 Subject: r125 - trunk/src Message-ID: <20050831094245.1039.qmail@icculus.org> Author: jonas Date: 2005-08-31 05:42:45 -0400 (Wed, 31 Aug 2005) New Revision: 125 Added: trunk/src/editor.cpp trunk/src/editor.h Modified: trunk/src/Makefile trunk/src/common.cpp trunk/src/common.h trunk/src/gfxeng.cpp trunk/src/input.cpp trunk/src/lost_penguins.cpp trunk/src/menu.cpp trunk/src/menu.h trunk/src/objectpools.cpp trunk/src/objectpools.h Log: added an Editor class, improved map editor (prelimenary object placements) Modified: trunk/src/Makefile =================================================================== --- trunk/src/Makefile 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/Makefile 2005-08-31 09:42:45 UTC (rev 125) @@ -9,7 +9,7 @@ OBJS = common.o gfxeng.o input.o font.o lost_penguins.o scenario.o\ objects_common.o sfxeng.o players_common.o monsters_common.o\ characters_common.o objectpools.o weapons.o events.o imgcache.o\ - sndcache.o physics.o animation.o menu.o SDL_rotozoom.o + sndcache.o physics.o animation.o menu.o editor.o SDL_rotozoom.o PLUGS = objects.a BIN = ../lost_penguins Modified: trunk/src/common.cpp =================================================================== --- trunk/src/common.cpp 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/common.cpp 2005-08-31 09:42:45 UTC (rev 125) @@ -13,6 +13,7 @@ Uint8 game_mode=NOTHING; Menu* menu=NULL; Box* box=NULL; +Editor* editor=NULL; #if SDL_BYTEORDER == SDL_BIG_ENDIAN const Uint32 rmask=0xff000000; const Uint32 gmask=0x00ff0000; Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/common.h 2005-08-31 09:42:45 UTC (rev 125) @@ -42,6 +42,7 @@ class Animation; class Menu; class Box; +class Editor; typedef std::set::iterator object_iterator; typedef std::set::iterator character_iterator; @@ -49,23 +50,23 @@ typedef std::set::iterator monster_iterator; //General definitions -#define NOTHING 0x00000000 -#define ALL 0xFFFFFFFF -#define DIR_RIGHT 0x00000001 -#define DIR_LEFT 0x00000002 -#define DIR_UP 0x00000004 -#define DIR_DOWN 0x00000008 -#define DIR_ALL 0x0000000F -#define DIR_UPR 0x00000005 -#define DIR_UPL 0x00000006 -#define DIR_DWR 0x00000009 -#define DIR_DWL 0x0000000A -#define DIR_LR 0x00000003 +#define NOTHING 0x00000000 +#define ALL 0xFFFFFFFF +#define DIR_RIGHT 0x00000001 +#define DIR_LEFT 0x00000002 +#define DIR_UP 0x00000004 +#define DIR_DOWN 0x00000008 +#define DIR_ALL 0x0000000F +#define DIR_UPR 0x00000005 +#define DIR_UPL 0x00000006 +#define DIR_DWR 0x00000009 +#define DIR_DWL 0x0000000A +#define DIR_LR 0x00000003 -#define GAME_PAUSED 0x00000001 -#define GAME_PLAY 0x00000002 -#define GAME_EDIT 0x00000004 -#define GAME_MENU 0x00000008 +#define GAME_PAUSED 0x00000001 +#define GAME_PLAY 0x00000002 +#define GAME_EDIT 0x00000004 +#define GAME_MENU 0x00000008 enum ConfigKey { KEY_START, @@ -148,10 +149,6 @@ Menu* closeMenu(); /// Close all menus (menu=NULL) void closeMenus(); -/// Set the current box -Box* setBox(Box* newbox); -/// Close the current box -void closeBox(); //@} //global variables @@ -183,8 +180,8 @@ extern Uint8 game_mode; /// Currently used menu, NULL if not inside a menu extern Menu* menu; -/// Currently used box, NULL if there is no box -extern Box* box; +/// Editor +extern Editor* editor; //@} #endif Added: trunk/src/editor.cpp =================================================================== --- trunk/src/editor.cpp 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/editor.cpp 2005-08-31 09:42:45 UTC (rev 125) @@ -0,0 +1,212 @@ +#include "common.h" +#include "scenario.h" +#include "objectpools.h" +#include "menu.h" +#include "font.h" +#include "editor.h" + + +Editor::Editor() { + run_action(EDIT_RESET_ACTIONS); + string place_name=""; +} + +Editor::~Editor() { + closeBox(); +} + +void Editor::run_action(Uint32 action, Uint16 x, Uint16 y) { + if (action==EDIT_RESET_ACTIONS) { + for (Uint8 i=0; i<6; i++) { + action_mouse_pressed[i]=NOTHING; + action_mouse_released[i]=NOTHING; + } + action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_ACT_BOX; + action_mouse_pressed[SDL_BUTTON_RIGHT]=EDIT_BOX; + action_mouse_released[SDL_BUTTON_RIGHT]=EDIT_ACT_BOX; + } else if (action==EDIT_BOX) { + setBox(new EditBox(x,y)); + } else if (action==EDIT_ACT_BOX) { + if (box) box->act(box->getCurrentEntry(x,y)); + } else if (action==EDIT_PLACE_OBJECT) { + scenario->pool->addObjectbyName(place_name,place_image,x,y,scenario->pool->getNextObjectName(place_name)); + action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_ACT_BOX; + } else { } +} + +Box* Editor::setBox(Box* newbox) { + return box=newbox; +} + +void Editor::closeBox() { + if (box) delete box; + box=NULL; +} + +Box::Box(Sint16 x, Sint16 y): + title("MENU"), + surface(NULL), + //don't forget the "::" + font(::font), + font_title(font), + font_high(font2) { + area.x=x; + area.y=y; +} +Box::~Box() { +} + +void Box::act(Sint8) { + editor->closeBox(); +} + +const SDL_Rect& Box::getArea() { + Uint16 tmp=0; + Uint16 maxwidth=font_title->getTextWidth(title); + for (Uint8 i=0; igetTextWidth(entries[i]),font_high->getTextWidth(entries[i])); + maxwidth=max(maxwidth,tmp); + } + area.w=maxwidth+2*WFONT; + area.h=entries.size()*(DFONT+font->getHeight())+2*WFONT+font_title->getHeight(); + return area; +} + +Sint8 Box::getCurrentEntry(Sint16 x, Sint16 y) { + getArea(); + if ( + (x>=(area.x+area.w)) || + (x<=area.x) || + (y>=(area.y+area.h)) || + (y<=(area.y+WFONT+font_title->getHeight()+(int)(DFONT/2)))) { + return -1; + } + Sint16 tmp=y-area.y-WFONT-font_title->getHeight()-(int)(DFONT/2); + Uint16 entrysize=DFONT+font->getHeight(); + Uint8 currententry=0; + while (tmp>entrysize) { + tmp-=entrysize; + ++currententry; + } + return currententry; +} + +void Box::update() { + if (surface==NULL) { + getArea(); + SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask); + surface=SDL_DisplayFormatAlpha(tmp); + SDL_FreeSurface(tmp); + SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180)); + + /* create a border */ + Sint16 tmph=0; + SDL_Rect line; + line.x=0; + line.y=0; + line.w=BORDERSIZE; + line.h=area.h; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.x=area.w-BORDERSIZE; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.x=0; + line.y=0; + line.w=area.w; + line.h=BORDERSIZE; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.y=area.h-BORDERSIZE; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + + /* write title */ + font_title->writeCenter(surface,title,WFONT); + line.y=font_title->getHeight()+(int)((DFONT-line.h)/2); + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.h=LINESIZE; + + /* write entries */ + for (Uint8 i=0; igetHeight()*i+WFONT+font_title->getHeight(); + font->writeCenter(surface,entries[i],tmph); + line.y=tmph+font->getHeight()+(int)((DFONT-line.h)/2); + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,180)); + } + } +} + +EditBox::EditBox(Sint16 x, Sint16 y): Box(x,y) { + title="PLACE"; + entries.push_back("Wall"); + entries.push_back("Exit"); + entries.push_back("Water"); + entries.push_back("Teleporter"); + entries.push_back("Wind"); + entries.push_back("Geyser"); + entries.push_back("Trigger"); + entries.push_back("Door"); + entries.push_back("Spike"); + + entries.push_back("Heart"); + entries.push_back("Key"); + entries.push_back("Bomb"); + + entries.push_back("Erik"); + entries.push_back("Olaf"); + entries.push_back("Baleog"); + entries.push_back("Fang"); + entries.push_back("Scorch"); + + entries.push_back("Plant"); + entries.push_back("Zombie"); + + update(); +} + +void EditBox::act(Sint8 curentry) { + if (curentry==-1 || curentry >= (Sint8)entries.size()) { + editor->closeBox(); + } else { + editor->place_name=entries[curentry]; + if (editor->place_name=="Wall") { + editor->place_image="viking1.bmp"; + } else if (editor->place_name=="Water") { + editor->place_image="water.bmp"; + } else if (editor->place_name=="Teleporter") { + editor->place_image="viking1.bmp"; + } else if (editor->place_name=="Wind") { + editor->place_image="teleport_01.bmp"; + } else if (editor->place_name=="Geyser") { + editor->place_image="viking1.bmp"; + } else if (editor->place_name=="Trigger") { + editor->place_image="key.bmp"; + } else if (editor->place_name=="Door") { + editor->place_image="viking1.bmp"; + } else if (editor->place_name=="Spike") { + editor->place_image="viking1.bmp"; + } else if (editor->place_name=="Heart") { + editor->place_image="heart.bmp"; + } else if (editor->place_name=="Key") { + editor->place_image="key.bmp"; + } else if (editor->place_name=="Bomb") { + editor->place_image="bomb_fire.bmp"; + } else if (editor->place_name=="Erik") { + editor->place_image="viking.bmp"; + } else if (editor->place_name=="Olaf") { + editor->place_image="viking.bmp"; + } else if (editor->place_name=="Baleog") { + editor->place_image="viking.bmp"; + } else if (editor->place_name=="Fang") { + editor->place_image="viking.bmp"; + } else if (editor->place_name=="Scorch") { + editor->place_image="viking.bmp"; + } else if (editor->place_name=="Plant") { + editor->place_image="viking1.bmp"; + } else if (editor->place_name=="Zombie") { + editor->place_image="viking.bmp"; + } else { + editor->place_image=""; + } + editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_PLACE_OBJECT; + editor->action_mouse_released[SDL_BUTTON_LEFT]=EDIT_RESET_ACTIONS; + editor->closeBox(); + } +} Added: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/editor.h 2005-08-31 09:42:45 UTC (rev 125) @@ -0,0 +1,86 @@ +#ifndef DEF_EDITOR_H +#define DEF_EDITOR_H 1 + +#define EDIT_RESET_ACTIONS 0x00000001 +#define EDIT_BOX 0x00000004 +#define EDIT_ACT_BOX 0x00000008 +#define EDIT_PLACE_OBJECT 0x00000010 + +/** \brief abstract selection box base class + +*/ +class Box { + friend class Editor; + friend class GraphicsEngine; + public: + Box(Sint16,Sint16); + virtual ~Box(); + /// Name of the menu + string title; + /// Main menu function, depends on currententry (changed by input), overload this. + virtual void act(Sint8) = 0; + Uint8 getSize() { + return entries.size(); + } + const SDL_Rect& getArea(); + Sint8 getCurrentEntry(Sint16,Sint16); + protected: + /// Menu surface to be drawn + SDL_Surface* surface; + /// List of all Box entry names + std::vector entries; + /// Font for non highlighted menu entries + Font* font; + /// Font for the menu title + Font* font_title; + /// Font for the selected menu entry + Font* font_high; + /// Area occupied by the selection box + SDL_Rect area; + /// Draw the box surface + void update(); +}; + +class EditBox : public Box { + public: + EditBox(Sint16,Sint16); + virtual void act(Sint8); +}; + +/** \brief Handels editor specific tasks + +*/ +class Editor { + friend class EditBox; + public: + Editor(); + ~Editor(); + void run_action(Uint32 action, Uint16 x=0, Uint16 y=0); + Uint32 getActionMPressed(Uint8 button) { + if (button>=1 && button <6) return action_mouse_pressed[button]; + else return NOTHING; + } + Uint32 getActionMReleased(Uint8 button) { + if (button>=1 && button <6) return action_mouse_released[button]; + else return NOTHING; + } + /// Set the current box + Box* setBox(Box* newbox); + /// Close the current box + void closeBox(); + bool hasBox() { + if (box && box->surface) return true; + else return false; + } + Box* box; + protected: + /// Object to place when clicking the left mouse button + string place_name; + /// Image name of the placed object + string place_image; + /// Action type for the mouse buttons when clicking + Uint32 action_mouse_pressed[6]; + Uint32 action_mouse_released[6]; +}; + +#endif Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/gfxeng.cpp 2005-08-31 09:42:45 UTC (rev 125) @@ -6,6 +6,7 @@ #include "imgcache.h" #include "scenario.h" #include "menu.h" +#include "editor.h" //Only needed for fps #include "scenario.h" #include "physics.h" @@ -327,10 +328,10 @@ } void GraphicsEngine::drawBox() { - if (box && box->surface) { + if (editor->hasBox()) { SDL_Rect tmprect; - tmprect=box->area; - SDL_BlitSurface(box->surface,0,screen,&tmprect); + tmprect=editor->box->area; + SDL_BlitSurface(editor->box->surface,0,screen,&tmprect); } } Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/input.cpp 2005-08-31 09:42:45 UTC (rev 125) @@ -9,8 +9,8 @@ #include "menu.h" #include "physics.h" #include "objects_common.h" +#include "editor.h" - InputHandler::InputHandler() { au_pause=sndcache->loadWAV("pause.wav"); SDL_PumpEvents(); @@ -193,40 +193,11 @@ quitGame(0); } case SDL_MOUSEBUTTONUP: { - switch (event.button.button) { - case SDL_BUTTON_LEFT: { - break; - } - case SDL_BUTTON_RIGHT: { - if (box) box->act(box->getCurrentEntry(event.button.x,event.button.y)); - break; - } - case SDL_BUTTON_MIDDLE: { - break; - } - default: { - break; - } - } + editor->run_action(editor->getActionMReleased(event.button.button),event.button.x,event.button.y); break; } case SDL_MOUSEBUTTONDOWN: { - switch (event.button.button) { - case SDL_BUTTON_LEFT: { - if (box) box->act(box->getCurrentEntry(event.button.x,event.button.y)); - break; - } - case SDL_BUTTON_RIGHT: { - setBox(new EditBox(event.button.x,event.button.y)); - break; - } - case SDL_BUTTON_MIDDLE: { - break; - } - default: { - break; - } - } + editor->run_action(editor->getActionMPressed(event.button.button),event.button.x,event.button.y); break; } case SDL_KEYDOWN: { Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/lost_penguins.cpp 2005-08-31 09:42:45 UTC (rev 125) @@ -10,6 +10,7 @@ #include "sfxeng.h" #include "objectpools.h" #include "menu.h" +#include "editor.h" #include "players_common.h" @@ -64,7 +65,6 @@ int quitGame(int errorcode=0) { cout << endl << "Quitting game (exit code: " << errorcode << ")...\n"; - closeBox(); closeMenus(); delete scenario; cout << "Scenario closed...\n"; @@ -77,8 +77,11 @@ delete sndcache; cout << "Deleting ImageCache...\n"; delete imgcache; + if (editor) { + cout << "Deleting Editor...\n"; + delete editor; + } cout << "Quiting SDL...\n"; - SDL_Quit(); exit(errorcode); } Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/menu.cpp 2005-08-31 09:42:45 UTC (rev 125) @@ -5,6 +5,7 @@ #include "sfxeng.h" #include "font.h" #include "menu.h" +#include "editor.h" Menu* setMenu(Menu* newmenu) { if (menu) gfxeng->update(UPDATE_MENU); @@ -76,8 +77,9 @@ //Add a proper Map creation menu, etc..., FIXME if ((config.map!="") && (scenario->loadMap(config.map)==0)) { closeMenu(); + cout << "Starting editor...\n" << endl; game_mode|=GAME_EDIT; - cout << "Starting game...\n" << endl; + if (!editor) editor=new Editor(); } else { cout << "Select a valid map first...\n" << endl; } @@ -284,122 +286,3 @@ } */ } - -Box* setBox(Box* newbox) { - gfxeng->update(UPDATE_ALL); - return box=newbox; -} - -void closeBox() { - if (box) delete box; - box=NULL; - gfxeng->update(UPDATE_ALL); -} - -Box::Box(Sint16 x, Sint16 y): - title("MENU"), - //don't forget the "::" - font(::font), - font_title(font), - font_high(font2), - surface(NULL) { - area.x=x; - area.y=y; -} -Box::~Box() { -} - -void Box::act(Sint8) { - closeBox(); -} - -const SDL_Rect& Box::getArea() { - Uint16 tmp=0; - Uint16 maxwidth=font_title->getTextWidth(title); - for (Uint8 i=0; igetTextWidth(entries[i]),font_high->getTextWidth(entries[i])); - maxwidth=max(maxwidth,tmp); - } - area.w=maxwidth+2*WFONT; - area.h=entries.size()*(DFONT+font->getHeight())+2*WFONT+font_title->getHeight(); - return area; -} - -Sint8 Box::getCurrentEntry(Sint16 x, Sint16 y) { - getArea(); - if ( - (x>=(area.x+area.w)) || - (x<=area.x) || - (y>=(area.y+area.h)) || - (y<=(area.y+WFONT+font_title->getHeight()+(int)(DFONT/2)))) { - return -1; - } - Sint16 tmp=y-area.y-WFONT-font_title->getHeight()-(int)(DFONT/2); - Uint16 entrysize=DFONT+font->getHeight(); - Uint8 currententry=0; - while (tmp>entrysize) { - tmp-=entrysize; - ++currententry; - } - return currententry; -} - -void Box::update() { - if (surface==NULL) { - getArea(); - SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask); - surface=SDL_DisplayFormatAlpha(tmp); - SDL_FreeSurface(tmp); - SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180)); - - /* create a border */ - Sint16 tmph=0; - SDL_Rect line; - line.x=0; - line.y=0; - line.w=BORDERSIZE; - line.h=area.h; - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - line.x=area.w-BORDERSIZE; - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - line.x=0; - line.y=0; - line.w=area.w; - line.h=BORDERSIZE; - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - line.y=area.h-BORDERSIZE; - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - - /* write title */ - font_title->writeCenter(surface,title,WFONT); - line.y=font_title->getHeight()+(int)((DFONT-line.h)/2); - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - line.h=LINESIZE; - - /* write entries */ - for (Uint8 i=0; igetHeight()*i+WFONT+font_title->getHeight(); - font->writeCenter(surface,entries[i],tmph); - line.y=tmph+font->getHeight()+(int)((DFONT-line.h)/2); - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,180)); - } - } -} - -EditBox::EditBox(Sint16 x, Sint16 y): Box(x,y) { - title="PLACE"; - entries.resize(4); - entries[0]="Olaf"; - entries[1]="Water"; - entries[2]="Zombie"; - entries[3]="Exit"; - update(); -} - -void EditBox::act(Sint8 curentry) { - if (curentry==1) { - setBox(new EditBox(area.x+10,area.y+10)); - } else { - closeBox(); - } -} Modified: trunk/src/menu.h =================================================================== --- trunk/src/menu.h 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/menu.h 2005-08-31 09:42:45 UTC (rev 125) @@ -110,46 +110,4 @@ void update(); }; - -/** \brief abstract selection box base class - -*/ -class Box { - friend class GraphicsEngine; - friend class InputHandler; - public: - Box(Sint16,Sint16); - virtual ~Box(); - /// Name of the menu - string title; - /// Main menu function, depends on currententry (changed by input), overload this. - virtual void act(Sint8) = 0; - Uint8 getSize() { - return entries.size(); - } - const SDL_Rect& getArea(); - Sint8 getCurrentEntry(Sint16,Sint16); - protected: - /// List of all Box entry names - std::vector entries; - /// Font for non highlighted menu entries - Font* font; - /// Font for the menu title - Font* font_title; - /// Font for the selected menu entry - Font* font_high; - /// Area occupied by the selection box - SDL_Rect area; - /// Menu surface to be drawn - SDL_Surface* surface; - /// Draw the box surface - void update(); -}; - -class EditBox : public Box { - public: - EditBox(Sint16,Sint16); - virtual void act(Sint8); -}; - #endif Modified: trunk/src/objectpools.cpp =================================================================== --- trunk/src/objectpools.cpp 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/objectpools.cpp 2005-08-31 09:42:45 UTC (rev 125) @@ -110,6 +110,14 @@ } } +string ObjectsPool::getNextObjectName(const string& basename) { + int objnum=1; + while(getObject(basename+itos(objnum))) { + objnum++; + } + return basename+itos(objnum); +} + //yeah, a pyramide... ;) serious, this is _NOT_ good //hmm, but it can be used as a bad example on how "_not_ to do things"... ;-) ///\todo Fix this mess Modified: trunk/src/objectpools.h =================================================================== --- trunk/src/objectpools.h 2005-08-30 16:48:53 UTC (rev 124) +++ trunk/src/objectpools.h 2005-08-31 09:42:45 UTC (rev 125) @@ -49,6 +49,8 @@ /// \pre The name must be unique (otherwise it's basically random) /// \return Pointer to the Object or NULL if it wasn't found Object* getObject(const string& oname); + /// Helper function to return the next available object name corresponding to the given base name + string getNextObjectName(const string& basename); //@{ /// Remove an Object (using an object_iterator) from all pools it belongs to /// \return object_iterator to the next entry in the pool or the end() From DONOTREPLY at icculus.org Wed Aug 31 09:09:29 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 31 Aug 2005 09:09:29 -0400 Subject: r126 - trunk/src Message-ID: <20050831130929.30278.qmail@icculus.org> Author: jonas Date: 2005-08-31 09:09:29 -0400 (Wed, 31 Aug 2005) New Revision: 126 Modified: trunk/src/editor.cpp trunk/src/editor.h trunk/src/physics.cpp trunk/src/scenario.cpp trunk/src/scenario.h Log: allow placing of objects + map buffering, reloading and saving Modified: trunk/src/editor.cpp =================================================================== --- trunk/src/editor.cpp 2005-08-31 09:42:45 UTC (rev 125) +++ trunk/src/editor.cpp 2005-08-31 13:09:29 UTC (rev 126) @@ -9,10 +9,13 @@ Editor::Editor() { run_action(EDIT_RESET_ACTIONS); string place_name=""; + save_name="newmap.txt"; + box=NULL; } Editor::~Editor() { closeBox(); + saveBuf(save_name); } void Editor::run_action(Uint32 action, Uint16 x, Uint16 y) { @@ -29,11 +32,46 @@ } else if (action==EDIT_ACT_BOX) { if (box) box->act(box->getCurrentEntry(x,y)); } else if (action==EDIT_PLACE_OBJECT) { - scenario->pool->addObjectbyName(place_name,place_image,x,y,scenario->pool->getNextObjectName(place_name)); + string next_name=scenario->pool->getNextObjectName(place_name); + if (scenario->pool->addObjectbyName(place_name,place_image,x,y,next_name)) { + appendtoBuf(place_name+" "+place_image+" "+itos(x)+" "+itos(y)+" "+next_name); + } action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_ACT_BOX; } else { } } +void Editor::appendtoBuf(string line) { + scenario->mapbuf.push_back(line); +} + +string Editor::removefromBuf(string match) { + for (Uint16 linenum=0; linenummapbuf.size(); linenum++) { + if (scenario->mapbuf[linenum].find(match)!=string::npos) { + vector::iterator it=scenario->mapbuf.begin()+linenum; + string returnstring=scenario->mapbuf[linenum]; + scenario->mapbuf.erase(it); + return returnstring; + } + } + return ""; +} + +int Editor::saveBuf(string filename) { + ofstream outfile; + outfile.open(filename.c_str()); + if (outfile.is_open()) { + for (Uint16 linenum=0; linenummapbuf.size(); linenum++) { + outfile << scenario->mapbuf[linenum] << endl; + } + outfile.close(); + cout << "Saved map to " << filename << endl; + return 0; + } else { + cout << "Failed to save map to " << filename << ": Could not open file!" << endl; + return -1; + } +} + Box* Editor::setBox(Box* newbox) { return box=newbox; } @@ -170,6 +208,8 @@ editor->place_image="viking1.bmp"; } else if (editor->place_name=="Water") { editor->place_image="water.bmp"; + } else if (editor->place_name=="Exit") { + editor->place_image="exit.bmp"; } else if (editor->place_name=="Teleporter") { editor->place_image="viking1.bmp"; } else if (editor->place_name=="Wind") { Modified: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2005-08-31 09:42:45 UTC (rev 125) +++ trunk/src/editor.h 2005-08-31 13:09:29 UTC (rev 126) @@ -74,13 +74,23 @@ } Box* box; protected: + /// Name the saved map file + string save_name; /// Object to place when clicking the left mouse button string place_name; /// Image name of the placed object string place_image; /// Action type for the mouse buttons when clicking Uint32 action_mouse_pressed[6]; + /// Action type for the mouse buttons when releasing the button Uint32 action_mouse_released[6]; + /// Append a command to the buffered map file + void appendtoBuf(string); + /* TODO: add header modifiers */ + /// Remove the first line in the buffered map file matching the specified string + string removefromBuf(string); + /// Save the map file buffer to the specified file if possible + int saveBuf(string); }; #endif Modified: trunk/src/physics.cpp =================================================================== --- trunk/src/physics.cpp 2005-08-31 09:42:45 UTC (rev 125) +++ trunk/src/physics.cpp 2005-08-31 13:09:29 UTC (rev 126) @@ -95,7 +95,7 @@ if (input->keyState(KEY_RIGHT)) scenario->player->in_right(dt); if (input->keyState(KEY_UP)) scenario->player->in_up(dt); if (input->keyState(KEY_DOWN)) scenario->player->in_down(dt); - } else { + } else if (scenario->player!=NULL) { scenario->player->unsetState(STATE_MLEFT); scenario->player->unsetState(STATE_MRIGHT); } Modified: trunk/src/scenario.cpp =================================================================== --- trunk/src/scenario.cpp 2005-08-31 09:42:45 UTC (rev 125) +++ trunk/src/scenario.cpp 2005-08-31 13:09:29 UTC (rev 126) @@ -49,23 +49,14 @@ background=NULL; area=NULL; player=NULL; - name=""; } -int Scenario::loadMap(string mapname) { - reinitMap(); - sfxeng->playMusic((config.datadir + "01theme.wav").c_str()); +int Scenario::loadMapBuf(string mapname) { name=mapname; ifstream mapfile; string tmpline; - string image; - string arg1,arg2,arg3; - Uint16 x,y; - background=NULL; - area=NULL; string loadfile=config.datadir+name; - bool header=false; - + mapfile.open(loadfile.c_str()); if (mapfile) { cout << "Loading new map: " << loadfile << endl; @@ -74,53 +65,68 @@ return -2; } + mapbuf.clear(); + while (getline(mapfile,tmpline)) { + mapbuf.push_back(tmpline); + } + + mapfile.close(); + mapfile.clear(); + return 0; +} + +int Scenario::reloadMap() { + reinitMap(); + sfxeng->playMusic((config.datadir + "01theme.wav").c_str()); + string image; + string cname,arg1,arg2,arg3; + Uint16 x,y; + bool header=false; + //check every line - while (getline(mapfile,tmpline)) { + for (Uint16 linenum=0; linenum> name >> arg1 >> arg2 >> arg3; - if (name[0]=='#') { - if (name=="#ENDHEADER") header=false; + std::istringstream tmpstream(mapbuf[linenum]); + tmpstream >> cname >> arg1 >> arg2 >> arg3; + if (cname[0]=='#') { + if (cname=="#ENDHEADER") header=false; continue; } continue; } - name.erase(); + cname.erase(); image.erase(); x=0; y=0; arg1=arg2="0"; arg3=""; - std::istringstream tmpstream(tmpline); - tmpstream >> name >> image >> x >> y >> arg1 >> arg2 >> arg3; + std::istringstream tmpstream(mapbuf[linenum]); + tmpstream >> cname >> image >> x >> y >> arg1 >> arg2 >> arg3; //Skip empty lines - if (name.empty()) continue; + if (cname.empty()) continue; //Skip comments - if (name[0]=='#') { - if (name=="#HEADER") header=true; + if (cname[0]=='#') { + if (cname=="#HEADER") header=true; continue; } - if (name=="Background" && (!background)) { + if (cname=="Background" && (!background)) { background=new Background(image); if (background) area=background->getPos(); //Background has to be first! } else if (background) { - pool->addObjectbyName(name,image,x,y,arg1,arg2,arg3); + pool->addObjectbyName(cname,image,x,y,arg1,arg2,arg3); } else { - cout << "No background found yet, skipping " << name << " ...\n"; + cout << "No background found yet, skipping " << cname << " ...\n"; } } - mapfile.close(); - mapfile.clear(); - //Has a background been found? if (background) { if (pool->playerspool.size()>0) player=*pool->playerspool.begin(); @@ -133,6 +139,11 @@ } } +int Scenario::loadMap(string mapname) { + if (!loadMapBuf(mapname) && !reloadMap()) return 0; + else return -1; +} + Uint16 Scenario::getDirection(const SDL_Rect& src, const SDL_Rect& dest) const { Uint16 dir=NOTHING; if ((src.x+src.w) < (dest.x+dest.w)) dir|=DIR_RIGHT; Modified: trunk/src/scenario.h =================================================================== --- trunk/src/scenario.h 2005-08-31 09:42:45 UTC (rev 125) +++ trunk/src/scenario.h 2005-08-31 13:09:29 UTC (rev 126) @@ -61,6 +61,10 @@ ObjectsPool* pool; /// Physic Handler PhysicHandler* physic; + /// Used to load the map file into a buffer + int loadMapBuf(string mapname); + /// Reload the map file using the buffered map file + int reloadMap(); ///\brief Loads and initializes the map data /// /// Parses the map file and tries to add the objects by using addObjectByName() @@ -71,6 +75,7 @@ bool failed; /// Name of the map file string name; + std::vector mapbuf; private: inline void reinitMap(); }; From DONOTREPLY at icculus.org Wed Aug 31 11:10:27 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 31 Aug 2005 11:10:27 -0400 Subject: r127 - trunk/src Message-ID: <20050831151027.11333.qmail@icculus.org> Author: jonas Date: 2005-08-31 11:10:27 -0400 (Wed, 31 Aug 2005) New Revision: 127 Modified: trunk/src/gfxeng.cpp trunk/src/lost_penguins.cpp trunk/src/objectpools.cpp trunk/src/scenario.cpp Log: few memory fixes... Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-08-31 13:09:29 UTC (rev 126) +++ trunk/src/gfxeng.cpp 2005-08-31 15:10:27 UTC (rev 127) @@ -19,6 +19,7 @@ show_bar(true), show_fps(true), fullscreen(config.full) { + updatetype=UPDATE_ALL; shift.x=0; shift.y=0; resize(config.width, config.height); @@ -32,8 +33,7 @@ } void GraphicsEngine::update(Uint8 upd) { - if (updatetype==UPDATE_ALL) return; - else updatetype=upd; + if (updatetype!=UPDATE_ALL) updatetype=upd; } void GraphicsEngine::draw() { Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-08-31 13:09:29 UTC (rev 126) +++ trunk/src/lost_penguins.cpp 2005-08-31 15:10:27 UTC (rev 127) @@ -66,6 +66,10 @@ int quitGame(int errorcode=0) { cout << endl << "Quitting game (exit code: " << errorcode << ")...\n"; closeMenus(); + if (editor) { + cout << "Deleting Editor...\n"; + delete editor; + } delete scenario; cout << "Scenario closed...\n"; delete sfxeng; @@ -77,10 +81,6 @@ delete sndcache; cout << "Deleting ImageCache...\n"; delete imgcache; - if (editor) { - cout << "Deleting Editor...\n"; - delete editor; - } cout << "Quiting SDL...\n"; SDL_Quit(); exit(errorcode); Modified: trunk/src/objectpools.cpp =================================================================== --- trunk/src/objectpools.cpp 2005-08-31 13:09:29 UTC (rev 126) +++ trunk/src/objectpools.cpp 2005-08-31 15:10:27 UTC (rev 127) @@ -123,10 +123,11 @@ ///\todo Fix this mess object_iterator ObjectsPool::removeObject(object_iterator it) { if (it!=objectspool.end()) { - objectspool.erase(*it); - if (Character* ptrc = dynamic_cast(*it)) { + Object* obj=*it; + objectspool.erase(obj); + if (Character* ptrc = dynamic_cast(obj)) { characterspool.erase(ptrc); - if(Player* ptrv = dynamic_cast(*it)) { + if(Player* ptrv = dynamic_cast(obj)) { if (playerspool.erase(ptrv)) { currentplayer=playerspool.begin(); if (currentplayer!=playerspool.end()) { @@ -134,10 +135,10 @@ scenario->player=*currentplayer; } else scenario->player=NULL; } - } else if (Monster* ptrm = dynamic_cast(*it)) monsterspool.erase(ptrm); + } else if (Monster* ptrm = dynamic_cast(obj)) monsterspool.erase(ptrm); } - (*it)->destroy(); - return (++it); + (obj)->destroy(); + return (objectspool.begin()); } else return objectspool.end(); } Modified: trunk/src/scenario.cpp =================================================================== --- trunk/src/scenario.cpp 2005-08-31 13:09:29 UTC (rev 126) +++ trunk/src/scenario.cpp 2005-08-31 15:10:27 UTC (rev 127) @@ -77,7 +77,6 @@ int Scenario::reloadMap() { reinitMap(); - sfxeng->playMusic((config.datadir + "01theme.wav").c_str()); string image; string cname,arg1,arg2,arg3; Uint16 x,y; @@ -127,6 +126,8 @@ } } + sfxeng->playMusic((config.datadir + "01theme.wav").c_str()); + //Has a background been found? if (background) { if (pool->playerspool.size()>0) player=*pool->playerspool.begin(); From DONOTREPLY at icculus.org Wed Aug 31 11:44:55 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 31 Aug 2005 11:44:55 -0400 Subject: r128 - trunk/src Message-ID: <20050831154455.13945.qmail@icculus.org> Author: jonas Date: 2005-08-31 11:44:55 -0400 (Wed, 31 Aug 2005) New Revision: 128 Modified: trunk/src/editor.cpp trunk/src/input.cpp trunk/src/input.h Log: minor editing changes (faster shift speed) Modified: trunk/src/editor.cpp =================================================================== --- trunk/src/editor.cpp 2005-08-31 15:10:27 UTC (rev 127) +++ trunk/src/editor.cpp 2005-08-31 15:44:55 UTC (rev 128) @@ -19,7 +19,7 @@ } void Editor::run_action(Uint32 action, Uint16 x, Uint16 y) { - if (action==EDIT_RESET_ACTIONS) { + if (action&EDIT_RESET_ACTIONS) { for (Uint8 i=0; i<6; i++) { action_mouse_pressed[i]=NOTHING; action_mouse_released[i]=NOTHING; @@ -27,16 +27,16 @@ action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_ACT_BOX; action_mouse_pressed[SDL_BUTTON_RIGHT]=EDIT_BOX; action_mouse_released[SDL_BUTTON_RIGHT]=EDIT_ACT_BOX; - } else if (action==EDIT_BOX) { + } else if (action&EDIT_BOX) { setBox(new EditBox(x,y)); - } else if (action==EDIT_ACT_BOX) { + } else if (action&EDIT_ACT_BOX) { if (box) box->act(box->getCurrentEntry(x,y)); - } else if (action==EDIT_PLACE_OBJECT) { + } else if (action&EDIT_PLACE_OBJECT) { string next_name=scenario->pool->getNextObjectName(place_name); if (scenario->pool->addObjectbyName(place_name,place_image,x,y,next_name)) { appendtoBuf(place_name+" "+place_image+" "+itos(x)+" "+itos(y)+" "+next_name); } - action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_ACT_BOX; +// action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_ACT_BOX; } else { } } @@ -246,7 +246,6 @@ editor->place_image=""; } editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_PLACE_OBJECT; - editor->action_mouse_released[SDL_BUTTON_LEFT]=EDIT_RESET_ACTIONS; editor->closeBox(); } } Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-08-31 15:10:27 UTC (rev 127) +++ trunk/src/input.cpp 2005-08-31 15:44:55 UTC (rev 128) @@ -221,12 +221,12 @@ } keystate = SDL_GetKeyState(NULL); if (keyState(KEY_LEFT)) { - gfxeng->addShift(-1,0); + gfxeng->addShift(-SHIFT_SPEED,0); } else if (keyState(KEY_RIGHT)) { - gfxeng->addShift(1,0); + gfxeng->addShift(SHIFT_SPEED,0); } else if (keyState(KEY_UP)) { - gfxeng->addShift(0,-1); + gfxeng->addShift(0,-SHIFT_SPEED); } else if (keyState(KEY_DOWN)) { - gfxeng->addShift(0,1); + gfxeng->addShift(0,SHIFT_SPEED); } } Modified: trunk/src/input.h =================================================================== --- trunk/src/input.h 2005-08-31 15:10:27 UTC (rev 127) +++ trunk/src/input.h 2005-08-31 15:44:55 UTC (rev 128) @@ -1,6 +1,8 @@ #ifndef DEF_INPUT_H #define DEF_INPUT_H 1 +#define SHIFT_SPEED 10 + /** \brief Handels keyboard events \remark A key release event which is passed on to the PhysicHandler From DONOTREPLY at icculus.org Wed Aug 31 16:41:43 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 31 Aug 2005 16:41:43 -0400 Subject: r129 - trunk/src Message-ID: <20050831204143.4113.qmail@icculus.org> Author: jonas Date: 2005-08-31 16:41:43 -0400 (Wed, 31 Aug 2005) New Revision: 129 Modified: trunk/src/common.cpp trunk/src/common.h trunk/src/editor.cpp trunk/src/gfxeng.cpp trunk/src/input.cpp trunk/src/lost_penguins.cpp trunk/src/menu.cpp trunk/src/physics.cpp Log: show cursor when appropriate, allow to disable animations (faster), always reloadMap before placing a unit Modified: trunk/src/common.cpp =================================================================== --- trunk/src/common.cpp 2005-08-31 15:44:55 UTC (rev 128) +++ trunk/src/common.cpp 2005-08-31 20:41:43 UTC (rev 129) @@ -37,3 +37,30 @@ if (a>=0) return a=max(0,a+b); else return a=min(0,a-b); } + +void setGameMode(Uint8 newmode) { + game_mode=newmode; + if (game_mode&GAME_EDIT && !(game_mode&GAME_MENU)) { + SDL_ShowCursor(SDL_ENABLE); + } else { + SDL_ShowCursor(SDL_DISABLE); + } +} + +void addGameMode(Uint8 addmode) { + game_mode|=addmode; + if (game_mode&GAME_EDIT && !(game_mode&GAME_MENU)) { + SDL_ShowCursor(SDL_ENABLE); + } else { + SDL_ShowCursor(SDL_DISABLE); + } +} + +void removeGameMode(Uint8 rmmode) { + game_mode&=~rmmode; + if (game_mode&GAME_EDIT && !(game_mode&GAME_MENU)) { + SDL_ShowCursor(SDL_ENABLE); + } else { + SDL_ShowCursor(SDL_DISABLE); + } +} Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-08-31 15:44:55 UTC (rev 128) +++ trunk/src/common.h 2005-08-31 20:41:43 UTC (rev 129) @@ -65,8 +65,9 @@ #define GAME_PAUSED 0x00000001 #define GAME_PLAY 0x00000002 -#define GAME_EDIT 0x00000004 -#define GAME_MENU 0x00000008 +#define GAME_MENU 0x00000004 +#define GAME_EDIT 0x00000008 +#define GAME_EDIT_NOANIM 0x00000010 enum ConfigKey { KEY_START, @@ -85,7 +86,8 @@ KEY_FPS, KEY_BAR, KEY_FULL, - KEY_QUIT + KEY_QUIT, + KEY_NOANIM }; /**\brief Collision type @@ -143,6 +145,12 @@ /// Helper function boost that increases/decreases the absolute value int boost(int,int); +/// Set game mode +void setGameMode(Uint8); +/// Add game mode +void addGameMode(Uint8); +/// Remove game mode +void removeGameMode(Uint8); /// Set the current menu Menu* setMenu(Menu* newmenu); /// Close the current menus Modified: trunk/src/editor.cpp =================================================================== --- trunk/src/editor.cpp 2005-08-31 15:44:55 UTC (rev 128) +++ trunk/src/editor.cpp 2005-08-31 20:41:43 UTC (rev 129) @@ -3,6 +3,7 @@ #include "objectpools.h" #include "menu.h" #include "font.h" +#include "gfxeng.h" #include "editor.h" @@ -19,6 +20,7 @@ } void Editor::run_action(Uint32 action, Uint16 x, Uint16 y) { + gfxeng->update(UPDATE_ALL); if (action&EDIT_RESET_ACTIONS) { for (Uint8 i=0; i<6; i++) { action_mouse_pressed[i]=NOTHING; @@ -32,6 +34,7 @@ } else if (action&EDIT_ACT_BOX) { if (box) box->act(box->getCurrentEntry(x,y)); } else if (action&EDIT_PLACE_OBJECT) { + scenario->reloadMap(); string next_name=scenario->pool->getNextObjectName(place_name); if (scenario->pool->addObjectbyName(place_name,place_image,x,y,next_name)) { appendtoBuf(place_name+" "+place_image+" "+itos(x)+" "+itos(y)+" "+next_name); @@ -73,10 +76,12 @@ } Box* Editor::setBox(Box* newbox) { + gfxeng->update(UPDATE_ALL); return box=newbox; } void Editor::closeBox() { + gfxeng->update(UPDATE_ALL); if (box) delete box; box=NULL; } @@ -95,6 +100,7 @@ } void Box::act(Sint8) { + gfxeng->update(UPDATE_ALL); editor->closeBox(); } @@ -130,6 +136,7 @@ } void Box::update() { + gfxeng->update(UPDATE_ALL); if (surface==NULL) { getArea(); SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask); @@ -200,6 +207,7 @@ } void EditBox::act(Sint8 curentry) { + gfxeng->update(UPDATE_ALL); if (curentry==-1 || curentry >= (Sint8)entries.size()) { editor->closeBox(); } else { Modified: trunk/src/gfxeng.cpp =================================================================== --- trunk/src/gfxeng.cpp 2005-08-31 15:44:55 UTC (rev 128) +++ trunk/src/gfxeng.cpp 2005-08-31 20:41:43 UTC (rev 129) @@ -71,9 +71,11 @@ } else if (game_mode&GAME_EDIT) { if (show_fps) toggleFPS(); if (show_bar) togglePlayerBar(); - drawScene(); - drawBox(); - updatetype=UPDATE_ALL; + if (!(game_mode&GAME_EDIT_NOANIM) || updatetype==UPDATE_ALL) { + drawScene(); + drawBox(); + updatetype=UPDATE_ALL; + } } else return; //This is the most time consuming operation if (updatetype!=UPDATE_NOTHING) SDL_Flip(screen); Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-08-31 15:44:55 UTC (rev 128) +++ trunk/src/input.cpp 2005-08-31 20:41:43 UTC (rev 129) @@ -109,7 +109,7 @@ if (key==config.keybind[KEY_SWITCH]) { scenario->pool->switchPlayer(); } else if (key==config.keybind[KEY_PAUSE]) { - game_mode&=~GAME_PAUSED; + removeGameMode(GAME_PAUSED); sfxeng->resumeMusic(); } else if (key==config.keybind[KEY_MENU]) { sfxeng->pauseMusic(); @@ -151,7 +151,7 @@ if (key==config.keybind[KEY_SWITCH]) { scenario->pool->switchPlayer(); } else if (key==config.keybind[KEY_PAUSE]) { - game_mode|=GAME_PAUSED; + addGameMode(GAME_PAUSED); sfxeng->playWAV(au_pause); sfxeng->pauseMusic(); } else if (key==config.keybind[KEY_MENU]) { @@ -204,13 +204,21 @@ SDLKey key=event.key.keysym.sym; keypressed[key]=true; if (key==config.keybind[KEY_FULL]) { - gfxeng->toggleFullScreen(); + gfxeng->toggleFullScreen(); } else if (key==config.keybind[KEY_MENU]) { - sfxeng->pauseMusic(); - setMenu(new EditMenu()); - gfxeng->update(UPDATE_ALL); + sfxeng->pauseMusic(); + setMenu(new EditMenu()); + gfxeng->update(UPDATE_ALL); } else if (key==config.keybind[KEY_QUIT]) { - quitGame(0); + quitGame(0); + } else if (key==config.keybind[KEY_NOANIM]) { + gfxeng->update(UPDATE_ALL); + if (game_mode&GAME_EDIT_NOANIM) { + removeGameMode(GAME_EDIT_NOANIM); + } else { + scenario->reloadMap(); + addGameMode(GAME_EDIT_NOANIM); + } } break; } Modified: trunk/src/lost_penguins.cpp =================================================================== --- trunk/src/lost_penguins.cpp 2005-08-31 15:44:55 UTC (rev 128) +++ trunk/src/lost_penguins.cpp 2005-08-31 20:41:43 UTC (rev 129) @@ -32,7 +32,7 @@ cout << "Couldn't initialize SDL!\n"; exit(-1); } - SDL_ShowCursor(SDL_ENABLE); + SDL_ShowCursor(SDL_DISABLE); //Change directory to datadir cout << "ImageCache...\n"; @@ -113,6 +113,7 @@ config.keybind[KEY_SWITCH] = SDLK_LCTRL; config.keybind[KEY_PAUSE] = SDLK_TAB; config.keybind[KEY_MENU] = SDLK_ESCAPE; + config.keybind[KEY_NOANIM] = SDLK_F3; config.keybind[KEY_FPS] = SDLK_F2; config.keybind[KEY_BAR] = SDLK_F1; config.keybind[KEY_FULL] = SDLK_f; Modified: trunk/src/menu.cpp =================================================================== --- trunk/src/menu.cpp 2005-08-31 15:44:55 UTC (rev 128) +++ trunk/src/menu.cpp 2005-08-31 20:41:43 UTC (rev 129) @@ -11,8 +11,8 @@ if (menu) gfxeng->update(UPDATE_MENU); else gfxeng->update(UPDATE_ALL); newmenu->setLast(menu); - if (newmenu) game_mode|=GAME_MENU; - else game_mode&=~GAME_MENU; + if (newmenu) addGameMode(GAME_MENU); + else removeGameMode(GAME_MENU); return menu=newmenu; } @@ -22,8 +22,8 @@ Menu* tmp=menu->getLast(); delete menu; if (!tmp) gfxeng->update(UPDATE_ALL); - if (tmp) game_mode|=GAME_MENU; - else game_mode&=~GAME_MENU; + if (tmp) addGameMode(GAME_MENU); + else removeGameMode(GAME_MENU); return menu=tmp; } else { gfxeng->update(UPDATE_ALL); @@ -66,7 +66,7 @@ case 0: { if ((config.map!="") && (scenario->loadMap(config.map)==0)) { closeMenu(); - game_mode|=GAME_PLAY; + addGameMode(GAME_PLAY); cout << "Starting game...\n" << endl; } else { cout << "Select a valid map first...\n" << endl; @@ -78,7 +78,7 @@ if ((config.map!="") && (scenario->loadMap(config.map)==0)) { closeMenu(); cout << "Starting editor...\n" << endl; - game_mode|=GAME_EDIT; + addGameMode(GAME_EDIT); if (!editor) editor=new Editor(); } else { cout << "Select a valid map first...\n" << endl; Modified: trunk/src/physics.cpp =================================================================== --- trunk/src/physics.cpp 2005-08-31 15:44:55 UTC (rev 128) +++ trunk/src/physics.cpp 2005-08-31 20:41:43 UTC (rev 129) @@ -38,6 +38,7 @@ reset_time=false; tcurrent=SDL_GetTicks(); updateGame(); + } else if (game_mode&GAME_EDIT_NOANIM) { } else if (game_mode&GAME_EDIT) { if (reset_time) { dt=0; From DONOTREPLY at icculus.org Wed Aug 31 20:01:51 2005 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 31 Aug 2005 20:01:51 -0400 Subject: r130 - trunk/src Message-ID: <20050901000151.16899.qmail@icculus.org> Author: jonas Date: 2005-08-31 20:01:51 -0400 (Wed, 31 Aug 2005) New Revision: 130 Modified: trunk/src/common.h trunk/src/editor.cpp trunk/src/editor.h trunk/src/input.cpp Log: fixed Editor::update() to always perform an update, added TextInputBox to read text input... Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2005-08-31 20:41:43 UTC (rev 129) +++ trunk/src/common.h 2005-09-01 00:01:51 UTC (rev 130) @@ -68,6 +68,7 @@ #define GAME_MENU 0x00000004 #define GAME_EDIT 0x00000008 #define GAME_EDIT_NOANIM 0x00000010 +#define GAME_TEXT_INPUT 0x00000020 enum ConfigKey { KEY_START, Modified: trunk/src/editor.cpp =================================================================== --- trunk/src/editor.cpp 2005-08-31 20:41:43 UTC (rev 129) +++ trunk/src/editor.cpp 2005-09-01 00:01:51 UTC (rev 130) @@ -137,44 +137,44 @@ void Box::update() { gfxeng->update(UPDATE_ALL); - if (surface==NULL) { - getArea(); - SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask); - surface=SDL_DisplayFormatAlpha(tmp); - SDL_FreeSurface(tmp); - SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180)); + getArea(); - /* create a border */ - Sint16 tmph=0; - SDL_Rect line; - line.x=0; - line.y=0; - line.w=BORDERSIZE; - line.h=area.h; - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - line.x=area.w-BORDERSIZE; - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - line.x=0; - line.y=0; - line.w=area.w; - line.h=BORDERSIZE; - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - line.y=area.h-BORDERSIZE; - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + if (surface!=NULL) SDL_FreeSurface(surface); + SDL_Surface* tmp=SDL_CreateRGBSurface(vflags, area.w, area.h, 32, rmask, gmask, bmask, amask); + surface=SDL_DisplayFormatAlpha(tmp); + SDL_FreeSurface(tmp); - /* write title */ - font_title->writeCenter(surface,title,WFONT); - line.y=font_title->getHeight()+(int)((DFONT-line.h)/2); - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - line.h=LINESIZE; + SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180)); + /* create a border */ + Sint16 tmph=0; + SDL_Rect line; + line.x=0; + line.y=0; + line.w=BORDERSIZE; + line.h=area.h; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.x=area.w-BORDERSIZE; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.x=0; + line.y=0; + line.w=area.w; + line.h=BORDERSIZE; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.y=area.h-BORDERSIZE; + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); - /* write entries */ - for (Uint8 i=0; igetHeight()*i+WFONT+font_title->getHeight(); - font->writeCenter(surface,entries[i],tmph); - line.y=tmph+font->getHeight()+(int)((DFONT-line.h)/2); - SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,180)); - } + /* write title */ + font_title->writeCenter(surface,title,WFONT); + line.y=font_title->getHeight()+(int)((DFONT-line.h)/2); + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255)); + line.h=LINESIZE; + + /* write entries */ + for (Uint8 i=0; igetHeight()*i+WFONT+font_title->getHeight(); + font->writeCenter(surface,entries[i],tmph); + line.y=tmph+font->getHeight()+(int)((DFONT-line.h)/2); + SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,180)); } } @@ -257,3 +257,38 @@ editor->closeBox(); } } + +TextInputBox::TextInputBox(Sint16 x,Sint16 y): Box(x,y), + currententry(-1) { + SDL_EnableUNICODE(1); + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL); + addGameMode(GAME_TEXT_INPUT); +} +TextInputBox::~TextInputBox() { + SDL_EnableUNICODE(0); + SDL_EnableKeyRepeat(0,SDL_DEFAULT_REPEAT_INTERVAL); + removeGameMode(GAME_TEXT_INPUT); + editor->run_action(EDIT_RESET_ACTIONS); +} + +void TextInputBox::act(Sint8 button) { + if (button>=0 && (Uint8)buttoncloseBox(); + // Backspace + } else if (akey==8) { + if ( entries[currententry].begin() != entries[currententry].end() ) { + entries[currententry].erase(entries[currententry].end()-1); + gfxeng->update(UPDATE_ALL); + update(); + } + } else if ((Uint16)akey<32 || (Uint16)akey>126) { + } else { + entries[currententry]+=(char)akey; + gfxeng->update(UPDATE_ALL); + update(); + } +} Modified: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2005-08-31 20:41:43 UTC (rev 129) +++ trunk/src/editor.h 2005-09-01 00:01:51 UTC (rev 130) @@ -15,10 +15,11 @@ public: Box(Sint16,Sint16); virtual ~Box(); - /// Name of the menu + /// Name of the box string title; - /// Main menu function, depends on currententry (changed by input), overload this. + /// Activate specified entry, if no entry is selected this is -1 virtual void act(Sint8) = 0; + virtual void input(Uint16) { } Uint8 getSize() { return entries.size(); } @@ -47,6 +48,17 @@ virtual void act(Sint8); }; +class TextInputBox : public Box { + public: + TextInputBox(Sint16,Sint16); + virtual ~TextInputBox(); + virtual void act(Sint8); + virtual void input(Uint16); + protected: + Sint8 currententry; +}; + + /** \brief Handels editor specific tasks */ Modified: trunk/src/input.cpp =================================================================== --- trunk/src/input.cpp 2005-08-31 20:41:43 UTC (rev 129) +++ trunk/src/input.cpp 2005-09-01 00:01:51 UTC (rev 130) @@ -203,21 +203,26 @@ case SDL_KEYDOWN: { SDLKey key=event.key.keysym.sym; keypressed[key]=true; - if (key==config.keybind[KEY_FULL]) { - gfxeng->toggleFullScreen(); - } else if (key==config.keybind[KEY_MENU]) { - sfxeng->pauseMusic(); - setMenu(new EditMenu()); - gfxeng->update(UPDATE_ALL); - } else if (key==config.keybind[KEY_QUIT]) { - quitGame(0); - } else if (key==config.keybind[KEY_NOANIM]) { - gfxeng->update(UPDATE_ALL); - if (game_mode&GAME_EDIT_NOANIM) { - removeGameMode(GAME_EDIT_NOANIM); - } else { - scenario->reloadMap(); - addGameMode(GAME_EDIT_NOANIM); + if (game_mode&GAME_TEXT_INPUT) { + Uint16 unikey=event.key.keysym.unicode; + if (unikey<127) editor->box->input(unikey); + } else { + if (key==config.keybind[KEY_FULL]) { + gfxeng->toggleFullScreen(); + } else if (key==config.keybind[KEY_MENU]) { + sfxeng->pauseMusic(); + setMenu(new EditMenu()); + gfxeng->update(UPDATE_ALL); + } else if (key==config.keybind[KEY_QUIT]) { + quitGame(0); + } else if (key==config.keybind[KEY_NOANIM]) { + gfxeng->update(UPDATE_ALL); + if (game_mode&GAME_EDIT_NOANIM) { + removeGameMode(GAME_EDIT_NOANIM); + } else { + scenario->reloadMap(); + addGameMode(GAME_EDIT_NOANIM); + } } } break;