pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/worldmap manager.cxx,1.4,1.5 manager.


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/worldmap manager.cxx,1.4,1.5 manager.hxx,1.3,1.4 node.cxx,1.4,1.5 worldmap.cxx,1.3,1.4 worldmap.hxx,1.2,1.3
Date: 1 Aug 2002 21:40:04 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv6419/worldmap

Modified Files:
        manager.cxx manager.hxx node.cxx worldmap.cxx worldmap.hxx 
Log Message:
more gui and input cleanup, client is still broken

Index: manager.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/manager.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- manager.cxx 2 Jul 2002 13:36:07 -0000       1.4
+++ manager.cxx 1 Aug 2002 21:40:02 -0000       1.5
@@ -27,12 +27,24 @@
 using namespace Pingus;
 using namespace Pingus::WorldMap;
 
-WorldMapManager* WorldMapManager::current_manager;
+WorldMapManager* WorldMapManager::instance_ = 0;
 
 WorldMapManager::WorldMapManager ()
 {
-  current_manager = this;
   is_init = false;
+  exit_worldmap = false;
+
+  init ();
+
+  worldmap = boost::shared_ptr<WorldMap::WorldMap>
+    (new WorldMap::WorldMap (path_manager.complete("worldmaps/volcano.xml")));
+
+  worldmap->init ();
+
+  // FIXME: a bit ugly because of the proteced member, but should work
+  // FIXME: well enough. GUIScreen could also use multi-inheritage,
+  // FIXME: but that could lead to member function name conflicts
+  gui_manager->add (&worldmap_component);
 }
 
 WorldMapManager::~WorldMapManager ()
@@ -49,21 +61,11 @@
     }
 }
 
+  /*
+
 void
 WorldMapManager::display ()
 {
-  on_button_press_slot   = CL_Input::sig_button_press ().connect (this, 
&WorldMapManager::on_button_press);
-  on_button_release_slot = CL_Input::sig_button_release ().connect (this, 
&WorldMapManager::on_button_release);
-  on_mouse_move_slot     = CL_Input::sig_mouse_move ().connect (this, 
&WorldMapManager::on_mouse_move);
-
-  init ();
-
-  worldmap = boost::shared_ptr<WorldMap::WorldMap>
-    (new WorldMap::WorldMap (path_manager.complete("worldmaps/volcano.xml")));
-
-  worldmap->init ();
-
-  exit_worldmap = false;
   DeltaManager delta;
   while (!worldmap->do_exit ())
     {
@@ -80,34 +82,28 @@
       CL_System::keep_alive ();
       Display::flip_display ();
     }
-
-  CL_Input::sig_button_press ().disconnect(on_button_press_slot);
-  CL_Input::sig_button_release ().disconnect(on_button_release_slot);
-  CL_Input::sig_mouse_move ().disconnect(on_mouse_move_slot);
 }
+  */
+
 
 void
-WorldMapManager::on_mouse_move (CL_InputDevice *, int /*mouse_x*/, int 
/*mouse_y*/)
+WorldMapManager::WorldMapComponent::draw ()
 {
-  //  std::cout << "mouse: " << mouse_x << " " << mouse_y << std::endl;  
+  WorldMapManager::instance ()->worldmap->draw ();
 }
 
-void 
-WorldMapManager::on_button_press (CL_InputDevice *device, const CL_Key &key)
+void
+WorldMapManager::WorldMapComponent::update (float delta)
 {
-  worldmap->on_button_press (device, key);
+  //std::cout << "update press" << std::endl;
+  WorldMapManager::instance ()->worldmap->update (delta);
 }
 
 void 
-WorldMapManager::on_button_release (CL_InputDevice * /*device*/, const CL_Key 
& /*key*/)
-{
-  //  std::cout << "key release: " << key.id << std::endl;
-}
-
-void
-WorldMapManager::on_resize(int w, int h)
+WorldMapManager::WorldMapComponent::on_button_press (int x, int y)
 {
-  std::cout << "Width: " << w << " Height: " << h << std::endl;
+  std::cout << "Buton press" << std::endl;
+  WorldMapManager::instance ()->worldmap->on_button_press (x, y);
 }
 
 void 
@@ -116,6 +112,15 @@
   new_worldmap = boost::shared_ptr<WorldMap::WorldMap>
     (new WorldMap::WorldMap (path_manager.complete("worldmaps/" + filename)));
   new_worldmap->set_pingus (node);
+}
+
+WorldMapManager*
+WorldMapManager::instance ()
+{
+  if (instance_)
+    return instance_;
+  else
+    return instance_ = new WorldMapManager ();
 }
 
 /* EOF */

