r166 - trunk/src

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Sep 11 07:22:43 EDT 2005


Author: jonas
Date: 2005-09-11 07:22:42 -0400 (Sun, 11 Sep 2005)
New Revision: 166

Modified:
   trunk/src/common.h
   trunk/src/editor.cpp
   trunk/src/editor.h
   trunk/src/gfxeng.cpp
   trunk/src/input.cpp
   trunk/src/lost_penguins.cpp
   trunk/src/objects_common.cpp
   trunk/src/objects_common.h
   trunk/src/scenario.cpp
   trunk/src/scenario.h
Log:
added editor selection support

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/common.h	2005-09-11 11:22:42 UTC (rev 166)
@@ -124,7 +124,10 @@
     KEY_FULL,
     KEY_QUIT,
     KEY_NOANIM,
-    KEY_DEBUG
+    KEY_DEBUG,
+    KEY_ADD_SEL,
+    KEY_RM_SEL,
+    KEY_DEL
 };
 
 enum BasePointType {

Modified: trunk/src/editor.cpp
===================================================================
--- trunk/src/editor.cpp	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/editor.cpp	2005-09-11 11:22:42 UTC (rev 166)
@@ -4,6 +4,7 @@
 #include "menu.h"
 #include "font.h"
 #include "gfxeng.h"
+#include "input.h"
 #include "objects_common.h"
 #include "editor.h"
 
@@ -19,37 +20,98 @@
     closeBox();
 }
 
+void Editor::updateSelection(Sint16 x, Sint16 y) {
+    if (!select_start) return;
+    select_rect.w=abs(x-select_start_x);
+    select_rect.h=abs(y-select_start_y);
+    if (x>select_start_x) select_rect.x=select_start_x;
+    else select_rect.x=x;
+    if (y>select_start_y) select_rect.y=select_start_y;
+    else select_rect.y=y;
+}
+
 void Editor::run_action(Uint32 action, Uint16 x, Uint16 y) {
     SDL_Rect shift=gfxeng->getShift();
     Sint16 xs=x-shift.x;
     Sint16 ys=y-shift.y;
 
     gfxeng->update(UPDATE_ALL);
-    if (action&EDIT_RESET_ACTIONS) {
+    if (action&EDIT_MOUSE_MOTION) {
+        updateSelection(xs,ys);
+    } else 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_LEFT]=EDIT_SEL_ACT_BOX;
+        action_mouse_released[SDL_BUTTON_LEFT]=EDIT_SELECT_END;
         action_mouse_pressed[SDL_BUTTON_RIGHT]=EDIT_BOX;
         action_mouse_released[SDL_BUTTON_RIGHT]=EDIT_ACT_BOX;
+        select_start=false;
     } else if (action&EDIT_BOX) {
         setBox(new EditBox(x,y));
+    } else if (action&EDIT_SEL_ACT_BOX) {
+        if (box) {
+            Sint8 tmp=box->getCurrentEntry(x,y);
+            if (tmp==-1) run_action(EDIT_SELECT_START,x,y);
+            else box->act(tmp);
+        } else {
+            run_action(EDIT_SELECT_START,x,y);
+        }
     } else if (action&EDIT_ACT_BOX) {
-        if (box) box->act(box->getCurrentEntry(x,y));
-    } else if (action&EDIT_REMOVE_OBJECT) {
-        Object* obj=scenario->getObjectAt(xs,ys);
-        if (obj) {
-            if (removefromBuf(obj->getName()).empty()) {
-                cout << "Unable to remove object " << obj->getName() << ": Name identifier not found!" << endl;
-            } else scenario->reloadMap();
+        Sint8 tmp=box->getCurrentEntry(x,y);
+        if (box) box->act(tmp);
+    } else if (action&EDIT_REMOVE_OBJECTS) {
+        std::set<string>::iterator sit=selection.begin();
+        while (sit!=selection.end()) {
+            if (removefromBuf(*sit).empty()) {
+                cout << "Unable to remove object " << (*sit) << endl;
+            }
+            ++sit;
         }
+        scenario->reloadMap();
     } else if (action&EDIT_PLACE_OBJECT) {
         scenario->reloadMap();
         if (scenario->pool->addObjectbyName(place_name,xs,ys,place_parameters)) {
             appendtoBuf(place_name+" "+itos(xs)+" "+itos(ys)+" "+putParameters(place_parameters));
         }
         place_parameters["name"]=scenario->pool->getNextObjectName(place_name);
+    } else if (action&EDIT_SELECT_START) {
+        select_start=true;
+        select_start_x=xs;
+        select_start_y=ys;
+        select_rect.x=select_start_x;
+        select_rect.y=select_start_y;
+        select_rect.w=select_rect.h=0;
+    } else if (action&EDIT_SELECT_END) {
+        updateSelection(xs,ys);
+        select_start=false;
+        std::set<Object*> objects_sel;
+        Object* obj=NULL;
+        if (select_rect.w==0 && select_rect.h==0) {
+            if ((obj=scenario->getObjectAt(xs,ys))!=NULL) objects_sel.insert(obj);
+        } else {
+            objects_sel=scenario->getObjectsIn(ALL,select_rect);
+        }
+        object_iterator obit=objects_sel.begin();
+
+        if (input->keyState(KEY_ADD_SEL)) {
+            while (obit!=objects_sel.end()) {
+                selection.insert((*obit)->getName());
+                ++obit;
+                                      }
+        } else if (input->keyState(KEY_RM_SEL)) {
+            while (obit!=objects_sel.end()) {
+                selection.erase((*obit)->getName());
+                ++obit;
+            }
+        } else {
+            selection.clear();
+            while (obit!=objects_sel.end()) {
+                selection.insert((*obit)->getName());
+                ++obit;
+            }
+        }
     } else { }
 }
 
