示例#1
0
        static private void LoadBackgroundMusic(XmlNode widget, XmlNode page)
        {
            //return;
            //var music = new SFML.Audio.Music("Assets\\" + XmlUtilities.GetString (widget, "file"));
            //music.Play ();
            Logger.Info("UiFactory", "LoadBackgroundMusic", "loaded music: " + "Assets\\" + XmlUtilities.GetString(widget, "file"));
            var music = IoManager.LoadMusic(XmlUtilities.GetString(widget, "file"));

            if (music != null)
            {
                Logger.Info("UiFactory", "LoadBackgroundMusic", "loaded music");
                try {
                    var loops = widget.ChildNodes;
                    for (var i = 0; i < loops.Count; i++)
                    {
                        var xloop = loops[i];
                        music.AddLoop(
                            XmlUtilities.GetString(xloop, "name"),
                            XmlUtilities.GetInt(xloop, "start"),
                            XmlUtilities.GetInt(xloop, "end")
                            );
                    }
                } catch (Exception ex) {
                    Logger.Warning("UiFactory", "LoadBackgroundMusic", ex.ToString());
                }
            }
        }
示例#2
0
        public Icon(string iconFileName, IntRect sprite) : base()
        {
            var tex = IoManager.LoadTexture(iconFileName);

            this.sprite             = new Sprite(tex);
            this.sprite.TextureRect = sprite;
            this.size = new Vector2f(sprite.Width, sprite.Height);
        }
示例#3
0
 public LightLayer(int width, int height) : base(width, height)
 {
     this.AmbientLight = new Color(255, 255, 255);
     this.layerTexture = new RenderTexture((uint)this.Width, (uint)this.Height);
     this.layerSprite  = new Sprite(this.layerTexture.Texture);
     this.lightTexture = IoManager.CreateShadedCircle();
     this.Blend        = BlendMode.Add;
 }
示例#4
0
        public Icon(string iconFileName, int x, int y, int w, int h) : base()
        {
            var tex = IoManager.LoadTexture(iconFileName);

            this.sprite             = new Sprite(tex);
            this.sprite.TextureRect = new IntRect(x, y, w, h);
            this.size = new Vector2f(w, h);
        }
示例#5
0
 public void SetTilemask(int gridWidth, int gridHeight, int cellWidth, int cellHeight, string texture)
 {
     this.refCellSize.X = cellWidth;
     this.refCellSize.Y = cellHeight;
     this.cellSize.X    = (int)(cellWidth * this.TileScale);
     this.cellSize.Y    = (int)(cellHeight * this.TileScale);
     this.GridWidth     = gridWidth;
     this.GridHeight    = gridHeight;
     maskMap            = new _Tile[gridHeight, gridWidth];
     this.tileset       = IoManager.LoadTexture(texture);
     this.AdjustLayer();
 }
示例#6
0
 public Label(string text, int size = 16, string fontFile = null)
 {
     if (fontFile != null)
     {
         var font = IoManager.LoadFont(fontFile);
         this.text = new Text(text, font, (uint)size);
     }
     else if (IoManager.DefaultFontId != null)
     {
         this.text = new Text(text, IoManager.DefaultFont, (uint)size);
     }
 }
示例#7
0
 public static Inputs GetInputs()
 {
     IoManager.window.DispatchEvents();
     //IoManager.window.WaitAndDispatchEvents ();
     IoManager.CheckKeyboard();              // KeyPressed is unrealiable, it inserts delays
     inputRes.Command = inputs.Command;
     inputRes.Unicode = inputs.Unicode;
     inputRes.MouseX  = inputs.MouseX;
     inputRes.MouseY  = inputs.MouseY;
     inputs.Command   = InputCommands.NONE;
     inputs.Unicode   = "";
     return(inputRes);
 }
