<commit_before>#include "game/ui/base/transferscreen.h"
#include "forms/form.h"
#include "forms/graphic.h"
#include "forms/graphicbutton.h"
#include "forms/label.h"
#include "forms/radiobutton.h"
#include "forms/scrollbar.h"
#include "forms/ui.h"
#include "framework/configfile.h"
#include "framework/data.h"
#include "framework/event.h"
#include "framework/framework.h"
#include "framework/logger.h"
#include "framework/renderer.h"
#include "game/state/city/agentmission.h"
#include "game/state/city/base.h"
#include "game/state/city/building.h"
#include "game/state/city/vehicle.h"
#include "game/state/city/vehiclemission.h"
#include "game/state/gamestate.h"
#include "game/state/rules/city/vammotype.h"
#include "game/state/shared/organisation.h"
#include "game/ui/base/recruitscreen.h"
#include "game/ui/general/agentsheet.h"
#include "game/ui/general/messagebox.h"
#include "game/ui/general/transactioncontrol.h"
#include <array>

namespace OpenApoc
{

TransferScreen::TransferScreen(sp<GameState> state, bool forceLimits)
    : TransactionScreen(state, forceLimits), bigUnitRanks(RecruitScreen::getBigUnitRanks())
{
	form->findControlTyped<Label>("TITLE")->setText(tr("TRANSFER"));
	form->findControlTyped<Graphic>("BG")->setImage(
	    fw().data->loadImage("xcom3/ufodata/transfer.pcx"));
	form->findControlTyped<Graphic>("DOLLAR_ICON")->setVisible(false);
	form->findControlTyped<Label>("TEXT_FUNDS_DELTA")->setVisible(false);
	form->findControlTyped<Graphic>("DELTA_UNDERPANTS")->setVisible(false);

	form->findControlTyped<RadioButton>("BUTTON_SOLDIERS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_BIOSCIS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_PHYSCIS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_ENGINRS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_ALIENS")->setVisible(true);

	form->findControlTyped<RadioButton>("BUTTON_VEHICLES")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_VEHICLES")->Location.y = 200;
	form->findControlTyped<RadioButton>("BUTTON_AGENTS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_AGENTS")->Location.y = 240;
	form->findControlTyped<RadioButton>("BUTTON_FLYING")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_FLYING")->Location.y = 280;
	form->findControlTyped<RadioButton>("BUTTON_GROUND")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_GROUND")->Location.y = 320;

	textViewSecondBaseStatic = form->findControlTyped<Label>("TEXT_BUTTON_SECOND_BASE_STATIC");
	textViewSecondBaseStatic->setVisible(true);

	// Adding callbacks after checking the button because we don't need to
	// have the callback be called since changeBase() will update display anyways

	form->findControlTyped<RadioButton>("BUTTON_SOLDIERS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Soldier); });
	form->findControlTyped<RadioButton>("BUTTON_BIOSCIS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::BioChemist); });
	form->findControlTyped<RadioButton>("BUTTON_PHYSCIS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Physicist); });
	form->findControlTyped<RadioButton>("BUTTON_ENGINRS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Engineer); });
	form->findControlTyped<RadioButton>("BUTTON_ALIENS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Aliens); });

	form->findControlTyped<RadioButton>("BUTTON_VEHICLES")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Vehicle); });
	form->findControlTyped<RadioButton>("BUTTON_AGENTS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::AgentEquipment); });
	form->findControlTyped<RadioButton>("BUTTON_FLYING")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::FlyingEquipment); });
	form->findControlTyped<RadioButton>("BUTTON_GROUND")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::GroundEquipment); });

	// Find first base that isn't current
	for (auto &b : state->player_bases)
	{
		if (b.first != state->current_base.id)
		{
			second_base = {state.get(), b.first};
			textViewSecondBaseStatic->setText(second_base->name);
			break;
		}
	}

	confirmClosureText = tr("Confirm Transfers");

	type = Type::Soldier;
	form->findControlTyped<RadioButton>("BUTTON_SOLDIERS")->setChecked(true);
}

void TransferScreen::changeSecondBase(sp<Base> newBase)
{
	second_base = newBase->building->base;
	textViewSecondBaseStatic->setText(second_base->name);

	// Set index for all controls
	int index = getRightIndex();
	for (auto &l : transactionControls)
	{
		for (auto &c : l.second)
		{
			c->setIndexRight(index);
		}
	}
	// Apply display type and base highlight
	setDisplayType(type);
}

