pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3162 - in trunk/pingus: . src src/editor


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3162 - in trunk/pingus: . src src/editor
Date: Sat, 15 Sep 2007 22:13:40 +0200

Author: grumbel
Date: 2007-09-15 22:13:40 +0200 (Sat, 15 Sep 2007)
New Revision: 3162

Added:
   trunk/pingus/src/editor/object_selector_set.cpp
   trunk/pingus/src/editor/object_selector_set.hpp
Modified:
   trunk/pingus/TODO
   trunk/pingus/src/SConscript
   trunk/pingus/src/editor/editor_screen.cpp
   trunk/pingus/src/editor/object_selector.cpp
   trunk/pingus/src/editor/object_selector.hpp
   trunk/pingus/src/editor/object_selector_list.cpp
   trunk/pingus/src/editor/object_selector_list.hpp
   trunk/pingus/src/surface.cpp
Log:
- added ObjectSelectorSet

Modified: trunk/pingus/TODO
===================================================================
--- trunk/pingus/TODO   2007-09-15 20:12:48 UTC (rev 3161)
+++ trunk/pingus/TODO   2007-09-15 20:13:40 UTC (rev 3162)
@@ -7,6 +7,8 @@
 Roadmap for Pingus 0.8.0:
 ~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- pingu explosions are rects, should be circles (Vel(rand()%10, rand()%10) vs 
Vel(angle, length))
+
 - add VCR like effect for fast forward
 
 - add slow motion button (dead, turtle, pingu, rabbit)
@@ -77,6 +79,8 @@
 Important:
 ==========
 
+- replace Windstille headers with Pingus header
+
 - create verdana11 for latin2 and latin9
 
 - miner remove graphics looks wrong (cmap instead of gfx?)
@@ -157,16 +161,17 @@
 Important:
 ==========
 
-- ObjectSelector scroll limit is missing, also doesn't display all objects
+- add color prop for surface-background
 
+- make GPType prop
+
 - ObjectSelector need to support more object types: Starbackground, 
SolidColorBackground
 
-- write ObjectSelectorSet: Collection of Objects for the selector
-  (thumbsize should be allowed to differ)
-
 - keyboard shortcuts need to be implemented (use input framework, but
   how without support for keymaps?)
 
+  a       - select all
+  shift+click - add object to selection/remove from selection
   d       - duplicate
   delete  - delete object
   insert  - show/hide objectselector

Modified: trunk/pingus/src/SConscript
===================================================================
--- trunk/pingus/src/SConscript 2007-09-15 20:12:48 UTC (rev 3161)
+++ trunk/pingus/src/SConscript 2007-09-15 20:13:40 UTC (rev 3162)
@@ -106,6 +106,7 @@
 'editor/inputbox.cpp',
 'editor/object_selector.cpp',
 'editor/object_selector_list.cpp',
+'editor/object_selector_set.cpp',
 'editor/object_properties.cpp',
 'editor/level_properties.cpp',
 'editor/action_properties.cpp', 

Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp   2007-09-15 20:12:48 UTC (rev 
3161)
+++ trunk/pingus/src/editor/editor_screen.cpp   2007-09-15 20:13:40 UTC (rev 
3162)
@@ -252,6 +252,7 @@
   plf->save_level(path_manager.complete("levels/editortmpfile.pingus"));
   PingusLevel level("levels/editortmpfile.pingus",
                     Pathname("levels/editortmpfile.pingus", 
Pathname::DATA_PATH));
+
   ScreenManager::instance()->push_screen(new PingusGameSession(level, false), 
true);
 }
 

Modified: trunk/pingus/src/editor/object_selector.cpp
===================================================================
--- trunk/pingus/src/editor/object_selector.cpp 2007-09-15 20:12:48 UTC (rev 
3161)
+++ trunk/pingus/src/editor/object_selector.cpp 2007-09-15 20:13:40 UTC (rev 
3162)
@@ -23,6 +23,7 @@
 **  02111-1307, USA.
 */
 
+#include <boost/bind.hpp>
 #include "gui/display.hpp"
 #include "gui_style.hpp"
 #include "sprite.hpp"
@@ -34,6 +35,7 @@
 #include "editor_viewport.hpp"
 #include "editor_level.hpp"
 #include "object_selector_list.hpp"
+#include "object_selector_set.hpp"
 #include "level_objs.hpp"
 #include "display/drawing_context.hpp"
 #include "gui/gui_manager.hpp"