示例#8
0
 override public void SetBackground(string texture)
 {
     if (texture == "")
     {
         this.DrawBackground = false;
         this.bgSprite       = new Sprite();
     }
     else
     {
         this.bgTexture      = IoManager.LoadTexture(texture, true);
         this.bgSprite       = new Sprite(this.bgTexture);
         this.DrawBackground = true;
         this.AdjustLayer();
     }
 }
示例#9
0
        override public void Update(Widget parent)
        {
            this.currRef += IoManager.DeltaTime;
            var icon = parent as Icon;

            if (this.currRef > this.endRef)
            {
                //var sprite = ((Icon)parent).sprite;
                this.currFrame = this.frames.Count - 1;
                icon.Sprite    = this.frames [this.frames.Count - 1].rect;
                icon.Padding   = this.frames [this.frames.Count - 1].offset;
                if (this.Looping == false)
                {
                    this.hasEnded = true;
                    return;
                }
                else
                {
                    this.currRef -= this.endRef;
                }
            }
            try {
                if (this.frames [this.currFrame].millis < this.currRef)
                {
                    this.currFrame += 1;
                    var sprite = icon.Sprite;
                    icon.Sprite  = this.frames [this.currFrame].rect;
                    icon.Padding = this.frames [this.currFrame].offset;
                    if (this.frames[this.currFrame].sfx != "")
                    {
                        IoManager.PlaySound(this.frames[this.currFrame].sfx);
                    }
                }
            }
            catch {
                this.hasEnded = true;
            }
            var p = parent as OutObject;

            if (p != null)
            {
                p.CurrentAnimationFrame = this.currFrame;
            }
        }
示例#10
0
        /// <summary>
        /// Loads a sound effect from file.
        /// </summary>
        /// <returns>The sfx.</returns>
        public static Sound LoadSound(string fileName)
        {
            Sound res;

            if (IoManager.sounds.TryGetValue(fileName, out res) == false)
            {
                try {
                    var path = IoManager.GetAssetPath(fileName);
                    res        = new Sound(new SoundBuffer(path));
                    res.Volume = 5;
                    IoManager.sounds.Add(fileName, res);
                }
                catch (Exception ex) {
                    // TODO log exception
                    Console.Write(ex.ToString());
                    res = null;
                }
            }
            return(res);
        }
示例#11
0
        /// <summary>
        /// Loads a texture from file.
        /// </summary>
        /// <returns>The texture.</returns>
        public static Texture LoadTexture(string fileName, bool smooth = false)
        {
            Texture res;

            if (IoManager.textures.TryGetValue(fileName, out res) == false)
            {
                try {
                    var path = IoManager.GetAssetPath(fileName);
                    res        = new Texture(path);
                    res.Smooth = smooth;
                    IoManager.textures.Add(fileName, res);
                }
                catch (Exception ex) {
                    // TODO log exception
                    Logger.Warning("IoManager", "LoadTexture", "Unable to load " + fileName + ": " + ex.ToString());
                    res = null;
                }
            }
            return(res);
        }
示例#12
0
        /// <summary>
        /// Append the sprite.
        /// </summary>
        /// <param name="sprite">Sprite.</param>
        /// <param name="duration">Duration of the sprite in milliseconds.
        /// Note that it is different from when instancing the Animation directly</param>
        public void AppendSprite(IntRect sprite, Vector2f soffset, int duration, string sfx = "")
        {
            var end = duration + this.endRef;

            if (sfx != "")
            {
                if (IoManager.LoadSound(sfx) == null)
                {
                    // cannot load the sound, useless to set it
                    sfx = "";
                }
            }
            var kf = new KeyFrame()
            {
                millis = end, rect = sprite, offset = soffset, sfx = sfx
            };

            //Console.WriteLine ("Appending sprite " + kf.rect.ToString() + " ending at " + end.ToString());
            this.frames.Add(kf);
            this.endRef += duration;
        }
