Subversion Repositories AndroidProjects

Rev

Rev 1460 | Rev 1477 | 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 BauzoidNET.math;
using BauzoidNET.parser;

using BurutaruEditor.view;

namespace BurutaruEditor.file
{
    public class CheckPoint : LevelObject
    {
        public const float INTERACTION_SIZE = DocumentView.CHECKPOINT_SIZE;

        [TypeConverter(typeof(ExpandableObjectConverter))]
        public Vector2 Position { get; set; }

        [TypeConverter(typeof(ExpandableObjectConverter))]
        public Vector2 FreeScroll { get; set; }

        public float ScrollSpeed { get; set; }

        public string ContinueCondition { get; set; }


        public CheckPoint(Document doc, string name)
            : base(doc, name)
        {
            Position = new Vector2();
            FreeScroll = new Vector2();
            ScrollSpeed = 10;
            ContinueCondition = "";
        }

        public override void RenderSelected(int selectedPart)
        {
            float posX = Position.x + Document.VIRTUAL_WIDTH / 2 + Doc.View.CurrentPosition.x;
            float posY = Position.y + Document.VIRTUAL_HEIGHT / 2 + Doc.View.CurrentPosition.y;
            float halfSize = INTERACTION_SIZE / 2 + DocumentView.SELECTION_FRAME_OFFSET;

            Doc.View.RenderSelectionFrame(posX - halfSize, posY - halfSize, posX + halfSize, posY + halfSize);
        }

        public override bool IsInside(float x, float y, out int selectedPart)
        {
            selectedPart = -1;
            if ((Math.Abs(x - Position.x) <= INTERACTION_SIZE) && (Math.Abs(y - Position.y) <= INTERACTION_SIZE))
                return true;
            return false;
        }

        public override void MoveBy(float dx, float dy, int selectedPart)
        {
            Position.x += (dx / Doc.View.ZoomFactor);
            Position.y += (dy / Doc.View.ZoomFactor);
        }

        public override bool ReadParameter(Tokenizer t, string id)
        {
            if (id.Equals("position", StringComparison.OrdinalIgnoreCase))
            {
                Position = ParseUtil.readVector2(t);
            }
            else if (id.Equals("freeScroll", StringComparison.OrdinalIgnoreCase))
            {
                FreeScroll = ParseUtil.readVector2(t);
            }
            else if (id.Equals("continueCondition", StringComparison.OrdinalIgnoreCase))
            {
                ContinueCondition = t.readString();
            }
            else if (id.Equals("scrollSpeed", StringComparison.OrdinalIgnoreCase))
            {
                ScrollSpeed = t.readNumber();
            }
            else
            {
                return base.ReadParameter(t, id);
            }

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


    }
}