[longomatch] Implement players substitutions in the team tagger
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Implement players substitutions in the team tagger
- Date: Mon, 7 Jul 2014 11:25:21 +0000 (UTC)
commit 2a357e7366a5415b72cb618f05a324c54f3d12ef
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu May 29 12:05:55 2014 +0200
Implement players substitutions in the team tagger
LongoMatch.Drawing/Widgets/TeamTagger.cs | 109 ++++++++++++++------
LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs | 36 ++-----
LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs | 1 +
3 files changed, 87 insertions(+), 59 deletions(-)
---
diff --git a/LongoMatch.Drawing/Widgets/TeamTagger.cs b/LongoMatch.Drawing/Widgets/TeamTagger.cs
index 2f9693a..3439de0 100644
--- a/LongoMatch.Drawing/Widgets/TeamTagger.cs
+++ b/LongoMatch.Drawing/Widgets/TeamTagger.cs
@@ -42,11 +42,14 @@ namespace LongoMatch.Drawing.Widgets
double currentWidth, currentHeight, scaleX, scaleY;
Point offset;
double backgroundWidth;
+ MultiSelectionMode prevMode;
+ bool inSubs;
public TeamTagger (IWidget widget): base (widget)
{
Accuracy = 0;
SelectionMode = MultiSelectionMode.MultipleWithModifier;
+ SubstitutionsMode = false;
HomeColor = Common.PLAYER_UNSELECTED_COLOR;
AwayColor = Common.PLAYER_UNSELECTED_COLOR;
}
@@ -68,6 +71,51 @@ namespace LongoMatch.Drawing.Widgets
Resize ();
}
+ public bool SubstitutionsMode {
+ set {
+ if (value) {
+ prevMode = SelectionMode;
+ SelectionMode = MultiSelectionMode.Multiple;
+ ClearSelection ();
+ } else {
+ SelectionMode = prevMode;
+ }
+ inSubs = value;
+ }
+ get {
+ return inSubs;
+ }
+ }
+ public void Select (Player p) {
+ 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));
+ }
+ }
+ widget.ReDraw ();
+ }
+
+ public void Reload () {
+ Objects.Clear();
+ if (homeTeam != null) {
+ LoadTeam (homeTeam, Team.LOCAL);
+ }
+ if (awayTeam != null) {
+ LoadTeam (awayTeam, Team.VISITOR);
+ }
+ widget.ReDraw ();
+ }
+
+ int NTeams {
+ get {
+ return awayTeam == null ? 1 : 2;
+ }
+ }
+
+
void LoadTeam (TeamTemplate template, Team team) {
int index = 0;
double width, colWidth, offsetX;
@@ -129,35 +177,6 @@ namespace LongoMatch.Drawing.Widgets
}
}
- public void Select (Player p) {
- 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));
- }
- }
- widget.ReDraw ();
- }
-
- public void Reload () {
- Objects.Clear();
- if (homeTeam != null) {
- LoadTeam (homeTeam, Team.LOCAL);
- }
- if (awayTeam != null) {
- LoadTeam (awayTeam, Team.VISITOR);
- }
- widget.ReDraw ();
- }
-
- int NTeams {
- get {
- return awayTeam == null ? 1 : 2;
- }
- }
-
void Resize () {
currentWidth = widget.Width;
currentHeight = widget.Height;
@@ -171,9 +190,35 @@ namespace LongoMatch.Drawing.Widgets
}
protected override void SelectionChanged (List<Selection> selections) {
- if (PlayersSelectionChangedEvent != null) {
- PlayersSelectionChangedEvent (
- selections.Select (s => (s.Drawable as
PlayerObject).Player).ToList());
+ List<Player> players;
+
+ players = selections.Select (s => (s.Drawable as PlayerObject).Player).ToList();
+
+ if (SubstitutionsMode) {
+ bool subsDone = false;
+ if (homeTeam != null) {
+ List<Player> hplayers = players.Where (p => homeTeam.Contains
(p)).ToList();
+ if (hplayers.Count == 2) {
+ homeTeam.Swap (hplayers[0], hplayers[1]);
+ subsDone = true;
+ }
+ }
+ if (awayTeam != null) {
+ List<Player> aplayers = players.Where (p => awayTeam.Contains
(p)).ToList();
+ if (aplayers.Count == 2) {
+ awayTeam.Swap (aplayers[0], aplayers[1]);
+ subsDone = true;
+ }
+ }
+ if (subsDone) {
+ ClearSelection ();
+ Reload ();
+ widget.ReDraw ();
+ }
+ } else {
+ if (PlayersSelectionChangedEvent != null) {
+ PlayersSelectionChangedEvent (players);
+ }
}
}
diff --git a/LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs
b/LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs
index e5b8551..b13ad34 100644
--- a/LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs
+++ b/LongoMatch.GUI/Gui/Component/TeamTemplateEditor.cs
@@ -44,7 +44,6 @@ namespace LongoMatch.Gui.Component
bool edited, ignoreChanges;
List<Player> selectedPlayers;
TeamTagger teamtagger;
- bool inSubs;
public TeamTemplateEditor ()
{
@@ -176,25 +175,14 @@ namespace LongoMatch.Gui.Component
}
void PlayersSelected (List<Player> players) {
- if (inSubs) {
- if (players.Count == 2) {
- ExtensionMethods.Swap (template, template.IndexOf (players[0]),
- template.IndexOf (players[1]));
- teamtagger.ClearSelection ();
- teamtagger.Reload ();
- Edited = true;
- }
- return;
+ playerframe.Sensitive = players.Count == 1;
+ selectedPlayers = players;
+ deletebutton.Sensitive = players.Count != 0;
+ playerframe.Sensitive = players.Count != 0;
+ if (players.Count == 1) {
+ LoadPlayer (players[0]);
} else {
- playerframe.Sensitive = players.Count == 1;
- selectedPlayers = players;
- deletebutton.Sensitive = players.Count != 0;
- playerframe.Sensitive = players.Count != 0;
- if (players.Count == 1) {
- LoadPlayer (players[0]);
- } else {
- loadedPlayer = null;
- }
+ loadedPlayer = null;
}
}
@@ -215,14 +203,8 @@ namespace LongoMatch.Gui.Component
void HandleSubsClicked (object sender, EventArgs e)
{
- inSubs = subsbutton.Active;
- teamtagger.ClearSelection ();
- if (inSubs) {
- teamtagger.SelectionMode = MultiSelectionMode.Multiple;
- } else {
- teamtagger.SelectionMode = MultiSelectionMode.MultipleWithModifier;
- }
- warninglabel.Visible = inSubs;
+ teamtagger.SubstitutionsMode = subsbutton.Active;
+ warninglabel.Visible = subsbutton.Active;
}
void HandlePlayersSelectionChangedEvent (List<Player> players)
diff --git a/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs b/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
index c8658c8..5efea35 100644
--- a/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
+++ b/LongoMatch.GUI/Gui/Panel/NewProjectPanel.cs
@@ -116,6 +116,7 @@ namespace LongoMatch.Gui.Panel
LoadTemplate (awayteamscombobox.ActiveText, Team.VISITOR);};
hometeamscombobox.Active = 0;
awayteamscombobox.Active = 0;
+ teamtagger.SubstitutionsMode = true;
}
void ConnectSignals () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]