int TransferScreen::getRightIndex()
{
	int index = 0;
	for (auto &b : state->player_bases)
	{
		if (b.first == second_base.id)
		{
			return index;
		}
		index++;
	}
	LogError("The right side base wasn't found.");
	return -1; // should not be reached
}

void TransferScreen::updateBaseHighlight()
{
	if (viewHighlightPrevious != viewHighlight)
	{
		int i = 0;
		for (auto &b : state->player_bases)
		{
			auto viewName = format("BUTTON_SECOND_BASE_%d", ++i);
			auto view = form->findControlTyped<GraphicButton>(viewName);
			auto viewImage = drawMiniBase(*b.second, viewHighlight, viewFacility);
			view->setImage(viewImage);
			view->setDepressedImage(viewImage);
		}
	}

	// Update first base
	TransactionScreen::updateBaseHighlight();

	// Update second base
	switch (viewHighlight)
	{
		case BaseGraphics::FacilityHighlight::Quarters:
		{
			auto facilityPic = form->findControlTyped<Graphic>("FACILITY_SECOND_PIC");
			facilityPic->setVisible(true);
			facilityPic->setImage(state->facility_types["FACILITYTYPE_LIVING_QUARTERS"]->sprite);
			form->findControlTyped<Graphic>("FACILITY_SECOND_BAR")->setVisible(true);
			int usage = second_base->getUsage(*state, FacilityType::Capacity::Quarters, lq2Delta);
			fillBaseBar(false, usage);
			auto facilityLabel = form->findControlTyped<Label>("FACILITY_SECOND_TEXT");
			facilityLabel->setVisible(true);
			facilityLabel->setText(format("%s%%", usage));
			break;
		}
		case BaseGraphics::FacilityHighlight::Stores:
		{
			auto facilityPic = form->findControlTyped<Graphic>("FACILITY_SECOND_PIC");
			facilityPic->setVisible(true);
			facilityPic->setImage(state->facility_types["FACILITYTYPE_STORES"]->sprite);
			form->findControlTyped<Graphic>("FACILITY_SECOND_BAR")->setVisible(true);
			int usage = second_base->getUsage(*state, FacilityType::Capacity::Stores, cargo2Delta);
			fillBaseBar(false, usage);
			auto facilityLabel = form->findControlTyped<Label>("FACILITY_SECOND_TEXT");
			facilityLabel->setVisible(true);
			facilityLabel->setText(format("%s%%", usage));
			break;
		}
		case BaseGraphics::FacilityHighlight::Aliens:
		{
			auto facilityPic = form->findControlTyped<Graphic>("FACILITY_SECOND_PIC");
			facilityPic->setVisible(true);
			facilityPic->setImage(state->facility_types["FACILITYTYPE_ALIEN_CONTAINMENT"]->sprite);
			form->findControlTyped<Graphic>("FACILITY_SECOND_BAR")->setVisible(true);
			int usage = second_base->getUsage(*state, FacilityType::Capacity::Aliens, bio2Delta);
			fillBaseBar(false, usage);
			auto facilityLabel = form->findControlTyped<Label>("FACILITY_SECOND_TEXT");
			facilityLabel->setVisible(true);
			facilityLabel->setText(format("%s%%", usage));
			break;
		}
		default:
		{
			form->findControlTyped<Graphic>("FACILITY_SECOND_PIC")->setVisible(false);
			form->findControlTyped<Graphic>("FACILITY_SECOND_BAR")->setVisible(false);
			form->findControlTyped<Graphic>("FACILITY_SECOND_FILL")->setVisible(false);
			form->findControlTyped<Label>("FACILITY_SECOND_TEXT")->setVisible(false);
			break;
		}
	}
}

