[longomatch] Implement players tagging from the coding UI



commit 7d4bb21914f2280a2b598deff313494c5ce16a59
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Jul 1 12:15:25 2014 +0200

    Implement players tagging from the coding UI

 LongoMatch.Core/Common/EventsBroker.cs             |    4 +-
 LongoMatch.Core/Handlers/Handlers.cs               |    2 +-
 LongoMatch.Drawing/Widgets/TeamTagger.cs           |   28 ++++++++++++++----
 .../Gui/Component/AnalysisTemplateEditor.cs        |    5 ++-
 LongoMatch.GUI/Gui/Component/ButtonTagger.cs       |    2 +-
 LongoMatch.GUI/Gui/Component/ButtonsWidget.cs      |   22 +++++++++-----
 LongoMatch.GUI/Gui/Component/CodingWidget.cs       |   30 +++++++++++++++++++-
 .../LongoMatch.Gui.Component.CodingWidget.cs       |    2 +-
 LongoMatch.GUI/gtk-gui/gui.stetic                  |    1 -
 LongoMatch.GUI/gtk-gui/objects.xml                 |    5 ++-
 LongoMatch.Services/Services/EventsManager.cs      |   17 ++++++----
 11 files changed, 87 insertions(+), 31 deletions(-)
---
diff --git a/LongoMatch.Core/Common/EventsBroker.cs b/LongoMatch.Core/Common/EventsBroker.cs
index 49d1edb..11ff874 100644
--- a/LongoMatch.Core/Common/EventsBroker.cs
+++ b/LongoMatch.Core/Common/EventsBroker.cs
@@ -100,9 +100,9 @@ namespace LongoMatch.Common
                                NewTagAtPosEvent(category, pos);
                }
 
-               public void EmitNewTag(Category category) {
+               public void EmitNewTag(Category category, List<Player> players = null) {
                        if (NewTagEvent != null)
-                               NewTagEvent(category);
+                               NewTagEvent(category, players);
                }
 
                public void EmitNewTagStart(Category category) {
diff --git a/LongoMatch.Core/Handlers/Handlers.cs b/LongoMatch.Core/Handlers/Handlers.cs
index b8be20a..ca8f283 100644
--- a/LongoMatch.Core/Handlers/Handlers.cs
+++ b/LongoMatch.Core/Handlers/Handlers.cs
@@ -34,7 +34,7 @@ namespace LongoMatch.Handlers
        /* A Play was selected */
        public delegate void PlaySelectedHandler(Play play);
        /* A new play needs to be create for a specific category at the current play time */
-       public delegate void NewTagHandler(Category category);
+       public delegate void NewTagHandler(Category category, List<Player> plays);
        /* Signal the start time to tag a new play */
        public delegate void NewTagStartHandler (Category category);
        /* Signal the stop time to tag a new play */
diff --git a/LongoMatch.Drawing/Widgets/TeamTagger.cs b/LongoMatch.Drawing/Widgets/TeamTagger.cs
index 4519f47..64b0640 100644
--- a/LongoMatch.Drawing/Widgets/TeamTagger.cs
+++ b/LongoMatch.Drawing/Widgets/TeamTagger.cs
@@ -96,17 +96,22 @@ namespace LongoMatch.Drawing.Widgets
                                return inSubs;
                        }
                }
