#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

#include <QtGui/QWidget>
#include <QtGui/QLabel>
#include <string>
#include <vector>
#include "ui_MainWindow.h"
#include "softProj\ScienceTreeWidget\ScienceTreeWidget.h"
#include "softProj\DetailsWidget\DetailsWidget.h"
#include "softProj\ChatWidget\ChatWidget.h"
#include "softProj\ChatWidget\IncomingWidget.h"
#include "softProj\DetailsWidget\SimpleItem.h"
#include "softProj\DetailsWidget\ComplexItem.h"
#include "softProj\TradeWidget\TradeWidget.h"
#include "softProj\WeaponsWidget\fightWidget.h"
#include "softProj\selectionWidget\selectionWidget.h"
#include "softProj\NavigationWidget\navigationwidget.h"
#include "softProj\clientServer\threads.h"
#include "qtOpenGLwidget\GL_widget2.h"
#include "softProj\clientServer\commandClient.h"
#include "softProj\selectionWidget\OtherviewWidget.h"
#include "softProj\AttackWidget\AttackWidget.h"
#include "softProj\DevicesWidget\allDevicesWidget.h"
#include "softProj\LoginWidget\LoginWidget.h"
#include "softProj\clientServer\structs.h"
#include "softProj\Main\warningDialog.h"
#include "softProj\Main\MessageDialog.h"
#include "softProj\BuildWidget\buildWidget.h"
#include "softProj\clientState.h"
#include "softProj\Main\inputDialog.h"

typedef std::vector<SimpleItem> GameItemsVector;

/*
const unsigned int RES_X = 900;
const unsigned int RES_Y = 620;
*/

class MainWindow : public QWidget
{
	Q_OBJECT

public:
	MainWindow( int argc, char **argv, Environment &environment );
	~MainWindow();
	
private:
	bool modelViewerActive;
	bool mapViewerActive;
	bool planetViewerActive;

	void showShipsTable(GameItemsVector & items);
	void showBasesTable(GameItemsVector & items);
	void showSpaceMap( void );

	void setActivity(const std::wstring & activity);

	void updateNavigation(id_t shipId);

	void setGameSecondsPerActualSecond(unsigned long value);

	void clearPlayerState();
public:
	void initOpenGl(void);
	void showScienceTree();
	void showTrade();
	void showFight();
	void showBuild();
	void showChat();
	void showDevices();
	void addChatBuddy(ChatBuddy * buddy);
	void receiveChatMessage(ChatMessage * message);
	void loadConnections(const QString & filePath);	



	/* Items list in details widget */
	void answerBases(GameItemsVector & items);
	void answerShips(GameItemsVector & items);	

	void updateSpaceMap(GameItemsVector & items);

	/* Navigation */
	void answerShipJourneyDetails(ShipJourneyDetailsFAIL & details);
	void answerShipJourneyDetails(ShipJourneyDetailsSTANDARD & details);
	void answerShipJourneyDetails(ShipJourneyDetailsPURSUIT & details);
	void answerShipJourneyDetails(ShipJourneyDetailsMOVE_TO & details);
	void answerShipJourneyDetails(ShipJourneyDetailsMOVE_TO_SPACE_OBJECT & details);
	void answerUpdateNavigationStatus(NavigationStatus & navigationStatus);

	void answerNavigationShipFAIL(unsigned long shipId, const std::string & fail);

	void answerNavigationMoveToSpaceObject(id_t shipId);
	void answerNavigationMoveToSpaceObjectByWarp(id_t shipId);
	void answerNavigationMoveTo(id_t shipId);
	void answerNavigationPursuit(id_t shipId);
	void answerNavigationBreakWarp(id_t shipId);
	void answerNavigationOrbit(id_t shipId);
	void answerNavigationStop(id_t shipId);	
	void answerNavigationWarp(id_t shipId);
	void answerNavigationDockDown(id_t shipId, id_t baseId, DockingResult result);	
	void answerNavigationUnbound(id_t shipId, DockingResult result);

