#ifndef HANGARUI_H
#define HANGARUI_H


#include <string>
#include <vector>

using namespace std;

#include <qobject.h>
#include <qtimer.h>
#include "SoftProj\GameApp\ModelViewerApp.h"
#include "softProj\HangarWidget\hangarSelectorButton.h"
#include "softProj\clientServer\structs.h"
#include "ui_HangarWidget.h"
#include "softProj\Main\INotifyUpdate.h"
#include "hangarItemWidget.h"

///Hangar widget is widget used for building new space objects.
/**
Hangar Widget displays revieved data, send data changes 
and allow user to interact with the data
**/
class HangarUI : public NotifyWidget
{
	Q_OBJECT

private:
	std::string productionTabState; /**<Holds type of object which is already constructed */
	HangarSelectorButton ** hangarButtons_;
	const static int HANGARS_MAXIMUM_COUNT = 20;
	std::vector<HangarItemWidget *> shipWidgets_;

	void enableSizeBox( bool enable );		/**< Makes size text box enable or disable */
	void enableQuantityBox( bool enable );	/**< Makes quantity text box enable or disable */
	void enableWeightBox( bool enable );	/**< Makes weight text box enable or disable */
	void enableBuyButton( bool enable );	/**< Makes buy button enable or disable */
	void enableCancelButton( bool enable );	/**< Makes cancel button enable or disable */
	void fillWidgetLabels( const hangar_item_status &data, bool isAlsoConstructed ); /**< Display informations about given object */	

	void deflectorShieldSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void weaponEnergyCircuitSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void quarkGluonCoreSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void intertialDamperSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void mechanicalDamperSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void navigationComputerSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void droneMissileSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void subspaceBeaconSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void impulsJetEngineSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void energeticAccumulatorSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void longRangeSensorSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void probeSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void submarineMiningMachineSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void droneMissileLauncherSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void transportBeamGeneratorSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void laserGunSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void undergroundDrillingMachineSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void submersibleFiltrationTankSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void magneticalPlasmaCollectorSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void highResolutionSensorSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void cloakingDeviceSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void transportContainerSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void magneticalGridSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void plasmaFilterSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void androidSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void scientificLabSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void energeticCellSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void subspaceTransmitterSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void lifeSupportSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void magneticalFilterSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void deuteriumDecomposerSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void hangarSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void mainframeSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void zirconiumReactorSynchronize( const hangar_item_status &data, bool isAlsoConstructed );
	void ilmeniteFurnaceSynchronize( const hangar_item_status &data, bool isAlsoConstructed );

	/** Sets frame with information about selected item to state when no item is selected, 
	so all parts of the frame are hidden and just name label informs that no item is selected */
	void setSelectedItemFrameAsEmpty();

	id_t selectedHangarId_;
	hangars_status state_;

	std::string selectedItemPattern_;
	id_t selectedShipID_;

	void markConstructedItem(const std::string & patternName);
private slots:

	// slots below are activated when its button is pressed

	void shipTypeSlot(id_t fortressClassId);

	void buyButtonSlot(void);
	void buildShipButtonSlot(void);
	void cancelButtonSlot(void);
	void constructionItemSlot(void);
	void deflectorShieldSlot(void);
	void weaponEnergyCircuitSlot(void);
	void quarkGluonCoreSlot(void);
	void intertialDamperSlot(void);
	void mechanicalDamperSlot(void);
	void navigationComputerSlot(void);
	void droneMissilesSlot(void);
	void subspaceBeaconSlot(void);
	void impulsJetEngineSlot(void);
	void energeticAccumulatorSlot(void);
	void longRangeSensorsSlot(void);
	void probeSlot(void);
	void submarineMiningMachineSlot(void);
	void droneMissileLauncherSlot(void);
	void transportBeamGeneratorSlot(void);
	void laserGunSlot(void);
	void undergroundDrillingMachineSlot(void);
	void submersibleFiltrationTankSlot(void);
	void magneticalPlasmaCollectorSlot(void);
	void highResolutionSensorSlot(void);
	void cloakingDeviceSlot(void);
	void transportContainerSlot(void);
	void magneticalGridSlot(void);
	void plasmaFilterSlot(void);
	void androidsSlot(void);
	void scientificLabSlot(void);
	void energeticCellSlot(void);
	void subspaceTransmitterSlot(void);
	void lifeSupportSlot(void);
	void magneticalFilterSlot(void);
	void deuteriumDecomposerSlot(void);
	void hangarSlot(void);
	void mainframeSlot(void);
	void zirconiumReactorSlot(void);
	void ilmeniteFurnaceSlot(void);

	void hangarButtonClickedSlot(id_t hangarId);
	void unmountHangarButtonClickedSlot();
public:

	void dataSynchronize( const hangar_item_status &data );
	void dataSynchronize( const hangar_item_status &data, bool isAlsoConstructed ); /**< Procces given data ( ie. displays them ) */
	void dataSynchronize( const hangars_status &data ); /**< Procces given data ( ie. displays them ) */
	void progressSynchronize( const unsigned int percentageProgress ); /**< Sets progress bar state for already constructed object */
	void shipTypeSynchronize(const fortress_class_complex_data & data);

	HangarUI( QWidget *parent = NULL );
	~HangarUI();

	Ui_HangarWidget ui_;

	fortress_class_complex_data shipClassData_;

	void notifyUpdate();

	id_t getSelectedHangarID();
	std::string getSelectedPatternName();
signals:
	void updateHangarItemSignal(const std::string & patternName);
	void updateHangarSignal(id_t hangarId, const std::string & patternName);
	void hangarBuyItemSignal(const HangarServerInputData & data);
	void hangarBuildShipSignal(id_t hangarId, id_t fortressClassId, unsigned long long buildingTitanium);
	void hangarCancelItemSignal(id_t hangarId, const std::string & patterName);
	void updateFortressClassSignal(id_t fortressClassId);

	/** Signals that user wants to unmount items
	@param patternName Name of pattern for device to unmount
	@param itemId Id of item to unmount
	*/
	void unmountSignal(const std::string & patternName, id_t itemId);
};

#endif
