#include "HangarUI.h"
#include "hangarSelectorButton.h"
#include "softProj\clientServer\structs.h"
#include <cassert>
#include "softProj\settings.h"

void HangarUI::hangarButtonClickedSlot(id_t hangarId) {
	emit updateHangarSignal(hangarId, productionTabState);
}

void HangarUI::progressSynchronize( const unsigned int percentageProgress )
{
	this->ui_.progressBar->setValue( percentageProgress );
}

void HangarUI::dataSynchronize(const hangars_status &data)
{
	selectedItemPattern_ = data.selectedItem.patternName;
	selectedShipID_ = 0;

	state_ = data;
	this->rememberUpdateTime();

	int hangarButtonIndex = 0;
	int selectedHangarPosition = 1;
	for (std::list<id_t>::const_iterator it = data.hangarIds.begin(); it != data.hangarIds.end(); ++it) {
		if (hangarButtonIndex >= HANGARS_MAXIMUM_COUNT) {
			break;
		}

		hangarButtons_[hangarButtonIndex]->setVisible(true);
		hangarButtons_[hangarButtonIndex]->setHangarId(*it);		

		if (data.selectedHangarId == *it) {
			hangarButtons_[hangarButtonIndex]->setActive(true);
			selectedHangarPosition = hangarButtonIndex + 1;
		}
		else {
			hangarButtons_[hangarButtonIndex]->setActive(false);
		}

		hangarButtonIndex++;
	}

	for (int hangarInactiveButtonIndex = hangarButtonIndex; hangarInactiveButtonIndex < HANGARS_MAXIMUM_COUNT; ++hangarInactiveButtonIndex) {
		hangarButtons_[hangarInactiveButtonIndex]->setVisible(false);
	}		

	if (data.selectedHangarId != 0) {
		selectedHangarId_ = data.selectedHangarId;

		ui_.selectedHangarNameButton->setText(QString::fromUtf16(L"Hangár č. ") + QString::number(selectedHangarPosition) + " (" + QString::number(data.selectedHangarId) + ")");

		ui_.tabWidget->setVisible(true);
		ui_.selectedHangarFrame->setVisible(true);		
		ui_.detailsMainFrame->setVisible(true);
		ui_.progressBarFrame->setVisible(true);

		bool isSelectedAlsoConstructed = data.selectedItem.patternName == data.constructedItem.patternName && data.selectedItem.patternName != "";		

		if (isSelectedAlsoConstructed) {
			dataSynchronize(data.constructedItem, true);
		}
		else {
			dataSynchronize(data.selectedItem, false);
		}		

		ui_.levelValue->setText(Settings::instance().formatNumber(data.actualLevel));
		ui_.damageStatusSlider->setValue(data.damageStatus * 100);

		if (data.isShipInDock) {
			ui_.shipLandActualValue->setText(QString::fromUtf16(L"V přístavu je loď"));
		}

		if (data.isHangarFree) {
			ui_.shipLandAvailableValue->setText(QString::fromUtf16(L"Hangár je pro loď volný"));
			ui_.shipLandAvailableValue->setProperty("green", true);
			ui_.shipLandAvailableValue->setStyleSheet(ui_.shipLandAvailableValue->styleSheet());			
		}
		else {
			ui_.shipLandAvailableValue->setText(QString::fromUtf16(L"Hangár není pro loď volný"));
			ui_.shipLandAvailableValue->setProperty("green", false);
			ui_.shipLandAvailableValue->setStyleSheet(ui_.shipLandAvailableValue->styleSheet());
		}

		if (data.isItemUnderConstruction) {
			ui_.stackedWidget->setCurrentWidget(ui_.buildPage);

			ui_.constructedItemNameLabel->setText(QString::fromUtf16(L"Vyrábí se předmět ") + QString::fromLocal8Bit(data.constructedItem.itemName.c_str()));

			ui_.progressBar->setVisible(true);
			ui_.progressBarLabel->setVisible(true);

			if (data.targetConstructedPoints != 0) { 
				ui_.progressBar->setValue((double)data.actualConstructedPoints / (double) data.targetConstructedPoints);
			}
			else {
				ui_.progressBar->setValue(0);
			}
		}
		else if (data.isShipUnderConstruction) {
			ui_.stackedWidget->setCurrentWidget(ui_.buildPage);

			ui_.constructedItemNameLabel->setText(QString::fromUtf16(L"Vyrábí se loď ") + QString::fromLocal8Bit(data.constructedItem.patternName.c_str()));

			ui_.progressBar->setVisible(true);
			ui_.progressBarLabel->setVisible(true);

			if (data.targetConstructedPoints != 0) { 
				ui_.progressBar->setValue((double)data.actualConstructedPoints / (double) data.targetConstructedPoints);
			}
			else {
				ui_.progressBar->setValue(0);
			}
		}
		else {
			ui_.constructedItemNameLabel->setText(QString::fromUtf16(L"Žádná výroba neprobíhá"));

			ui_.stackedWidget->setCurrentWidget(ui_.cannotBuildPage);

			if (data.isHangarFree) {
				ui_.cannotBuildLabel->setText(QString::fromUtf16(L"Žádná výroba neprobíhá, ale lze zahájit novou"));
				ui_.cannotBuildLabel->setProperty("green", true);
				ui_.cannotBuildLabel->setStyleSheet(ui_.cannotBuildLabel->styleSheet());
			}
			else if (data.isShipInDock) {
				ui_.cannotBuildLabel->setText(QString::fromUtf16(L"Žádná výroba neprobíhá, ani nelze zahájit novou, v hangáru přistála loď"));
				ui_.cannotBuildLabel->setProperty("green", false);
				ui_.cannotBuildLabel->setStyleSheet(ui_.cannotBuildLabel->styleSheet());
			}

			ui_.progressBar->setVisible(false);
			ui_.progressBarLabel->setVisible(false);
		}
	}
	else {
		selectedHangarId_ = 0;

		ui_.tabWidget->setVisible(false);
		ui_.selectedHangarFrame->setVisible(false);
		ui_.detailsMainFrame->setVisible(false);
		ui_.progressBarFrame->setVisible(false);
	}

	// Yes, start from 0, it is index to an array
	int classIndex = 0;
	for (std::list<fortress_class_simple_data>::const_iterator it = data.availableShipClasses.begin(); it != data.availableShipClasses.end(); ++it) {
		HangarItemWidget * shipWidget = NULL;

		if (classIndex < shipWidgets_.size()) {
			shipWidget = shipWidgets_[classIndex];
		}
		else {
			shipWidget = new HangarItemWidget(ui_.shipScrollArea);
			ui_.shipVerticalLayout->addWidget(shipWidget);
			ui_.shipVerticalLayout->setSpacing(1);
			shipWidgets_.push_back(shipWidget);

			bool connected = connect(shipWidget, SIGNAL(clickedSignal(id_t)), this, SLOT(shipTypeSlot(id_t)));
			assert(connected && "Signals not connected");
		}		

		classIndex++;

		shipWidget->setItemId(it->id);
		shipWidget->setItemName(it->name);
		shipWidget->setVisible(true);
	}	

	for (int i = classIndex; i < shipWidgets_.size(); ++i) {
		HangarItemWidget * shipWidget = shipWidgets_[classIndex];
		classIndex++;

		shipWidget->setVisible(false);
	}
}

