pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2555 - trunk/src/editor


From: jave27
Subject: [Pingus-CVS] r2555 - trunk/src/editor
Date: Fri, 9 Dec 2005 21:27:06 +0100

Author: jave27
Date: 2005-12-09 21:26:59 +0100 (Fri, 09 Dec 2005)
New Revision: 2555

Modified:
   trunk/src/editor/editor_viewport.cxx
   trunk/src/editor/editor_viewport.hxx
   trunk/src/editor/level_impl.hxx
   trunk/src/editor/level_objs.cxx
   trunk/src/editor/level_objs.hxx
   trunk/src/editor/xml_level.cxx
Log:
Patched up some level editor things.  It's working a little bit more now.  
Still a ways to go.

Modified: trunk/src/editor/editor_viewport.cxx
===================================================================
--- trunk/src/editor/editor_viewport.cxx        2005-12-09 15:57:23 UTC (rev 
2554)
+++ trunk/src/editor/editor_viewport.cxx        2005-12-09 20:26:59 UTC (rev 
2555)
@@ -58,6 +58,11 @@
        // FIXME: Hardcoded 15 & 25 should probably be dynamic
        std::cout << "Right-click at " << x - 15 - (state.get_width()/2 - 
state.get_pos().x) << ", " 
                << y - 25 - (state.get_height()/2 - state.get_pos().y) << 
std::endl;
+       
+       LevelObj* obj = object_at(x - 15 - (state.get_width()/2 - 
(int)state.get_pos().x),
+               y - 25 - (state.get_height()/2 - (int)state.get_pos().y));
+       if (obj)
+               obj->on_primary_button_click(x, y);
 }
 
 // Draws all of the objects in the viewport and the background (if any)
@@ -118,6 +123,22 @@
                }
        }
 }
+
+LevelObj*
+EditorViewport::object_at (int x, int y)
+{
+       // we travel reversly through the object list, so that we get the
+       // top-most object
+       std::vector<LevelObj*> levelobjs = editor->get_level()->get_objects();
+       for (std::vector<LevelObj*>::reverse_iterator i = levelobjs.rbegin ();
+               i != levelobjs.rend (); ++i)
+       {
+               if ((*i)->is_at (x, y))
+                       return *i;
+       }
+       return 0;
+}
+
 } // Editor namespace
 } // Pingus namespace
 

Modified: trunk/src/editor/editor_viewport.hxx
===================================================================
--- trunk/src/editor/editor_viewport.hxx        2005-12-09 15:57:23 UTC (rev 
2554)
+++ trunk/src/editor/editor_viewport.hxx        2005-12-09 20:26:59 UTC (rev 
2555)
@@ -34,6 +34,7 @@
 
 namespace Editor {
 
+       class LevelObj;
        class EditorScreen;
 
 /** This class is where the actual level graphics will display in the
@@ -90,6 +91,9 @@
 
        /** Where the mouse is right now - used for autoscrolling */
        Vector mouse_at;
+
+       /** Returns the topmost object at this x, y location */
+       LevelObj* object_at(int x, int y);
 };
 
 } // Editor namespace

Modified: trunk/src/editor/level_impl.hxx
===================================================================
--- trunk/src/editor/level_impl.hxx     2005-12-09 15:57:23 UTC (rev 2554)
+++ trunk/src/editor/level_impl.hxx     2005-12-09 20:26:59 UTC (rev 2555)
@@ -23,16 +23,20 @@
 #include <ClanLib/Core/System/sharedptr.h>
 #include <ClanLib/Core/Math/size.h>
 #include <ClanLib/Display/color.h>
+#include <map>
 #include <string>
 #include <vector>
