]> git.tdb.fi Git - r2c2.git/commitdiff
Move goto destination picking to RouterPanel
authorMikko Rasa <tdb@tdb.fi>
Fri, 9 Aug 2013 17:35:37 +0000 (20:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 11 Aug 2013 12:25:52 +0000 (15:25 +0300)
source/engineer/routerpanel.cpp
source/engineer/routerpanel.h

index e69a436d8f10661b97b63d1644d9cd81e2c3de72..5097edaedf84046fc63765322c4cf8d6c1288a7f 100644 (file)
@@ -21,7 +21,10 @@ RouterPanel::RouterPanel(Engineer &e, Train &t):
        engineer(e),
        train(t),
        routes(&route_name),
-       updating(false)
+       updating(false),
+       goto_pick(false),
+       goto_target(0),
+       goto_highlight(0)
 {
        Loader::WidgetMap widgets;
        DataFile::load(*this, "data/routerpanel.ui", widgets);
@@ -72,12 +75,45 @@ void RouterPanel::route_selected(unsigned index)
 
 void RouterPanel::goto_clicked()
 {
-       engineer.pick(false);
-       pick_conn = engineer.signal_pick_done.connect(sigc::mem_fun(this, &RouterPanel::goto_pick_done));
+       goto_pick = true;
+       signal_grab_pointer.emit();
 }
 
-void RouterPanel::goto_pick_done(Track *track, unsigned)
+void RouterPanel::button_press(int x, int y, unsigned btn)
 {
-       pick_conn.disconnect();
-       train.ai_message(TrainAI::Message("set-destination-block", &track->get_block()));
+       Panel::button_press(x, y, btn);
+
+       if(goto_pick)
+       {
+               signal_ungrab_pointer.emit();
+               goto_pick = false;
+
+               delete goto_highlight;
+               goto_highlight = 0;
+
+               if(goto_target && btn==1)
+                       train.ai_message(TrainAI::Message("set-destination-block", goto_target));
+       }
+}
+
+void RouterPanel::pointer_motion(int x, int y)
+{
+       Panel::pointer_motion(x, y);
+       
+       if(goto_pick)
+       {
+               int rx = x;
+               int ry = y;
+               map_coords_to_ancestor(rx, ry, *find_ancestor<GLtk::Root>());
+               Ray ray = engineer.get_main_view().create_ray(rx, ry);
+               Track *track = engineer.get_layout().pick<Track>(ray);
+               if(track)
+               {
+                       goto_target = &track->get_block();
+                       delete goto_highlight;
+                       goto_highlight = new TrackChain3D(engineer.get_layout_3d(), *goto_target);
+                       goto_highlight->set_color(GL::Color(0.7));
+                       goto_highlight->set_layer(2);
+               }
+       }
 }
index 826e9a74bf45247875370a3987eb793759c816d4..93fabab6d25079ee374f951968b0a351daae5625 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/gltk/label.h>
 #include <msp/gltk/panel.h>
 #include "libr2c2/train.h"
+#include "3d/trackchain.h"
 
 class Engineer;
 
@@ -19,6 +20,10 @@ private:
        sigc::connection pick_conn;
        bool updating;
 
+       bool goto_pick;
+       R2C2::Block *goto_target;
+       R2C2::TrackChain3D *goto_highlight;
+
 public:
        RouterPanel(Engineer &, R2C2::Train &);
 
@@ -27,7 +32,9 @@ private:
        void update_route(const R2C2::Route *);
        void route_selected(unsigned);
        void goto_clicked();
-       void goto_pick_done(R2C2::Track *, unsigned);
+
+       virtual void button_press(int, int, unsigned);
+       virtual void pointer_motion(int, int);
 };
 
 #endif