void TransferScreen::displayItem(sp<TransactionControl> control)
{
	TransactionScreen::displayItem(control);

	switch (control->itemType)
	{
		case TransactionControl::Type::BioChemist:<commit_msg>Fix usage formatting string in transfer screen<commit_after>#include "game/ui/base/transferscreen.h"
#include "forms/form.h"
#include "forms/graphic.h"
#include "forms/graphicbutton.h"
#include "forms/label.h"
#include "forms/radiobutton.h"
#include "forms/scrollbar.h"
#include "forms/ui.h"
#include "framework/configfile.h"
#include "framework/data.h"
#include "framework/event.h"
#include "framework/framework.h"
#include "framework/logger.h"
#include "framework/renderer.h"
#include "game/state/city/agentmission.h"
#include "game/state/city/base.h"
#include "game/state/city/building.h"
#include "game/state/city/vehicle.h"
#include "game/state/city/vehiclemission.h"
#include "game/state/gamestate.h"
#include "game/state/rules/city/vammotype.h"
#include "game/state/shared/organisation.h"
#include "game/ui/base/recruitscreen.h"
#include "game/ui/general/agentsheet.h"
#include "game/ui/general/messagebox.h"
#include "game/ui/general/transactioncontrol.h"
#include <array>

namespace OpenApoc
{

TransferScreen::TransferScreen(sp<GameState> state, bool forceLimits)
    : TransactionScreen(state, forceLimits), bigUnitRanks(RecruitScreen::getBigUnitRanks())
{
	form->findControlTyped<Label>("TITLE")->setText(tr("TRANSFER"));
	form->findControlTyped<Graphic>("BG")->setImage(
	    fw().data->loadImage("xcom3/ufodata/transfer.pcx"));
	form->findControlTyped<Graphic>("DOLLAR_ICON")->setVisible(false);
	form->findControlTyped<Label>("TEXT_FUNDS_DELTA")->setVisible(false);
	form->findControlTyped<Graphic>("DELTA_UNDERPANTS")->setVisible(false);

	form->findControlTyped<RadioButton>("BUTTON_SOLDIERS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_BIOSCIS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_PHYSCIS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_ENGINRS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_ALIENS")->setVisible(true);

	form->findControlTyped<RadioButton>("BUTTON_VEHICLES")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_VEHICLES")->Location.y = 200;
	form->findControlTyped<RadioButton>("BUTTON_AGENTS")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_AGENTS")->Location.y = 240;
	form->findControlTyped<RadioButton>("BUTTON_FLYING")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_FLYING")->Location.y = 280;
	form->findControlTyped<RadioButton>("BUTTON_GROUND")->setVisible(true);
	form->findControlTyped<RadioButton>("BUTTON_GROUND")->Location.y = 320;

	textViewSecondBaseStatic = form->findControlTyped<Label>("TEXT_BUTTON_SECOND_BASE_STATIC");
	textViewSecondBaseStatic->setVisible(true);

	// Adding callbacks after checking the button because we don't need to
	// have the callback be called since changeBase() will update display anyways

	form->findControlTyped<RadioButton>("BUTTON_SOLDIERS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Soldier); });
	form->findControlTyped<RadioButton>("BUTTON_BIOSCIS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::BioChemist); });
	form->findControlTyped<RadioButton>("BUTTON_PHYSCIS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Physicist); });
	form->findControlTyped<RadioButton>("BUTTON_ENGINRS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Engineer); });
	form->findControlTyped<RadioButton>("BUTTON_ALIENS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Aliens); });

	form->findControlTyped<RadioButton>("BUTTON_VEHICLES")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::Vehicle); });
	form->findControlTyped<RadioButton>("BUTTON_AGENTS")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::AgentEquipment); });
	form->findControlTyped<RadioButton>("BUTTON_FLYING")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::FlyingEquipment); });
	form->findControlTyped<RadioButton>("BUTTON_GROUND")
	    ->addCallback(FormEventType::CheckBoxSelected,
	                  [this](Event *) { this->setDisplayType(Type::GroundEquipment); });

	// Find first base that isn't current
	for (auto &b : state->player_bases)
	{
		if (b.first != state->current_base.id)
		{
			second_base = {state.get(), b.first};
			textViewSecondBaseStatic->setText(second_base->name);
			break;
		}
	}

	confirmClosureText = tr("Confirm Transfers");

	type = Type::Soldier;
	form->findControlTyped<RadioButton>("BUTTON_SOLDIERS")->setChecked(true);
}

void TransferScreen::changeSecondBase(sp<Base> newBase)
{
	second_base = newBase->building->base;
	textViewSecondBaseStatic->setText(second_base->name);

	// Set index for all controls
	int index = getRightIndex();
	for (auto &l : transactionControls)
	{
		for (auto &c : l.second)
		{
			c->setIndexRight(index);
		}
	}
	// Apply display type and base highlight
	setDisplayType(type);
}

