#include "allWeaponsWidget.h"
#include <cassert>
#include "../streams/ErrorStream.h"
#include "softProj\settings.h"

extern KODIAK_DEBUG_STREAM KODIAK_DEBUG_COUT;

void AllWeaponsWidget::weaponsSubmitedSlot(bool) {
	lockForUpdate(false);
	WeaponsChangeDetails state = getState();
	emit submitWeaponsSignal(state);
}

void AllWeaponsWidget::weaponsResetedSlot(bool) {
	lockForUpdate(false);
	emit resetWeaponsSignal();
}

void AllWeaponsWidget::droneSettingsChangedSlot(const std::pair<id_t, unsigned long long> & state) {
	if (isSmall_) {
		if (!isSynchronizing_) {
			// If widget is synchronizing with server, do not update7
			WeaponsChangeDetails fullState;
			fullState.droneGuns.push_back(state);
			emit submitWeaponsSignal(fullState);
		}
	}
	else {
		lockForUpdate(true);
	}
}

void AllWeaponsWidget::laserSettingsChangedSlot(const std::pair<id_t, unsigned long long> & state) {
	if (isSmall_) {
		if (!isSynchronizing_) {
			// If widget is synchronizing with server, do not update
			WeaponsChangeDetails fullState;
			fullState.laserGuns.push_back(state);
			emit submitWeaponsSignal(fullState);
		}
	}
	else {
		lockForUpdate(true);
	}

}

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

	isSmall_ = false; 

	availableButtonStyle_ = Settings::instance().getStyle(STYLE_AVAILABLE_DEVICE_BUTTON);
	unavailableButtonStyle_ = Settings::instance().getStyle(STYLE_UNAVAILABLE_DEVICE_BUTTON);

	availableSmallButtonStyle_ = Settings::instance().getStyle(STYLE_AVAILABLE_DEVICE_SMALL_BUTTON);
	unavailableSmallButtonStyle_ = Settings::instance().getStyle(STYLE_UNAVAILABLE_DEVICE_SMALL_BUTTON);

	laserLayout_ = new WeaponLayout(ui_.laserGunsFrame);
	laserLayout_->createLaserWeapons();

	droneLayout_ = new WeaponLayout(ui_.droneGunsFrame);		
	droneLayout_->createDroneWeapons();

	bool connected = true;
	
	connected = connected && connect(laserLayout_, SIGNAL(settingsChangedSignal(const std::pair<id_t, unsigned long long> &)),
		this, SLOT(laserSettingsChangedSlot(const std::pair<id_t, unsigned long long> &)));

	connected = connected && connect(droneLayout_, SIGNAL(settingsChangedSignal(const std::pair<id_t, unsigned long long> &)),
		this, SLOT(droneSettingsChangedSlot(const std::pair<id_t, unsigned long long> &)));

	ui_.damageStatusLabel->setText(QString::fromUtf16(L"Stav"));
	ui_.damageStatusSlider->setLimits(0, 100);
	ui_.damageStatusSlider->setEnabled(false);
	ui_.damageStatusSlider->setUnit(L"%");

	connected = connected && QObject::connect(ui_.weaponsSection->submitButton, SIGNAL(clicked(bool)), this, SLOT(weaponsSubmitedSlot(bool)));
	connected = connected && QObject::connect(ui_.weaponsSection->cancelButton, SIGNAL(clicked(bool)), this, SLOT(weaponsResetedSlot(bool)));

	connected = connected && QObject::connect(ui_.unmountCircuitButton, SIGNAL(clicked(bool)), this, SLOT(unmountCircuitButtonClickedSlot()));
	connected = connected && QObject::connect(ui_.unmountDronesButton, SIGNAL(clicked(bool)), this, SLOT(unmountDronesButtonClickedSlot()));

	connected = connected && QObject::connect(droneLayout_, SIGNAL(unmountDroneWeaponSignal(id_t)), this, SLOT(unmountDroneWeaponSlot(id_t)));
	connected = connected && QObject::connect(laserLayout_, SIGNAL(unmountLaserWeaponSignal(id_t)), this, SLOT(unmountLaserWeaponSlot(id_t)));

	assert(connected && "Signals not connected");

	ui_.weaponsSection->setName(L"Zbraňový okruh");

	isSynchronizing_ = false;
	lockForUpdate(false);
}