void HangarUI::markConstructedItem(const std::string & patternName) {
	ui_.deflectorShieldButton->setAsBeingConstructed(false);
	ui_.weaponEnergyCircuitButton->setAsBeingConstructed(false);
	ui_.quarkGluonCoreButton->setAsBeingConstructed(false);
	ui_.intertialDamperButton->setAsBeingConstructed(false);
	ui_.mechanicalDamperButton->setAsBeingConstructed(false);
	ui_.navigationComputerButton->setAsBeingConstructed(false);
	ui_.droneMissileButton->setAsBeingConstructed(false);
	ui_.subspaceBeaconButton->setAsBeingConstructed(false);
	ui_.impulsJetEngineButton->setAsBeingConstructed(false);
	ui_.energeticAccumulatorButton->setAsBeingConstructed(false);
	ui_.longRangeSensorsButton->setAsBeingConstructed(false);
	ui_.probeButton->setAsBeingConstructed(false);
	ui_.submarineMiningMachineButton->setAsBeingConstructed(false);
	ui_.droneMissileLauncherButton->setAsBeingConstructed(false);
	ui_.transportBeamGeneratorButton->setAsBeingConstructed(false);
	ui_.laserGunButton->setAsBeingConstructed(false);
	ui_.undergroundDrillingMachineButton->setAsBeingConstructed(false);
	ui_.submersibleFiltrationTankButton->setAsBeingConstructed(false);
	ui_.magneticalPlasmaCollectorButton->setAsBeingConstructed(false);
	ui_.highResolutionSensorButton->setAsBeingConstructed(false);
	ui_.cloakingDeviceButton->setAsBeingConstructed(false);
	ui_.transportContainerButton->setAsBeingConstructed(false);
	ui_.magneticalGridButton->setAsBeingConstructed(false);
	ui_.plasmaFilterButton->setAsBeingConstructed(false);
	ui_.androidButton->setAsBeingConstructed(false);
	ui_.scientificLabButton->setAsBeingConstructed(false);
	ui_.energeticCellButton->setAsBeingConstructed(false);
	ui_.subspaceTransmitterButton->setAsBeingConstructed(false);
	ui_.lifeSupportButton->setAsBeingConstructed(false);
	ui_.magneticalFilterButton->setAsBeingConstructed(false);
	ui_.deuteriumDecomposerButton->setAsBeingConstructed(false);
	ui_.hangarButton->setAsBeingConstructed(false);
	ui_.mainframeButton->setAsBeingConstructed(false);
	ui_.zirconiumReactorButton->setAsBeingConstructed(false);
	ui_.ilmeniteFurnaceButton->setAsBeingConstructed(false);

	if (patternName == PROTOCOL_HANGARS_PATTERN_ID_DEFLECTOR_SHIELDS) {
		ui_.deflectorShieldButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_WEAPON_ENERGY_CIRCUIT) {
		ui_.weaponEnergyCircuitButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_QUARK_GLUON_CORE) {
		ui_.quarkGluonCoreButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_INERTIAL_DAMPERS) {
		ui_.intertialDamperButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_MECHANICAL_DAMPERS) {
		ui_.mechanicalDamperButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_NAVIGATION_COMPUTER) {
		ui_.navigationComputerButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILES) {
		ui_.droneMissileButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_SUBSPACE_BEACON) {
		ui_.subspaceBeaconButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_IMPULS_JET_ENGINE) {
		ui_.impulsJetEngineButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_ENERGETIC_ACCUMULATOR) {
		ui_.energeticAccumulatorButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_LONG_RANGE_SENSORS) {
		ui_.longRangeSensorsButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_PROBE) {
		ui_.probeButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_SUBMARINE_MINING_MACHINE) {
		ui_.submarineMiningMachineButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILE_LAUNCHER) {
		ui_.droneMissileLauncherButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_TRANSPORT_BEAM_GENERATOR) {
		ui_.transportBeamGeneratorButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_LASER_GUN) {
		ui_.laserGunButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_UNDERGROUND_DRILLIG_MACHINE) {
		ui_.undergroundDrillingMachineButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_SUBMERSIBLE_FILTRATION_TANK) {
		ui_.submersibleFiltrationTankButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_COLLECTORS_OF_PLASMA) {
		ui_.magneticalPlasmaCollectorButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_HIGH_RESOLUTION_SENSORS) {
		ui_.highResolutionSensorButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_CLOAKING_DEVICE) {
		ui_.cloakingDeviceButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_TRANSPORT_CONTAINER) {
		ui_.transportContainerButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_GRID) {
		ui_.magneticalGridButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_PLASMA_FILTER) {
		ui_.plasmaFilterButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_ANDROIDS) {
		ui_.androidButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_SCIENTIFIC_LAB) {
		ui_.scientificLabButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_ENERGETIC_CELL) {
		ui_.energeticCellButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_SUBSPACE_TRANSMITTER) {
		ui_.subspaceTransmitterButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_LIFE_SUPPORT) {
		ui_.lifeSupportButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_FILTER) {
		ui_.magneticalFilterButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_DEUTERIUM_DECOMPOSER) {
		ui_.deuteriumDecomposerButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_HANGAR) {
		ui_.hangarButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_MAINFRAME) {
		ui_.mainframeButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_ZIRCONIUM_REACTOR) {
		ui_.zirconiumReactorButton->setAsBeingConstructed(true);
	}
	else if (patternName == PROTOCOL_HANGARS_PATTERN_ID_ILMENITE_FURNACE) {
		ui_.ilmeniteFurnaceButton->setAsBeingConstructed(true);
	}
}

