<commit_before>#include "game/ui/base/vequipscreen.h"
#include "forms/form.h"
#include "forms/graphic.h"
#include "forms/label.h"
#include "forms/radiobutton.h"
#include "forms/textedit.h"
#include "forms/ui.h"
#include "framework/apocresources/cursor.h"
#include "framework/configfile.h"
#include "framework/data.h"
#include "framework/event.h"
#include "framework/font.h"
#include "framework/framework.h"
#include "framework/keycodes.h"
#include "framework/renderer.h"
#include "game/state/city/base.h"
#include "game/state/city/building.h"
#include "game/state/city/vehicle.h"
#include "game/state/city/vequipment.h"
#include "game/state/gamestate.h"
#include "game/state/rules/city/vehicletype.h"
#include "game/state/tilemap/tilemap.h"
#include "game/ui/components/equipscreen.h"
#include "game/ui/general/vehiclesheet.h"
#include "library/strings_format.h"
#include <cmath>

namespace OpenApoc
{
const Vec2<int> VEquipScreen::EQUIP_GRID_SLOT_SIZE{16, 16};
const Vec2<int> VEquipScreen::EQUIP_GRID_SLOTS{16, 16};

static const Colour EQUIP_GRID_COLOUR{40, 40, 40, 255};
static const Colour EQUIP_GRID_COLOUR_ENGINE{255, 255, 40, 255};
static const Colour EQUIP_GRID_COLOUR_WEAPON{255, 40, 40, 255};
static const Colour EQUIP_GRID_COLOUR_GENERAL{255, 40, 255, 255};

VEquipScreen::VEquipScreen(sp<GameState> state)
    : Stage(), form(ui().getForm("vequipscreen")),
      pal(fw().data->loadPalette("xcom3/ufodata/vroadwar.pcx")),
      labelFont(ui().getFont("smalfont")), drawHighlightBox(false), state(state)

{
	formVehicleItem = form->findControlTyped<Form>("VEHICLE_STATS_VIEW");
	form->findControlTyped<RadioButton>("BUTTON_SHOW_WEAPONS")->setChecked(true);

	auto paperDollPlaceholder = form->findControlTyped<Graphic>("PAPER_DOLL");

	this->paperDoll = form->createChild<EquipmentPaperDoll>(
	    paperDollPlaceholder->Location, paperDollPlaceholder->Size, EQUIP_GRID_SLOT_SIZE);

	// when hovering the paperdoll, display the selected vehicle stats
	paperDoll->addCallback(FormEventType::MouseEnter, [this](FormsEvent *e) {
		highlightedVehicle = selected;
		VehicleSheet(formVehicleItem).display(selected);
	});

	for (auto &v : state->vehicles)
	{
		auto vehicle = v.second;
		if (vehicle->owner != state->getPlayer())
			continue;
		this->setSelectedVehicle(vehicle);
		highlightedVehicle = vehicle;
		VehicleSheet(formVehicleItem).display(vehicle);
		break;
	}
	if (!this->selected)
	{
		LogError("No vehicles found - the original apoc didn't open the equip screen in this case");
	}

	// Vehicle name edit
	form->findControlTyped<TextEdit>("TEXT_VEHICLE_NAME")
		->addCallback(FormEventType::TextEditFinish, [this](FormsEvent *e) {
			if (this->selected)
			{
				this->selected->name = std::dynamic_pointer_cast<TextEdit>(e->forms().RaisedBy)->getText();
			}
		});
	form->findControlTyped<TextEdit>("TEXT_VEHICLE_NAME")
		->addCallback(FormEventType::TextEditCancel, [this](FormsEvent *e) {
			if (this->selected)
			{
				std::dynamic_pointer_cast<TextEdit>(e->forms().RaisedBy)->setText(this->selected->name);
			}
		});

	this->paperDoll->setNonHighlightColour(EQUIP_GRID_COLOUR);
	this->setHighlightedSlotType(EquipmentSlotType::VehicleWeapon);
}

VEquipScreen::~VEquipScreen() = default;

void VEquipScreen::begin()
{
	form->findControlTyped<Label>("TEXT_FUNDS")->setText(state->getPlayerBalance());

	vehicleSelectBox = form->findControlTyped<ListBox>("VEHICLE_SELECT_BOX");

	for (auto &v : state->vehicles)
	{
		auto vehicle = v.second;
		if (vehicle->owner != state->getPlayer())
			continue;
		auto graphic = mksp<Graphic>(vehicle->type->equip_icon_big);

		// when entering a selectbox item, display that vehicle's stats
		graphic->addCallback(FormEventType::MouseEnter, [this, vehicle](FormsEvent *e) {
			highlightedVehicle = vehicle;
			VehicleSheet(formVehicleItem).display(vehicle);
		});
		vehicleSelectBox->addCallback(FormEventType::MouseLeave, [this](FormsEvent *e) {
			highlightedVehicle = selected;
			VehicleSheet(formVehicleItem).display(selected);
		});
		graphic->AutoSize = true;<commit_msg>fix typos2<commit_after>#include "game/ui/base/vequipscreen.h"
#include "forms/form.h"
#include "forms/graphic.h"
#include "forms/label.h"
#include "forms/radiobutton.h"
#include "forms/textedit.h"
#include "forms/ui.h"
#include "framework/apocresources/cursor.h"
#include "framework/configfile.h"
#include "framework/data.h"
#include "framework/event.h"
#include "framework/font.h"
#include "framework/framework.h"
#include "framework/keycodes.h"
#include "framework/renderer.h"
#include "game/state/city/base.h"
#include "game/state/city/building.h"
#include "game/state/city/vehicle.h"
#include "game/state/city/vequipment.h"
#include "game/state/gamestate.h"
#include "game/state/rules/city/vehicletype.h"
#include "game/state/tilemap/tilemap.h"
#include "game/ui/components/equipscreen.h"
#include "game/ui/general/vehiclesheet.h"
#include "library/strings_format.h"
#include <cmath>

namespace OpenApoc
{
const Vec2<int> VEquipScreen::EQUIP_GRID_SLOT_SIZE{16, 16};
const Vec2<int> VEquipScreen::EQUIP_GRID_SLOTS{16, 16};

static const Colour EQUIP_GRID_COLOUR{40, 40, 40, 255};
static const Colour EQUIP_GRID_COLOUR_ENGINE{255, 255, 40, 255};
static const Colour EQUIP_GRID_COLOUR_WEAPON{255, 40, 40, 255};
static const Colour EQUIP_GRID_COLOUR_GENERAL{255, 40, 255, 255};

VEquipScreen::VEquipScreen(sp<GameState> state)
    : Stage(), form(ui().getForm("vequipscreen")),
      pal(fw().data->loadPalette("xcom3/ufodata/vroadwar.pcx")),
      labelFont(ui().getFont("smalfont")), drawHighlightBox(false), state(state)

{
	formVehicleItem = form->findControlTyped<Form>("VEHICLE_STATS_VIEW");
	form->findControlTyped<RadioButton>("BUTTON_SHOW_WEAPONS")->setChecked(true);

	auto paperDollPlaceholder = form->findControlTyped<Graphic>("PAPER_DOLL");

	this->paperDoll = form->createChild<EquipmentPaperDoll>(
	    paperDollPlaceholder->Location, paperDollPlaceholder->Size, EQUIP_GRID_SLOT_SIZE);

	// when hovering the paperdoll, display the selected vehicle stats
	paperDoll->addCallback(FormEventType::MouseEnter, [this](FormsEvent *e) {
		highlightedVehicle = selected;
		VehicleSheet(formVehicleItem).display(selected);
	});

	for (auto &v : state->vehicles)
	{
		auto vehicle = v.second;
		if (vehicle->owner != state->getPlayer())
			continue;
		this->setSelectedVehicle(vehicle);
		highlightedVehicle = vehicle;
		VehicleSheet(formVehicleItem).display(vehicle);
		break;
	}
	if (!this->selected)
	{
		LogError("No vehicles found - the original apoc didn't open the equip screen in this case");
	}

	// Vehicle name edit
	form->findControlTyped<TextEdit>("TEXT_VEHICLE_NAME")
	    ->addCallback(FormEventType::TextEditFinish, [this](FormsEvent *e) {
		    if (this->selected)
		    {
			    this->selected->name =
			        std::dynamic_pointer_cast<TextEdit>(e->forms().RaisedBy)->getText();
		    }
		});
	form->findControlTyped<TextEdit>("TEXT_VEHICLE_NAME")
	    ->addCallback(FormEventType::TextEditCancel, [this](FormsEvent *e) {
		    if (this->selected)
		    {
			    std::dynamic_pointer_cast<TextEdit>(e->forms().RaisedBy)
			        ->setText(this->selected->name);
		    }
		});

	this->paperDoll->setNonHighlightColour(EQUIP_GRID_COLOUR);
	this->setHighlightedSlotType(EquipmentSlotType::VehicleWeapon);
}

VEquipScreen::~VEquipScreen() = default;

void VEquipScreen::begin()
{
	form->findControlTyped<Label>("TEXT_FUNDS")->setText(state->getPlayerBalance());

	vehicleSelectBox = form->findControlTyped<ListBox>("VEHICLE_SELECT_BOX");

	for (auto &v : state->vehicles)
	{
		auto vehicle = v.second;
		if (vehicle->owner != state->getPlayer())
			continue;
		auto graphic = mksp<Graphic>(vehicle->type->equip_icon_big);

		// when entering a selectbox item, display that vehicle's stats
		graphic->addCallback(FormEventType::MouseEnter, [this, vehicle](FormsEvent *e) {
			highlightedVehicle = vehicle;
			VehicleSheet(formVehicleItem).display(vehicle);
		});
		vehicleSelectBox->addCallback(FormEventType::MouseLeave, [this](FormsEvent *e) {
			highlightedVehicle = selected;
			VehicleSheet(formVehicleItem).display(selected);
		});
		graphic->AutoSize = true;
{'fraction_non_alphanumeric': 0.1500984251968504, 'fraction_numerical': 0.012918307086614173, 'mean_word_length': 6.062554300608167, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 121, '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': '5975584', 'n_tokens_mistral': 3105, 'n_tokens_neox': 2879, 'n_words': 443}