Subversion Repositories AndroidProjects

Rev

Rev 1460 | Rev 1464 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;

using BauzoidNET.graphics.sprite;
using BauzoidNET.parser;
using BauzoidNET.math;

namespace BurutaruEditor.file.elements
{
    public class BackgroundElement : LevelElement
    {
        private String mTextureFile = null;
        private SpriteTransform mTransform = new SpriteTransform();
        private Vector2 mScrollFactor = new Vector2(1, 1);


        private SimpleSprite mSprite = null;

        [TypeConverter(typeof(ExpandableObjectConverter))]
        public Vector2 ScrollFactor
        {
            get { return mScrollFactor; }
        }

        public BackgroundElement(Document doc, string name)
            : base(doc, name)
        {
        }

        public override void Init()
        {
            string s = Path.Combine(Application.StartupPath, @"..\\..\\..\\..\\..\\BauzoidApps\\BurutaruZ_v2\\burutaru-android\\assets");
            string fullPath = Path.GetFullPath(s) + "\\" + mTextureFile;

            mSprite = new SimpleSprite(MainForm.App.getGraphics(), fullPath);
            mSprite.init();
        }

        public override void Exit()
        {
            if (mSprite != null)
            {
                mSprite.dispose();
                mSprite = null;
            }
        }

        public override void Render()
        {
            mSprite.getSpriteTransform().set(mTransform);
            mSprite.getSpriteTransform().x += Doc.View.CurrentPosition.x * mScrollFactor.x;
            mSprite.getSpriteTransform().y += Doc.View.CurrentPosition.y * mScrollFactor.y;
            mSprite.render();
        }

        public override void RenderSelected(int selectedPart, bool forHover = false)
        {
            /*if (selectedPart == PART_SPAWN_TRIGGER)
                base.RenderSelected(selectedPart);

            float posX = SpawnTrigger.x + SpawnPosition.x + Doc.View.CurrentPosition.x;
            float posY = SpawnTrigger.y + SpawnPosition.y + Doc.View.CurrentPosition.y;

            float halfSize = BLOB_ENEMY_SIZE / 2 + DocumentView.SELECTION_FRAME_OFFSET;

            Doc.View.RenderSelectionFrame(posX - halfSize, posY - halsSize, posX + halfSize, posY + halfSize);*/

        }

        public override bool IsInside(float x, float y, out int selectedPart)
        {
            selectedPart = -1;
            // TODO:
            return false;
        }

        public override void MoveBy(float x, float y, int selectedPart)
        {
            // TODO:
        }

        public override bool ReadParameter(Tokenizer t, string id)
        {
            // texture
            if (id.Equals("texture", StringComparison.OrdinalIgnoreCase))
            {
                mTextureFile = t.readString();
            }
            // scroll speed
            else if (id.Equals("scrollFactor", StringComparison.OrdinalIgnoreCase))
            {
                mScrollFactor = ParseUtil.readVector2(t);
            }
            // read other parameter types
            else if (!parseSpriteTransform(t, id, mTransform))
            {
                // no other parameter type, so check super-class
                return base.ReadParameter(t, id);
            }

            t.readToken(";");
            return true;
        }
    }
}