Skinning contest: One month to go (1 Viewer)

Albert

MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    45
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: Skinning contest: One month to go

    System.ArgumentException: WorkflowManager: Model with id '5726da5a-70d5-458f-af67-611293d97912' is not available

    I didn't check your whole files yet.
    But the problem here is that you create Windows UI objects, for example Ellipse in method CreateParticle().
    Remove those usings:

    using System.Windows.Media.Media3D;
    using System.Windows.Media.Effects;
    using System.Windows.Shapes;

    and, off course, all usages of classes which belong to them. They don't belong into a MediaPortal 2 model.
    I guess you copied the code from the original Particles program.
    You have to provide the code which calculates the particle positions and maybe some properties for the particles, but not the UI elements of the particles in your model. The UI elements come from the skin file.
     

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    AW: Skinning contest: One month to go

    Concerning the resourceWrapper and the contentPresnert:
    I think I got the point now ;) You use it that you have always a menu / the same menu, similar to PHP and templates where you have a main template and include the content templates^^ This would be the main usage of the resourceWrapper I guess. I will try this if I'm more advanced in the basics of MPF.
    I somebody else wants to read smoe details about the contentPresenter:
    What is a ContentPresenter? | .NET Zone

    and a German one: wozu genau dient der ContentPresenter????

    To make that work, in your "label", you need to write "{StaticResource BlackColor}" or "{ThemeResource BlackColor}".
    Sorry, I forgotten the StaticResource/ThemeResource^^

    Now to the timer problem:

    Oh no, I would never change the skinEngine with my little knowledge of MPF right now^^
    I'm playing with the helloWorld Plugin.. okay there is nothing as it was, but playing with MPF and doing some useless stuff gives you a feeling for MPF over the time :)

    How can I block the windows message loop?!

    it depends on this namespace:
    Code:
    using System.Windows.Threading;
    ...
    DispatcherTimer timer = new DispatcherTimer();

    I really don't know what's wrong because there is no much different to my test WPF application and there it worked fine. Maybe I have to subscribe to some MessageQueue?!
    In the BaseTimerControlledModel.cs you subscribe to Messages, but you only detect the "SystemState.Running" and "SystemState.ShuttingDown"...

    Here is my complete Model.cs, maybe you have a hint and thanks for your great help above ;)

    Code:
    #region Copyright (C) 2007-2010 Team MediaPortal
    
    /*
        Copyright (C) 2007-2010 Team MediaPortal
        https://www.team-mediaportal.com
    
        This file is part of MediaPortal 2
    
        MediaPortal 2 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 3 of the License, or
        (at your option) any later version.
    
        MediaPortal 2 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 MediaPortal 2.  If not, see <http://www.gnu.org/licenses/>.
    */
    
    #endregion
    
    using MediaPortal.Core.General;
    using MediaPortal.UI.Presentation.Models;
    
    using MediaPortal.UI.SkinEngine.MpfElements;
    using MediaPortal.UI.SkinEngine.SkinManagement;
    using MediaPortal.UI.SkinEngine.Xaml;
    using MediaPortal.UI.SkinEngine.Xaml.Interfaces;
    using MediaPortal.UI.SkinEngine.Controls.Visuals;
    using MediaPortal.UI.SkinEngine.MpfElements.Resources;
    
    using MediaPortal.Core;
    using MediaPortal.Core.Logging;
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    
    using System.Windows.Threading;
    //using System.Windows.Media;
    using System.Windows.Media.Media3D;
    using System.Windows.Media.Effects;
    using System.Windows.Shapes;
    using System.Collections;
    
    namespace Models.HelloWorld
    {
      /// <summary>
      /// Example for a simple model.
      /// The screenfile to this model is located at:
      /// /Skins/default/screens/hello_world.xaml
      /// </summary>
      /// <remarks>
      /// <para>
      /// Models are used for providing data from the system to the skin and for executing actions (commands)
      /// which are triggered by the Skin, for example by clicking a button.
      /// </para>
      /// <para>
      /// All public properties can be data-bound by the skin, for example the <see cref="HelloString"/> property.
      /// Note that properties, which are updated by the model and whose new value should be propagated to the
      /// skin, must be backed by an instance of <see cref="AbstractProperty"/>. That instance must be made available
      /// to the skin engine by publishing it under the same name as the actual property plus "Property", see for example
      /// <see cref="HelloStringProperty"/>.
      /// </para>
      /// <para>
      /// You can also consider to implement the interface <see cref="IWorkflowModel"/>, which makes it
      /// possible to attend the screenflow = workflow of the user session. When that interface is implemented and this
      /// model is registered in a workflow state as backing workflow model, the model will get notifications when the
      /// GUI navigation switches to or away from its workflow state.
      /// </para>
      /// <para>
      /// To make an UI model known by the system (and thus loadable by the skin), it is necessary to register it
      /// in the <c>plugin.xml</c> file.
      /// </para>
      /// </remarks>
      public class Model
      {
        // ListItem
        public List<Particle> particleList = new List<Particle>();
          
        /// <summary>
        /// This is a localized string resource. Localized string resources always look like this:
        /// <example>
        /// [Section.Name]
        /// </example>
        /// Localized resources must be present at least in the english language, as this is the default.
        /// In the english language file of this hello world plugin, you'll find the translation of this string.
        /// The language file is located at: /Language/strings_en.xml
        /// </summary>
        protected const string HELLOWORLD_RESOURCE = "[HelloWorld.HelloWorldText]";
        protected const string TranslateTransform0_X_RESOURCE = "20";
        protected const string TranslateTransform0_Y_RESOURCE = "20";
    
        /// <summary>
        /// Another localized string resource.
        /// </summary>
        protected const string COMMAND_TRIGGERED_RESOURCE = "[HelloWorld.ButtonTextCommandExecuted]";
    
        /// <summary>
        /// This property holds a string that we will modify in this tutorial.
        /// </summary>
        private readonly AbstractProperty _helloStringProperty;
        private readonly AbstractProperty _TranslateTransform0_XProperty;
        private readonly AbstractProperty _TranslateTransform0_YProperty;
    
        /// <summary>
        /// Constructor... this one is called by the WorkflowManager when this model is loaded due to a screen reference.
        /// </summary>
        public Model()
        {
          // In models, properties will always be WProperty instances. When using SProperties for screen databinding,
          // the system might run into memory leaks.
          _helloStringProperty = new WProperty(typeof(string), HELLOWORLD_RESOURCE);
          _TranslateTransform0_XProperty = new WProperty(typeof(string), TranslateTransform0_X_RESOURCE);
          _TranslateTransform0_YProperty = new WProperty(typeof(string), TranslateTransform0_Y_RESOURCE);
          //_ParticleHost = new WProperty(typeof(string), ParticleHost);
    
          Window_Loaded();
        }
          
        /// <summary>
        /// This sample property will be accessed by the hello_world screen. Note that the data type must be the same
        /// as in the instantiation of our backing property <see cref="_helloStringProperty"/>.
        /// </summary>
        public string HelloString
        {
          get { return (string) _helloStringProperty.GetValue(); }
          set { _helloStringProperty.SetValue(value); }
        }
    
        public string TranslateTransform0_X
        {
            get { return (string)_TranslateTransform0_XProperty.GetValue(); }
            set { _TranslateTransform0_XProperty.SetValue(value); }
        }
    
        public string TranslateTransform0_Y
        {
            get { return (string)_TranslateTransform0_YProperty.GetValue(); }
            set { _TranslateTransform0_YProperty.SetValue(value); }
        }
    
        /// <summary>
        /// This is the dependency property for our sample string. It is needed to propagate changes to the skin.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the screen databinds to the <see cref="HelloString"/> property in a binding mode which will propagate data
        /// changes from the model to the skin, the SkinEngine will attach a change handler to this property.
        /// </para>
        /// <para>
        /// In other words: Every property <c>Xyz</c>, which should be able to be attached to, must be present also as
        /// <c>XyzProperty</c>.
        /// Only if <c>XyzProperty</c> is present in the model, value changes can be propagated to the skin.
        /// </remarks>
        public AbstractProperty HelloStringProperty
        {
          get { return _helloStringProperty; }
        }
    
        public AbstractProperty TranslateTransform0_XProperty
        {
            get { return _TranslateTransform0_XProperty; }
        }
    
        public AbstractProperty TranslateTransform0_YProperty
        {
            get { return _TranslateTransform0_YProperty; }
        }
    
        /// <summary>
        /// Method which will be called from our screen. We will change the value of our HelloWorld string here.
        /// </summary>
        public void ChangeHelloWorldString()
        {
          HelloString = COMMAND_TRIGGERED_RESOURCE;
        }
    
        DispatcherTimer timer = new DispatcherTimer();
        Random random = new Random(DateTime.Now.Millisecond);
    
        // Some general values 
        double MaxSize = 30;
        double NumberOfParticles = 1;
        int Width = 800;
        int Height = 600;
        /*double VerticalVelocity = 0.4;
        double HorizontalVelocity = -2.2;
        double elapsed = 0.1;*/
    
        ILogger logger = ServiceRegistration.Get<ILogger>();
          
        public void Window_Loaded()
        {
            for (int i = 0; i < NumberOfParticles; i++)
            {
                CreateParticle();
            }
    
            timer.Interval = TimeSpan.FromMilliseconds(33.33);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
    
            logger.Info("HelloWorld: Window_Loaded() - timer started: " + timer.IsEnabled.ToString());
            HelloString = "EXECUTED";
        }
          
        public void timer_Tick(object sender, EventArgs e)
        {
            logger.Info("HelloWorld: TimerTick");
            // I control "particle" from their ellipse representation 
            //foreach (Ellipse ellipse in ParticleHost.Children)
            //{
                /*var p = ellipse.Tag as Particle;
                var t = ellipse.RenderTransform as TranslateTransform;
    
                // Update location 
                t.X += p.Velocity.X;
                t.Y += p.Velocity.Y;
    
    
                // Check if the particle is too high 
                if (t.Y < -MaxSize)
                {
                    t.Y = Height + MaxSize;
                }
    
                // Check if the particle has gone outside 
                if (t.X < -MaxSize || t.X > Width + MaxSize)
                {
                    t.X = random.NextDouble() * Width;
                    t.Y = Height + MaxSize;
                }
    
                // Brush & Effect 
                //ellipse.Fill = p.Brush;
                ellipse.Fill = (Brush)Brushes.White.Clone();
                // Comment this line to deactivate the Blur Effect 
                ellipse.Effect = p.Blur;*/
            //}
    
            //----------------------------
    
            foreach (Particle particle in particleList)
            {
                TranslateTransform0_X = (ToDouble(TranslateTransform0_X) + particle.Velocity.X).ToString();
                TranslateTransform0_Y = (ToDouble(TranslateTransform0_Y) + particle.Velocity.Y).ToString();
    
                HelloString = "Transform X to " + TranslateTransform0_X;
    
                // Check if the particle is too high 
                if (ToDouble(TranslateTransform0_Y) < -MaxSize)
                {
                    TranslateTransform0_Y = (Height + MaxSize).ToString();
                }
    
                // Check if the particle has gone outside 
                if (ToDouble(TranslateTransform0_X) < -MaxSize || ToDouble(TranslateTransform0_X) > Width + MaxSize)
                {
                    TranslateTransform0_X = (random.NextDouble() * Width).ToString();
                    TranslateTransform0_Y = (Height + MaxSize).ToString();
                }
            }
        }
          
        private void CreateParticle()
        {
            
            
            // Brush (White) 
            //var brush = System.Windows.Media.Brushes.White.Clone();
            // Opacity (0.2 <= 1) 
            //brush.Opacity = 0.2 + random.NextDouble() * 0.8;
            // Blur effect 
            //var blur = new BlurEffect();
            //blur.RenderingBias = RenderingBias.Performance;
            // Radius (1 <= 40) 
            //blur.Radius = 1 + random.NextDouble() * 39;
            // Ellipse 
            //var ellipse = new Ellipse();
            // Size (from 15% to 95% of MaxSize) 
            //ellipse.Width = ellipse.Height = MaxSize * 0.15 + random.NextDouble() * MaxSize * 0.8;
            // Starting location of the ellipse (anywhere in the scree
    
            // extraTags adden
            var p = new Particle();
    
            // Speed
            double speed = RandomWithVariance(20, 15);
            double velocityMultiplier = (random.NextDouble() + 0.25) * speed;
            double vX = (1.0 - (random.NextDouble() * 2.0)) * velocityMultiplier;
            // Only going from the bottom of the screen to the top (for now)
            double vY = -Math.Abs((1.0 - (random.NextDouble() * 2.0)) * velocityMultiplier);
    
            p.Velocity = p.Velocity = new Point(vX, vY);
            //p.Blur = blur;
            //ellipse.Tag = p;
            
    
            //this.ParticleHost.Children.Add(ellipse);
    
            //TranslateTransform t;
    
            //t = new TranslateTransform();
            //ellipse.RenderTransform = t;
            //ellipse.RenderTransformOrigin = new Point(0.5, 0.5);
            
            //t.X = RandomWithVariance(Width / 2, Width / 2);
            //t.Y = Height;
    
            //----------------------------------------
    
            // add particle to list
            particleList.Add(p);
    
            // set position
            TranslateTransform0_X = RandomWithVariance(Width / 2, Width / 2).ToString();
            TranslateTransform0_Y = Height.ToString();
        }
    
    
        private double RandomWithVariance(double midvalue, double variance)
        {
            double min = Math.Max(midvalue - (variance / 2), 0);
            double max = midvalue + (variance / 2);
            double value = min + ((max - min) * random.NextDouble());
            return value;
        }
    
          #region helper functions
    
        /// <summary>
        /// Wandelt in String in Double um
        /// </summary>
        /// <param name="In"></param>
        /// <returns></returns>
        public static double ToDouble(string In)
        {
            In = In.Replace(",", ".");
    
            return double.Parse(In, System.Globalization.CultureInfo.InvariantCulture);
        }
    
        /// <summary>
        /// Wandelt String in Double um mit Default falls es nicht möglich ist
        /// </summary>
        /// <param name="In"></param>
        /// <param name="Default"></param>
        /// <returns></returns>
        public static double ToDouble(string In, double Default)
        {
            double dblOut;
    
            In = In.Replace(",", ".");
    
            try
            {
                dblOut = double.Parse(In, System.Globalization.CultureInfo.InvariantCulture);
            }
            catch
            {
                dblOut = Default;
            }
    
            return dblOut;
        }
    
        /// <summary>
        /// Wandelt einen String in Double um (Default = 0 oder es wird eine Exception ausgelöst)
        /// </summary>
        /// <param name="In">String</param>
        /// <param name="UseExceptions">True (Exception wird ausgelöst) oder False (Default 0 wird verwendet)</param>
        /// <returns></returns>
        public static double ToDouble(string In, bool UseExceptions)
        {
            double dblOut;
    
            In = In.Replace(",", ".");
    
            try
            {
                dblOut = double.Parse(In, System.Globalization.CultureInfo.InvariantCulture);
            }
            catch (Exception ex)
            {
                if (UseExceptions)
                    throw ex;
                else
                    dblOut = 0;
            }
    
            return dblOut;
        }
    
          #endregion
      }
    }
     

    Users who are viewing this thread

    Top Bottom