Index: manager.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/manager.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- manager.hxx 24 Jun 2002 22:52:59 -0000      1.3
+++ manager.hxx 1 Aug 2002 21:40:02 -0000       1.4
@@ -22,10 +22,13 @@
 
 #include <string>
 #include <ClanLib/Signals/slot.h>
+#include "../gui/gui_manager.hxx"
 #include "../boost/smart_ptr.hpp"
+#include "../gui_screen.hxx"
 
 class CL_InputDevice;
 class CL_Key;
+class GameDelta;
 
 namespace Pingus
 {
@@ -35,43 +38,39 @@
   }
 
   /**  */
-  class WorldMapManager
+  class WorldMapManager : public GUIScreen
   {
+    class WorldMapComponent : public GUI::Component
+    {
+    public:
+      void on_button_press (int x, int y);
+
+      void draw ();
+      void update (float delta);
+      
+      bool is_at (int, int) { return true; }
+    } worldmap_component;
+    
+    friend class WorldMapComponent;
   private:
+    static WorldMapManager* instance_;
+
     bool is_init;
     bool exit_worldmap;
     boost::shared_ptr<WorldMap::WorldMap> worldmap;
     boost::shared_ptr<WorldMap::WorldMap> new_worldmap;
 
-    /// Some slots to manage the event handling
-    //@{
-    CL_Slot on_button_press_slot;
-    CL_Slot on_button_release_slot;
-    CL_Slot on_mouse_move_slot;
-    CL_Slot on_resize_slot;
-    //@}
-
-    static WorldMapManager* current_manager;
-
-  public:
     WorldMapManager ();
+  public:
     ~WorldMapManager ();
   
   private:
     /// Load all required resources if not already done
     void init ();
 
-    void on_button_press (CL_InputDevice *device, const CL_Key &key);
-    void on_button_release (CL_InputDevice *device, const CL_Key &key);
-    void on_mouse_move(CL_InputDevice *,int mouse_x, int mouse_y);
-    void on_resize(int w, int h);
-
   public:
-    /// Display the worldmap and let the user select a level
-    void display ();
     void change_map (const std::string& filename, int node);
-
-    static WorldMapManager* get_current () { return current_manager; } 
+    static WorldMapManager* instance ();
   };
 
 }

Index: node.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/node.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- node.cxx    2 Jul 2002 13:36:07 -0000       1.4
+++ node.cxx    1 Aug 2002 21:40:02 -0000       1.5
@@ -46,7 +46,7 @@
 TubeNode::on_click ()
 {
   std::cout << "Not Supported" << std::endl;
-  WorldMapManager::get_current ()->change_map (worldmap_name, link_node);
+  WorldMapManager::instance ()->change_map (worldmap_name, link_node);
 }
 
 void 

Index: worldmap.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- worldmap.cxx        2 Jul 2002 13:36:07 -0000       1.3
+++ worldmap.cxx        1 Aug 2002 21:40:02 -0000       1.4
@@ -152,113 +152,92 @@
 }
 
 void 
