using System;
using System.Collections.Generic;
using System.Text;
using Yamalib.Draw;
using Yanesdk.Ytl;
using Yamalib.Util;
using Yamalib.Yanesdkext.Draw;
using Yanesdk.Draw;
using System.Diagnostics;
using Yamalib.Scenario;

namespace Yamalib.Model
{
    /// <summary>
    /// 背景画像管理者
    /// </summary>
    public class BgImage : IBgImageResource
    {
        #region メンバフィールド

        //private bool showing;
        private int effectNo;
        private readonly RootCounterS effectPhaseCounter;
        private int posX;
        private int posY;
        private float drawSize = 1.0f;
        private Color4ub color = new Color4ub(255, 255, 255, 255);
        private readonly ITexture texture;

        #endregion

        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="texture_"></param>
        public BgImage(ITexture texture_)
        {
            Debug.Assert(texture_ != null);
            texture = texture_;
            effectPhaseCounter = new RootCounterS();
            effectPhaseCounter.Set(TransBltter.PAHSE_MAX, TransBltter.PAHSE_MAX, 1);
        }

        /// <summary>
        /// このリソースは表示中か
        /// </summary>
        public  virtual bool IsShowing
        {
            get { return false; }
        }

        /// <summary>
        /// エフェクト中か
        /// </summary>
        public bool IsEffecting
        {
            get { return !effectPhaseCounter.IsEnd; }
        }

        public void SetEffect(int effectNo, int start, int end, int speed)
        {
            this.effectNo = effectNo;
            effectPhaseCounter.Set(start, end, speed);
        }

        /// <summary>
        /// エフェクト番号の取得
        /// </summary>
        public int EffectNo
        {
            get { return effectNo; }
        }

        /// <summary>
        /// エフェクト位相の取得
        /// エフェクトしていなければTransBltter.PAHSE_MAXが返却される
        /// </summary>
        public int EffectPhase
        {
            get
            {
                if (IsEffecting)
                {
                    return effectPhaseCounter.Value();
                }
                // エフェクトしていないということは完了していると見なすか
                return TransBltter.PAHSE_MAX;
            }
        }

        /// <summary>
        /// 描画位置
        /// </summary>
        public int X
        {
            set { posX = value; }
            get { return posX; }
        }
        public int Y
        {
            set { posY = value; }
            get { return posY; }
        }

        /// <summary>
        /// 描画サイズ
        /// </summary>
        public float Size
        {
            set { drawSize = value; }
            get { return drawSize; }
        }

        /// <summary>
        /// 色
        /// </summary>
        public Color4ub Color
        {
            set { color = value; }
            get { return color; }
        }

        /// <summary>
        /// テクスチャの取得
        /// </summary>
        /// <returns></returns>
        public ITexture GetTexture()
        {
            return texture;
        }

        /// <summary>
        /// リソースの管理値を次に移行させる
        /// </summary>
        /// <param name="screen"></param>
        /// <returns></returns>
        public YanesdkResult OnMove(IScreen screen)
        {
            return YanesdkResult.NoError;
        }
    }
}