	void answerNavigationMoveToSpaceObjectFAIL();
	void answerNavigationMoveToSpaceObjectByWarpFAIL();
	void answerNavigationMoveToFAIL();
	void answerNavigationPursuitFAIL();
	void answerNavigationBreakWarpFAIL();
	void answerNavigationOrbitFAIL();
	void answerNavigationStopFAIL();	
	void answerNavigationWarpFAIL();	
	void answerNavigationDockDownFAIL(id_t shipId, const std::string & reason);
	void answerNavigationUnboundFAIL(id_t shipId, const std::string & reason);

	void answerUpdateShip(id_t shipId);
	void answerUpdateFortress(id_t fortressId);

	/* Devices widget */
	void answerChangeDeviceEnergyStateERROR(id_t shipId, const std::string & fail);
	void answerUpdateDeviceEnergyStateFAIL(id_t shipId, const std::string & fail);
	void answerUpdateDeviceEnergyState(id_t shipId, answerDeviceEnergy & state);

	/* Chat widget */
	void answerBuddies(std::vector<ChatBuddy *> buddies);

	/* Render */
	void answerShipsInShipAreaFAIL(id_t areaId, const std::string & fail);
	void answerPlanetsInStarAreaFAIL(id_t areaId, const std::string & fail);
	void answerShipLocation(id_t shipId, location_status & activeShipLocation );
	void answerPlanetsInStarArea(PlanetsInStarAreaDetails & planetsInArea);
	void answerNavigationPlanets(NavigationPlanetsInStarAreaDetails & planetsInArea);
	
	void answerPlayerExploredStars( discovered_stars & discoveredStars );
	void synchronizeGenericPlanet(PlanetDetails & details, const dv_time::datetime &gameTime );
	void answerShipWarpInfo( WarpInfo &shipWarpInfo );

	/* Science tree */
	void answerUpdateScienceTree(ScienceTreeRawUpdateData & data);

	/* Central Info */
	void answerUpdateCentralInformation(CentralInfoDetails & details);
	void answerUpdateCentralInformationFAIL(id_t fortressId, const std::string & reason);

	/* Shields */
	void answerUpdateShieldsInformation(ShieldsDetails & details);
	void answerUpdateShieldsInformationFAIL(id_t fortressId, const std::string & reason);

	/* Impuls drive */
	void answerUpdateImpulsDriveInformation(id_t shipId, impulse_drive_status & details);
	void answerUpdateImpulsDriveInformationFAIL(id_t shipId, const std::string & reason);

	/* Subspace drive */
	void answerUpdateSubspaceDriveInformation(id_t shipId, subspace_drive_status & details);
	void answerUpdateSubspaceDriveInformationFAIL(id_t shipId, const std::string & reason);

	/* Mainframe */
	void answerUpdateMainframeInformation(id_t fortressId, mainframe_status & details);
	void answerUpdateMainframeInformationFAIL(id_t fortressId, const std::string & reason);

	/* Weapons */
	void answerUpdateWeaponsInformation(id_t fortressId, weapons_status & state);
	void answerUpdateWeaponsInformationFAIL(id_t fortressId, const std::string & fail);
	void answerChangeWeaponsInformationFAIL(id_t fortressId, const std::string & fail);

	/* Crew */
	void answerUpdateCrewInformation(id_t fortressId, crew_status & state);
	void answerUpdateCrewInformationFAIL(id_t fortressId, const std::string & fail);
	void answerFortressAddCrew(id_t fortressId, unsigned long able, unsigned long wounded, crew_type crewType);
	void answerFortressAddCrewFAIL(id_t fortressId, const std::string & reason);
	void answerFortressRemoveCrew(id_t fortressId, unsigned long able, unsigned long wounded, crew_type crewType);
	void answerFortressRemoveCrewFAIL(id_t fortressId, const std::string & reason);

	/* Quarry */
	void answerUpdateQuarryInformation(id_t fortressId, quarry_status & state);
	void answerUpdateQuarryInformationFAIL(id_t fortressId, const std::string & fail);