void HangarUI::dataSynchronize( const hangar_item_status &data ) {	

	if (state_.constructedItem.patternName == data.patternName) {
		dataSynchronize(state_.constructedItem, true);
	}
	else {
		dataSynchronize(data, false);
	}
}

void HangarUI::dataSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	selectedItemPattern_ = data.patternName;
	selectedShipID_ = 0;

	markConstructedItem("");

	if (data.patternName == "") {
		setSelectedItemFrameAsEmpty();
	}
	else {
		ui_.newItemQuantityParamLabel->setVisible(true);
		ui_.newItemQuantityParamSpinBox->setVisible(true);
		ui_.newItemWeightParamLabel->setVisible(true);
		ui_.newItemWeightParamSlider->setVisible(true);
		ui_.newItemSizeParamLabel->setVisible(true);
		ui_.valuesFrame->setVisible(true);
		ui_.buyButton->setVisible(true);
		ui_.newItemSizeParamLengthSpinBox->setVisible(true);
		ui_.newItemSizeParamWidthSpinBox->setVisible(true);
		ui_.newItemSizeParamHeightSpinBox->setVisible(true);

		bool isDisplayed = true;

		if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_DEFLECTOR_SHIELDS) {
			this->deflectorShieldSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_WEAPON_ENERGY_CIRCUIT) {
			this->weaponEnergyCircuitSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_QUARK_GLUON_CORE) {
			this-> quarkGluonCoreSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_INERTIAL_DAMPERS) {
			this->intertialDamperSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_MECHANICAL_DAMPERS) {
			this->mechanicalDamperSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_NAVIGATION_COMPUTER) {
			this->navigationComputerSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILES) {
			this->droneMissileSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_SUBSPACE_BEACON) {
			this-> subspaceBeaconSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_IMPULS_JET_ENGINE) {
			this->impulsJetEngineSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_ENERGETIC_ACCUMULATOR) {
			this->energeticAccumulatorSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_LONG_RANGE_SENSORS) {
			this->longRangeSensorSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_PROBE) {
			this->probeSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_SUBMARINE_MINING_MACHINE) {
			this->submarineMiningMachineSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILE_LAUNCHER) {
			this->droneMissileLauncherSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_TRANSPORT_BEAM_GENERATOR) {
			this->transportBeamGeneratorSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_LASER_GUN) {
			this->laserGunSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_UNDERGROUND_DRILLIG_MACHINE) {
			this->undergroundDrillingMachineSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_SUBMERSIBLE_FILTRATION_TANK) {
			this->submersibleFiltrationTankSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_COLLECTORS_OF_PLASMA) {
			this->magneticalPlasmaCollectorSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_HIGH_RESOLUTION_SENSORS) {
			this-> highResolutionSensorSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_CLOAKING_DEVICE) {
			this->cloakingDeviceSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_TRANSPORT_CONTAINER) {
			this->transportContainerSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_GRID) {
			this->magneticalGridSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_PLASMA_FILTER) {
			this->plasmaFilterSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_ANDROIDS) {
			this->androidSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_SCIENTIFIC_LAB) {
			this-> scientificLabSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_ENERGETIC_CELL) {
			this-> energeticCellSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_SUBSPACE_TRANSMITTER) {
			this->subspaceTransmitterSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_LIFE_SUPPORT) {
			this->lifeSupportSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_FILTER) {
			this->magneticalFilterSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_DEUTERIUM_DECOMPOSER) {
			this->deuteriumDecomposerSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_HANGAR) {
			this->hangarSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_MAINFRAME) {
			this->mainframeSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_ZIRCONIUM_REACTOR) {
			this->zirconiumReactorSynchronize( data, isAlsoConstructed );
		}

		else if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_ILMENITE_FURNACE) {
			this->ilmeniteFurnaceSynchronize( data, isAlsoConstructed );
		}
		else {
			isDisplayed = false;
			setSelectedItemFrameAsEmpty();
		}

		if (isDisplayed) {
			ui_.dimensionsStackedWidget->setVisible(true);

			if (data.patternName == PROTOCOL_HANGARS_PATTERN_ID_HANGAR) {
				ui_.dimensionsStackedWidget->setCurrentWidget(ui_.sizePage);
			}
			else {
				ui_.dimensionsStackedWidget->setCurrentWidget(ui_.weightPage);
			}
					
			ui_.newItemNameButton->setText(QString::fromLocal8Bit(data.itemName.c_str()));
			ui_.newItemWeightParamSlider->setMinimum(data.minWeight);
			
			ui_.newItemWeightParamSlider->setMaximum(data.maxWeight);

			if (state_.isItemUnderConstruction) {
				this->enableBuyButton(false);
				this->ui_.buildShipButton->setVisible(false);
				this->ui_.cancelButton->setVisible(true);

				ui_.stackedWidget->setCurrentWidget(ui_.buildPage);

				ui_.newItemConstructionTimeLabel->setVisible(true);
				ui_.newItemConstructionTimeValue->setVisible(true);

				if (state_.constructedItem.patternName == data.patternName) {
					ui_.dimensionsStackedWidget->setVisible(true);
					ui_.dimensionsStackedWidget->setCurrentWidget(ui_.buildInfoPage);

					if (data.isStackable) {
						ui_.newItemQuantityParamLabel->setVisible(true);
						ui_.newItemQuantityParamSpinBox->setVisible(true);
						ui_.newItemQuantityParamSpinBox->setValue(state_.constructedItem.count);
						ui_.newItemQuantityParamSpinBox->setEnabled(false);
					}
					else {
						ui_.newItemQuantityParamLabel->setVisible(false);
						ui_.newItemQuantityParamSpinBox->setVisible(false);
					}
				}
				else {
					ui_.dimensionsStackedWidget->setVisible(false);
					ui_.newItemQuantityParamLabel->setVisible(false);
					ui_.newItemQuantityParamSpinBox->setVisible(false);
				}

				markConstructedItem(state_.constructedItem.patternName);
			}
			else if (state_.isShipUnderConstruction) {
				this->enableBuyButton(false);
				this->ui_.buildShipButton->setVisible(false);
				this->ui_.cancelButton->setVisible(true);

				markConstructedItem("");

				ui_.stackedWidget->setCurrentWidget(ui_.buildPage);

				ui_.newItemConstructionTimeLabel->setVisible(false);
				ui_.newItemConstructionTimeValue->setVisible(false);

				ui_.dimensionsStackedWidget->setVisible(true);				

				ui_.dimensionsStackedWidget->setVisible(false);
				ui_.newItemQuantityParamLabel->setVisible(false);
				ui_.newItemQuantityParamSpinBox->setVisible(false);
			}
			else {				
				this->enableBuyButton(true);
				this->ui_.buildShipButton->setVisible(true);
				this->ui_.cancelButton->setVisible(false);

				ui_.stackedWidget->setCurrentWidget(ui_.cannotBuildPage);
				ui_.newItemConstructionTimeLabel->setVisible(false);
				ui_.newItemConstructionTimeValue->setVisible(false);

				if (data.isStackable) {
					ui_.newItemQuantityParamSpinBox->setEnabled(true);
					ui_.newItemQuantityParamLabel->setVisible(true);
					ui_.newItemQuantityParamSpinBox->setVisible(true);
				}
				else {
					ui_.newItemQuantityParamSpinBox->setEnabled(false);
					ui_.newItemQuantityParamLabel->setVisible(false);
					ui_.newItemQuantityParamSpinBox->setVisible(false);
				}

				ui_.dimensionsStackedWidget->setVisible(true);

				markConstructedItem("");
			}

		}
	}

	if (selectedShipID_ != 0) {
		ui_.detailsStackedWidget->setVisible(true);
		ui_.detailsStackedWidget->setCurrentWidget(ui_.shipDetailsPage);
	}
	else if (selectedItemPattern_ != "") {
		ui_.detailsStackedWidget->setVisible(true);
		ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	}
	else {
		ui_.detailsStackedWidget->setVisible(false);
	}
}

