using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace pcd_g1
{
	class HPWidghet:IWidghet
	{
		public int X { get; private set; }
		public int Y { get; private set; }
		public int Width { get; private set; }
		public int Height { get; private set; }
		public bool IsModal { get { return false; } }
		public bool IsSleeping { get { return false; } }
		public bool Visibility { get { return true; } }

		public int hp;//ヒットポイントの値
		private const int MAXVALUE = 100;//ヒットポイントの最大値
		public int level;
		private const int MAXLV = 100;
		public int exp;
		public int next_exp;
		private Brush backc0;
		private Brush backc1;
		private MainCharacterStageObject ownerchar;

		public HPWidghet(MainCharacterStageObject owner)
		{
			X = 16;
			Y = 16;
			Width = 4 * 2 + (16 + 4) * MAXVALUE / 10 + 8 * 8;
			Height = 16 * 4 + 4 * 2;
			backc0 = new SolidBrush(Color.FromArgb(128, 255, 255, 255));
			backc1 = new SolidBrush(Color.FromArgb(128, 128, 255, 128));
			ownerchar = owner;
		}

		public bool Update(int keyStatus)
		{
			hp = ownerchar.hp;
			exp = ownerchar.skill;
			level = ownerchar.level;
			next_exp = ownerchar.nextLevelSkill;

			if (next_exp == 0) {
				next_exp = 16777216;	//ゼロ除算防止
			}

			return false;
		}

		//thumb+charID
		public void Draw(Graphics g, int width, int height)
		{
			int i, k;
			Font font;
			font = new Font("MS Gothic", 16);

			g.FillRectangle(backc0, 0, 0, width, height);
			g.FillRectangle(backc1, 4, 4, width - 8, height - 8);
			g.DrawImage(ImageManager.Search("thumb" + ownerchar.character_number.ToString()), 4, 4, 64, 64);
			g.DrawString("LIFE", font, Brushes.Black, 64 + 4 + 4, 6);
			k = (int)Math.Ceiling((double)hp / 10);
			for (i = 0; i < k; i++)
			{
				g.DrawImage(ImageManager.Search("700-0.gif"), i * (16 + 4) + 64 + 4, 24, 16, 16);
			}
			for (; i < ownerchar.max_hp / 10; i++)
			{
				g.DrawImage(ImageManager.Search("700-1.gif"), i * (16 + 4) + 64 + 4, 24, 16, 16);
			}
			if (level < 3)
			{
				g.FillRectangle(Brushes.White, 64 + 4 + 4, 4 + 64 - 8, width - (64 + 4 + 4) - 4 - 4, 6);
				g.FillRectangle(Brushes.Orange, 64 + 4 + 4 + 1, 4 + 64 - 8 + 1, (float)exp / (float)next_exp * (width - (64 + 4 + 4) - 4 - 4 - 1 - 1), 4);
				g.DrawString("EXP", font, Brushes.Black, 64 + 4 + 4, 4 + 64 - 8 - 20);
			}
			else
			{
				g.DrawString("EXP  --MAX--", font, Brushes.Black, 64 + 4 + 4, 4 + 64 - 8 - 20);
			}
            switch (StageManager.CurrentDataSet.GetInt("WorldTense")) 
            { 
                case -1:
                    g.DrawString("過去", font, Brushes.Black, width - 70, 4 + 64 - 8 - 20);
                    break;
                case 0:
                    g.DrawString("現在", font, Brushes.Black, width - 70, 4 + 64 - 8 - 20);
                    break;
                case 1:
                    g.DrawString("未来", font, Brushes.Black, width - 70, 4 + 64 - 8 - 20);
                    break;
            }
			g.DrawString("LV" + level.ToString(), font, Brushes.Black, 200, 6);

		}
	}
}