	void answerChangeQuarryStateFAIL(id_t fortressId, const std::string & fail);

	/* Accommodations */
	void answerUpdateAccommodationsInformation(id_t fortressId, accommodation_status & state);
	void answerUpdateAccommodationsInformationFAIL(id_t fortressId, const std::string & fail);
	void answerFortressAddAccommodations(id_t fortressId, unsigned long count, accommodation_type accommodationType);
	void answerFortressAddAccommodationsFAIL(id_t fortressId, const std::string & reason);

	/* Other equipment */
	void answerUpdateOtherEquipmentInformation(id_t fortressId, other_equipment_status & state);
	void answerUpdateOtherEquipmentInformationFAIL(id_t fortressId, const std::string & fail);

	/* Factories */
	void answerUpdateFactoriesInformation(id_t fortressId, factories_status & state);
	void answerUpdateFactoriesInformationFAIL(id_t fortressId, const std::string & fail);

	/* Warehouses */
	void answerUpdateWarehousesInformation(id_t fortressId, warehouses_status & state);
	void answerUpdateWarehousesInformationFAIL(id_t fortressId, const std::string & fail);

	/* Androids */
	void answerUpdateShipAndroidsInformation(id_t fortressId, ship_androids_status & state);
	void answerUpdateShipAndroidsInformationFAIL(id_t fortressId, const std::string & fail);

	void answerUpdateBaseAndroidsInformation(id_t fortressId, base_androids_status & state);
	void answerUpdateBaseAndroidsInformationFAIL(id_t fortressId, const std::string & fail);

	void answerChangeShipAndroidsStateFAIL(id_t fortressId, const std::string & fail);
	void answerChangeBaseAndroidsStateFAIL(id_t fortressId, const std::string & fail);

	/* Hangars */
	void answerUpdateBaseHangarItemInformation(hangar_item_status & state);
	void answerUpdateBaseHangarsInformation(hangars_status & state);
	void answerUpdateBaseHangarsInformationFAIL(id_t fortressId, const std::string & reason);
	void answerHangarBuildItem(id_t fortessId, id_t hangarId, const std::string & result);
	void answerHangarBuildItemFAIL(id_t fortessId, id_t hangarId, const std::string & reason);
	void answerHangarCancelItem(id_t fortessId, id_t hangarId);
	void answerHangarCancelItemFAIL(id_t fortessId, id_t hangarId, const std::string & reason);
	void answerHangarBuildShip(id_t fortessId, id_t hangarId, const std::string & result);
	void answerHangarBuildShipFAIL(id_t fortessId, id_t hangarId, const std::string & reason);

	/* Trade */

	void answerSendTradeInvitation(const trade_invitation_data & invitation, const std::string & reason, const std::string & tradeRole);
	void answerSendTradeInvitation(const trade_invitation_data & invitation, const trade_data & selfTradeData, const std::string & reason, const std::string & tradeRole);
	void answerSendTradeInvitation(const trade_invitation_data & invitation, const trade_data & selfTradeData, const trade_data & partnerTradeData, const std::string & reason, const std::string & tradeRole);
	void answerTradePartnerFortresses(id_t fortressId, const std::vector<SimpleItem> & ownedFortresses, const std::vector<SimpleItem> & notOwnedFortresses);
	void answerTradePartnerFortressesFAIL(id_t fortressId, const std::string & reason);
	void answerUncontrollableFortresses(id_t fortressId, const std::vector<FortressInRangeData> & ships, const std::vector<FortressInRangeData> & bases);
	void answerUncontrollableFortressesFAIL(id_t fortressId, const std::string & reason);
	void receiveTradeInvitation(const trade_invitation_data & data);
	void answerDecideTradeInvitation(const trade_invitation_data & invitation);
	void answerDecideTradeInvitation(const trade_invitation_data & invitation, const trade_data & tradeData);
	void receiveTradeInvitationDecision(const trade_invitation_data & invitation);
	void receiveTradeInvitationDecision(const trade_invitation_data & invitation, const trade_data & tradeData);
	void answerCancelTrade(id_t ownedFortressId, id_t partnerFortressId, const std::string & reason, const std::string & tradeRole);
	void receiveTradeCancelation(id_t ownedFortressId, id_t partnerFortressId);

