[longomatch] WIP



commit 61e0f361e2b742a73e3446ff24a7effcd4b6e188
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Oct 14 02:16:45 2014 +0200

    WIP

 LongoMatch.Core/Handlers/Handlers.cs               |    1 +
 LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs |    8 +++-
 LongoMatch.Drawing/CanvasObjects/TimelineObject.cs |    6 +-
 LongoMatch.Drawing/Widgets/PlaysTimeline.cs        |   14 +++++--
 LongoMatch.Drawing/Widgets/TimersTimeline.cs       |   16 +++++++-
 LongoMatch.GUI/Gui/Component/ProjectPeriods.cs     |   42 ++++++++++++++++++-
 LongoMatch.GUI/LongoMatch.GUI.csproj               |    2 +
 7 files changed, 77 insertions(+), 12 deletions(-)
---
diff --git a/LongoMatch.Core/Handlers/Handlers.cs b/LongoMatch.Core/Handlers/Handlers.cs
index fe1f203..e1e994d 100644
--- a/LongoMatch.Core/Handlers/Handlers.cs
+++ b/LongoMatch.Core/Handlers/Handlers.cs
@@ -128,6 +128,7 @@ namespace LongoMatch.Core.Handlers
        public delegate void TagSubcategoriesChangedHandler (bool tagsubcategories);
        public delegate void ShowTimelineMenuHandler (List<TimelineEvent> plays,EventType cat,Time time);
        public delegate void ShowTimersMenuHandler (List<TimeNode> timenodes);
+       public delegate void ShowTimerMenuHandler (Timer timer, Time time);
        public delegate void ShowTaggerMenuHandler (List<TimelineEvent> plays);
        public delegate void ShowDrawToolMenuHandler (IBlackboardObject drawable);
        public delegate void ConfigureDrawingObjectHandler (IBlackboardObject drawable, DrawTool tool);
diff --git a/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs 
b/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
index 331276b..599fc33 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
@@ -222,8 +222,14 @@ namespace LongoMatch.Drawing.CanvasObjects
        
        public class TimerTimeNodeObject: TimeNodeObject
        {
-               public TimerTimeNodeObject (TimeNode tn): base (tn)
+               public TimerTimeNodeObject (Timer t, TimeNode tn): base (tn)
                {
+                       Timer = t;
+               }
+               
+               public Timer Timer {
+                       get;
+                       set;
                }
        }
 }
diff --git a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs 
b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
index d68c2ac..9eec3ad 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
@@ -258,7 +258,7 @@ namespace LongoMatch.Drawing.CanvasObjects
        
                        foreach (Timer t in timers) {
                                foreach (TimeNode tn in t.Nodes) {
-                                       AddTimeNode (tn);
+                                       AddTimeNode (t, tn);
                                }
                        }
                }
@@ -288,9 +288,9 @@ namespace LongoMatch.Drawing.CanvasObjects
                        return nodes.FirstOrDefault (n => n.TimeNode == tn) != null;
                }
 