示例#13
0
 /// <summary>
 /// Loads the background music. The music is streamed from file.
 /// </summary>
 /// <param name="fileName">File name.</param>
 public static BackgroundMusic LoadMusic(string fileName)
 {
     try {
         if (IoManager.music != null && IoManager.music.FileName == fileName)
         {
             Logger.Info("IoManager", "LoadMusic", "Already loaded " + fileName);
         }
         else
         {
             var path = IoManager.GetAssetPath(fileName);
             var mus  = new Sound();
             mus.SoundBuffer = new SoundBuffer(path);
             mus.Volume      = 15;
             IoManager.music = new BackgroundMusic(mus, fileName);
             Logger.Info("IoManager", "LoadMusic", "loaded music " + fileName);
         }
         return(IoManager.music);
     } catch (Exception ex) {
         Logger.Warning("IoManager", "LoadMusic", "Unable to load " + fileName + ": " + ex.ToString());
         return(null);
     }
 }
示例#14
0
        /// <summary>
        /// Loads a font from file.
        /// </summary>
        /// <returns>The font.</returns>
        /// <param name="fileName">Font file.</param>
        /// <param name="size">The font Size, it is in fact used to set the smoothin for a specific mipmap.</param>
        public static Font LoadFont(string fileName, int size = 24)
        {
            Font res;

            try {
                if (IoManager.fonts.TryGetValue(fileName, out res) == false)
                {
                    var path = IoManager.GetAssetPath(fileName);
                    res = new Font(path);
                    IoManager.fonts.Add(fileName, res);
                    if (IoManager.fonts.Count == 1)
                    {
                        IoManager.DefaultFontId = fileName;
                    }
                }
                res.GetTexture((uint)size).Smooth = false;
            } catch (Exception ex) {
                Logger.Warning("IoManager", "LoadFont", "Unable to load " + fileName + ": " + ex.ToString());
                res = null;
            }
            return(res);
        }
示例#15
0
        static public WorldView LoadPage(string xmlfile, string pageId = "page_0")
        {
            IoManager.Clear();
            XmlDocument xdoc = new XmlDocument();

            xdoc.Load(xmlfile);
            WorldView res = null;

            try {
                XmlNode pageNode = xdoc.SelectSingleNode("//page[@id='" + pageId + "']");
                var     widgets  = pageNode.ChildNodes;
                for (var i = 0; i < widgets.Count; i++)
                {
                    var widget = widgets[i];
                    switch (widget.Name)
                    {
                    case "backgroundmusic":
                        LoadBackgroundMusic(widget, pageNode);
                        break;

                    case "icon":
                        IoManager.AddWidget(UiFactory.LoadIcon(widget, pageNode));
                        break;

                    case "worldView":
                        res = UiFactory.LoadWorldView(widget, pageNode);
                        IoManager.AddWidget(res);
                        break;

                    default:
                        break;
                    }
                }
            } catch (Exception ex) {
                Logger.Error("UiFactory", "LoadPage", ex.ToString());
            }
            return(res);
        }
示例#16
0
 public SfxSpawner(string sfx)
 {
     this.sfx = sfx;
     IoManager.LoadSound(sfx);
 }
示例#17
0
 /// <summary>
 /// Sets the background.
 /// </summary>
 /// <param name="texture">The file name of the texture.</param>
 virtual public void SetBackground(string texture)
 {
     this.bgTexture = IoManager.LoadTexture(texture, true);
     this.bgSprite  = new Sprite(this.bgTexture);
     this.AdjustLayer();
 }
示例#18
0
 public void SetLightTexture(string texture, int u, int v, int w, int h)
 {
     this.lightTexture = IoManager.LoadTexture(texture);
     //TODO
 }
示例#19
0
 static public void Clear()
 {
     IoManager.ClearWidgets();
     IoManager.ClearAssets();
 }
示例#20
0
 override public void Apply(Particle particle)
 {
     IoManager.PlaySound(this.sfx);
 }