	void answerMoveTradeItem(const trade_movement_data & tradeData, bool isAuthor);
	void answerMoveTradeItemFAIL(const trade_movement_data & tradeData, const std::string & reason);

	void answerCommitTrade(unsigned long selfFortressId, unsigned long partnerFortressId, ETradingResult result);
	void answerPrepareCommitTrade(unsigned long selfFortressId, unsigned long partnerFortressId, ETradingCommitRole commitRole);

	void answerMoveTradeResource(const trade_resource_movement_data & tradeData, bool isAuthor);
	void answerMoveTradeResourceFAIL(const trade_resource_movement_data & tradeData, const std::string & reason);
	void answerCancelTradeCommit(id_t selfFortressId, id_t partnerFortressId, const std::string & reason);

	void answerUnmountFortressDevice(const unmount_device_info & unmountData, const std::string & mountingResult);
	void answerUnmountFortressDeviceFAIL(id_t fortressId, const std::string & reason);
	void answerMountFortressDevice(id_t fortressId, id_t itemId, const std::string & mountingResult);
	void answerMountFortressDeviceFAIL(id_t fortressId, id_t itemId, const std::string & reason);

	/* Fight */

	void answerFortressesAttackInformation(const std::vector<fortress_attack_information>& fortresses);
	void answerFortressesInRange(const fortress_attack_information & ownedFortress, const std::vector<SimpleItem> & ships, const std::vector<SimpleItem> & bases);
	void answerAttackFortress(id_t selfFortressId, id_t enemyFortressId);
	void answerAttackFortressFAIL(id_t selfFortressId, id_t enemyFortressId, const std::string & reason);
	void answerStopAttackFortress(id_t selfFortressId);
	void answerStopAttackFortressFAIL(id_t selfFortressId, const std::string & reason);
	void answerFightActionReport(const fight_action_report & report);
	void answerFightProgressReport(const fight_progress_report & report);

	/* Build */
	void answerBuildNewBaseShell(id_t selfFortressId, BaseBuildingResult result, unsigned long long newTitan);
	void answerBuildNewBaseShellFAIL(id_t selfFortressId, const std::string & reason);
	void answerAvailableFortressClasses(id_t selfFortressId, const std::list<fortress_class_simple_data> & shipClasses, const std::list<fortress_class_simple_data> & baseClasses);
	void answerAvailableFortressClassesFAIL(id_t selfFortressId, const std::string & reason);
	void answerFortressClassData(const fortress_class_complex_data & data);
	void answerFortressClassDataFAIL(id_t fortressClassId, const std::string & reason);
	void answerFortressesBuildInformation(const std::list<fortress_build_information> & ships, const std::list<fortress_build_information> & bases);
	void answerFortresses(const std::vector<SimpleItem> & fortresses);
	void answerConquerFortress(const ConquerResultData & data);
	void answerConquerFortressFAIL(id_t selfFortressId, const std::string & reason);

	/* Registration */
	void answerRegistration(const RegistrationResult & result);

	void answerGameSecondsPerActualSecond(unsigned long value);

	void answerRenameFortress(id_t fortressId, const std::string & newNameeP);
	void answerRenameFortressFAIL(id_t fortressId, const std::string & reason);
public:
	Ui::mainWindow ui_;

	OtherviewWidget * otherviewWidget;
	SelectionLogic * otherviewLogic;

	GLwidget2 * renderWidgetBig;
	GLwidget2 * renderWidgetSmall;
	ClientSynchronizer * synchronizer_;

	location_status activeShipLocation;
	unsigned long activeShipIdSpaceMap;
	bool newShipSelected;
	bool callPlanetsInStarAreaWithUpdatedNearestStar;
	bool centerAsSoonAsPossible;
	bool isPossibleToCenter;