-               public void Select (Player p) {
+
+               public void Select (List<Player> players) {
                        ClearSelection ();
-                       if (p != null) {
-                               ICanvasObject co = Objects.LastOrDefault (pl => (pl as PlayerObject).Player 
== p);
-                               PlayerObject po = co as PlayerObject;
-                               if (po != null) {
-                                       UpdateSelection (new Selection (po, SelectionPosition.All));
+                       if (players != null) {
+                               foreach (Player p in players) {
+                                       SelectPlayer (p);
                                }
                        }
                        widget.ReDraw ();
                }
+
+               public void Select (Player p) {
+                       ClearSelection ();
+                       SelectPlayer (p);
+                       widget.ReDraw ();
+               }
                
                public void Reload () {
                        Objects.Clear();
@@ -131,6 +136,17 @@ namespace LongoMatch.Drawing.Widgets
                        }
                }
                
+               void SelectPlayer (Player p)
+               {
+                       if (p != null) {
+                               ICanvasObject co = Objects.LastOrDefault (pl => (pl as 
PlayerObject).Player.ID == p.ID);
+                               PlayerObject po = co as PlayerObject;
+                               if (po != null) {
+                                       UpdateSelection (new Selection (po, SelectionPosition.All));
+                               }
+                       }
+               }
+               
                PlayersIconSize BestIconSize (int[] formation) {
                        double width = backgroundWidth / NTeams;
                        double optWidth = width / formation.Count();
diff --git a/LongoMatch.GUI/Gui/Component/AnalysisTemplateEditor.cs 
b/LongoMatch.GUI/Gui/Component/AnalysisTemplateEditor.cs
index 1108477..14660a4 100644
--- a/LongoMatch.GUI/Gui/Component/AnalysisTemplateEditor.cs
+++ b/LongoMatch.GUI/Gui/Component/AnalysisTemplateEditor.cs
@@ -21,6 +21,7 @@ using LongoMatch.Common;
 using LongoMatch.Gui.Helpers;
 using LongoMatch.Store;
 using Mono.Unix;
+using System.Collections.Generic;
 
 namespace LongoMatch.Gui.Component
 {
@@ -35,7 +36,7 @@ namespace LongoMatch.Gui.Component
                {
                        this.Build ();
                        buttonswidget.Mode = LongoMatch.Common.TagMode.Predifined;
-                       buttonswidget.CategorySelected += HandleCategorySelected;
+                       buttonswidget.NewTagEvent += HandleCategorySelected;
                        categoryproperties.Visible = false;
                        savebutton.Clicked += HandleSaveClicked;
                        deletebutton.Sensitive = false;
@@ -81,7 +82,7 @@ namespace LongoMatch.Gui.Component
                        Edited = true;
                }
                
-               void HandleCategorySelected (Category category)
+               void HandleCategorySelected (Category category, List<Player> players)
                {
                        categoryproperties.Visible = true;
                        deletebutton.Sensitive = true;
diff --git a/LongoMatch.GUI/Gui/Component/ButtonTagger.cs b/LongoMatch.GUI/Gui/Component/ButtonTagger.cs
index ac0a41f..98c9750 100644
--- a/LongoMatch.GUI/Gui/Component/ButtonTagger.cs
+++ b/LongoMatch.GUI/Gui/Component/ButtonTagger.cs
@@ -119,7 +119,7 @@ namespace LongoMatch.Gui.Component
                
                void EmitNewTag () {
                        if (NewTag != null)
-                               NewTag (category);
+                               NewTag (category, null);
                }
                
                void OnButtonClicked (object sender, EventArgs args)
diff --git a/LongoMatch.GUI/Gui/Component/ButtonsWidget.cs b/LongoMatch.GUI/Gui/Component/ButtonsWidget.cs
index bb1dcc1..652daf1 100644
--- a/LongoMatch.GUI/Gui/Component/ButtonsWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/ButtonsWidget.cs
@@ -34,7 +34,11 @@ namespace LongoMatch.Gui.Component
        [System.ComponentModel.ToolboxItem(true)]
        public partial class ButtonsWidget : Gtk.Bin
        {
-               public event NewTagHandler CategorySelected;
+               public event NewTagHandler NewTagEvent;
+               public event NewTagStartHandler NewTagStartEvent;
+               public event NewTagStopHandler NewTagStopEvent;
+               public event NewTagCancelHandler NewTagCancelEvent;
+
                TagMode tagMode;
                Dictionary<ButtonTagger, Category> buttonsDic;
                const int N_COLUMNS = 5;
@@ -88,20 +92,22 @@ namespace LongoMatch.Gui.Component
                        for(int i=0; i<sectionsCount; i++) {
                                Category cat = categories.List[i];
                                ButtonTagger b = new ButtonTagger (cat);
-                                       b.NewTag += (category) => {
-                                       Config.EventsBroker.EmitNewTag (category);
-                                       if (CategorySelected != null) {
-                                               CategorySelected (category);
+                                       b.NewTag += (category, p) => {
+                                       if (NewTagEvent != null) {
+                                               NewTagEvent (category, p);
                                        }
                                };
                                b.NewTagStart += (category) => {
-                                       Config.EventsBroker.EmitNewTagStart (category);
+                                       if (NewTagStartEvent != null)
+                                               NewTagStartEvent (category);
                                };
                                b.NewTagStop += (category) => {
-                                       Config.EventsBroker.EmitNewTagStop (category);
+                                       if (NewTagStopEvent != null)
+                                               NewTagStopEvent (category);
                                };
                                b.NewTagCancel += (category) => {
-                                       Config.EventsBroker.EmitNewTagCancel (category);
+                                       if (NewTagCancelEvent != null)
+                                               NewTagCancelEvent (category);
                                };
                                b.Mode = tagMode;
                                
diff --git a/LongoMatch.GUI/Gui/Component/CodingWidget.cs b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
index c1eb4e1..1ad6a67 100644
--- a/LongoMatch.GUI/Gui/Component/CodingWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
@@ -33,6 +33,8 @@ namespace LongoMatch.Gui.Component
                TeamTagger teamtagger;
                Project project;
                ProjectType projectType;
+               List<Player> selectedPlayers;
+               Play loadedPlay;
                
                public CodingWidget ()
                {
@@ -46,6 +48,8 @@ namespace LongoMatch.Gui.Component
                        teamtagger = new TeamTagger (new WidgetWrapper (drawingarea1));
                        teamtagger.HomeColor = Constants.HOME_COLOR;
                        teamtagger.AwayColor = Constants.AWAY_COLOR;
+                       teamtagger.SelectionMode = MultiSelectionMode.Multiple;
+                       teamtagger.PlayersSelectionChangedEvent += HandlePlayersSelectionChangedEvent;
 
                        drawingarea1.HeightRequest = 200;
                        drawingarea1.WidthRequest = 300;
@@ -55,8 +59,10 @@ namespace LongoMatch.Gui.Component
                        Config.EventsBroker.Tick += HandleTick;
                        Config.EventsBroker.PlaySelected += HandlePlaySelected;
                        Misc.DisableFocus (vbox2);
+                       
+                       buttonswidget.NewTagEvent += HandleNewTagEvent;
                }
-               
+
                protected override void OnDestroyed ()
                {
                        Config.EventsBroker.Tick -= HandleTick;
@@ -114,13 +120,35 @@ namespace LongoMatch.Gui.Component
                
                void HandlePlaySelected (Play play)
                {
+                       loadedPlay = play;
                        timeline.SelectedTimeNode = play;
+                       if (play != null) {
+                               teamtagger.Select (play.Players);
+                       } else {
+                               teamtagger.ClearSelection ();
+                       }
                }
 
                void HandleTick (Time currentTime, Time streamLength, double currentPosition)
                {
                        timeline.CurrentTime = currentTime;
                }
+
+               void HandleNewTagEvent (Category category, List<Player> players)
+               {
+                       Config.EventsBroker.EmitNewTag (category, selectedPlayers);
+                       teamtagger.ClearSelection ();
+               }
+
+               void HandlePlayersSelectionChangedEvent (List<Player> players)
+               {
+                       if (loadedPlay != null) {
+                               loadedPlay.Players = players;
+                               Config.EventsBroker.EmitTeamTagsChanged ();
+                       } else {
+                               selectedPlayers = players;
+                       }
+               }
        }
 
 }
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.CodingWidget.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.CodingWidget.cs
index 5da0931..e29e158 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.CodingWidget.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.Component.CodingWidget.cs
@@ -40,7 +40,7 @@ namespace LongoMatch.Gui.Component
                        this.UIManager.InsertActionGroup (w2, 0);
                        global::Gtk.ActionGroup w3 = new global::Gtk.ActionGroup ("Timeline");
                        this.positionMode = new global::Gtk.RadioAction ("positionMode", null, null, 
"gtk-justify-fill", 0);
-                       this.positionMode.Group = this.convertAction.Group;
+                       this.positionMode.Group = this.autoTaggingMode.Group;
                        w3.Add (this.positionMode, null);
                        this.UIManager.InsertActionGroup (w3, 1);
                        this.Name = "LongoMatch.Gui.Component.CodingWidget";
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index 3efae96..7edd81f 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -2585,7 +2585,6 @@ Hotkeys with a single key are also allowed with Ctrl+key.</property>
                             <property name="Tooltip" translatable="yes">Angle tool</property>
                             <property name="CanFocus">True</property>
                             <property name="Label" translatable="yes" />
-                            <property name="Active">True</property>
                             <property name="DrawIndicator">False</property>
                             <property name="HasLabel">False</property>
                             <property name="UseUnderline">True</property>
diff --git a/LongoMatch.GUI/gtk-gui/objects.xml b/LongoMatch.GUI/gtk-gui/objects.xml
index 72c5073..2669357 100644
--- a/LongoMatch.GUI/gtk-gui/objects.xml
+++ b/LongoMatch.GUI/gtk-gui/objects.xml
@@ -7,7 +7,10 @@
     <itemgroups />
     <signals>
       <itemgroup label="ButtonsWidget Signals">
-        <signal name="CategorySelected" />
+        <signal name="NewTagEvent" />
+        <signal name="NewTagStartEvent" />
+        <signal name="NewTagStopEvent" />
+        <signal name="NewTagCancelEvent" />
       </itemgroup>
     </signals>
   </object>
diff --git a/LongoMatch.Services/Services/EventsManager.cs b/LongoMatch.Services/Services/EventsManager.cs
index 449af86..c8ed357 100644
--- a/LongoMatch.Services/Services/EventsManager.cs
+++ b/LongoMatch.Services/Services/EventsManager.cs
@@ -156,7 +156,7 @@ namespace LongoMatch.Services
                        }
                }
                
-               private void ProcessNewTag(Category category,Time pos) {
+               private void ProcessNewTag(Category category,Time pos, List<Player> players) {
                        Time length, startTime, stopTime, start, stop, fStart, fStop;
 
                        if(player == null || openedProject == null)
@@ -178,10 +178,10 @@ namespace LongoMatch.Services
                                length = player.StreamLength;
                                fStop = (stop > length) ? length: stop;
                        }
-                       AddNewPlay(fStart, fStop, category);
+                       AddNewPlay(fStart, fStop, category, players);
                }
 
-               private void AddNewPlay(Time start, Time stop, Category category) {
+               private void AddNewPlay(Time start, Time stop, Category category, List<Player> players) {
                        Image miniature;
 
                        Log.Debug(String.Format("New play created start:{0} stop:{1} category:{2}",
@@ -204,6 +204,9 @@ namespace LongoMatch.Services
                        
                        /* Add the new created play to the project and update the GUI*/
                        var play = openedProject.AddPlay(category, start, stop,miniature);
+                       if (players != null) {
+                               play.Players = players;
+                       }
                        /* Tag subcategories of the new play */
                        if (!Config.FastTagging)
                                guiToolkit.TagPlay (play, openedProject);
@@ -228,10 +231,10 @@ namespace LongoMatch.Services
 
                        player.CloseSegment();
                        player.Seek (pos, true);
-                       ProcessNewTag(category,pos);
+                       ProcessNewTag(category,pos, null);
                }
 
-               public void OnNewTag(Category category) {
+               public void OnNewTag(Category category, List<Player> players) {
                        Time pos;
                        
                        if (openedProject == null)
@@ -244,7 +247,7 @@ namespace LongoMatch.Services
                        } else {
                                pos = player.CurrentTime;
                        }
-                       ProcessNewTag(category,pos);
+                       ProcessNewTag(category,pos, players);
                }
 
                void OnNewPlayStart (Category category) {
@@ -280,7 +283,7 @@ namespace LongoMatch.Services
                                else
                                        stopTime = stopTime + correction;
                        }
-                       AddNewPlay(startTime, stopTime, category);
+                       AddNewPlay(startTime, stopTime, category, null);
                }
                
                void OnNewPlayCancel (Category category) {


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