-#include <map>
+#include <algorithm>
 #include "level_objs.hxx"
 
 namespace Pingus {
 
 namespace Editor {
 
-       class LevelObj;
+       static bool LevelObjSort(LevelObj *a, LevelObj *b)
+       {
+               return (a->get_pos().z < b->get_pos().z);
+       }
 
 class LevelImpl
 {
@@ -75,6 +79,12 @@
 
   std::vector<LevelObj*> objects;
 
+       /** Sort the objects by their z position */
+       void sort_objs()
+       {
+               std::stable_sort(objects.begin(), objects.end(), LevelObjSort);
+       }
+
 private:
        LevelImpl (const LevelImpl&);
   LevelImpl& operator= (const LevelImpl&);

Modified: trunk/src/editor/level_objs.cxx
===================================================================
--- trunk/src/editor/level_objs.cxx     2005-12-09 15:57:23 UTC (rev 2554)
+++ trunk/src/editor/level_objs.cxx     2005-12-09 20:26:59 UTC (rev 2555)
@@ -78,6 +78,26 @@
        }
 }
 
+bool
+LevelObj::is_at(int x, int y)
+{
+       if (attribs & HAS_SURFACE)
+               return (x > pos.x && x < pos.x + sprite.get_width()
+                       && y > pos.y && y < pos.y + sprite.get_height());
+       else
+               return false;
+}
+
+void 
+LevelObj::on_primary_button_click (int x, int y)
+{
+       UNUSED_ARG(x);
+       UNUSED_ARG(y);
+       pos.x += 10;
+       // FIXME: Remove debugging stuff.
+       std::cout << "New pos.x: " << pos.x << ", y: " << pos.y << std::endl;
+}
+
 void
 LevelObj::set_stretch_x(const bool s)
 { 

Modified: trunk/src/editor/level_objs.hxx
===================================================================
--- trunk/src/editor/level_objs.hxx     2005-12-09 15:57:23 UTC (rev 2554)
+++ trunk/src/editor/level_objs.hxx     2005-12-09 20:26:59 UTC (rev 2555)
@@ -69,7 +69,7 @@
 
 /** Generic Level Object (groundpiece, sign, etc.)  Only special objects will 
have
                to inherit from this class - most objects will be able to use 
this class alone */
-class LevelObj
+       class LevelObj
 {
 protected:
        /** Sprite used to draw this object */
@@ -161,6 +161,9 @@
        /** Retrieve the object's speed */
        int get_speed() const { return speed; }
 
+       /** Retrieve the object's release rate (entrances) */
+       int get_release_rate() const { return release_rate; }
+
        /** Retrive the object's parallax (is this even used???) */
        float get_parallax() const { return parallax; }
 
@@ -219,6 +222,9 @@
        /** Set the object's speed */
        void set_speed(const int s) { speed = s; }
 
+       /** Set the objects release rate */
+       void set_release_rate(const int r) { release_rate = r; }
+
        /** Set the object's parallax */
        void set_parallax(const float para) { parallax = para; }
 
@@ -263,6 +269,13 @@
        /** Draws the sprite with the modifier applied */
        virtual void draw(DrawingContext &gc);
 
+       /** Returns true if the mouse is hovering over this object */
+  virtual bool is_at (int x, int y);
+
+       /** Action taken when the primary mouse button is clicked */
+       virtual void on_primary_button_click (int x, int y);
+
+
        /** Default Constructor */
        LevelObj(const std::string obj_name);
 

Modified: trunk/src/editor/xml_level.cxx
===================================================================
--- trunk/src/editor/xml_level.cxx      2005-12-09 15:57:23 UTC (rev 2554)
+++ trunk/src/editor/xml_level.cxx      2005-12-09 20:26:59 UTC (rev 2555)
@@ -43,7 +43,8 @@
 // Default Destructor
 XMLLevel::~XMLLevel()
 {
-       delete impl;
+       if (impl)
+               delete impl;
 }
 
 /** Verify that level is valid:
@@ -61,7 +62,10 @@
 bool XMLLevel::is_valid()
 {
        std::cout << "XMLLevel::is_valid() - Not yet implemented" << std::endl;
-       return true;
+       if (impl)
+               return true;
+       else
+               return false;
 }
 
 // Save the level to a file.  Returns true if successful
@@ -122,6 +126,10 @@
 // Load an existing level from a file
 void XMLLevel::load_level(const std::string& filename)
 {
+       if (impl)
+               delete impl;
+       impl = new LevelImpl();
+
        // Load the level from the file - we don't care what it's res_name is.
        XMLPingusLevel existing_level("", filename);
        
@@ -158,13 +166,13 @@
 
                // All objects have a position - get that.
                i->read_vector("position", p);
+               obj->set_pos(p);
 
                // Get optional attributes based on the attribs value
                if (attribs & HAS_SURFACE)
                {
                        i->read_desc("surface", desc);
                        obj->set_res_desc(desc);
-                       obj->set_pos(p);
                }
                if (attribs & HAS_TYPE)
                {       
@@ -224,9 +232,17 @@
                        i->read_float("para-y", tmp_float);
                        obj->set_para_y(tmp_float);
                }
+               if (attribs & HAS_RELEASE_RATE)
+               {
+                       i->read_int("release-rate", tmp_int);
+                       obj->set_release_rate(tmp_int);
+               }
 
                impl->objects.push_back((LevelObj*)obj);
        }
+
+       // Sort by Z coordinate
+       impl->sort_objs();
 }
 
 }      // Editor namespace





reply via email to

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