void HangarUI::setSelectedItemFrameAsEmpty() {
	ui_.newItemNameButton->setText(QString::fromUtf16(L"Nic není vybráno"));

	ui_.newItemQuantityParamLabel->setVisible(false);
	ui_.newItemQuantityParamSpinBox->setVisible(false);
	ui_.newItemWeightParamLabel->setVisible(false);
	ui_.newItemWeightParamSlider->setVisible(false);
	ui_.newItemSizeParamLabel->setVisible(false);
	ui_.valuesFrame->setVisible(false);
	ui_.buyButton->setVisible(false);
	ui_.newItemSizeParamLengthSpinBox->setVisible(false);
	ui_.newItemSizeParamWidthSpinBox->setVisible(false);
	ui_.newItemSizeParamHeightSpinBox->setVisible(false);
	ui_.dimensionsStackedWidget->setVisible(false);
}

void HangarUI::enableSizeBox( bool enable )
{
	ui_.newItemSizeParamLabel->setVisible(enable);
	ui_.newItemSizeParamLengthSpinBox->setVisible(enable);
	ui_.newItemSizeParamWidthSpinBox->setVisible(enable);
	ui_.newItemSizeParamHeightSpinBox->setVisible(enable);
}

void HangarUI::enableQuantityBox( bool enable )
{
	this->ui_.newItemQuantityParamSpinBox->setVisible( enable );
	this->ui_.newItemQuantityParamLabel->setVisible( enable );
}

void HangarUI::enableWeightBox( bool enable )
{
	this->ui_.newItemWeightParamSlider->setVisible( enable );
	this->ui_.newItemWeightParamLabel->setVisible( enable );
}

void HangarUI::enableBuyButton( bool enable )
{
	this->ui_.buyButton->setVisible( enable );
}

void HangarUI::enableCancelButton( bool enable )
{
	this->ui_.cancelButton->setVisible( enable );
}