-WorldMap::on_button_press (CL_InputDevice *device, const CL_Key &key)
+WorldMap::on_button_press (int x, int y)
 {
   if (!catch_input) return;
 
-  if (device == CL_Input::keyboards[0])
-    {
+  /*  if (device == CL_Input::keyboards[0])
+      {
       switch(key.id)
-       {
-       case CL_KEY_ESCAPE:
-         do_quit = true;
-         break;
-       default:
-         break;
-       }
-    }
-  else if (device == CL_Input::pointers[0])
-    {
-      CL_Vector offset = get_offset ();
-      
-      switch (key.id)
-       {
-       case CL_MOUSE_LEFTBUTTON:
+      {
+      case CL_KEY_ESCAPE:
+      do_quit = true;
+      break;
+      default:
+      break;
+      }
+      }
+  */
+  CL_Vector offset = get_offset ();
+
+  {      
+    NodePtr node
+      = get_node ((int) (x - offset.x), (int) (y - offset.y));
+
+    if (node.get() && !node->accessible)
+      {
+       PingusSound::play_sound("sounds/chink.wav");
+      }
+    else if (node.get() && node->accessible)
+      {
+       Pingus::WorldMap::Node* pingus_node = pingus->get_node ();
+       if (maintainer_mode)
          {
-           NodePtr node
-             = get_node ((int) (key.x - offset.x), (int) (key.y - offset.y));
+           std::cout << "Click on: " << node->get_id () << std::endl;
+           std::cout << "Pingu at: " << pingus_node->get_id () << std::endl;
+         }
 
-           if (node.get() && !node->accessible)
-             {
-               PingusSound::play_sound("sounds/chink.wav");
-             }
-           else if (node.get() && node->accessible)
+       if (pingus_node && pingus_node->get_id () == node->get_id ())
+         {
+           disable_button_events ();
+           node->on_click ();
+                   
+           // FIXME: Ugly marking code... should be rewritten
+           for (std::list<int>::iterator k = node->get_links ().begin();
+                k != node->get_links ().end();
+                ++k)
              {
-               Pingus::WorldMap::Node* pingus_node = pingus->get_node ();
-               if (maintainer_mode)
+               for (GraphIter i = graph_data.nodes.begin ();
+                    i != graph_data.nodes.end ();
+                    ++i)
                  {
-                   std::cout << "Click on: " << node->get_id () << std::endl;
-                   std::cout << "Pingu at: " << pingus_node->get_id () << 
std::endl;
+                   if ((*i)->get_id () == *k)
+                     (*i)->accessible = true;
                  }
-
-               if (pingus_node && pingus_node->get_id () == node->get_id ())
-                 {
-                   disable_button_events ();
-                   node->on_click ();
-                   
-                   // FIXME: Ugly marking code... should be rewritten
-                   for (std::list<int>::iterator k = node->get_links 
().begin();
-                        k != node->get_links ().end();
-                        ++k)
-                     {
-                       for (GraphIter i = graph_data.nodes.begin ();
-                            i != graph_data.nodes.end ();
-                            ++i)
-                         {
-                           if ((*i)->get_id () == *k)
-                             (*i)->accessible = true;
-                         }
-                     }
+             }
                    
-                   // Save the changes
-                   save ();
+           // Save the changes
+           save ();
       
-                   enable_button_events ();
-                 }
-               else
-                 {
-                   pingus->walk_to (node.get ());
-                 }
-             }
-           else
-             {
-               if (maintainer_mode)
-                 std::cout << "no id clicked" << std::endl;
-             }
+           enable_button_events ();
          }
-         break;
-       case CL_MOUSE_MIDDLEBUTTON:
+       else
          {
-           if (maintainer_mode)
-             {
-               std::cout << "<position>" << std::endl;
-               std::cout << "  <x-pos>" << key.x - offset.x << "</x-pos>" << 
std::endl;
-               std::cout << "  <y-pos>" << key.y - offset.y << "</y-pos>" << 
std::endl;
-               std::cout << "</position>" << std::endl;
-             }
+           pingus->walk_to (node.get ());
          }
-         break;
-       case CL_MOUSE_RIGHTBUTTON:
-         {
-           //Node* node = get_node (key.x - offset.x, key.y - offset.y);
+      }
+    else
+      {
+       if (maintainer_mode)
+         std::cout << "no id clicked" << std::endl;
+      }
+  }
 
-           /*if (node) {
-             std::cout << "Node: " << node->id << std::endl;
-             } else {
-             std::cout << "No node selected" << std::endl;
-             }*/
-         }
-         break;
-       }
+
+  /*
+    case CL_MOUSE_MIDDLEBUTTON:
+    {
+    if (maintainer_mode)
+    {
+    std::cout << "<position>" << std::endl;
+    std::cout << "  <x-pos>" << key.x - offset.x << "</x-pos>" << std::endl;
+    std::cout << "  <y-pos>" << key.y - offset.y << "</y-pos>" << std::endl;
+    std::cout << "</position>" << std::endl;
+    }
     }
+    break;*/
 }
  
-void 
-WorldMap::on_button_release (CL_InputDevice * /*device*/, const CL_Key & 
/*key*/)
-{
-  if (!catch_input) return;
-}
-
 void
 WorldMap::start_level (Pingus::WorldMap::Node* /*node*/)
 {

Index: worldmap.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- worldmap.hxx        24 Jun 2002 22:52:59 -0000      1.2
+++ worldmap.hxx        1 Aug 2002 21:40:02 -0000       1.3
@@ -80,11 +80,8 @@
          - calculate which level was clicked
          - calculate the shortest path
          - let the pingu walk */
-      void on_button_press (CL_InputDevice *device, const CL_Key &key);
+      void on_button_press (int x, int y);
  
-      /** React on button release */
-      void on_button_release (CL_InputDevice *device, const CL_Key &key);
-
       /** Disable all event catching */
       void disable_button_events ();
   




reply via email to

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