void AllWeaponsWidget::lockForUpdate(bool lock) {
	isLockedForUpdate_ = lock;

	if (lock) {
		ui_.weaponsSection->setAsChanged();
		ui_.unmountDronesButton->setEnabled(false);
		ui_.unmountCircuitButton->setEnabled(false);
	}
	else {
		ui_.weaponsSection->setAsNormal();

		if (state_.avalWeaponEnergyCircuit) {
			ui_.unmountCircuitButton->setEnabled(true);
		}

		if (state_.avalDroneMissiles && state_.drone_missiles_count > 0) {
			ui_.unmountDronesButton->setEnabled(true);
		}
	}
}

AllWeaponsWidget::~AllWeaponsWidget() {
	delete laserLayout_;
	delete droneLayout_;
}

void AllWeaponsWidget::unmountAllWeapons() {
	laserLayout_->unmountAllWeapons();
	droneLayout_->unmountAllWeapons();
}

void AllWeaponsWidget::setState(weapons_status & state) {	
	ui_.damageStatusSlider->setValue(state.weapon_energy_circuit_status * 100);

	if (!isLockedForUpdate_) {
		isSynchronizing_ = true;

		this->state_ = state;
		rememberUpdateTime();

		if (state.avalWeaponEnergyCircuit) {
			ui_.laserGrunsValue->setText(QString::number(state.max_laser_guns));
			ui_.droneGunsValue->setText(QString::number(state.max_drone_missile_launchers));	
			ui_.maxValueFrame->setVisible(true);

			if (isSmall_) {				
				ui_.circuitTitleButton->setStyleSheet(availableSmallButtonStyle_);
			}
			else {
				ui_.circuitTitleButton->setStyleSheet(availableButtonStyle_);
			}

			ui_.damageStatusLabel->setVisible(true);
			ui_.damageStatusSlider->setVisible(true);
			ui_.unmountCircuitButton->setEnabled(true);
			ui_.unmountCircuitButton->setText("Odmontovat");

			ui_.chargingValue->setText(QString::number(state.weapon_energy_circuit_charging) + " TW");
			ui_.actualChargingValue->setText(QString::number(state.weapon_energy_circuit_client_charging) + " TW");
		}
		else {
			ui_.maxValueFrame->setVisible(false);

			if (isSmall_) {				
				ui_.circuitTitleButton->setStyleSheet(unavailableSmallButtonStyle_);
			}
			else {
				ui_.circuitTitleButton->setStyleSheet(unavailableButtonStyle_);
			}

			ui_.damageStatusLabel->setVisible(false);
			ui_.damageStatusSlider->setVisible(false);
			ui_.unmountCircuitButton->setEnabled(false);
			ui_.unmountCircuitButton->setText(QString::fromUtf16(L"Není"));
		}

		/* Laser guns */

		int mountLaserIndex = 0;
		for (std::list<laser_gun_status>::const_iterator it = state.laser_guns.begin(); it != state.laser_guns.end(); ++it) {
			LaserWeaponWidget * weapon = dynamic_cast<LaserWeaponWidget *>(laserLayout_->getWeapon(mountLaserIndex));

			if (weapon == NULL) {
				KODIAK_DEBUG_COUT << "Laser layout widget contains non laser weapon in AllWeaponsWidget::setState";
				continue;
			}

			weapon->setState(*it);
			weapon->setAsMounted(true);				
			mountLaserIndex++;
		}

		for (int unmountLaserIndex = mountLaserIndex; unmountLaserIndex < WeaponLayout::MAX_WEAPON_COUNT; ++unmountLaserIndex) {
			LaserWeaponWidget * weapon = dynamic_cast<LaserWeaponWidget *>(laserLayout_->getWeapon(unmountLaserIndex));

			if (weapon == NULL) {
				KODIAK_DEBUG_COUT << "Laser layout widget contains non laser weapon in AllWeaponsWidget::setState";
				continue;
			}

			weapon->setAsMounted(false);				
		}

		laserLayout_->setDisplayedWeaponCount(mountLaserIndex);

		/* Drone missile launchers */

		int mountDroneIndex = 0;
		for (std::list<drone_missile_launcher_status>::const_iterator it = state.drone_missile_launchers.begin(); it != state.drone_missile_launchers.end(); ++it) {
			DroneWeaponWidget * weapon = dynamic_cast<DroneWeaponWidget *>(droneLayout_->getWeapon(mountDroneIndex));

			if (weapon == NULL) {
				KODIAK_DEBUG_COUT << "Drone layout widget contains non drone weapon in AllWeaponsWidget::setState";
				continue;
			}

			weapon->setState(*it, state.drone_missiles_actual_launch);
			weapon->setAsMounted(true);
			mountDroneIndex++;
		}		

		for (int unmountDroneIndex = mountDroneIndex; unmountDroneIndex < WeaponLayout::MAX_WEAPON_COUNT; ++unmountDroneIndex) {
			DroneWeaponWidget * weapon = dynamic_cast<DroneWeaponWidget *>(droneLayout_->getWeapon(unmountDroneIndex));

			if (weapon == NULL) {
				KODIAK_DEBUG_COUT << "Laser layout widget contains non laser weapon in AllWeaponsWidget::setState";
				continue;
			}

			weapon->setAsMounted(false);				
		}

		droneLayout_->setDisplayedWeaponCount(mountDroneIndex);

		isSynchronizing_ = false;
		lockForUpdate(false);
	}

	if (state.avalDroneMissiles) {
		ui_.precisionValue->setText(Settings::instance().formatNumber((state.drone_missiles_actual_precision)));
		ui_.damageValue->setText(Settings::instance().formatNumber((state.drone_missiles_actual_damage)));
		ui_.countValue->setText(Settings::instance().formatNumber((state.drone_missiles_count)));
		ui_.chargeToFireValue->setText(Settings::instance().formatNumber((state.drone_missiles_actual_launch)) + " TJ");
		ui_.rangeValue->setText(Settings::instance().formatNumber((state.drone_missiles_actual_range)));		
		ui_.dronesValueFrame->setVisible(true);

		if (state.drone_missiles_count > 0) {
			ui_.unmountDronesButton->setEnabled(true);
			ui_.unmountDronesButton->setText("Odmontovat");
		}
		else {
			ui_.unmountDronesButton->setVisible(false);
		}

		if (isSmall_) {
			ui_.dronesTitleButton->setStyleSheet(availableSmallButtonStyle_);
		}
		else {
			ui_.dronesTitleButton->setStyleSheet(availableButtonStyle_);
		}
	}
	else {
		ui_.dronesValueFrame->setVisible(false);
		ui_.unmountDronesButton->setVisible(false);

		if (isSmall_) {
			ui_.dronesTitleButton->setStyleSheet(unavailableSmallButtonStyle_);
		}
		else {
			ui_.dronesTitleButton->setStyleSheet(unavailableButtonStyle_);
		}
	}
}

