[longomatch] Add timeline for game units



commit a30c6c6a0d17a9448a317837b571740fc7919ba6
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Nov 29 22:13:31 2011 +0100

    Add timeline for game units

 .../Gui/Component/GameUnitsTimelineWidget.cs       |  120 ++++++++++++++++++++
 LongoMatch.GUI/LongoMatch.GUI.mdp                  |    1 +
 LongoMatch.GUI/Makefile.am                         |    1 +
 3 files changed, 122 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Component/GameUnitsTimelineWidget.cs b/LongoMatch.GUI/Gui/Component/GameUnitsTimelineWidget.cs
new file mode 100644
index 0000000..d3ae014
--- /dev/null
+++ b/LongoMatch.GUI/Gui/Component/GameUnitsTimelineWidget.cs
@@ -0,0 +1,120 @@
+// TimeLineWidget.cs
+//
+//  Copyright (C) 2007-2009 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Gtk;
+
+using LongoMatch.Gui.Base;
+using LongoMatch.Handlers;
+using LongoMatch.Store;
+using LongoMatch.Store.Templates;
+
+namespace LongoMatch.Gui.Component {
+
+	public class GameUnitsTimelineWidget : TimelineBase<GameUnitTimeScale, TimelineNode> 
+	{
+
+		public event UnitChangedHandler UnitChanged;
+		public event UnitSelectedHandler UnitSelected;
+		public event UnitsDeletedHandler UnitDeleted;
+		public event UnitAddedHandler UnitAdded;
+
+		GameUnitsList gameUnits;
+
+		public GameUnitsTimelineWidget(): base()
+		{
+		}
+
+		public Project Project {
+			set {
+				ResetGui();
+
+				if(value == null) {
+					gameUnits = null;
+					tsList.Clear();
+					loaded = false;
+					return;
+				}
+				loaded = true;
+				gameUnits = value.GameUnits;
+				tsList.Clear(); 
+				frames = value.Description.File.GetFrames();
+
+				cs.Labels = gameUnits.Select(g => g.Name).ToList(); 
+				cs.Show();
+
+				tr.Frames = frames;
+				tr.FrameRate = value.Description.File.Fps;
+				tr.Show();
+
+				foreach(GameUnit gameUnit in gameUnits) {
+					GameUnitTimeScale ts = new GameUnitTimeScale(gameUnit, frames);
+					tsList[gameUnit] = ts;
+					ts.UnitAdded += HandleUnitAdded;
+					ts.UnitDeleted += HandleUnitDeleted;
+					ts.UnitChanged += HandleUnitChanged;
+					ts.UnitSelected += HandleUnitSelected;
+					TimelineBox.PackStart(ts,false,true,0);
+					ts.Show();
+				}
+				SetPixelRatio(3);
+			}
+		}
+
+		public void AddUnit(GameUnit gameUnit, TimelineNode unit) {
+			GameUnitTimeScale ts;
+			if(tsList.TryGetValue(gameUnit, out ts))
+				ts.AddUnit(unit);
+		}
+
+		public void RemoveUnit(GameUnit gameUnit, List<TimelineNode> units) {
+			GameUnitTimeScale ts;
+			foreach(TimelineNode unit in units) {
+				if(tsList.TryGetValue(gameUnit, out ts))
+					ts.RemoveUnit(unit);
+			}
+		}
+		
+		void HandleUnitSelected (GameUnit gameUnit, TimelineNode unit)
+		{
+			if (UnitSelected != null)
+				UnitSelected(gameUnit, unit);
+		}
+
+		void HandleUnitChanged (GameUnit gameUnit, TimelineNode unit, Time time)
+		{
+			if (UnitChanged != null)
+				UnitChanged(gameUnit, unit, time);
+		}
+
+		void HandleUnitDeleted (GameUnit gameUnit, List<TimelineNode> unit)
+		{
+			if (UnitDeleted != null)
+				UnitDeleted(gameUnit, unit);
+		}
+
+		void HandleUnitAdded (GameUnit gameUnit, int frame)
+		{
+			if (UnitAdded != null)
+				UnitAdded(gameUnit, frame);
+		}
+	}
+}
diff --git a/LongoMatch.GUI/LongoMatch.GUI.mdp b/LongoMatch.GUI/LongoMatch.GUI.mdp
index 743a897..a9d339a 100644
--- a/LongoMatch.GUI/LongoMatch.GUI.mdp
+++ b/LongoMatch.GUI/LongoMatch.GUI.mdp
@@ -148,6 +148,7 @@
     <File subtype="Code" buildaction="Compile" name="Gui/Component/GameUnitTimeScale.cs" />
     <File subtype="Code" buildaction="Compile" name="Gui/Base/TimelineWidgetBase.cs" />
     <File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.Base.TimelineWidgetBase.cs" />
+    <File subtype="Code" buildaction="Compile" name="Gui/Component/GameUnitsTimelineWidget.cs" />
   </Contents>
   <MonoDevelop.Autotools.MakefileInfo RelativeMakefileName="../CesarPlayer/Makefile.am" RelativeConfigureInPath="../">
     <BuildFilesVar Name="FILES" />
diff --git a/LongoMatch.GUI/Makefile.am b/LongoMatch.GUI/Makefile.am
index 003107a..bb0c53b 100644
--- a/LongoMatch.GUI/Makefile.am
+++ b/LongoMatch.GUI/Makefile.am
@@ -64,6 +64,7 @@ SOURCES = \
 	Gui/Component/GameUnitsEditor.cs \
 	Gui/Component/GameUnitsTagger.cs \
 	Gui/Component/GameUnitTimeScale.cs \
+	Gui/Component/GameUnitsTimelineWidget.cs \
 	Gui/Component/GameUnitWidget.cs \
 	Gui/Component/NotesWidget.cs \
 	Gui/Component/PlayerProperties.cs \



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