@@ -144,7 +206,7 @@
     }
     Sint16 tmp=y-area.y-WFONT-font_title->getHeight()-(int)(DFONT/2);
     Uint16 entrysize=DFONT+font->getHeight();
-    Uint8 currententry=0;
+    Sint8 currententry=0;
     while (tmp>entrysize) {
         tmp-=entrysize;
         ++currententry;
@@ -205,10 +267,8 @@
     entries.push_back("Run");
     entries.push_back("Quit");
     entries.push_back("");
-    entries.push_back("Place Object");
-    entries.push_back("Remove Object");
-    entries.push_back("Move Object");
-    entries.push_back("Configure Object");
+    entries.push_back("Place Objects");
+    entries.push_back("Select Objects");
     update();
 }
 
@@ -233,15 +293,12 @@
         setGameMode(GAME_PLAY);
         scenario->reloadMap();
         editor->closeBox();
-    } else if (entries[curentry]=="Place Object") {
+    } else if (entries[curentry]=="Place Objects") {
         editor->setBox(new PlaceBox(area.x,area.y));
-    } else if (entries[curentry]=="Remove Object") {
-        editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_REMOVE_OBJECT;
+    } else if (entries[curentry]=="Select Objects") {
+        editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_SELECT_START;
+        editor->action_mouse_released[SDL_BUTTON_LEFT]=EDIT_SELECT_END;
         editor->closeBox();
-    } else if (entries[curentry]=="Move Object") {
-        editor->closeBox();
-    } else if (entries[curentry]=="Configure Object") {
-        editor->closeBox();
     } else if (entries[curentry]=="Quit") {
         quitGame(0);
     } else {

Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/editor.h	2005-09-11 11:22:42 UTC (rev 166)
@@ -2,10 +2,14 @@
 #define DEF_EDITOR_H 1
 
 #define EDIT_RESET_ACTIONS  0x00000001
+#define EDIT_MOUSE_MOTION   0x00000002
 #define EDIT_BOX            0x00000004
 #define EDIT_ACT_BOX        0x00000008
-#define EDIT_PLACE_OBJECT   0x00000010
-#define EDIT_REMOVE_OBJECT  0x00000020
+#define EDIT_SEL_ACT_BOX    0x00000010
+#define EDIT_PLACE_OBJECT   0x00000020
+#define EDIT_REMOVE_OBJECTS 0x00000040
+#define EDIT_SELECT_START   0x00000080
+#define EDIT_SELECT_END     0x00000100
 
 /** \brief abstract Box base class
 
@@ -164,6 +168,13 @@
         Uint32 action_mouse_pressed[6];
         /// Action type for the mouse buttons when releasing the button
         Uint32 action_mouse_released[6];
+        std::set<string> selection;
+        bool select_start;
+        SDL_Rect select_rect;
+        Sint16 select_start_x;
+        Sint16 select_start_y;
+    private:
+        void updateSelection(Sint16 x, Sint16 y);
 };
 
 #endif

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/gfxeng.cpp	2005-09-11 11:22:42 UTC (rev 166)
@@ -165,9 +165,21 @@
             debugrect=*(*obit)->getPos();
             drawRectangle(debugrect,1,SDL_MapRGB(screen->format,100,20,0));
         }
+        // TODO: fix this gfxeng mess
+        if (editor && game_mode&GAME_EDIT) {
+            if (editor->selection.find((*obit)->getName())!=editor->selection.end()) {
+                debugrect=*(*obit)->getPos();
+                drawRectangle(debugrect,3,SDL_MapRGB(screen->format,100,100,0));
+            }
+        }
         SDL_BlitSurface((*obit)->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
         ++obit;
     }
+    // TODO: fix this gfxeng mess
+    if (editor->select_start) {
+        debugrect=editor->select_rect;
+        drawRectangle(debugrect,1,SDL_MapRGB(screen->format,50,50,50));
+    }
 
     if (game_mode&GAME_PLAY && scenario->player!=NULL) {
         tmprect=(scenario->player->getDrawPos());

Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/input.cpp	2005-09-11 11:22:42 UTC (rev 166)
@@ -194,6 +194,10 @@
             case SDL_QUIT: {
                 quitGame(0);
             }
+            case SDL_MOUSEMOTION: {
+                editor->run_action(EDIT_MOUSE_MOTION,event.motion.x,event.motion.y);
+                break;
+            }
             case SDL_MOUSEBUTTONUP: {
                 editor->run_action(editor->getActionMReleased(event.button.button),event.button.x,event.button.y);
                 break;
@@ -215,6 +219,8 @@
                         sfxeng->pauseMusic();
                         setMenu(new EditMenu());
                         gfxeng->update(UPDATE_ALL);
+                    } else if (key==config.keybind[KEY_DEL]) {
+                        editor->run_action(EDIT_REMOVE_OBJECTS);
                     } else if (key==config.keybind[KEY_QUIT]) {
                         quitGame(0);
                     } else if (key==config.keybind[KEY_NOANIM]) {

Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/lost_penguins.cpp	2005-09-11 11:22:42 UTC (rev 166)
@@ -130,6 +130,9 @@
     config.keybind[KEY_BAR]     = SDLK_F1;
     config.keybind[KEY_FULL]    = SDLK_f;
     config.keybind[KEY_QUIT]    = SDLK_q;
+    config.keybind[KEY_ADD_SEL] = SDLK_LSHIFT;
+    config.keybind[KEY_RM_SEL]  = SDLK_LCTRL;
+    config.keybind[KEY_DEL]     = SDLK_DELETE;
 
     configfile.open(filename.c_str());
     if (!configfile) return 0;

Modified: trunk/src/objects_common.cpp
===================================================================
--- trunk/src/objects_common.cpp	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/objects_common.cpp	2005-09-11 11:22:42 UTC (rev 166)
@@ -10,7 +10,7 @@
 Object::Object(Sint16 xcord, Sint16 ycord, ParameterMap& parameters):
   state(NOTHING),
   event(NULL),
-  otype(NOTHING),
+  otype(OTYPE_COMMON),
   delete_flag(false) {
     onum=++scenario->max_obj_num;
 

Modified: trunk/src/objects_common.h
===================================================================
--- trunk/src/objects_common.h	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/objects_common.h	2005-09-11 11:22:42 UTC (rev 166)
@@ -8,6 +8,7 @@
 #define OTYPE_DENSE_U   0x00000004
 #define OTYPE_DENSE_D   0x00000008
 #define OTYPE_DENSE     0x0000000F
+#define OTYPE_COMMON    0x00000010
 #define OTYPE_TOUCH     0x00000020
 #define OTYPE_ENTER     0x00000040
 #define OTYPE_CHARACTER 0x00000080

Modified: trunk/src/scenario.cpp
===================================================================
--- trunk/src/scenario.cpp	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/scenario.cpp	2005-09-11 11:22:42 UTC (rev 166)
@@ -333,6 +333,33 @@
     return tmpset;
 }
 
+std::set<Object *> Scenario::getObjectsIn(Uint16 mask, const SDL_Rect& rect, bool touch, Uint16 distance, Uint16 dir) const {
+    SDL_Rect tmprect=rect;
+    if (dir&DIR_LEFT) {
+        tmprect.x-=distance;
+        tmprect.w+=distance;
+    }
+    if (dir&DIR_RIGHT) {
+        tmprect.x+=distance;
+        tmprect.w+=distance;
+    }
+    if (dir&DIR_UP) {
+        tmprect.y-=distance;
+        tmprect.h+=distance;
+    }
+    if (dir&DIR_DOWN) {
+        tmprect.y+=distance;
+        tmprect.h+=distance;
+    }
+    std::set<Object *> tmpset;
+    object_iterator obit=pool->objectspool.begin();
+    while (obit != pool->objectspool.end()) {
+        if ((((*obit)->getType())&mask) && ((*obit)->isIn(tmprect,touch))) tmpset.insert(*obit);
+        ++obit;
+    }
+    return tmpset;
+}
+
 Object* Scenario::getObjectAt(Sint16 x, Sint16 y, Uint16 mask) const {
     SDL_Rect tmprect;
     tmprect.x=x;

Modified: trunk/src/scenario.h
===================================================================
--- trunk/src/scenario.h	2005-09-09 15:49:26 UTC (rev 165)
+++ trunk/src/scenario.h	2005-09-11 11:22:42 UTC (rev 166)
@@ -46,6 +46,7 @@
         /// \return A set of characters that are inside the enlarged source rectangle
         ///   and that match the specified mask.
         std::set<Character *> getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch=false, Uint16 radius=0, Uint16 dir=DIR_ALL) const;
+        std::set<Object *> getObjectsIn(Uint16 mask, const SDL_Rect& rect, bool touch=false, Uint16 radius=0, Uint16 dir=DIR_ALL) const;
         /// Returns the first found object at the given position
         Object* getObjectAt(Sint16 x, Sint16 y, Uint16 mask=ALL) const;
         /// Returns the directions from the source rectangle to the destination rectangle




More information about the lostpenguins-commits mailing list