WeaponsChangeDetails AllWeaponsWidget::getState() {
	WeaponsChangeDetails weaponsState;
		
	int displayedLaserWeaponCount = laserLayout_->getDisplayedWeaponCount();
		
	for (int i = 0; i != displayedLaserWeaponCount; ++i) {
		BasicWeaponWidget * widget = laserLayout_->getWeapon(i);

		if (widget == NULL) {
			continue;
		}

		weaponsState.laserGuns.push_back(widget->getState());
	}

	int displayedDroneWeaponCount = droneLayout_->getDisplayedWeaponCount();
		
	for (int i = 0; i != displayedDroneWeaponCount; ++i) {
		BasicWeaponWidget * widget = droneLayout_->getWeapon(i);
		
		if (widget == NULL) {
			continue;
		}

		weaponsState.droneGuns.push_back(widget->getState());
	}


	return weaponsState;
}

void AllWeaponsWidget::unmountDronesButtonClickedSlot() {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILES, state_.drone_missiles_working, state_.drone_missiles_damaged);
}

void AllWeaponsWidget::unmountCircuitButtonClickedSlot() {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_WEAPON_ENERGY_CIRCUIT);
}

void AllWeaponsWidget::unmountDroneWeaponSlot(id_t itemId) {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_DRONE_MISSILE_LAUNCHER, itemId);
}

