#include "otherEquipmentWidget.h"
#include "softProj\settings.h"

OtherEquipmentWidget::OtherEquipmentWidget(QWidget * parent) : NotifyWidget(parent) {
	ui_.setupUi(this);

	bool connected = true;

	ui_.otherEquipmentSection->setName(L"Vybavení");

	ui_.lifeSupport->setCapacityUnit(L"lidí");
	ui_.lifeSupport->setConsumptionUnit(L"TJ/s");
	connected = connected && connect(ui_.lifeSupport, SIGNAL(unmountButtonClickedSignal(bool)), this, SLOT(lifeSupportUnmountButtonClickedSlot(bool)));

	ui_.scientificLab->setCapacityUnit(L"lidí");
	connected = connected && connect(ui_.scientificLab, SIGNAL(unmountButtonClickedSignal(bool)), this, SLOT(scientificLabUnmountButtonClickedSlot(bool)));
		
	ui_.plasmaFilter->setFilteringSpeedUnit(L"mg/s");
	connected = connected && connect(ui_.plasmaFilter, SIGNAL(unmountButtonClickedSignal(bool)), this, SLOT(plasmaFilterUnmountButtonClickedSlot(bool)));

	ui_.subspaceTransmitter->setMessageCostUnit(L"?");
	connected = connected && connect(ui_.subspaceTransmitter, SIGNAL(unmountButtonClickedSignal(bool)), this, SLOT(subspaceTransmitterUnmountButtonClickedSlot(bool)));

	weightUnit_ = " kg";
	consumptionUnit_ = " TJ/s";
}

void OtherEquipmentWidget::setState(other_equipment_status & state) {
	this->rememberUpdateTime();

	ui_.lifeSupport->setAvailable(state.isLifeSupportAvailable);
	ui_.lifeSupport->setCapacity(state.lifeSupportActualCapacity);
	ui_.lifeSupport->setConsumption(state.lifeSupportActualConsumption);
	ui_.lifeSupport->setDamageStatus(state.lifeSupportStatus * 100);

	ui_.scientificLab->setAvailable(state.isScietificLabAvailable);
	ui_.scientificLab->setCapacity(state.scientificLabActualCapacity);
	ui_.scientificLab->setLevel(state.scientificLabActualLevel);
	ui_.scientificLab->setDamageStatus(state.scientificLabStatus * 100);

	ui_.plasmaFilter->setAvailable(state.isPlasmaFilterAvailable);
	ui_.plasmaFilter->setFilteringSpeed(state.plasmaFilterActualTotalFilteringSpeed);
	ui_.plasmaFilter->setDamageStatus(state.plasmaFilterStatus * 100);

	ui_.subspaceTransmitter->setAvailable(state.isSubspaceTransmitterAvailable);
	ui_.subspaceTransmitter->setMessageCost(state.subspaceTransmitterActualMessageCost);
	ui_.subspaceTransmitter->setDamageStatus(state.subspaceTransmitterStatus * 100);

	ui_.consumptionValue->setText(Settings::instance().formatNumber(state.actualEnergyConsumption) + consumptionUnit_);
	ui_.weightValue->setText(Settings::instance().formatNumber(state.otherEquipmentWeight) + weightUnit_);
}

void OtherEquipmentWidget::notifyUpdate() {
}

void OtherEquipmentWidget::lifeSupportUnmountButtonClickedSlot(bool checked) {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_LIFE_SUPPORT);
}

void OtherEquipmentWidget::scientificLabUnmountButtonClickedSlot(bool checked) {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_SCIENTIFIC_LAB);
}

void OtherEquipmentWidget::plasmaFilterUnmountButtonClickedSlot(bool checked) {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_PLASMA_FILTER);
}

void OtherEquipmentWidget::subspaceTransmitterUnmountButtonClickedSlot(bool checked) {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_SUBSPACE_TRANSMITTER);
}

OtherEquipmentWidget::~OtherEquipmentWidget() {
}