@@ -43,6 +45,107 @@
 
 namespace Editor {
 
+struct Groundpiece : public ObjectSelectorList::Object 
+{
+  ResDescriptor desc;
+  std::string   type;
+  
+  Groundpiece(const std::string& name, const std::string& type)
+    : Object(Resource::load_sprite(name),
+             Resource::load_thumb_sprite(name)),
+      desc(name),
+      type(type)
+  {}      
+  
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("groundpiece", impl);
+    obj->set_pos(pos);
+    obj->set_res_desc(desc);
+    obj->set_type(type);
+    return obj;
+  }
+};
+
+struct Entrance : public ObjectSelectorList::Object 
+{
+  Entrance()
+    : Object(Resource::load_sprite("entrances/generic"),
+             Resource::load_thumb_sprite("entrances/generic"))
+  {}
+
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("entrance", impl);
+    obj->set_type("generic");
+    obj->set_pos(pos);
+    obj->set_direction("misc");
+    obj->set_release_rate(150);
+    obj->set_owner(0);
+    return obj;
+  }
+};
+
+struct Exit : public ObjectSelectorList::Object 
+{
+  ResDescriptor desc;
+  
+  Exit(const std::string& name)
+    : Object(Resource::load_sprite(name), 
+             Resource::load_thumb_sprite(name)),
+      desc(name)
+  {}
+
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("exit", impl);
+    obj->set_pos(pos);
+    obj->set_res_desc(desc);
+    // obj->set_para();
+    return obj;
+  }
+};
+
+struct Hotspot : public ObjectSelectorList::Object 
+{
+  ResDescriptor desc;
+  
+  Hotspot(const std::string& name)
+    : Object(Resource::load_sprite(name),
+             Resource::load_thumb_sprite(name)),
+      desc(name)
+  {}
+
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("hotspot", impl);
+    obj->set_pos(pos);
+    obj->set_res_desc(desc);
+    // obj->set_para();
+    return obj;
+  }
+};
+
+struct SurfaceBackground : public ObjectSelectorList::Object 
+{
+  ResDescriptor desc;
+  
+  SurfaceBackground(const std::string& name)
+    : Object(Resource::load_sprite(name),
+             Resource::load_thumb_sprite(name)),
+      desc(name)
+  {}
+
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("surface-background", impl);
+    obj->set_pos(Vector3f((float)pos.x, (float)pos.y, -1000.0f)); // FIXME: 
Hack, z-pos handling is messed up
+    obj->set_para_x(1.0f);
+    obj->set_para_y(1.0f);
+    obj->set_scroll_x(0.0f);
+    obj->set_scroll_y(0.0f);
+    obj->set_res_desc(desc);
+    // obj->set_para();
+
+    return obj;
+  }
+};
+
 class ObjectSelectorButton : public GUI::RectComponent
 {
 private:
@@ -54,14 +157,13 @@
   bool   mouse_over;
   bool   mouse_down;
   std::string tooltip;
+  
+public:
+  boost::signal<void()> on_click;
 
-  typedef void (ObjectSelectorList::*Callback)();
-  Callback callback;
-
 public:
   ObjectSelectorButton(ObjectSelectorList* object_list_,
-                       const Vector2i& pos, const std::string& sprite, const 
std::string& tooltip_, 
-                       Callback callback_ = 0)
+                       const Vector2i& pos, const std::string& sprite, const 
std::string& tooltip_)
     : RectComponent(Rect(pos, Size(30, 30))),
       object_list(object_list_),
       button_raised(Resource::load_sprite("core/editor/obj_button-raised")),
@@ -69,8 +171,7 @@
       sprite(Resource::load_sprite(sprite)),
       mouse_over(false),
       mouse_down(false),
-      tooltip(tooltip_),
-      callback(callback_)
+      tooltip(tooltip_)
   {
   }
 
@@ -95,13 +196,13 @@
   }
 
   /** Emmitted when pointer enters the region of the component */
-  void on_pointer_enter () 
+  void on_pointer_enter() 
   {
     mouse_over = true;
   }
 
   /** Emmitted when pointer leaves the region of the component */
-  void on_pointer_leave () 
+  void on_pointer_leave() 
   {
     mouse_over = false;
   }
@@ -114,8 +215,8 @@
   void on_primary_button_release (int x, int y) 
   { 
     mouse_down = false;
-    if (mouse_over && callback)
-      ((*object_list).*callback)();
+    if (mouse_over)
+      on_click();
   }
   
   void update (float delta)
@@ -141,24 +242,51 @@
                                            Rect(2, 2 + 60 + 2, 
rect.get_width() - 2, rect.get_height() - 2)), 
       true);
 