-               public void AddTimeNode (TimeNode tn)
+               public void AddTimeNode (Timer t, TimeNode tn)
                {
-                       TimerTimeNodeObject to = new TimerTimeNodeObject (tn);
+                       TimerTimeNodeObject to = new TimerTimeNodeObject (t, tn);
                        to.OffsetY = OffsetY;
                        to.SecondsPerPixel = SecondsPerPixel;
                        to.MaxTime = maxTime;
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index 385e160..60717f1 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -32,6 +32,7 @@ namespace LongoMatch.Drawing.Widgets
        
                public event ShowTimelineMenuHandler ShowMenuEvent;
                public event ShowTimersMenuHandler ShowTimersMenuEvent;
+               public event ShowTimerMenuHandler ShowTimerMenuEvent;
 
                Project project;
                EventsFilter playsFilter;
@@ -200,10 +201,15 @@ namespace LongoMatch.Drawing.Widgets
 
                void ShowTimersMenu (Point coords)
                {
-                       List<TimeNode> nodes = Selections.Select (p => (p.Drawable as 
TimeNodeObject).TimeNode).ToList ();
-                       if (nodes.Count > 0 && ShowTimersMenuEvent != null) {
-                               /* Periods are not deletable */
-                               if (!periodsTimeline.HasNode (nodes[0])) {
+                       if (coords.Y >= periodsTimeline.OffsetY &&
+                               coords.Y < periodsTimeline.OffsetY + periodsTimeline.Height) {
+                               Timer t = Selections.FirstOrDefault.Select (p => (p.Drawable as 
TimerTimeNodeObject).Timer);
+                               if (ShowTimerMenuEvent != nul) {
+                                       ShowTimerMenuEvent (t, Utils.PosToTime (coords, SecondsPerPixel));
+                               }
+                       } else {
+                               List<TimeNode> nodes = Selections.Select (p => (p.Drawable as 
TimeNodeObject).TimeNode).ToList ();
+                               if (nodes.Count > 0 && ShowTimersMenuEvent != null) {
                                        ShowTimersMenuEvent (nodes);
                                }
                        }
diff --git a/LongoMatch.Drawing/Widgets/TimersTimeline.cs b/LongoMatch.Drawing/Widgets/TimersTimeline.cs
index 8c7c058..bb2ab6a 100644
--- a/LongoMatch.Drawing/Widgets/TimersTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/TimersTimeline.cs
@@ -13,6 +13,7 @@ namespace LongoMatch.Drawing.Widgets
        {
        
                public event TimeNodeChangedHandler TimeNodeChanged;
+               public event ShowTimerMenuHandler ShowTimerMenuEvent;
 
                double secondsPerPixel;
                Time duration;
@@ -36,6 +37,7 @@ namespace LongoMatch.Drawing.Widgets
                        this.timers = new Dictionary<Timer, TimerTimeline> ();
                        this.duration = duration;
                        FillCanvas (timers, splitTimers);
+                       widget.ReDraw ();
                }
 
                public Time CurrentTime {
@@ -74,7 +76,7 @@ namespace LongoMatch.Drawing.Widgets
                {
                        if (!splitTimers) {
                                widget.Height = Constants.TIMER_HEIGHT;
-                               TimerTimeline tl = new TimerTimeline (timers, true, false, true, duration, 0,
+                               TimerTimeline tl = new TimerTimeline (timers, true, true, true, duration, 0,
                                                                      Config.Style.PaletteBackground,
                                                                      Config.Style.PaletteBackgroundLight);
                                foreach (Timer t in timers) {
@@ -116,5 +118,17 @@ namespace LongoMatch.Drawing.Widgets
                                TimeNodeChanged (tn, moveTime);
                        }
                }
+               
+               protected override void ShowMenu (Point coords)
+               {
+                       if (ShowTimerMenuEvent != null) {
+                               Timer t = null;
+                               if (Selections.Count > 0) {
+                                       TimerTimeNodeObject to = Selections.Last ().Drawable as 
TimerTimeNodeObject; 
+                                       t = to.Timer;
+                               } 
+                               ShowTimerMenuEvent (t, Utils.PosToTime (coords, SecondsPerPixel));
+                       }
+               }
        }
 }
diff --git a/LongoMatch.GUI/Gui/Component/ProjectPeriods.cs b/LongoMatch.GUI/Gui/Component/ProjectPeriods.cs
index 7685d53..f6ba571 100644
--- a/LongoMatch.GUI/Gui/Component/ProjectPeriods.cs
+++ b/LongoMatch.GUI/Gui/Component/ProjectPeriods.cs
@@ -23,6 +23,7 @@ using LongoMatch.Drawing.Cairo;
 using Mono.Unix;
 using LongoMatch.Gui.Helpers;
 using LongoMatch.Core.Common;
+using Gtk;
 
 namespace LongoMatch.Gui.Component
 {
@@ -32,6 +33,7 @@ namespace LongoMatch.Gui.Component
                TimersTimeline timersTimenline;
                Timerule timerule;
                Time duration;
+               Project project;
                
                public ProjectPeriods ()
                {
@@ -45,13 +47,14 @@ namespace LongoMatch.Gui.Component
                        drawingarea1.HeightRequest = LongoMatch.Drawing.Constants.TIMERULE_HEIGHT;
                        drawingarea2.HeightRequest = LongoMatch.Drawing.Constants.TIMER_HEIGHT;
                        timersTimenline.TimeNodeChanged += HandleTimeNodeChanged;
+                       timersTimenline.ShowTimerMenuEvent += HandleShowTimerMenuEvent;
                        scrolledwindow2.Hadjustment.ValueChanged += HandleValueChanged;
                        synclabel.Markup = String.Format ("{0} {1} {2}", "<b>⬇  ",
                                                        Catalog.GetString ("Synchronize the game periods"),
                                                        "  ⬇</b>");
-                       Misc.SetFocus (this, false);
+                       LongoMatch.Gui.Helpers.Misc.SetFocus (this, false);
                }
-               
+
                protected override void OnDestroyed ()
                {
                        playerbin2.Destroy ();
@@ -67,7 +70,7 @@ namespace LongoMatch.Gui.Component
                                MediaFile file;
                                
                                playerbin2.ShowControls = false;
-                               
+                               this.project = value;
                                gamePeriods = value.Dashboard.GamePeriods;
 
                                file = value.Description.FileSet.GetAngle (MediaFileAngle.Angle1);
@@ -135,6 +138,39 @@ namespace LongoMatch.Gui.Component
                        drawingarea1.QueueDraw();
                        drawingarea2.QueueDraw();
                }
+               
+               void HandleShowTimerMenuEvent (Timer timer, Time time)
+               {
+                       Menu menu = new Menu ();
+                       MenuItem additem = new MenuItem (Catalog.GetString ("Add period"));
+                       additem.Activated += (sender, e) => {
+                               string periodname = Config.GUIToolkit.QueryMessage (Catalog.GetString 
("Period name"), null,
+                                                                                   (project.Periods.Count + 
1).ToString(),
+                                                                                   this);
+                               if (periodname != null) {
+                                       project.Dashboard.GamePeriods.Add (periodname);
+                                       Period p = new Period {Name = periodname};
+                                       p.Nodes.Add (new TimeNode {
+                                               Name = periodname,
+                                               Start = new Time {Seconds = time.Seconds - 10},
+                                               Stop = new Time {Seconds = time.Seconds + 10}});
+                                       project.Periods.Add (p);
+                                       timersTimenline.LoadPeriods (project.Periods, duration);
+                               }
+                       };
+                       menu.Add (additem);
+                       if (timer != null) {
+                               MenuItem delitem = new MenuItem (Catalog.GetString ("Delete period"));
+                               delitem.Activated += (sender, e) => {
+                                       project.Periods.Remove (timer as Period);
+                                       timersTimenline.LoadPeriods (project.Periods, duration);
+                               };
+                               menu.Add (delitem);
+                       }
+                       menu.ShowAll ();
+                       menu.Popup ();
+               }
+               
        }
 }
 
diff --git a/LongoMatch.GUI/LongoMatch.GUI.csproj b/LongoMatch.GUI/LongoMatch.GUI.csproj
index 0b4ca14..8205188 100644
--- a/LongoMatch.GUI/LongoMatch.GUI.csproj
+++ b/LongoMatch.GUI/LongoMatch.GUI.csproj
@@ -189,6 +189,8 @@
     <Compile Include="gtk-gui\LongoMatch.Gui.Dialog.EventTypeTagsEditor.cs" />
     <Compile Include="Gui\Component\MediaFileSetSelection.cs" />
     <Compile Include="gtk-gui\LongoMatch.Gui.Component.MediaFileSetSelection.cs" />
+    <Compile Include="Gui\Menu\PeriodsMenu.cs" />
+    <Compile Include="gtk-gui\LongoMatch.Gui.Menu.PeriodsMenu.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="gtk-gui\gui.stetic">


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