	ModelViewerApp *modelViewerApp;
	MapViewerApp *mapViewerApp;
	PlanetViewerApp *planetViewerApp;
	OpenGlSharedData *sharedData;
	Environment environment;

	void notifyUpdate();

	void shipsInShipAreaDone(void);

public slots:
	void showDialogSlot();
	void hideDialogSlot();
	void unmountSlot(const std::string & patternName, unsigned long long working, unsigned long long damaged);
	void unmountSlot(const std::string & patternName, id_t itemId);
	void unmountSlot(const std::string & patternName);	
	void activateMapViewerSlot(void);
	void activateModelViewerSlot(void);
	void activatePlanetViewerSlot(void);
	void renderSlot(void);
	void simulateSlot( float dt );
	void renameFortressSlot();

	void submitInputDialogSlot();
	void cancelInputDialogSlot();
	void rejectDialogSlot();

	void showShipsTableSlot();
	void showBasesTableSlot();
	void showScienceTreeSlot();	
	void showChatSlot();
	void showTradeSlot();
	void showFightSlot();
	void showBuildSlot();
	void showSpaceMapSlot(void);
	void showNavigationSlot(void);

	void changeSelectedFortressSlot(SimpleItem & item);
	void changeShipSectionSlot(SimpleItem & item, EShipSectionState data);
	void changeBaseSectionSlot(SimpleItem & item, EBaseSectionState data);

	/* Chat */
	void sendChatMessageSlot(ChatMessage * message);
	void receiveUnreadChatMessageSlot(ChatMessage * message);
	void markChatMessagesReadSlot(int count);	

	/* Devices */
	void submitDevicesSlot(requestDeviceEnergy & state);
	void resetDevicesSlot();

	/* Navigation */
	void navigationMoveToSpaceObjectSlot(unsigned long shipId, unsigned long spaceObjectId, unsigned long limit);
	void navigationMoveToSlot(unsigned long shipId, position_t positionx, position_t positiony, unsigned long limit);
	void navigationMoveToSpaceObjectByWarpSlot(unsigned long shipId, unsigned long spaceObjectId);
	void navigationPursuitSlot(unsigned long shipId, unsigned long spaceObjectId, unsigned long limit);
	void navigationBreakWarpSlot(unsigned long shipId);
	void navigationOrbitSlot(unsigned long shipId);
	void navigationStopSlot(unsigned long shipId);	
	void navigationWarpSlot(unsigned long shipId, position_t positionx, position_t positiony);
	void navigationPlanetsSlot(id_t starId);
	void navigationDockDownSlot(id_t baseId);
	void navigationUnboundSlot();

	/* Render */
	void getRadarDataSlot(  unsigned long shipId );
	void setSelectedShipSlot( unsigned long shipId );
	void getAttackListSlot( unsigned long shipId );
	void setAttackTargetSlot( unsigned long targetShipId );

	void shipSettingsSlot(unsigned long shipId ); /**< Called from otherview widget when user wants quick edit ship */
	void shipNavigationSlot(unsigned long shipId ); /**< Called from otherview widget when user wants quick show ship navigation */
	void shipWeaponsSlot(unsigned long shipId ); /**< Called from otherview widget when user wants quick show ship weapons */

	void updateSpaceMap( void );  /**< Updates complete space map data . */

	/* Login */
	void loggedWidgetLoginClickedSignal(LoginDetails & loginDetails);
	void loggedWidgetUnloginClickedSignal(LoginDetails & loginDetails);
	void submitLoginSlot(const LoginDetails & loginDetails);

	/* Weapons */
	void submitWeaponsSlot(WeaponsChangeDetails & state);
	void resetWeaponsSlot();

	void submitWeaponsSlot(id_t fortressId, WeaponsChangeDetails & state);
	void resetWeaponsSlot(id_t fortressId);

	/* Science tree */
	void changeScienceTreeStateSlot(sciencetree_raw_data & state);
	void updateScienceTreeStateSlot();