-  add_button("core/editor/obj_entrance",   "Entrance", 
&ObjectSelectorList::set_entrance);
-  add_button("core/editor/obj_gp_ground",  "Groundpiece (ground)", 
&ObjectSelectorList::set_gp_ground);
-  add_button("core/editor/obj_gp_solid",   "Groundpiece (solid)", 
&ObjectSelectorList::set_gp_solid);
-  add_button("core/editor/obj_gp_bridge",      "Groundpiece (bridge)", 
&ObjectSelectorList::set_gp_bridge);
-  add_button("core/editor/obj_gp_transparent", "Groundpiece (transparent)", 
&ObjectSelectorList::set_gp_transparent);
-  add_button("core/editor/obj_gp_remove",      "Groundpiece (remove)", 
&ObjectSelectorList::set_gp_remove);
-  add_button("core/editor/obj_hotspot",    "Hotspot", 
&ObjectSelectorList::set_hotspot);
-  add_button("core/editor/obj_background", "Background", 
&ObjectSelectorList::set_background);
+  gp_ground_set  = create_gp_ground();
+  gp_solid_set   = create_gp_solid();
+  gp_bridge_set  = create_gp_bridge();
+  gp_transparent_set = create_gp_transparent();
+  gp_remove_set  = create_gp_remove();
+  hotspot_set    = create_hotspot();
+  background_set = create_background();
+  entrance_set   = create_entrance();
+  exit_set       = create_exit();
+  liquid_set     = create_liquid();
+  trap_set       = create_trap();
+  weather_set    = create_weather();
+  worldobj_set   = create_worldobj();
+
+  add_button("core/editor/obj_entrance",   "Entrance", entrance_set);
+  add_button("core/editor/obj_gp_ground",  "Groundpiece (ground)", 
gp_ground_set);
+  add_button("core/editor/obj_gp_solid",   "Groundpiece (solid)", 
gp_solid_set);
+  add_button("core/editor/obj_gp_bridge",  "Groundpiece (bridge)", 
gp_bridge_set);
+  add_button("core/editor/obj_gp_transparent", "Groundpiece (transparent)", 
gp_transparent_set);
+  add_button("core/editor/obj_gp_remove",  "Groundpiece (remove)", 
gp_remove_set);
+  add_button("core/editor/obj_hotspot",    "Hotspot", hotspot_set);
+  add_button("core/editor/obj_background", "Background", background_set);
   // -------------------------------
-  add_button("core/editor/obj_exit", "Exit", &ObjectSelectorList::set_exit);
-  add_button("core/editor/obj_liquid", "Liquid", 
&ObjectSelectorList::set_liquid);
-  add_button("core/editor/obj_trap", "Trap", &ObjectSelectorList::set_trap);
-  add_button("core/editor/obj_weather", "Weather", 
&ObjectSelectorList::set_weather);
-  add_button("core/editor/obj_worldobj", "Special Object", 
&ObjectSelectorList::set_worldobj);
+  add_button("core/editor/obj_exit",     "Exit", exit_set);
+  add_button("core/editor/obj_liquid",   "Liquid", liquid_set);
+  add_button("core/editor/obj_trap",     "Trap", trap_set);
+  add_button("core/editor/obj_weather",  "Weather", weather_set);
+  add_button("core/editor/obj_worldobj", "Special Object", worldobj_set);
 }
 
 ObjectSelector::~ObjectSelector()
 {
+  delete worldobj_set;
+  delete weather_set;
+  delete trap_set;
+  delete liquid_set; 
+  delete exit_set;
+  delete entrance_set;
+  delete background_set;
+  delete hotspot_set;
+  delete gp_remove_set;
+  delete gp_transparent_set;
+  delete gp_bridge_set;
+  delete gp_solid_set;
+  delete gp_ground_set;
 }
 
 void
@@ -168,14 +296,16 @@
 }
 
 void
-ObjectSelector::add_button(const std::string& image, const std::string& 
tooltip, Callback callback)
+ObjectSelector::add_button(const std::string& image, const std::string& 
tooltip, 
+                           ObjectSelectorSet* set)
 {
-  add(new ObjectSelectorButton(object_list,
+  ObjectSelectorButton* button;
+  add(button = new ObjectSelectorButton(object_list,
                                Vector2i(2 + button_pos.x * 30,  
                                         2 + button_pos.y * 30),
-                               image, tooltip,
-                               callback), true);
-  
+                               image, tooltip), true);
+  button->on_click.connect(boost::bind(&ObjectSelectorList::set_objects, 
object_list, set));
+
   button_pos.x += 1;
   if (button_pos.x > 7)
     {
@@ -184,6 +314,152 @@
     }
 }
 