int TransferScreen::getRightIndex()
{
	int index = 0;
	for (auto &b : state->player_bases)
	{
		if (b.first == second_base.id)
		{
			return index;
		}
		index++;
	}
	LogError("The right side base wasn't found.");
	return -1; // should not be reached
}

void TransferScreen::updateBaseHighlight()
{
	if (viewHighlightPrevious != viewHighlight)
	{
		int i = 0;
		for (auto &b : state->player_bases)
		{
			auto viewName = format("BUTTON_SECOND_BASE_%d", ++i);
			auto view = form->findControlTyped<GraphicButton>(viewName);
			auto viewImage = drawMiniBase(*b.second, viewHighlight, viewFacility);
			view->setImage(viewImage);
			view->setDepressedImage(viewImage);
		}
	}

	// Update first base
	TransactionScreen::updateBaseHighlight();

	// Update second base
	switch (viewHighlight)
	{
		case BaseGraphics::FacilityHighlight::Quarters:
		{
			auto facilityPic = form->findControlTyped<Graphic>("FACILITY_SECOND_PIC");
			facilityPic->setVisible(true);
			facilityPic->setImage(state->facility_types["FACILITYTYPE_LIVING_QUARTERS"]->sprite);
			form->findControlTyped<Graphic>("FACILITY_SECOND_BAR")->setVisible(true);
			int usage = second_base->getUsage(*state, FacilityType::Capacity::Quarters, lq2Delta);
			fillBaseBar(false, usage);
			auto facilityLabel = form->findControlTyped<Label>("FACILITY_SECOND_TEXT");
			facilityLabel->setVisible(true);
			facilityLabel->setText(format("%d%%", usage));
			break;
		}
		case BaseGraphics::FacilityHighlight::Stores:
		{
			auto facilityPic = form->findControlTyped<Graphic>("FACILITY_SECOND_PIC");
			facilityPic->setVisible(true);
			facilityPic->setImage(state->facility_types["FACILITYTYPE_STORES"]->sprite);
			form->findControlTyped<Graphic>("FACILITY_SECOND_BAR")->setVisible(true);
			int usage = second_base->getUsage(*state, FacilityType::Capacity::Stores, cargo2Delta);
			fillBaseBar(false, usage);
			auto facilityLabel = form->findControlTyped<Label>("FACILITY_SECOND_TEXT");
			facilityLabel->setVisible(true);
			facilityLabel->setText(format("%d%%", usage));
			break;
		}
		case BaseGraphics::FacilityHighlight::Aliens:
		{
			auto facilityPic = form->findControlTyped<Graphic>("FACILITY_SECOND_PIC");
			facilityPic->setVisible(true);
			facilityPic->setImage(state->facility_types["FACILITYTYPE_ALIEN_CONTAINMENT"]->sprite);
			form->findControlTyped<Graphic>("FACILITY_SECOND_BAR")->setVisible(true);
			int usage = second_base->getUsage(*state, FacilityType::Capacity::Aliens, bio2Delta);
			fillBaseBar(false, usage);
			auto facilityLabel = form->findControlTyped<Label>("FACILITY_SECOND_TEXT");
			facilityLabel->setVisible(true);
			facilityLabel->setText(format("%d%%", usage));
			break;
		}
		default:
		{
			form->findControlTyped<Graphic>("FACILITY_SECOND_PIC")->setVisible(false);
			form->findControlTyped<Graphic>("FACILITY_SECOND_BAR")->setVisible(false);
			form->findControlTyped<Graphic>("FACILITY_SECOND_FILL")->setVisible(false);
			form->findControlTyped<Label>("FACILITY_SECOND_TEXT")->setVisible(false);
			break;
		}
	}
}

void TransferScreen::displayItem(sp<TransactionControl> control)
{
	TransactionScreen::displayItem(control);

	switch (control->itemType)
	{
		case TransactionControl::Type::BioChemist:
{'fraction_non_alphanumeric': 0.15429145253706658, 'fraction_numerical': 0.002244668911335578, 'mean_word_length': 6.146475306036303, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 345, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '903876', 'n_tokens_mistral': 5848, 'n_tokens_neox': 5642, 'n_words': 691}