From c2dd8856c3d97667953a0b73403b5e5cade5ce9b Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sun, 7 Apr 2002 23:02:48 +0000 Subject: [PATCH] adding, removing and chaning fleets now works. Started the the actual simulation work now. --- bs/bsdoc.cpp | 16 ++++++++++ bs/bsdoc.h | 3 ++ bs/bsview.cpp | 74 ++++++++++++++++++++++++++++++++++++++------ bs/bsview.h | 2 ++ bs/planet.cpp | 5 +++ bs/planet.h | 2 ++ bs/ui/bsappbase.ui | 28 ++++++++++++++--- bs/ui/bsappbase.ui.h | 8 +++++ bs/ui/infoview.ui | 24 ++++++++++++-- 9 files changed, 146 insertions(+), 16 deletions(-) diff --git a/bs/bsdoc.cpp b/bs/bsdoc.cpp index 70cfd89..d7e04ce 100644 --- a/bs/bsdoc.cpp +++ b/bs/bsdoc.cpp @@ -133,3 +133,19 @@ void BSDoc::newFleet(QString battle, QString group, QString fleet, Fleet* fl) emit documentChanged(); } +////////////////////////////////////////////////////////////////////////// +// +void BSDoc::removeFleet(QString battle, QString group, QString fleet) +{ + delete m_Battles[battle][group][fleet]; + m_Battles[battle][group].erase(fleet); + emit documentChanged(); +} + +////////////////////////////////////////////////////////////////////////// +// +void BSDoc::runBattleSimulation() +{ + + emit documentChanged(); +} diff --git a/bs/bsdoc.h b/bs/bsdoc.h index 6d6375a..bcfcfd0 100644 --- a/bs/bsdoc.h +++ b/bs/bsdoc.h @@ -73,6 +73,9 @@ class BSDoc : public QObject void newFleet(QString battle, QString group, QString fleet, Fleet* fl); + void removeFleet(QString battle, QString group, QString fleet); + + void runBattleSimulation(); signals: void documentChanged(); diff --git a/bs/bsview.cpp b/bs/bsview.cpp index f5e74bc..c050952 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -35,10 +35,13 @@ using namespace std; #include "tickview.h" #include "fleetview.h" #include "fleet.h" +#include "planet.h" BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent) { /** connect doc with the view*/ + + m_bMoreDocChanges = false; connect(doc, SIGNAL(documentChanged()), this, SLOT(slotDocumentChanged())); m_doc = doc; @@ -120,6 +123,9 @@ void BSView::addBattle(QString name) */ void BSView::slotDocumentChanged() { + if (m_bMoreDocChanges) + return; + m_NumberView->clear(); const BattleList& battles = m_doc->battles(); @@ -235,6 +241,38 @@ void BSView::slotFleetChanged(const Fleet* fleet) // void BSView::slotInfoApply() { + QString battle = m_InfoView->battle(); + QString group = m_InfoView->group(); + QString fleet = m_InfoView->fleetName(); + + + + const Fleet* old = m_doc->specificFleet(m_sBattle, m_sGroup, m_sFleet); + + const Planet* oldpl = dynamic_cast(old); + + Fleet* fl; + if(oldpl) + fl = new Planet(*oldpl); + else + fl = new Fleet(*old); + + + + m_bMoreDocChanges = true; + m_doc->removeFleet(m_sBattle, m_sGroup, m_sFleet); + m_bMoreDocChanges = false; + + m_sBattle = battle; + m_sGroup = group; + m_sFleet = fleet; + + + fl->setETA(m_InfoView->eta()); + fl->setName(m_sFleet.latin1()); + fl->setRace(m_InfoView->race().latin1()); + + m_doc->newFleet(m_sBattle, m_sGroup, m_sFleet, fl); } ////////////////////////////////////////////////////////////////////////// @@ -248,11 +286,26 @@ void BSView::slotInfoCancel() // void BSView::slotInfoNew() { + + QString battle = m_InfoView->battle(); + QString group = m_InfoView->group(); + QString fleet = m_InfoView->fleetName(); + + const Fleet* fl1 = m_doc->specificFleet(battle, group, fleet); + if (fl1) + { + //fleet does already exist, do not overwrite. + //Need something else here.... + return; + } + + + Fleet* fl = new Fleet(); - m_sBattle = m_InfoView->battle(); - m_sGroup = m_InfoView->group(); - m_sFleet = m_InfoView->fleetName(); + m_sBattle = battle; + m_sGroup = group; + m_sFleet = fleet; fl->setETA(m_InfoView->eta()); fl->setName(m_sFleet.latin1()); @@ -266,6 +319,8 @@ void BSView::slotInfoNew() // void BSView::slotInfoRemove() { + m_doc->removeFleet(m_sBattle, m_sGroup, m_sFleet); + m_sFleet = ""; } ////////////////////////////////////////////////////////////////////////// @@ -276,26 +331,27 @@ void BSView::updateInfoView() if(!fl) { - m_InfoView->setRace(""); m_InfoView->setFleetName(""); m_InfoView->setEta(0); - m_InfoView->setGroup(""); - m_InfoView->setBattle(""); m_InfoView->enableNameChange(true); m_InfoView->enableRemove(false); return; } + m_InfoView->setGroup(m_sGroup); + m_InfoView->setBattle(m_sBattle); - if(m_sFleet == tr("Home Planet")) +/* NO LONGER NEEDED SINCE IT'S INTEGRATED IN THE InfoView CLASS + * if(m_sFleet == tr("Home Planet") && m_sGroup == tr("Friendly")) { - m_InfoView->enableNameChange(false); - m_InfoView->enableRemove(false); + //m_InfoView->enableNameChange(false); + //m_InfoView->enableRemove(false); } else { m_InfoView->enableNameChange(true); m_InfoView->enableRemove(true); } +*/ m_InfoView->setRace(fl->race().c_str()); m_InfoView->setFleetName(m_sFleet); diff --git a/bs/bsview.h b/bs/bsview.h index 8707e0b..16acc2b 100644 --- a/bs/bsview.h +++ b/bs/bsview.h @@ -82,6 +82,8 @@ class BSView : public QSplitter QString m_sBattle; QString m_sGroup; QString m_sFleet; + + bool m_bMoreDocChanges; public slots: // Public slots /** No descriptions */ diff --git a/bs/planet.cpp b/bs/planet.cpp index c72fb4e..81d7daa 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -78,4 +78,9 @@ void Planet::setRoids(std::string type, int number) m_Roids[type][0] = number; } +////////////////////////////////////////////////////////////////////////// +// +void runBattle(std::vector friendly, std::vector hostile) +{ +} diff --git a/bs/planet.h b/bs/planet.h index 1fd9109..e59007c 100644 --- a/bs/planet.h +++ b/bs/planet.h @@ -42,6 +42,8 @@ public: int roids(std::string type, int tick = 0) const; void setRoids(std::string type, int number); + void runBattle(std::vector friendly, std::vector hostile); + protected: unsigned m_iScore; RoidList m_Roids; diff --git a/bs/ui/bsappbase.ui b/bs/ui/bsappbase.ui index e6baafa..ed97f11 100644 --- a/bs/ui/bsappbase.ui +++ b/bs/ui/bsappbase.ui @@ -25,7 +25,7 @@ 0 0 726 - 29 + 26 @@ -50,6 +50,7 @@ + @@ -329,6 +330,17 @@ 4194382 + + + battleSimulateAction + + + Run Simulate Battle + + + 4194386 + + @@ -453,12 +465,19 @@ BSAppBase battleNew() + + battleSimulateAction + activated() + BSAppBase + battleSimulate() + - ../bsconf.h - qinputdialog.h - ../bsview.h + qapplication.h ../bsdoc.h + ../bsview.h + qinputdialog.h + ../bsconf.h bsappbase.ui.h @@ -488,6 +507,7 @@ helpContents() helpAbout() battleNew() + battleSimulate() diff --git a/bs/ui/bsappbase.ui.h b/bs/ui/bsappbase.ui.h index 0787e81..da293f2 100644 --- a/bs/ui/bsappbase.ui.h +++ b/bs/ui/bsappbase.ui.h @@ -99,4 +99,12 @@ void BSAppBase::battleNew() { // user entered nothing or pressed Cancel } +} + +void BSAppBase::battleSimulate() +{ + QApplication::setOverrideCursor( Qt::WaitCursor ); + + //doc->runBattleSimulation(); + QApplication::restoreOverrideCursor(); } \ No newline at end of file diff --git a/bs/ui/infoview.ui b/bs/ui/infoview.ui index 411daeb..33135f7 100644 --- a/bs/ui/infoview.ui +++ b/bs/ui/infoview.ui @@ -77,11 +77,17 @@ GroupCombo + + NoInsertion + BattleCombo + + NoInsertion + @@ -104,7 +110,7 @@ NameLabel - &Name + Na&me NameLine @@ -120,7 +126,7 @@ EtaLabel - &Eta + E&ta EtaSpin @@ -214,7 +220,7 @@ false - &Remove + Remo&ve @@ -263,6 +269,12 @@ InfoView ApplyButton_clicked() + + NameLine + textChanged(const QString&) + InfoView + slotNameChanged(const QString&) + NameLine @@ -277,6 +289,11 @@ vector infoview.ui.h + + QString m_Name; + QString m_Battle; + QString m_Group; + remove() cancel() @@ -305,6 +322,7 @@ fleetName() group() race() + slotNameChanged( const QString & s ) -- 2.39.2