void HangarUI::fillWidgetLabels( const hangar_item_status &data, bool isAlsoConstructed)
{
	this->ui_.newItemNameButton->setText(QString::fromUtf8(data.patternName.c_str()));

	if (isAlsoConstructed) {
		this->ui_.newItemConstructionTimeValue->setVisible(true);
		this->ui_.newItemConstructionTimeValue->setText(Settings::instance().formatNumber(data.constructionTime));

		this->ui_.newItemAndroidRequirementsLabel->setText(QString::fromUtf16(L"Maximum androidů na konstrukci zadaného množství"));
		this->ui_.newItemAndroidRequirementsValue->setText(Settings::instance().formatNumber(data.actRequiredAndroidCount));
	}
	else {
		this->ui_.newItemConstructionTimeValue->setVisible(false);

		this->ui_.newItemAndroidRequirementsLabel->setText(QString::fromUtf16(L"Maximum androidů na konstrukci jednoho předmětu"));

		if (data.minRequiredAndroidCount != data.maxRequiredAndroidCount) {
			this->ui_.newItemAndroidRequirementsValue->setText(
				Settings::instance().formatNumber(data.minRequiredAndroidCount) + " - " + Settings::instance().formatNumber(data.maxRequiredAndroidCount));
		}
		else {
			this->ui_.newItemAndroidRequirementsValue->setText(
				Settings::instance().formatNumber(data.maxRequiredAndroidCount));
		}
	}

	if (isAlsoConstructed) {
		this->ui_.newItemSpaceRequirementsValue->setText(
			Settings::instance().formatNumber(data.actSize) + "m^3");
	}
	else {
		if (data.minSize != data.maxSize) {
			this->ui_.newItemSpaceRequirementsValue->setText(
				Settings::instance().formatNumber(data.minSize) + + " m^3" + " - " + Settings::instance().formatNumber(data.maxSize) + " m^3");
		}
		else {
			this->ui_.newItemSpaceRequirementsValue->setText(
				 Settings::instance().formatNumber(data.maxSize) + " m^3");
		}
	}

	this->ui_.newItemUlreaCostValue->setText(Settings::instance().formatNumber(data.constructionUlrei) + " ks");

	if (isAlsoConstructed) {
		this->ui_.newItemTitanCostValue->setText(Settings::instance().formatNumber(data.constructionTitanium * data.minWeight)  + " kg");
	}
	else {
		if (data.minWeight != data.maxWeight) {
			this->ui_.newItemTitanCostValue->setText(
				Settings::instance().formatNumber(data.constructionTitanium * data.minWeight) + " kg - " + Settings::instance().formatNumber(data.constructionTitanium * data.maxWeight) + " kg");
		}
		else {
			this->ui_.newItemTitanCostValue->setText(
				Settings::instance().formatNumber(data.constructionTitanium * data.maxWeight) + " kg");
		}
	}

	if (isAlsoConstructed) {
		this->ui_.newItemDeuteriumCostValue->setText(Settings::instance().formatNumber(data.constructionDeuterium * data.minWeight)  + " kg");
	}
	else {
		if (data.minWeight != data.maxWeight) {
			this->ui_.newItemDeuteriumCostValue->setText(
				Settings::instance().formatNumber(data.constructionDeuterium * data.minWeight) + " kg - " + Settings::instance().formatNumber(data.constructionDeuterium * data.maxWeight) + " kg");
		}
		else {
			this->ui_.newItemDeuteriumCostValue->setText(
				Settings::instance().formatNumber(data.constructionDeuterium * data.maxWeight) + " kg");
		}
	}

	if (isAlsoConstructed) {
		this->ui_.newItemHeavyWaterCostValue->setText(Settings::instance().formatNumber(data.constructionHeavyWater * data.minWeight)  + " kg");
	}
	else {
		if (data.minWeight != data.maxWeight) {
			this->ui_.newItemHeavyWaterCostValue->setText(
				Settings::instance().formatNumber(data.constructionHeavyWater * data.minWeight) + " kg - " + Settings::instance().formatNumber(data.constructionHeavyWater * data.maxWeight) + " kg");
		}
		else {
			this->ui_.newItemHeavyWaterCostValue->setText(
				Settings::instance().formatNumber(data.constructionHeavyWater * data.maxWeight) + " kg");
		}
	}
}

void HangarUI::shipTypeSynchronize(const fortress_class_complex_data & data)
{
	selectedItemPattern_ = "";
	selectedShipID_ = data.id;

	ui_.detailsStackedWidget->setCurrentWidget(ui_.shipDetailsPage);

	ui_.maxDroneLaunchersValue->setText(Settings::instance().formatNumber(data.maxDroneMissileLaunchers));
	ui_.maxHeightValue->setText(Settings::instance().formatNumber(data.maxHeight) + " m");
	ui_.maxWidthValue->setText(Settings::instance().formatNumber(data.maxWidth) + " m");
	ui_.maxLaserGunsValue->setText(Settings::instance().formatNumber(data.maxLaserGuns));
	ui_.maxLengthValue->setText(Settings::instance().formatNumber(data.maxLength) + " m");
	ui_.maxStructuralIntegrityValue->setText(Settings::instance().formatNumber(data.maxTotalStructuralIntegrity));
	ui_.maxWeaponsValue->setText(Settings::instance().formatNumber(data.maxWeapons));
	ui_.minStructuralIntegrityValue->setText(Settings::instance().formatNumber(data.minTotalStructuralIntegrity));
	ui_.minWeightValue->setText(Settings::instance().formatNumber(data.minWeight) + " kg");
	ui_.maxWeightValue->setText(Settings::instance().formatNumber(data.maxWeight) + " kg");
	ui_.newShipNameButton->setText(QString::fromUtf8(data.name.c_str()));
	ui_.qualityValue->setText(Settings::instance().formatNumber(data.qualityRating));
	
	ui_.titaniumSlider->setMaximum(data.maxWeight);
	ui_.titaniumSlider->setMinimum(data.minWeight);	
	
	ui_.titaniumSlider->setValue(data.minWeight);

	shipClassData_ = data;

	if (state_.isShipUnderConstruction) {
		ui_.shipTimeLabel->setVisible(true);
		ui_.shipTimeValue->setVisible(true);
	}
	else {
		ui_.shipTimeLabel->setVisible(false);
		ui_.shipTimeValue->setVisible(false);
	}

	if (selectedShipID_ != 0) {
		ui_.detailsStackedWidget->setVisible(true);
		ui_.detailsStackedWidget->setCurrentWidget(ui_.shipDetailsPage);
	}
	else if (selectedItemPattern_ != "") {
		ui_.detailsStackedWidget->setVisible(true);
		ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	}
	else {
		ui_.detailsStackedWidget->setVisible(false);
	}
}

void HangarUI::deflectorShieldSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);

	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_DEFLECTOR_SHIELDS;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}


