[longomatch/newui: 122/157] Support removing players for the current match



commit 1e520306ddce2bf64ba5e7ff858bdadd5c39b8a8
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Aug 28 17:14:21 2014 +0200

    Support removing players for the current match

 LongoMatch.Core/Store/Templates/TeamTemplate.cs    |   35 ++++++++++++++++---
 .../CanvasObjects/PlayersTaggerObject.cs           |   13 +++++--
 LongoMatch.Drawing/Widgets/TeamTagger.cs           |   16 +++++++--
 LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs |    2 +-
 LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs        |   16 +++++++++
 5 files changed, 67 insertions(+), 15 deletions(-)
---
diff --git a/LongoMatch.Core/Store/Templates/TeamTemplate.cs b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
index e2aa919..d9513e1 100644
--- a/LongoMatch.Core/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
@@ -68,7 +68,7 @@ namespace LongoMatch.Store.Templates
                }
                
                [JsonIgnore]
-               public int PlayingPlayers {
+               public int StartingPlayers {
                        get {
                                return Formation.Sum();
                        }
@@ -110,23 +110,46 @@ namespace LongoMatch.Store.Templates
                [JsonIgnore]
                public List<Player> StartingPlayersList {
                        get {
-                               int count = Math.Min (PlayingPlayers, List.Count);
-                               return List.GetRange (0, count);
+                               List<Player> playingPlayers = PlayingPlayersList;
+                               int count = Math.Min (StartingPlayers, StartingPlayers);
+                               return playingPlayers.GetRange (0, count);
                        }
                }
 
                [JsonIgnore]
                public List<Player> BenchPlayersList {
                        get {
-                               int playing = PlayingPlayers;
-                               if (List.Count > playing) {
-                                       return List.GetRange (playing, List.Count - playing);
+                               List<Player> playingPlayers = PlayingPlayersList;
+                               int starting = StartingPlayers;
+                               if (playingPlayers.Count > starting) {
+                                       return playingPlayers.GetRange (starting, playingPlayers.Count - 
starting);
                                } else {
                                        return new List<Player> ();
                                }
                        }
                }
 
+               public void RemovePlayers (List<Player> players, bool delete)
+               {
+                       List<Player> bench, starters;
+                       
+                       bench = BenchPlayersList;
+                       starters = StartingPlayersList;
+
+                       foreach (Player p in players) {
+                               if (List.Contains (p)) {
+                                       if (starters.Contains (p) && bench.Count > 0) {
+                                               List.Swap (p, bench [0]);
+                                       }
+                                       List.Remove (p);
+                                       if (!delete) {
+                                               List.Add (p);
+                                               p.Playing = false;
+                                       }
+                               }
+                       }
+               }
+
                public void Save(string filePath) {
                        Serializer.Save(this, filePath);
                }
diff --git a/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs 
b/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
index 95e2a10..57fc23e 100644
--- a/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/PlayersTaggerObject.cs
@@ -150,11 +150,15 @@ namespace LongoMatch.Drawing.CanvasObjects
                {
                        SelectedPlayers.Clear ();
                        substitutionPlayer = null;
-                       foreach (PlayerObject player in homePlayers) {
-                               player.Active = false;
+                       if (homePlayers != null) {
+                               foreach (PlayerObject player in homePlayers) {
+                                       player.Active = false;
+                               }
                        }
-                       foreach (PlayerObject player in awayPlayers) {
-                               player.Active = false;
+                       if (awayPlayers != null) {
+                               foreach (PlayerObject player in awayPlayers) {
+                                       player.Active = false;
+                               }
                        }
                }
 
@@ -189,6 +193,7 @@ namespace LongoMatch.Drawing.CanvasObjects
                                field.Width = 300;
                                field.Height = 250;
                        }
+                       ResetSelection ();
                        ClearPlayers ();
                        homePlayingPlayers = awayPlayingPlayers = null;
 
diff --git a/LongoMatch.Drawing/Widgets/TeamTagger.cs b/LongoMatch.Drawing/Widgets/TeamTagger.cs
index 3e59460..d909b18 100644
--- a/LongoMatch.Drawing/Widgets/TeamTagger.cs
+++ b/LongoMatch.Drawing/Widgets/TeamTagger.cs
@@ -87,11 +87,19 @@ namespace LongoMatch.Drawing.Widgets
 
                protected override void ShowMenu (Point coords)
                {
-                       Selection sel = tagger.GetSelection (coords, 0);
+                       List<Player> players = tagger.SelectedPlayers;
+
+                       if (players.Count == 0) {
+                               Selection sel = tagger.GetSelection (coords, 0, true);
+                               if (sel != null) {
+                                       players = new List<Player> { (sel.Drawable as PlayerObject).Player };
+                               }
+                       } else {
+                               players = tagger.SelectedPlayers;
+                       }
                        
-                       if (sel != null && ShowMenuEvent != null) {
-                               PlayerObject po = sel.Drawable as PlayerObject;
-                               ShowMenuEvent (new List<Player> { po.Player });
+                       if (players.Count > 0 && ShowMenuEvent != null) {
+                               ShowMenuEvent (players);
                        }
                }
 
diff --git a/LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs 
b/LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs
index c123b8f..cdd6bb4 100644
--- a/LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs
+++ b/LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs
@@ -183,7 +183,7 @@ namespace LongoMatch.Gui.Component
 
                void FillFormation () {
                        tacticsentry.Text = template.FormationStr;
-                       nplayerslabel.Text = template.PlayingPlayers.ToString();
+                       nplayerslabel.Text = template.StartingPlayers.ToString();
                }
                
                void LoadPlayer (Player p) {
diff --git a/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs b/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
index de38c61..96c1367 100644
--- a/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
+++ b/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
@@ -138,6 +138,7 @@ namespace LongoMatch.Gui.Panel
                        
                        drawingarea.HeightRequest = 200;
                        teamtagger = new TeamTagger (new WidgetWrapper (drawingarea));
+                       teamtagger.ShowMenuEvent += HandleShowMenuEvent;
                        teamtagger.SubstitutionMode = true;
                        teams = Config.TeamTemplatesProvider.Templates;
                        hometeamscombobox.Load (teams);
@@ -435,6 +436,21 @@ namespace LongoMatch.Gui.Panel
                        }
                        UpdateTitle ();
                }
+
+               void HandleShowMenuEvent (List<Player> players)
+               {
+                       Menu menu = new Menu ();
+                       MenuItem item = new MenuItem ("Remove for this match");
+                       item.Activated += (sender, e) => {
+                                       hometemplate.RemovePlayers (players, false);
+                                       awaytemplate.RemovePlayers (players, false);
+                                       teamtagger.Reload ();
+                                       drawingarea.QueueDraw ();
+                       };
+                       menu.Add (item);
+                       menu.ShowAll ();
+                       menu.Popup ();
+               }
        }
 }
 


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