void AllWeaponsWidget::unmountLaserWeaponSlot(id_t itemId) {
	emit unmountSignal(PROTOCOL_HANGARS_PATTERN_ID_LASER_GUN, itemId);
}

void AllWeaponsWidget::setAsBig() {
	isSmall_ = false; 

	resize(736, 646);

	ui_.weaponsSection->setVisible(true);

	ui_.mainFrame->setGeometry(0, 0, 736, 646);
	ui_.deviceFrame->setGeometry(0, 0, 736, 646);
	ui_.circuitMainFrame->setGeometry(5, 40, 107, 267);
	ui_.circuitDeviceFrame->setGeometry(1, 1, 105, 265);
	ui_.circuitTitleButton->setGeometry(5, 5, 95, 20);
	ui_.circuitTitleButton->setIconSize(QSize(16, 16));
	ui_.circuitTitleButton->setStyleSheet("QPushButton { background-color: rgb(48, 66, 35, 230); color: #ffffff; border: 0; font-size: 11px; }");
	ui_.damageStatusLabel->setGeometry(5, 30, 95, 25);
	ui_.damageStatusLabel->setStyleSheet("background-color: rgb(35, 35, 35, 140); color:  rgb(75, 120, 175); font-size: 11px;");
	ui_.damageStatusSlider->setGeometry(5, 60, 95, 30);
	ui_.damageStatusSlider->showMaximum(true);
	ui_.damageStatusSlider->setFontSize(8, QFont::Bold);
	ui_.maxValueFrame->setGeometry(3, 95, 98, 140);
	ui_.chargingSpeedLabel->setGeometry(0, 100, 98, 20);
	ui_.chargingSpeedLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.chargingValue->setGeometry(0, 120, 98, 20);
	ui_.droneGunsLabel->setVisible(true);
	ui_.droneGunsLabel->setGeometry(0, 50, 98, 30);
	ui_.droneGunsValue->setVisible(true);
	ui_.droneGunsValue->setGeometry(0, 80, 98, 20);
	ui_.laserGrunsValue->setVisible(true);
	ui_.laserGrunsValue->setGeometry(0, 30, 98, 20);
	ui_.laserGunsLabel->setVisible(true);
	ui_.laserGunsLabel->setGeometry(0, 0, 98, 30);
	ui_.unmountCircuitButton->setGeometry(3, 240, 98, 20);
	ui_.dronesMainFrame->setGeometry(5, 312, 107, 272);
	ui_.dronesDeviceFrame->setGeometry(1, 1, 105, 270);
	ui_.dronesTitleButton->setGeometry(5, 5, 95, 20);
	ui_.dronesTitleButton->setIconSize(QSize(16, 16));
	ui_.dronesTitleButton->setStyleSheet("QPushButton { background-color: rgb(48, 66, 35, 230); color: #ffffff; border: 0; font-size: 11px; }");
	ui_.dronesValueFrame->setGeometry(5, 35, 95, 210);
	ui_.chargeToFireLabel->setGeometry(0, 40, 95, 20);
	ui_.chargeToFireLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.chargeToFireValue->setGeometry(0, 70, 95, 20);
	ui_.chargeToFireValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.countLabel->setGeometry(0, 0, 95, 20);
	ui_.countLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.countValue->setGeometry(0, 20, 95, 20);
	ui_.countValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.damageLabel->setGeometry(0, 170, 95, 20);
	ui_.damageLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.damageValue->setGeometry(0, 190, 95, 20);
	ui_.damageValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.precisionLabel->setGeometry(0, 130, 95, 20);
	ui_.precisionLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.precisionValue->setGeometry(0, 150, 95, 20);
	ui_.precisionValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.rangeLabel->setGeometry(0, 90, 95, 20);
	ui_.rangeLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.rangeValue->setGeometry(0, 110, 95, 20);
	ui_.rangeValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 11px;");
	ui_.unmountDronesButton->setGeometry(5, 245, 95, 20);
	ui_.tabWidget->setGeometry(115, 40, 615, 604);
	ui_.droneGunsTab->setGeometry(0, 0, 613, 580);
	ui_.droneGunsFrame->setGeometry(4, 4, 604, 574);
	ui_.laserGunsTab->setGeometry(0, 0, 613, 580);
	ui_.laserGunsFrame->setGeometry(4, 4, 604, 574);
	ui_.weaponsSection->setVisible(true);
	ui_.weaponsSection->setGeometry(5, 5, 726, 30);

	droneLayout_->setAsBig();
	laserLayout_->setAsBig();
}