void HangarUI::weaponEnergyCircuitSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_WEAPON_ENERGY_CIRCUIT;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Energetický okruh")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::quarkGluonCoreSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_QUARK_GLUON_CORE;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Quark-Gluonové jádro")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::intertialDamperSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_INERTIAL_DAMPERS;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Inercielní pružiny")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::mechanicalDamperSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_MECHANICAL_DAMPERS;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Mechanické pružiny")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::navigationComputerSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_NAVIGATION_COMPUTER;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Navigační počítač")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::droneMissileSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILES;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Dronní střely")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::subspaceBeaconSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_SUBSPACE_BEACON;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Podprostorový beacon")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::impulsJetEngineSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_IMPULS_JET_ENGINE;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Impulzní motor")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::energeticAccumulatorSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_ENERGETIC_ACCUMULATOR;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Energetický akumulátor")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}
void HangarUI::longRangeSensorSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_LONG_RANGE_SENSORS;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Dálkové senzory")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::probeSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_PROBE;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Sonda")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::submarineMiningMachineSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_SUBMARINE_MINING_MACHINE;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Podmořské těžební zařízení")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::droneMissileLauncherSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILE_LAUNCHER;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Raketomety dronních střel")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::transportBeamGeneratorSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_TRANSPORT_BEAM_GENERATOR;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Transportní paprsek")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::laserGunSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_LASER_GUN;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Laserové dělo")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::undergroundDrillingMachineSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_UNDERGROUND_DRILLIG_MACHINE;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Podzemní těžební zařízení")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::submersibleFiltrationTankSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_SUBMERSIBLE_FILTRATION_TANK;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Podmořské filtrační nádrže")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::magneticalPlasmaCollectorSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_COLLECTORS_OF_PLASMA;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Magnetické kolektory plazmy")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::highResolutionSensorSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_HIGH_RESOLUTION_SENSORS;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Rozlišovací senzory")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::cloakingDeviceSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_CLOAKING_DEVICE;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Maskovací zařízení")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::transportContainerSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_TRANSPORT_CONTAINER;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Transportní kontejnery")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::magneticalGridSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_GRID;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Magnetická mřížka")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::plasmaFilterSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_PLASMA_FILTER;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Plazmový filtr")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::androidSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_ANDROIDS;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Androidi")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::scientificLabSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_SCIENTIFIC_LAB;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Vědecká laboratoř")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::energeticCellSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_ENERGETIC_CELL;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Magnetická buňka")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::subspaceTransmitterSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_SUBSPACE_TRANSMITTER;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Podprostorový přenašeč")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::lifeSupportSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_DEFLECTOR_SHIELDS;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Podpora života")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::magneticalFilterSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_FILTER;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Magnetický filtr")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::deuteriumDecomposerSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_DEUTERIUM_DECOMPOSER;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Rozkladač deuteria")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::hangarSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_HANGAR;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Hangár")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( true );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( false );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::mainframeSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_MAINFRAME;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Mainframe")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::zirconiumReactorSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_ZIRCONIUM_REACTOR;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Zirkonový reaktor okruh")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox( true );
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

void HangarUI::ilmeniteFurnaceSynchronize( const hangar_item_status &data, bool isAlsoConstructed )
{
	ui_.detailsStackedWidget->setCurrentWidget(ui_.itemDetailsPage);
	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_ILMENITE_FURNACE;

	this->ui_.newItemNameButton->setText( QString::fromLocal8Bit("Ilmenitová pec")) ;

	this->fillWidgetLabels( data, isAlsoConstructed );

	this->enableSizeBox( false );
	this->enableQuantityBox(data.isStackable);
	this->enableWeightBox( true );
	// this->enableBuyButton( true );
	// this->enableCancelButton( false );
}

// SLOTS -----------------------------------
void HangarUI::shipTypeSlot(id_t fortressClassId)
{
	emit updateFortressClassSignal(fortressClassId);
}

void HangarUI::constructionItemSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_ANDROIDS);
}

void HangarUI::weaponEnergyCircuitSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_WEAPON_ENERGY_CIRCUIT);
}

void HangarUI::deflectorShieldSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_DEFLECTOR_SHIELDS);
}

void HangarUI::quarkGluonCoreSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_QUARK_GLUON_CORE);
}

void HangarUI::intertialDamperSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_INERTIAL_DAMPERS);
}

void HangarUI::mechanicalDamperSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_MECHANICAL_DAMPERS);
}

void HangarUI::navigationComputerSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_NAVIGATION_COMPUTER);
}

void HangarUI::droneMissilesSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILES);
}

void HangarUI::subspaceBeaconSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_SUBSPACE_BEACON);
}

void HangarUI::impulsJetEngineSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_IMPULS_JET_ENGINE);
}

void HangarUI::energeticAccumulatorSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_ENERGETIC_ACCUMULATOR);
}
void HangarUI::longRangeSensorsSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_LONG_RANGE_SENSORS);
}

void HangarUI::probeSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_PROBE);
}

void HangarUI::submarineMiningMachineSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_SUBMARINE_MINING_MACHINE);
}

void HangarUI::droneMissileLauncherSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILE_LAUNCHER);
}

void HangarUI::transportBeamGeneratorSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_TRANSPORT_BEAM_GENERATOR);
}

void HangarUI::laserGunSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_LASER_GUN);
}

void HangarUI::undergroundDrillingMachineSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_UNDERGROUND_DRILLIG_MACHINE);
}

void HangarUI::submersibleFiltrationTankSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_SUBMERSIBLE_FILTRATION_TANK);
}

void HangarUI::magneticalPlasmaCollectorSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_COLLECTORS_OF_PLASMA);
}

void HangarUI::highResolutionSensorSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_HIGH_RESOLUTION_SENSORS);
}

void HangarUI::cloakingDeviceSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_CLOAKING_DEVICE);
}

void HangarUI::transportContainerSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_TRANSPORT_CONTAINER);
}

void HangarUI::magneticalGridSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_GRID);
}

void HangarUI::plasmaFilterSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_PLASMA_FILTER);
}