	/* Quarry */
	void changeQuarkGluonPlasmaQuarryStateSlot(id_t fortressId, bool isQuarrying);
	void changeHeavyWaterQuarryStateSlot(id_t fortressId, bool isQuarrying);
	void changeZirconiumCrystalQuarryStateSlot(id_t fortressId, bool isQuarrying);
	void changeIlmeniteQuarryStateSlot(id_t fortressId, bool isQuarrying);

	/* Androids */
	void androidsShipResetSlot();
	void androidsShipSubmitSlot(ship_androids_request_status & state);

	void androidsBaseResetSlot();
	void androidsBaseSubmitSlot(base_androids_request_status & state);

	/* Hangars */
	void updateFortressClassSlot(id_t fortressClassId);
	void updateHangarItemSlot(const std::string & patternName);
	void updateHangarSlot(id_t hangarId, const std::string & patternName);

	void hangarBuildItemSlot(const HangarServerInputData & data);
	void hangarBuildShipSlot(id_t hangarId, id_t fortressClassId, unsigned long long buildingTitanium);
	void hangarCancelItemSlot(id_t hangarId);

	/* Trade */
	void inviteTradePartnerSlot(id_t hostFortressId, id_t invitedFortressId);
	void cancelTradeSlot();
	void tradePartnerFortressesSlot(id_t ownedFortressId);
	void decideTradeInvitationSlot(id_t hostFortressId, id_t invitedFortressId, bool accept);
	void cancelTradeCommitSlot(id_t selfFortressId, id_t partnerFortressId);
	void startTradeSlot();
	void moveTradeItemSlot(const trade_client_movement_data & tradeData);
	void commitTradeSlot(id_t selfFortressId, id_t partnerFortressId, const client_trade_data & selfOffer, const client_trade_data & partnerOffer);
	void moveTradeResourceSlot(const trade_resource_movement_data & data);
	void ownedFortressesSlot();
	void ownedFortressesBuildInformationSlot();

	/* General */

	/** Slot for informing that user canceled unmount dialog */
	void cancelUnmountDialogSlot();

	/** Slot for informing that user confirmed unmount dialog */
	void submitUnmountDialogSlot();

	void submitWarningDialogSlot();
	void submitMessageDialogSlot();

	void mountSlot(id_t itemId, unsigned long long count);

	/* Fight */ 

	void fortressInWeaponsRangeSlot(id_t fortressId);
	void fortressWeaponsSettingsSlot(id_t fortressId);
	void attackFortressSlot(id_t selfFortressId, id_t enemyFortressId);
	void stopAttackFortressSlot(id_t selfFortressId);
	void updateAttackWarningsSlot(const std::map<id_t, fortress_under_attack_data> & fortresses);
	void removeFortressSlot(id_t fortressId, const std::string & fortressName);

	/* Build */
	void fortressesInConquerRangeSlot(id_t fortressId);
	void fortressClassesSlot(id_t fortressId);
	void fortressClassDetailsSlot(id_t fortressClassId);
	void buildNewBaseShellSlot(id_t fortressId, id_t fortressClassId, unsigned long long titanium);
	void conquerSlot(id_t selfFortressId, id_t partnerFortressId);
	void tradeFromBuildSlot(id_t selfFortressId, id_t partnerFortressId);

	/* Registration */
	void submitRegistrationSlot(const RegistrationData & data);

	/* Accommodations */
	void addAccommodationsSlot(unsigned long count, accommodation_type accommodationType);

	/* Crew */
	void addCrewSlot(unsigned long able, unsigned long wounded, crew_type crewType);
	void removeCrewSlot(unsigned long able, unsigned long wounded, crew_type crewType);

	/* Sensors */
	void answerUpdateFortressSensors(id_t fortressId, const sensors_data & sensors, const sensors_data & lrSensors);
	void answerUpdateFortressSensorsFAIL(id_t fortressId, const std::string & reason);

	/* Cloaking */
	void answerUpdateFortressCloaking(id_t fortressId, const cloaking_data & data);
	void answerUpdateFortressCloakingFAIL(id_t fortressId, const std::string & reason);
signals:
	void showShipsTableSignal();
	void showBasesTableSignal();
	void showScienceTreeSignal();

