void Window_MenuStatus::Refresh() {
	contents->SetTransparentColor(windowskin->GetTransparentColor());
	contents->Clear();

	DisplayUi->SetBackcolor(Cache::system_info.bg_color);

	item_max = Game_Party::GetActors().size();

	int y = 0;
	for (int i = 0; i < item_max; ++i)
	{
		Game_Actor* actor = Game_Party::GetActors()[i];

		int face_x = 0;
		if (Player::engine == Player::EngineRpg2k3) {
			face_x = actor->GetBattleRow() == 1 ? 5 : 0;
		}
		DrawActorFace(actor, face_x, i*48 + y);

		DrawActorName(actor, 48 + 8, i*48 + 2 + y);
		DrawActorClass(actor, 48 + 8 + 88, i*48 + 2 + y);
		DrawActorLevel(actor, 48 + 8, i*48 + 2 + 16 + y);
		DrawActorState(actor, 48 + 8 + 42, i*48 + 2 + 16 + y);
		DrawActorExp(actor, 48 + 8, i*48 + 2 + 16 + 16 + y);
		DrawActorHp(actor, 48 + 8 + 106, i*48 + 2 + 16 + y);
		DrawActorSp(actor, 48 + 8 + 106, i*48 + 2 + 16 + 16 + y);

		y += 10;
	}
}
void Window_ActorInfo::DrawInfo() {

	// Draw Row formation.
	std::string battle_row = Game_Actors::GetActor(actor_id)->GetBattleRow() == 1 ? "Back" : "Front";
	contents->TextDraw(contents->GetWidth(), 5, Font::ColorDefault, battle_row, Text::AlignRight);

	// Draw Face
	DrawActorFace(Game_Actors::GetActor(actor_id), 0, 0);
	
	// Draw Name
	contents->TextDraw(3, 50, 1, "Name");
	DrawActorName(Game_Actors::GetActor(actor_id), 36, 65);
	
	// Draw Profession
	contents->TextDraw(3, 80, 1, "Profession");
	DrawActorClass(Game_Actors::GetActor(actor_id), 36, 95);

	// Draw Rank
	contents->TextDraw(3, 110, 1, "Title");
	DrawActorTitle(Game_Actors::GetActor(actor_id), 36, 125);

	// Draw Status
	contents->TextDraw(3, 140, 1, "Status");
	DrawActorState(Game_Actors::GetActor(actor_id), 36, 155);

	//Draw Level
	contents->TextDraw(3, 170, 1, Data::terms.lvl_short);
	std::stringstream ss;
	ss << Game_Actors::GetActor(actor_id)->GetLevel();
	contents->TextDraw(79, 170, Font::ColorDefault, ss.str(), Text::AlignRight);

}
void Window_BattleStatus::RefreshGauge() {
	if (Player::IsRPG2k3()) {
		if (Data::battlecommands.battle_type != RPG::BattleCommands::BattleType_gauge) {
			contents->ClearRect(Rect(198, 0, 25 + 16, 15 * item_max));
		}

		for (int i = 0; i < item_max; ++i) {
			Game_Battler* actor;
			if (enemy) {
				actor = &(*Main_Data::game_enemyparty)[i];
			}
			else {
				actor = &(*Main_Data::game_party)[i];
			}

			if (!enemy && Data::battlecommands.battle_type == RPG::BattleCommands::BattleType_gauge) {
				FileRequestAsync* request = AsyncHandler::RequestFile("System2", Data::system.system2_name);
				if (!request->IsReady()) {
					request_id = request->Bind(&Window_BattleStatus::OnSystem2Ready, this);
					request->Start();
					break;
				}
				else {
					BitmapRef system2 = Cache::System2(Data::system.system2_name);
					
					// Clear number drawing area
					contents->ClearRect(Rect(40 + 80 * i, 24, 8 * 4, 16));
					contents->ClearRect(Rect(40 + 80 * i, 24 + 12 + 4, 8 * 4, 16));

					// Number clearing removed part of the face, but both, clear and redraw
					// are needed because some games don't have face graphics that are huge enough
					// to clear the number area (e.g. Ara Fell)
					DrawActorFace(static_cast<Game_Actor*>(actor), 80 * i, 24);

					// Background
					contents->StretchBlit(Rect(32 + i * 80, 24, 57, 48), *system2, Rect(0, 32, 48, 48), Opacity::opaque);

					// HP
					DrawGaugeSystem2(48 + i * 80, 24, actor->GetHp(), actor->GetMaxHp(), 0);
					// SP
					DrawGaugeSystem2(48 + i * 80, 24 + 16, actor->GetSp(), actor->GetMaxSp(), 1);
					// Gauge
					DrawGaugeSystem2(48 + i * 80, 24 + 16 * 2, actor->GetGauge() * actor->GetMaxGauge() / 100, actor->GetMaxGauge(), 2);
					
					// Numbers
					DrawNumberSystem2(40 + 80 * i, 24, actor->GetHp());
					DrawNumberSystem2(40 + 80 * i, 24 + 12 + 4, actor->GetSp());
				}
			}
			else {
				int y = 2 + i * 16;

				DrawGauge(actor, 198 - 10, y - 2);
				DrawActorSp(actor, 198, y, false);
			}
		}
	}
}
void Window_ActorTarget::Refresh() {
	contents->Clear();

	item_max = Main_Data::game_party->GetActors().size();

	int y = 0;
	for (int i = 0; i < item_max; ++i) {
		DrawActorFace(Main_Data::game_party->GetActors()[i], 0, i * 48 + y);
		DrawActorName(Main_Data::game_party->GetActors()[i], 48 + 8, i * 48 + 2 + y);
		DrawActorLevel(Main_Data::game_party->GetActors()[i], 48 + 8, i * 48 + 2 + 16 + y);
		DrawActorState(Main_Data::game_party->GetActors()[i], 48 + 8, i * 48 + 2 + 16 + 16 + y);
		int x_offset = 48 + 8 + 42 + (Player::IsRPG2k() ? 16 : 0);
		DrawActorHp(Main_Data::game_party->GetActors()[i], x_offset, i * 48 + 2 + 16 + y);
		DrawActorSp(Main_Data::game_party->GetActors()[i], x_offset, i * 48 + 2 + 16 + 16 + y);

		y += 10;
	}
}
void Window_BattleStatus::Refresh() {
	contents->Clear();

	if (enemy) {
		item_max = Main_Data::game_enemyparty->GetBattlerCount();
	}
	else {
		item_max = Main_Data::game_party->GetBattlerCount();
	}

	item_max = std::min(item_max, 4);

	for (int i = 0; i < item_max; i++) {
		Game_Battler* actor;
		if (enemy) {
			actor = &(*Main_Data::game_enemyparty)[i];
		}
		else {
			actor = &(*Main_Data::game_party)[i];
		}

		if (!enemy && Data::battlecommands.battle_type == RPG::BattleCommands::BattleType_gauge) {
			FileRequestAsync* request = AsyncHandler::RequestFile("System2", Data::system.system2_name);
			if (!request->IsReady()) {
				request_id = request->Bind(&Window_BattleStatus::OnSystem2Ready, this);
				request->Start();
				break;
			}
			else {
				DrawActorFace(static_cast<Game_Actor*>(actor), 80 * i, 24);
			}
		}
		else {
			int y = 2 + i * 16;

			DrawActorName(actor, 4, y);
			DrawActorState(actor, 84, y);
			DrawActorHp(actor, 126, y, true);
			DrawActorSp(actor, 198, y, false);
		}
	}

	RefreshGauge();
}
void Window_ActorTarget::Refresh() {
	contents->Clear();

	DisplayUi->SetBackcolor(Cache::system_info.bg_color);

	item_max = Game_Party::GetActors().size();

	int y = 0;
	for (int i = 0; i < item_max; ++i) {
		DrawActorFace(Game_Party::GetActors()[i], 0, i * 48 + y);
		DrawActorName(Game_Party::GetActors()[i], 48 + 8, i * 48 + 2 + y);
		DrawActorLevel(Game_Party::GetActors()[i], 48 + 8, i * 48 + 2 + 16 + y);
		DrawActorState(Game_Party::GetActors()[i], 48 + 8, i * 48 + 2 + 16 + 16 + y);
		DrawActorHp(Game_Party::GetActors()[i], 48 + 8 + 58, i * 48 + 2 + 16 + y);
		DrawActorSp(Game_Party::GetActors()[i], 48 + 8 + 58, i * 48 + 2 + 16 + 16 + y);

		y += 10;
	}
}