void HangarUI::androidsSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_ANDROIDS);
}

void HangarUI::scientificLabSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_SCIENTIFIC_LAB);
}

void HangarUI::energeticCellSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_ENERGETIC_CELL);
}

void HangarUI::subspaceTransmitterSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_SUBSPACE_TRANSMITTER);
}

void HangarUI::lifeSupportSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_LIFE_SUPPORT);
}

void HangarUI::magneticalFilterSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_MAGNETICAL_FILTER);
}

void HangarUI::deuteriumDecomposerSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_DEUTERIUM_DECOMPOSER);
}

void HangarUI::hangarSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_HANGAR);
}

void HangarUI::mainframeSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_MAINFRAME);
}

void HangarUI::zirconiumReactorSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_ZIRCONIUM_REACTOR);
}

void HangarUI::ilmeniteFurnaceSlot(void)
{
	emit updateHangarItemSignal(PROTOCOL_HANGARS_PATTERN_ID_ILMENITE_FURNACE);
}

void HangarUI::buyButtonSlot(void)
{
	HangarServerInputData data;

	data.hangarId = this->selectedHangarId_;
	data.quantity = this->ui_.newItemQuantityParamSpinBox->value();
	data.length =  this->ui_.newItemSizeParamLengthSpinBox->value();
	data.width =  this->ui_.newItemSizeParamWidthSpinBox->value();
	data.height =  this->ui_.newItemSizeParamHeightSpinBox->value();
	data.weight	 =	this->ui_.newItemWeightParamSlider->getValue();
	data.type	 =	this->productionTabState;

	emit hangarBuyItemSignal(data);
}

void HangarUI::buildShipButtonSlot(void)
{
	HangarServerInputData data;

	id_t hangarId = this->selectedHangarId_;
	id_t fortressClassId = shipClassData_.id;
	unsigned long long buildingTitanium = ui_.titaniumSlider->getValue();

	emit hangarBuildShipSignal(hangarId, fortressClassId, buildingTitanium);
}

void HangarUI::cancelButtonSlot(void)
{
	std::string type = this->productionTabState;
	emit hangarCancelItemSignal(selectedHangarId_, type);
}

// ########################################
// constructors