void AllWeaponsWidget::setAsSmall() {
	isSmall_ = true;

	resize(435, 384);
	ui_.mainFrame->setGeometry(0, 0, 435, 384);
	ui_.mainFrame->setStyleSheet(
		"#mainFrame {"
		"	background: url(:/pictures/images/backgrounds/otherviewPanel.png);"
		"	background-position: center center;"
		"	border: 0;"
		"}"
		);

	ui_.weaponsSection->setVisible(false);

	ui_.deviceFrame->setGeometry(0, 0, 435, 384);
	ui_.circuitMainFrame->setGeometry(0, 0, 78, 194);
	ui_.circuitDeviceFrame->setGeometry(1, 1, 76, 192);
	ui_.circuitTitleButton->setGeometry(3, 3, 70, 15);
	ui_.circuitTitleButton->setIconSize(QSize(12, 12));
	ui_.circuitTitleButton->setStyleSheet(availableSmallButtonStyle_);
	ui_.damageStatusLabel->setGeometry(3, 21, 70, 15);
	ui_.damageStatusLabel->setStyleSheet("background-color: rgb(35, 35, 35, 140); color:  rgb(75, 120, 175); font-size: 10px;");
	ui_.damageStatusSlider->setGeometry(3, 40, 70, 15);
	ui_.damageStatusSlider->showMaximum(false);
	ui_.damageStatusSlider->setFontSize(7, QFont::Normal);
	ui_.maxValueFrame->setGeometry(3, 58, 70, 130);
	ui_.chargingSpeedLabel->setGeometry(0, 0, 75, 15);
	ui_.chargingSpeedLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.chargingSpeedLabel->setText(QString::fromUtf16(L"nabíjení"));
	ui_.chargingValue->setGeometry(0, 15, 70, 15);
	ui_.chargingValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.droneGunsLabel->setVisible(true);
	ui_.droneGunsLabel->setGeometry(0, 75, 70, 30);
	ui_.droneGunsLabel->setText(QString::fromUtf16(L"maximum torpedometů"));
	ui_.droneGunsLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.droneGunsValue->setVisible(true);
	ui_.droneGunsValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.droneGunsValue->setGeometry(0, 110, 70, 15);
	ui_.laserGrunsValue->setVisible(true);
	ui_.laserGrunsValue->setGeometry(0, 60, 70, 15);
	ui_.laserGrunsValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.laserGunsLabel->setVisible(true);
	ui_.laserGunsLabel->setGeometry(0, 30, 70, 30);
	ui_.laserGunsLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.laserGunsLabel->setText(QString::fromUtf16(L"maximum laserových děl"));
	ui_.unmountCircuitButton->setVisible(false);
	ui_.dronesMainFrame->setGeometry(0, 197, 78, 176);
	ui_.dronesDeviceFrame->setGeometry(1, 1, 76, 174);
	ui_.dronesTitleButton->setGeometry(3, 3, 70, 15);
	ui_.dronesTitleButton->setIconSize(QSize(12, 12));
	ui_.dronesTitleButton->setText(QString::fromUtf16(L"Drony"));
	ui_.dronesTitleButton->setStyleSheet(availableSmallButtonStyle_);
	ui_.dronesValueFrame->setGeometry(3, 21, 75, 150);
	ui_.chargeToFireLabel->setGeometry(0, 0, 70, 15);
	ui_.chargeToFireLabel->setText(QString::fromUtf16(L"energie"));
	ui_.chargeToFireLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.chargeToFireValue->setGeometry(0, 15, 70, 15);
	ui_.chargeToFireValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.countLabel->setGeometry(0, 30, 70, 15);
	ui_.countLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.countLabel->setText(QString::fromUtf16(L"počet"));
	ui_.countValue->setGeometry(0, 45, 70, 15);
	ui_.countValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.damageLabel->setGeometry(0, 120, 70, 15);
	ui_.damageLabel->setText(QString::fromUtf16(L"škody"));
	ui_.damageLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.damageValue->setGeometry(0, 135, 70, 15);
	ui_.damageValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.precisionLabel->setGeometry(0, 90, 70, 15);
	ui_.precisionLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.precisionLabel->setText(QString::fromUtf16(L"přesnost"));
	ui_.precisionValue->setGeometry(0, 105, 70, 15);	
	ui_.precisionValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.rangeLabel->setGeometry(0, 60, 70, 15);
	ui_.rangeLabel->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.rangeLabel->setText(QString::fromUtf16(L"dosah"));
	ui_.rangeValue->setGeometry(0, 75, 70, 15);
	ui_.rangeValue->setStyleSheet("background-color: transparent; color: #ffffff; border: 0; font-size: 10px;");
	ui_.unmountDronesButton->setVisible(false);
	ui_.tabWidget->setGeometry(82, 0, 354, 384);
	ui_.droneGunsTab->setGeometry(0, 0, 350, 360);
	ui_.droneGunsFrame->setGeometry(2, 2, 350, 358);
	ui_.laserGunsTab->setGeometry(0, 0, 350, 360);
	ui_.laserGunsFrame->setGeometry(2, 2, 350, 358);

	droneLayout_->setAsSmall();
	laserLayout_->setAsSmall();
}

void AllWeaponsWidget::notifyUpdate() {
	if (isLockedForUpdate_) {
		return;
	}	

	double difference = getDifferenceFromUpdateTime();

	int displayedLaserWeaponCount = laserLayout_->getDisplayedWeaponCount();
		
	for (int i = 0; i != displayedLaserWeaponCount; ++i) {
		BasicWeaponWidget * widget = laserLayout_->getWeapon(i);
		
		if (widget == NULL) {
			continue;
		}

		widget->notifyUpdate(difference);
	}

	int displayedDroneWeaponCount = droneLayout_->getDisplayedWeaponCount();
		
	for (int i = 0; i != displayedDroneWeaponCount; ++i) {
		BasicWeaponWidget * widget = droneLayout_->getWeapon(i);
		
		if (widget == NULL) {
			continue;
		}

		widget->notifyUpdate(difference);
	}
}