	void showSpaceMapSignal();
	void showNavigationSignal();

	void sendChatMessageSignal(ChatMessage * message);
private:
	std::string ADMIN_LOGIN;

	CommandClient * commandClient_;

	/** Clears client state of the widget */
	void clearState();

	void restoreClientState();

	void updateShipSection();
	void updateBaseSection();

	void unmountFortressDevice(const std::string & patternName);
	void unmountFortressDevice(const std::string & patternName, id_t itemId);
	void unmountFortressDevice(const std::string & patternName, unsigned long long working, unsigned long long damaged);
	void createUnmountDialog();
	void createMountDialog();
	void createWarningDialog();	
	void createMessageDialog();	

	void showMessage(const QString & title, const QString & message, const std::string & iconKey);
	void showWarning(const std::wstring & title, const std::wstring & message, const std::string & iconKey, const std::string & reason = "");		
	void showWarning(const std::wstring & title, const std::wstring & message, const std::string & iconKey, const std::wstring & reason);
	void showMessage(const std::wstring & title, const std::wstring & message, const std::string & iconKey);

	void showInputDialog(const SimpleItem & fortress);
	void createInputDialog();

	ScienceTreeWidget * treeWidget_;
	DetailsWidget * detailsWidget_;
	ChatWidget * chatWidget_;
	IncomingWidget * incomingWidget_;
	TradeWidget * tradeWidget_;
	FightWidget * fightWidget_;
	BuildWidget * buildWidget_;

	WarningDialog * warningDialog_;
	MessageDialog * messageDialog_;
	UnmountDialog * unmountDialog_;
	MountDialog * mountDialog_;
	InputDialog * inputDialog_;
	
	SelectionWidget *shipSelectionWidget_;
	SelectionWidget *baseSelectionWidget_;
	AttackWidget *attackWidget;	

	ClientState currentState_;

	void showScienceTreePanel();
	void hideScienceTreePanel();

	void showDetailsWidget();
	void hideDetailsWidget();

	void showChatPanel();
	void hideChatPanel();

	void showTradePanel();
	void hideTradePanel();

	void showFightPanel();
	void hideFightPanel();

	void showBuildPanel();
	void hideBuildPanel();

	void showBigRenderPanel();
	void hideBigRenderPanel();

	void showSmallRenderPanel( SimpleItem & item );
	void hideSmallRenderPanel();

	void showLoginPanel();
	void hideLoginPanel();		

	/* States */
	void changeMainState(EMainState state);	

	/* Something else */

	void hideAttackPanel();
	void hideAllWidgets();

	QString createDetailsTitle(int id, const std::wstring & name);
	ScienceTreeWidget * createAndInitTree(QWidget * parentWidget);

	LoginWidget * loginWidget_;	

	bool assertFortressExistence(const std::string & errorText); 
	bool assertFortressEquality(id_t fortressId, const std::string & errorText);

	void connectSignals();
	void connectDialogSignals(QWidget * widget);
	void connectUnmountStackableSignals(QWidget * widget);
	void connectUnmountSeparateSignals(QWidget * widget);
	void connectUnmountWeaponsSignals(QWidget * widget);

	bool isWaitingForUpdateFortressResponse;
	bool isThereAnotherUpdateFortressNotification;
	bool checkIfWaitingForUpdateFortressResponse();
	void setWaitingForUpdateFortressResponse(bool wait);
public:
	bool isInMainState(EMainState state);

	/** Informs that client is disconnected due to lost connection
	@param milliseconds Number of milliseconds of how long ping was not acknowledged by server
	*/
	void connectionLostEvent(int milliseconds);

	void setCommandClient(CommandClient * commandClient) {
		this->commandClient_ = commandClient;
	}

	CommandClient * getCommandClient() {
		return commandClient_;
	}

	void answerLogin();
	void answerLoginFAIL(const std::string & reason);
};

#endif