HangarUI::HangarUI( QWidget *parent ): NotifyWidget( parent)
{
	this->ui_.setupUi( this );

	this->selectedHangarId_ = 0;

	selectedItemPattern_ = "";
	selectedShipID_ = 0;

	this->productionTabState = PROTOCOL_HANGARS_PATTERN_ID_ANDROIDS;

	this->ui_.progressBar->setRange(0,100);  // 0-100%
	this->ui_.damageStatusSlider->setUnit(L"%");
	
	ui_.titaniumSlider->setFontColor(QColor::fromRgb(40, 40, 40));
	ui_.titaniumSlider->setUnit(L"kg");
	ui_.newItemWeightParamSlider->setFontColor(QColor::fromRgb(40, 40, 40));
	ui_.newItemWeightParamSlider->setUnit(L"kg");

	hangarButtons_ = new HangarSelectorButton*[HANGARS_MAXIMUM_COUNT];

	for (int i = 0; i < HANGARS_MAXIMUM_COUNT; ++i) {
		hangarButtons_[i] = new HangarSelectorButton(ui_.hangarSelectorFrame);		
		hangarButtons_[i]->setShownNumber(i+1);

		ui_.hangarSelectorLayout->addWidget(hangarButtons_[i]);			
		hangarButtons_[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
		hangarButtons_[i]->setMinimumSize(25, 25);	
		hangarButtons_[i]->setMaximumSize(25, 25);				

		bool connected = connect(hangarButtons_[i], SIGNAL(clickedSignal(id_t)), this, SLOT(hangarButtonClickedSlot(id_t)));
		assert(connected && "Signals not connected");
	}

	ui_.hangarSelectorLayout->addStretch(0);	
	ui_.hangarsSection->setName(L"Hangáry");

	ui_.verticalLayout->setGeometry(ui_.scrollAreaWidgetContents->geometry());

	this->ui_.deflectorShieldButton->setItemName(L"Štíty");
	this->ui_.weaponEnergyCircuitButton->setItemName(L"Zbraňový energetický okruh");
	this->ui_.quarkGluonCoreButton->setItemName(L"Quark-gluonové jádro");
	this->ui_.intertialDamperButton->setItemName(L"Inerciálmí tlumiče");
	this->ui_.mechanicalDamperButton->setItemName(L"Mechanické tlumiče");
	this->ui_.navigationComputerButton->setItemName(L"Navigační počítač");
	this->ui_.droneMissileButton->setItemName(L"Torpéda");
	this->ui_.subspaceBeaconButton->setItemName(L"Podprostorový maják");
	this->ui_.impulsJetEngineButton->setItemName(L"Impulsní pohon"); 
	this->ui_.energeticAccumulatorButton->setItemName(L"Energetický akumulátor");
	this->ui_.longRangeSensorsButton->setItemName(L"Dálkové senzory");
	this->ui_.probeButton->setItemName(L"Sondy");
	this->ui_.submarineMiningMachineButton->setItemName(L"Podmořské těžební zařízení");
	this->ui_.droneMissileLauncherButton->setItemName(L"Torpédomet");
	this->ui_.transportBeamGeneratorButton->setItemName(L"Generátor transportního paprsku");
	this->ui_.laserGunButton->setItemName(L"Laserové dělo");
	this->ui_.undergroundDrillingMachineButton->setItemName(L"Podzemní těžební zařízení");
	this->ui_.submersibleFiltrationTankButton->setItemName(L"Podmořské filtrační nádrže");
	this->ui_.magneticalPlasmaCollectorButton->setItemName(L"Magnetické kolektory plazmy");
	this->ui_.highResolutionSensorButton->setItemName(L"Senzory s vysokým rozlišením");
	this->ui_.cloakingDeviceButton->setItemName(L"Maskování");
	this->ui_.transportContainerButton->setItemName(L"Transportní kontejner");
	this->ui_.magneticalGridButton->setItemName(L"Magnetická mřížka");
	this->ui_.plasmaFilterButton->setItemName(L"Plasmový filtr");
	this->ui_.androidButton->setItemName(L"Androidi");
	this->ui_.scientificLabButton->setItemName(L"Vědecká laboratoř");
	this->ui_.energeticCellButton->setItemName(L"Energetický článek");
	this->ui_.subspaceTransmitterButton->setItemName(L"Podprostorový vysílač");
	this->ui_.lifeSupportButton->setItemName(L"Podpora života");
	this->ui_.magneticalFilterButton->setItemName(L"Magnetický filtr");
	this->ui_.deuteriumDecomposerButton->setItemName(L"Rozkladač deuteria");
	this->ui_.hangarButton->setItemName(L"Hangár");
	this->ui_.mainframeButton->setItemName(L"Palubní počítač");
	this->ui_.zirconiumReactorButton->setItemName(L"Zirkoniový reaktor");
	this->ui_.ilmeniteFurnaceButton->setItemName(L"Ilmenitová pec");

	bool ok = true;
	
	ok = ok && QObject::connect( this->ui_.buyButton, SIGNAL( clicked(bool) ), this, SLOT( buyButtonSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.deflectorShieldButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( deflectorShieldSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.weaponEnergyCircuitButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( weaponEnergyCircuitSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.quarkGluonCoreButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( quarkGluonCoreSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.intertialDamperButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( intertialDamperSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.mechanicalDamperButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( mechanicalDamperSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.navigationComputerButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( navigationComputerSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.droneMissileButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( droneMissilesSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.subspaceBeaconButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( subspaceBeaconSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.impulsJetEngineButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( impulsJetEngineSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.energeticAccumulatorButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( energeticAccumulatorSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.longRangeSensorsButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( longRangeSensorsSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.probeButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( probeSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.submarineMiningMachineButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( submarineMiningMachineSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.droneMissileLauncherButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( droneMissileLauncherSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.transportBeamGeneratorButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( transportBeamGeneratorSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.laserGunButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( laserGunSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.undergroundDrillingMachineButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( undergroundDrillingMachineSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.submersibleFiltrationTankButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( submersibleFiltrationTankSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.magneticalPlasmaCollectorButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( magneticalPlasmaCollectorSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.highResolutionSensorButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( highResolutionSensorSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.cloakingDeviceButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( cloakingDeviceSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.transportContainerButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( transportContainerSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.magneticalGridButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( magneticalGridSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.plasmaFilterButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( plasmaFilterSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.androidButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( androidsSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.scientificLabButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( scientificLabSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.energeticCellButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( energeticCellSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.subspaceTransmitterButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( subspaceTransmitterSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.lifeSupportButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( lifeSupportSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.magneticalFilterButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( magneticalFilterSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.deuteriumDecomposerButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( deuteriumDecomposerSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.hangarButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( hangarSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.mainframeButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( mainframeSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.zirconiumReactorButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( zirconiumReactorSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.ilmeniteFurnaceButton, SIGNAL( clickedSignal(id_t) ), this, SLOT( ilmeniteFurnaceSlot(void) ) );
	
	ok = ok && QObject::connect( this->ui_.cancelButton, SIGNAL( clicked(bool) ), this, SLOT( cancelButtonSlot(void) ) );
	ok = ok && QObject::connect( this->ui_.buildShipButton, SIGNAL( clicked(bool) ), this, SLOT( buildShipButtonSlot(void) ) );
	
	assert( ok && "Connection failed!" );

	bool connected = connect(ui_.unmountButton, SIGNAL(clicked(bool)), this, SLOT(unmountHangarButtonClickedSlot()));
	assert(connected && "Signals not connected");

	this->progressSynchronize( 50 );	

	ui_.tabWidget->setVisible(false);
	ui_.selectedHangarFrame->setVisible(false);
	ui_.detailsMainFrame->setVisible(false);
	ui_.progressBarFrame->setVisible(false);

	ui_.damageStatusSlider->setMinimum(0);
	ui_.damageStatusSlider->setMaximum(100);

	setSelectedItemFrameAsEmpty();
}

HangarUI::~HangarUI()
{
	for (int i = 0; i < HANGARS_MAXIMUM_COUNT; ++i) 
	{
		delete hangarButtons_[i];
	}

	delete [] hangarButtons_;

	for (std::vector<HangarItemWidget *>::iterator it = shipWidgets_.begin(); it != shipWidgets_.end(); ++it) { 
		delete *it;
	}
}

void HangarUI::unmountHangarButtonClickedSlot() {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_HANGAR, this->selectedHangarId_);
}

id_t HangarUI::getSelectedHangarID() {
	return selectedHangarId_;
}

std::string HangarUI::getSelectedPatternName() {
	return this->productionTabState;
}


void HangarUI::notifyUpdate() {
	if (state_.isItemUnderConstruction || state_.isShipUnderConstruction) {
		double difference = getDifferenceFromUpdateTime();

		unsigned long long newActualConstructedPoints = getUpdatedValue(state_.actualConstructedPoints, state_.constructionGradient, difference);

		if (state_.targetConstructedPoints != 0) {
			ui_.progressBar->setValue((newActualConstructedPoints / (double) state_.targetConstructedPoints) * 100);
		}

		if (state_.selectedItem.patternName == state_.constructedItem.patternName || state_.isShipUnderConstruction) {
			if (state_.constructionGradient != 0) {
				unsigned long long newEstimatedTime = (state_.targetConstructedPoints  - newActualConstructedPoints) / state_.constructionGradient;
				ui_.newItemConstructionTimeValue->setText(Settings::instance().formatNumber(newEstimatedTime) + " hs");
				ui_.shipTimeValue->setText(Settings::instance().formatNumber(newEstimatedTime) + " hs");
			}
		}
	}
}