+ObjectSelectorSet*
+ObjectSelector::create_objects(const std::string& prefix)
+{
+  ObjectSelectorSet* set = new ObjectSelectorSet(object_list, 48, 48);
+
+  // FIXME: Simple debugging aid, needs to be replaced with custom code for 
the object types
+  std::vector<std::string> lst = Resource::resmgr.get_section(prefix);
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    {
+      // need to reset the align to top/left
+      set->add(new ObjectSelectorList::Object(Resource::load_sprite(*i),
+                          Resource::load_thumb_sprite(*i)));
+    }
+  
+  return set;
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_groundpiece(const std::string& prefix, const 
std::string& type)
+{
+  ObjectSelectorSet* set = new ObjectSelectorSet(object_list, 48, 48);
+
+  std::vector<std::string> lst = Resource::resmgr.get_section(prefix);
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    {
+      //sprite.scale(48, 48);
+      set->add(new Groundpiece(*i, type));
+    }
+
+  return set;
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_gp_ground()
+{
+  return create_groundpiece("groundpieces/ground", "ground");
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_gp_solid()
+{
+  return create_groundpiece("groundpieces/solid", "solid");
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_gp_bridge()
+{
+  return create_groundpiece("groundpieces/bridge", "bridge");
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_gp_transparent()
+{
+  return create_groundpiece("groundpieces/transparent", "transparent");
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_gp_remove()
+{
+  return create_groundpiece("groundpieces/remove", "remove");
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_hotspot()
+{
+  ObjectSelectorSet* set = new ObjectSelectorSet(object_list, 48, 48);
+
+  std::vector<std::string> lst = Resource::resmgr.get_section("hotspots");
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    set->add(new Hotspot(*i));
+  
+  return set;
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_background()
+{
+  ObjectSelectorSet* set = new ObjectSelectorSet(object_list, 48, 48);
+  std::vector<std::string> lst = Resource::resmgr.get_section("textures");
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    set->add(new SurfaceBackground(*i));
+
+  return set;
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_entrance()
+{
+  ObjectSelectorSet* set = new ObjectSelectorSet(object_list, 48, 48);
+  
+  set->add(new Entrance());
+
+  std::vector<std::string> lst = Resource::resmgr.get_section("entrances");
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    {
+      //sprite.scale(48, 48);
+      if (*i != "entrances/generic")
+        set->add(new Hotspot(*i));
+    }
+
+  return set;
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_exit()
+{
+ ObjectSelectorSet* set = new ObjectSelectorSet(object_list, 48, 48);
+
+ std::vector<std::string> lst = Resource::resmgr.get_section("exit");
+ for(std::vector<std::string>::const_iterator i = lst.begin(); i != lst.end(); 
++i)
+    {
+      //sprite.scale(48, 48);
+      set->add(new Exit(*i));
+    }
+ 
+ return set;
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_liquid()
+{
+  return create_objects("liquids");
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_trap()
+{
+  // Need to differentiate the different trap types
+  return create_objects("traps");
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_weather()
+{
+  //create_objects("weather");
+  std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" << 
__LINE__ << std::endl;
+  return new ObjectSelectorSet(object_list, 48, 48);
+}
+
+ObjectSelectorSet*
+ObjectSelector::create_worldobj()
+{
+  std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" << 
__LINE__ << std::endl;
+  return new ObjectSelectorSet(object_list, 48, 48);
+}
+
 } // namespace Editor
 
 /* EOF */

Modified: trunk/pingus/src/editor/object_selector.hpp
===================================================================
--- trunk/pingus/src/editor/object_selector.hpp 2007-09-15 20:12:48 UTC (rev 
3161)
+++ trunk/pingus/src/editor/object_selector.hpp 2007-09-15 20:13:40 UTC (rev 
3162)
@@ -34,6 +34,7 @@
 
 class EditorScreen;
 class ObjectSelectorList;
+class ObjectSelectorSet;
 
 /** */
 class ObjectSelector : public GUI::GroupComponent
@@ -43,6 +44,20 @@
   Vector2i button_pos;
   ObjectSelectorList* object_list;
 
+  ObjectSelectorSet*  gp_ground_set;
+  ObjectSelectorSet*  gp_solid_set;
+  ObjectSelectorSet*  gp_bridge_set;
+  ObjectSelectorSet*  gp_transparent_set;
+  ObjectSelectorSet*  gp_remove_set;
+  ObjectSelectorSet*  hotspot_set;
+  ObjectSelectorSet*  background_set;
+  ObjectSelectorSet*  entrance_set;
+  ObjectSelectorSet*  exit_set;
+  ObjectSelectorSet*  liquid_set;
+  ObjectSelectorSet*  trap_set;
+  ObjectSelectorSet*  weather_set;
+  ObjectSelectorSet*  worldobj_set;
+
 public:
   typedef void (ObjectSelectorList::*Callback)();
   Callback callback;
@@ -51,8 +66,23 @@
   ~ObjectSelector();
 
   void draw_background(DrawingContext& gc);
+  void add_button(const std::string& image, const std::string& tooltip, 
ObjectSelectorSet* set);
 
-  void add_button(const std::string& image, const std::string& tooltip = "", 
Callback callback = 0);
+  ObjectSelectorSet* create_objects(const std::string& prefix);
+  ObjectSelectorSet* create_groundpiece(const std::string& prefix, const 
std::string& type);
+  ObjectSelectorSet* create_gp_ground();
+  ObjectSelectorSet* create_gp_solid();
+  ObjectSelectorSet* create_gp_bridge();
+  ObjectSelectorSet* create_gp_transparent();
+  ObjectSelectorSet* create_gp_remove();
+  ObjectSelectorSet* create_hotspot();
+  ObjectSelectorSet* create_background();
+  ObjectSelectorSet* create_entrance();
+  ObjectSelectorSet* create_exit();
+  ObjectSelectorSet* create_liquid();
+  ObjectSelectorSet* create_trap();
+  ObjectSelectorSet* create_weather();
+  ObjectSelectorSet* create_worldobj();
 
 private:
   ObjectSelector (const ObjectSelector&);

Modified: trunk/pingus/src/editor/object_selector_list.cpp
===================================================================
--- trunk/pingus/src/editor/object_selector_list.cpp    2007-09-15 20:12:48 UTC 
(rev 3161)
+++ trunk/pingus/src/editor/object_selector_list.cpp    2007-09-15 20:13:40 UTC 
(rev 3162)
@@ -26,6 +26,7 @@
 #include <iostream>
 #include "math.hpp"
 #include "editor_screen.hpp"
+#include "object_selector_set.hpp"
 #include "object_selector.hpp"
 #include "editor_viewport.hpp"
 #include "editor_level.hpp"
@@ -36,107 +37,6 @@
 
 namespace Editor {
 
-struct Groundpiece : public ObjectSelectorList::Object 
-{
-  ResDescriptor desc;
-  std::string   type;
-  
-  Groundpiece(const std::string& name, const std::string& type)
-    : Object(Resource::load_sprite(name),
-             Resource::load_thumb_sprite(name)),
-      desc(name),
-      type(type)
-  {}      
-  
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("groundpiece", impl);
-    obj->set_pos(pos);
-    obj->set_res_desc(desc);
-    obj->set_type(type);
-    return obj;
-  }
-};
-
-struct Entrance : public ObjectSelectorList::Object 
-{
-  Entrance()
-    : Object(Resource::load_sprite("entrances/generic"),
-             Resource::load_thumb_sprite("entrances/generic"))
-  {}
-
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("entrance", impl);
-    obj->set_type("generic");
-    obj->set_pos(pos);
-    obj->set_direction("misc");
-    obj->set_release_rate(150);
-    obj->set_owner(0);
-    return obj;
-  }
-};
-
-struct Exit : public ObjectSelectorList::Object 
-{
-  ResDescriptor desc;
-  
-  Exit(const std::string& name)
-    : Object(Resource::load_sprite(name), 
-             Resource::load_thumb_sprite(name)),
-      desc(name)
-  {}
-
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("exit", impl);
-    obj->set_pos(pos);
-    obj->set_res_desc(desc);
-    // obj->set_para();
-    return obj;
-  }
-};
-
-struct Hotspot : public ObjectSelectorList::Object 
-{
-  ResDescriptor desc;
-  
-  Hotspot(const std::string& name)
-    : Object(Resource::load_sprite(name),
-             Resource::load_thumb_sprite(name)),
-      desc(name)
-  {}
-
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("hotspot", impl);
-    obj->set_pos(pos);
-    obj->set_res_desc(desc);
-    // obj->set_para();
-    return obj;
-  }
-};
-
-struct SurfaceBackground : public ObjectSelectorList::Object 
-{
-  ResDescriptor desc;
-  
-  SurfaceBackground(const std::string& name)
-    : Object(Resource::load_sprite(name),
-             Resource::load_thumb_sprite(name)),
-      desc(name)
-  {}
-
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("surface-background", impl);
-    obj->set_pos(Vector3f((float)pos.x, (float)pos.y, -1000.0f)); // FIXME: 
Hack, z-pos handling is messed up
-    obj->set_para_x(1.0f);
-    obj->set_para_y(1.0f);
-    obj->set_scroll_x(0.0f);
-    obj->set_scroll_y(0.0f);
-    obj->set_res_desc(desc);
-    // obj->set_para();
-
-    return obj;
-  }
-};
-
 ObjectSelectorList::ObjectSelectorList(EditorScreen* editor_, ObjectSelector* 
object_selector_, const Rect& rect_)
   : RectComponent(rect_),
     editor(editor_),
@@ -146,55 +46,55 @@
     old_offset(0),
     mode(NOTHING),
     current_object(-1),
-    drag_object(-1)
+    drag_object(-1),
+    set(0)
 {  
 }
 
 void
 ObjectSelectorList::draw(DrawingContext& parent_gc)
 {
-  parent_gc.fill_screen(Color(0,0,0));
-
   DrawingContext& gc = *drawing_context;
   gc.clear();
   gc.fill_screen(Color(100, 100, 100));
-  gc.push_modelview();
-  gc.translate(0, offset);
 
-  Objects::iterator i = objects.begin();
-
-  for(Objects::iterator i = objects.begin(); i != objects.end(); ++i)
+  if (set)
     {
-      int x = (i - objects.begin()) % 5;
-      int y = (i - objects.begin()) / 5;
+      gc.push_modelview();
+      gc.translate(0, offset);
 
-      gc.draw((*i)->thumbnail, Vector2i(x * 48, y * 48));
-
-      gc.draw_rect(x * 48,      y * 48, 
-                   x * 48 + 48, y * 48 + 48, 
-                   Color(155,155,155));
-
-      if (has_mouse_over() && current_object != -1 && (i - objects.begin()) == 
current_object)
+      for(Objects::const_iterator i = set->get_objects().begin(); i != 
set->get_objects().end(); ++i)
         {
-          gc.draw_fillrect(x * 48,      y * 48, 
-                           x * 48 + 48, y * 48 + 48, 
-                           Color(255,255,255, 100));
+          int x = (i - set->get_objects().begin()) % 5;
+          int y = (i - set->get_objects().begin()) / 5;
 
+          gc.draw((*i)->thumbnail, Vector2i(x * 48, y * 48));
+
           gc.draw_rect(x * 48,      y * 48, 
                        x * 48 + 48, y * 48 + 48, 
-                       Color(255,255,255));
+                       Color(155,155,155));
+
+          if (has_mouse_over() && current_object != -1 && (i - 
set->get_objects().begin()) == current_object)
+            {
+              gc.draw_fillrect(x * 48,      y * 48, 
+                               x * 48 + 48, y * 48 + 48, 
+                               Color(255,255,255, 100));
+
+              gc.draw_rect(x * 48,      y * 48, 
+                           x * 48 + 48, y * 48 + 48, 
+                           Color(255,255,255));
+            }
         }
-    }
   
-  gc.pop_modelview();
-
+      gc.pop_modelview();
+    }
   parent_gc.draw(gc);
 
-  if (mode == OBJECT_DRAG)
+  if (set && mode == OBJECT_DRAG)
     {
-      parent_gc.draw(objects[current_object]->sprite, 
-                     real_mouse_pos - 
Vector2i(objects[current_object]->sprite.get_width()/2,
-                                               
objects[current_object]->sprite.get_height()/2), 
+      parent_gc.draw(set->get_objects()[current_object]->sprite, 
+                     real_mouse_pos - 
Vector2i(set->get_objects()[current_object]->sprite.get_width()/2,
+                                               
set->get_objects()[current_object]->sprite.get_height()/2), 
                      2000.0f);
     }
 }
@@ -202,6 +102,8 @@
 void
 ObjectSelectorList::on_primary_button_press (int x, int y)
 {
+  if (!set) return;
+
   if (mode == NOTHING && current_object != -1)
     {
       drag_object = current_object;
@@ -212,6 +114,8 @@
 void
 ObjectSelectorList::on_primary_button_release (int x, int y)
 {
+  if (!set) return;
+
   if (mode == OBJECT_DRAG)
     {
       mode = NOTHING;
@@ -229,10 +133,10 @@
                                                                 y + 
object_selector->get_rect().top);
 
               // place object with left/top instead of center origin
-              p -= Vector2i(objects[current_object]->sprite.get_width()/2,
-                            objects[current_object]->sprite.get_height()/2);
+              p -= 
Vector2i(set->get_objects()[current_object]->sprite.get_width()/2,
+                            
set->get_objects()[current_object]->sprite.get_height()/2);
 
-              LevelObj* obj = objects[current_object]->create(p, 
editor->get_level()->get_level_impl());
+              LevelObj* obj = set->get_objects()[current_object]->create(p, 
editor->get_level()->get_level_impl());
               if (obj)
                 editor->add_object(obj);
               else
@@ -245,6 +149,8 @@
 void
 ObjectSelectorList::on_secondary_button_press (int x, int y)
 {
+  if (!set) return;
+
   if (mode == NOTHING)
     {
       drag_start = Vector2i(x,y);
@@ -256,6 +162,8 @@
 void
 ObjectSelectorList::on_secondary_button_release (int x, int y)
 {  
+  if (!set) return;
+
   if (mode == SCROLLING)
     mode = NOTHING;
 }
@@ -263,21 +171,23 @@
 void
 ObjectSelectorList::on_pointer_move (int x, int y)
 {
+  if (!set) return;
+
   real_mouse_pos = Vector2i(x, y);
 
   mouse_pos = Vector2i(x - rect.left, y - rect.top);
 
   int width = 5;
-  int height = (objects.size() / width) + ((objects.size() % width > 0) ? 1 : 
0);
+  int height = (set->get_objects().size() / width) + 
((set->get_objects().size() % width > 0) ? 1 : 0);
 
   if (mode != OBJECT_DRAG)
     {
-      if (!objects.empty())
+      if (!set->get_objects().empty())
         {
           int obj_x = Math::clamp(0, mouse_pos.x / 48, width - 1);
           int obj_y = Math::clamp(0, int(mouse_pos.y - offset) / 48, height-1);
 
-          current_object = Math::clamp(-1, (obj_y * 5) + obj_x, 
int(objects.size()-1));
+          current_object = Math::clamp(-1, (obj_y * 5) + obj_x, 
int(set->get_objects().size()-1));
         }
     }
 
@@ -289,159 +199,10 @@
 }
 
 void
-ObjectSelectorList::clear_object_list()
+ObjectSelectorList::set_objects(ObjectSelectorSet* set_)
 {
-  for(Objects::iterator i = objects.begin(); i != objects.end(); ++i)
-    delete (*i);
-  objects.clear();
+  set = set_;
 }
-
-void
-ObjectSelectorList::set_objects(const std::string& prefix)
-{
-  clear_object_list();
-
-  // FIXME: Simple debugging aid, needs to be replaced with custom code for 
the object types
-  std::vector<std::string> lst = Resource::resmgr.get_section(prefix);
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      std::cout << "Objects: " << *i << std::endl;
-      //sprite.scale(48, 48);
-      // need to reset the align to top/left
-      objects.push_back(new Object(Resource::load_sprite(*i),
-                                   Resource::load_thumb_sprite(*i)));
-    }
-  offset = 0;
-}
-
-void
-ObjectSelectorList::set_groundpiece(const std::string& prefix, const 
std::string& type)
-{
-  clear_object_list();
-
-  std::vector<std::string> lst = Resource::resmgr.get_section(prefix);
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      objects.push_back(new Groundpiece(*i, type));
-    }
-  offset = 0;
-}
-
-void
-ObjectSelectorList::set_gp_ground()
-{
-  set_groundpiece("groundpieces/ground", "ground");
-}
-
-void
-ObjectSelectorList::set_gp_solid()
-{
-  set_groundpiece("groundpieces/solid", "solid");
-}
-
-void
-ObjectSelectorList::set_gp_bridge()
-{
-  set_groundpiece("groundpieces/bridge", "bridge");
-}
-
-void
-ObjectSelectorList::set_gp_transparent()
-{
-  set_groundpiece("groundpieces/transparent", "transparent");
-}
-
-void
-ObjectSelectorList::set_gp_remove()
-{
-  set_groundpiece("groundpieces/remove", "remove");
-}
-
-void
-ObjectSelectorList::set_hotspot()
-{
-  clear_object_list();
-
-  std::vector<std::string> lst = Resource::resmgr.get_section("hotspots");
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      objects.push_back(new Hotspot(*i));
-    }
-  offset = 0;
-}
-
-void
-ObjectSelectorList::set_background()
-{
-  clear_object_list();
-
-  std::vector<std::string> lst = Resource::resmgr.get_section("textures");
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      objects.push_back(new SurfaceBackground(*i));
-    }
-  offset = 0;
-}
-
-void
-ObjectSelectorList::set_entrance()
-{
-  clear_object_list();
-
-  objects.push_back(new Entrance());
-
-  std::vector<std::string> lst = Resource::resmgr.get_section("entrances");
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      if (*i != "entrances/generic")
-        objects.push_back(new Hotspot(*i));
-    }
-  offset = 0;
-}
-
-void
-ObjectSelectorList::set_exit()
-{
-  clear_object_list();
-
-  std::vector<std::string> lst = Resource::resmgr.get_section("exit");
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      objects.push_back(new Exit(*i));
-    }
-  offset = 0;
-}
-
-void
-ObjectSelectorList::set_liquid()
-{
-  set_objects("liquids");
-}
-
-void
-ObjectSelectorList::set_trap()
-{
-  // Need to differentiate the different trap types
-  set_objects("traps");
-}
-
-void
-ObjectSelectorList::set_weather()
-{
-  //set_objects("weather");
-  std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" << 
__LINE__ << std::endl;
-}
-
-void
-ObjectSelectorList::set_worldobj()
-{
-  std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" << 
__LINE__ << std::endl;
-}
 
 } // namespace Editor
 

Modified: trunk/pingus/src/editor/object_selector_list.hpp
===================================================================
--- trunk/pingus/src/editor/object_selector_list.hpp    2007-09-15 20:12:48 UTC 
(rev 3161)
+++ trunk/pingus/src/editor/object_selector_list.hpp    2007-09-15 20:13:40 UTC 
(rev 3162)
@@ -37,6 +37,7 @@
 class LevelImpl;
 class EditorScreen;
 class ObjectSelector;
+class ObjectSelectorSet;
 
 /** */
 class ObjectSelectorList : public GUI::RectComponent
@@ -68,13 +69,13 @@
   enum Mode { NOTHING, SCROLLING, OBJECT_DRAG };
   Mode mode;
 
-
   typedef std::vector<Object*> Objects;
-  Objects objects;
 
   int current_object;
   int drag_object;
 
+  ObjectSelectorSet* set;
+
 public:
   ObjectSelectorList(EditorScreen* editor_, ObjectSelector* object_selector_, 
const Rect& rect);
 
@@ -88,25 +89,8 @@
 
   void draw(DrawingContext& gc);
 
-  void set_objects(const std::string& prefix);
+  void set_objects(ObjectSelectorSet* object_set);
 
-  void clear_object_list();
-
-  void set_groundpiece(const std::string& prefix, const std::string& type);
-  void set_gp_ground();
-  void set_gp_solid();
-  void set_gp_bridge();
-  void set_gp_transparent();
-  void set_gp_remove();
-  void set_hotspot();
-  void set_background();
-  void set_entrance();
-  void set_exit();
-  void set_liquid();
-  void set_trap();
-  void set_weather();
-  void set_worldobj();
-
   void update_layout() {}
 private:
   ObjectSelectorList (const ObjectSelectorList&);

Added: trunk/pingus/src/editor/object_selector_set.cpp
===================================================================
--- trunk/pingus/src/editor/object_selector_set.cpp     2007-09-15 20:12:48 UTC 
(rev 3161)
+++ trunk/pingus/src/editor/object_selector_set.cpp     2007-09-15 20:13:40 UTC 
(rev 3162)
@@ -0,0 +1,63 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  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.
+*/
+
+#include "object_selector_set.hpp"
+
+namespace Editor {
+
+ObjectSelectorSet::ObjectSelectorSet(ObjectSelectorList* list_, int thumb_w, 
int thumb_h)
+  : list(list_),
+    thumb_size(thumb_w, thumb_h),
+    offset(0)
+{
+}
+
+ObjectSelectorSet::~ObjectSelectorSet()
+{
+  for(Objects::iterator i = objects.begin(); i != objects.end(); ++i)
+    delete (*i);
+}
+
+void
+ObjectSelectorSet::add(ObjectSelectorList::Object* obj)
+{
+  objects.push_back(obj);
+}
+
+int
+ObjectSelectorSet::get_width() const
+{
+  return list->get_rect().get_width() / thumb_size.width;
+}
+
+int
+ObjectSelectorSet::get_height() const
+{
+  return (objects.size() / get_width()) + ((objects.size() % get_width() > 0) 
? 1 : 0);
+}
+
+} // namespace Editor
+
+/* EOF */


Property changes on: trunk/pingus/src/editor/object_selector_set.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/editor/object_selector_set.hpp
===================================================================
--- trunk/pingus/src/editor/object_selector_set.hpp     2007-09-15 20:12:48 UTC 
(rev 3161)
+++ trunk/pingus/src/editor/object_selector_set.hpp     2007-09-15 20:13:40 UTC 
(rev 3162)
@@ -0,0 +1,74 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  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.
+*/
+
+#ifndef HEADER_OBJECT_SELECTOR_SET_HPP
+#define HEADER_OBJECT_SELECTOR_SET_HPP
+
+#include <vector>
+#include "math/size.hpp"
+#include "object_selector_list.hpp"
+
+namespace Editor {
+
+/** */
+class ObjectSelectorSet
+{
+private:
+  ObjectSelectorList* list;
+  Size thumb_size;
+
+  typedef std::vector<ObjectSelectorList::Object*> Objects;
+  Objects objects;
+  
+  /** Used to record the scroll offset of the set */
+  float offset;
+
+public:
+  ObjectSelectorSet(ObjectSelectorList* list, int thumb_w, int thumb_h);
+  ~ObjectSelectorSet();
+
+  void add(ObjectSelectorList::Object* obj);
+
+  int get_width() const;
+  int get_height() const;
+
+  int get_thumb_width() const  { return thumb_size.width; }
+  int get_thumb_height() const { return thumb_size.height; }
+
+  float get_offset() const { return offset; }
+  void  set_offset(float o)  { offset = 0; }
+
+  const Objects& get_objects() const { return objects; }
+
+private:
+  ObjectSelectorSet (const ObjectSelectorSet&);
+  ObjectSelectorSet& operator= (const ObjectSelectorSet&);
+};
+
+} // namespace Editor
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/editor/object_selector_set.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/pingus/src/surface.cpp
===================================================================
--- trunk/pingus/src/surface.cpp        2007-09-15 20:12:48 UTC (rev 3161)
+++ trunk/pingus/src/surface.cpp        2007-09-15 20:13:40 UTC (rev 3162)
@@ -290,7 +290,7 @@
                                                                  
impl->surface->w, impl->surface->h);
   SDL_BlitSurface(impl->surface, NULL, new_surface, NULL);
  
- return Surface(boost::shared_ptr<SurfaceImpl>(new SurfaceImpl(new_surface, 
true)));
+  return Surface(boost::shared_ptr<SurfaceImpl>(new SurfaceImpl(new_surface, 
true)));
 }
 
 Surface





reply via email to

[Prev in Thread] Current Thread [Next in Thread]