]> ruin.nu Git - hbs.git/commitdiff
Added the possibility to add new battles.
authorMichael Andreen <harv@ruin.nu>
Thu, 7 Mar 2002 23:40:58 +0000 (23:40 +0000)
committerMichael Andreen <harv@ruin.nu>
Thu, 7 Mar 2002 23:40:58 +0000 (23:40 +0000)
bs/bs.cpp
bs/bs.h
bs/bsdoc.cpp
bs/bsdoc.h
bs/bsview.cpp
bs/bsview.h
bs/fleet.cpp
bs/fleet.h
bs/ui/bsappbase.ui
bs/ui/bsappbase.ui.h

index eeea37a1926ed07fe5497580b75af79cdd4bf513..1998441d7e84e89525923d93ae24adee1b8abbec 100644 (file)
--- a/bs/bs.cpp
+++ b/bs/bs.cpp
@@ -1,9 +1,9 @@
 #include "bs.h"
 
 //Own includes
 #include "bs.h"
 
 //Own includes
-#include "bsview.h"
-#include "bsdoc.h"
 
 
+#include "bsdoc.h"
+#include "bsview.h"
 /* 
  *  Constructs a BSApp which is a child of 'parent', with the 
  *  name 'name' and widget flags set to 'f' 
 /* 
  *  Constructs a BSApp which is a child of 'parent', with the 
  *  name 'name' and widget flags set to 'f' 
 BSApp::BSApp( QWidget* parent,  const char* name, WFlags fl )
     : BSAppBase( parent, name, fl )
 {
 BSApp::BSApp( QWidget* parent,  const char* name, WFlags fl )
     : BSAppBase( parent, name, fl )
 {
-       doc = new BSDoc();
+/*     doc = new BSDoc();
        view = new BSView(this,doc);
        setCentralWidget(view);
        view = new BSView(this,doc);
        setCentralWidget(view);
+       */
 }
 
 /*  
 }
 
 /*  
diff --git a/bs/bs.h b/bs/bs.h
index 3ccaa42a8e702d74263d650a1f5820b23d8c7a08..e25c3388d73e3ecac6a25411a46a4611d107a7c8 100644 (file)
--- a/bs/bs.h
+++ b/bs/bs.h
@@ -3,8 +3,8 @@
 #include "ui/bsappbase.h"
 
 //My own forwards
 #include "ui/bsappbase.h"
 
 //My own forwards
-class BSView;
-class BSDoc;
+//class BSView;
+//class BSDoc;
 
 class BSApp : public BSAppBase
 { 
 
 class BSApp : public BSAppBase
 { 
@@ -32,8 +32,8 @@ public slots:
     void helpAbout();
 
 protected:
     void helpAbout();
 
 protected:
-       BSView* view;
-       BSDoc*  doc;
+//     BSView* view;
+//     BSDoc*  doc;
 
 };
 
 
 };
 
index 3d32cad004dd1aa92a123bdbc730ab7755d4115d..e3e046986418caaad4d4147646c393fbe2fb293b 100644 (file)
@@ -50,3 +50,24 @@ bool BSDoc::isModified() const
 {
   return modified;
 }
 {
   return modified;
 }
+
+///////////////////////////////////////////////////////////////////////////
+//
+
+int BSDoc::newBattle(QString name)
+{
+       m_Battles[name]["Friendly"]["Home Planet"];
+       m_Battles[name]["Hostile"];
+
+       emit documentChanged();
+       return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////
+//
+
+std::map<QString, std::map<QString, std::map<QString, Fleet> > >& BSDoc::Battles()
+{
+       return m_Battles;
+}
+
index 0c02c6fa3fe0a19773ba8acb44356d4f03c27f22..eac45f40432b1a62ee0865ba64d3a8961d07f9a0 100644 (file)
 // include files for QT
 #include <qobject.h>
 
 // include files for QT
 #include <qobject.h>
 
+// standard library
+#include <map>
+
 // application specific includes
 // application specific includes
+#include "fleet.h"
 
 
-/**
-  * the Document Class
+//! The document class
+/** This class is holding all the data, handles the transportation of the
+  * data to a couple of different mediums and informs users of the data
+  * if it's changed (through the documentChnaged() signal)
+  * \bug it's too open.. 
+  * \todo make this class more closed.
+  * \author Michael Andreen
   */
 
 class BSDoc : public QObject
   */
 
 class BSDoc : public QObject
@@ -39,11 +48,25 @@ class BSDoc : public QObject
     bool load(const QString &filename);
     bool isModified() const;
 
     bool load(const QString &filename);
     bool isModified() const;
 
+       /**Adds a new battle to the dokument and emits documentChanged.
+        * \todo add some checks to see if the battle exist and so and return the status.
+        * \return returns 0 if everything is ok.
+        */
+       int newBattle(QString name);
+
+       /**This returns the the data structure, so other can work on it, but not supposed
+        * change it.
+        * \todo remove this, and replace it with a better more closed interface.
+        */
+       std::map<QString, std::map<QString, std::map<QString, Fleet> > >& Battles();
+
   signals:
     void documentChanged();
 
   protected:
     bool modified;
   signals:
     void documentChanged();
 
   protected:
     bool modified;
+
+       std::map<QString, std::map<QString, std::map<QString, Fleet> > > m_Battles;
 };
 
 #endif
 };
 
 #endif
index 5da0e0654c36b0b323b6a9aa23678453da303336..9af428df1fed72e90c88ebc4599c2e6521c7de81 100644 (file)
 
 #include "bsview.h"
 
 
 #include "bsview.h"
 
-#include "battlesum.h"
-#include "scanview.h"
-#include "ui/infoview.h"
-#include "tickview.h"
-#include "ui/fleetviewbase.h"
+//standard library
+#include <iostream>
+#include <map>
+#include <vector>
+#include <string>
+
+using namespace std;
 
 //QT includes
 #include <qlistview.h>
 #include <qwidgetstack.h>
 
 
 //QT includes
 #include <qlistview.h>
 #include <qwidgetstack.h>
 
-#include <iostream>
-using namespace std;
+#include "battlesum.h"
+#include "scanview.h"
+#include "ui/infoview.h"
+#include "tickview.h"
+#include "ui/fleetviewbase.h"
+#include "fleet.h"
 
 BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent)
 {
   /** connect doc with the view*/
   connect(doc, SIGNAL(documentChanged()), this, SLOT(slotDocumentChanged()));
        
 
 BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent)
 {
   /** connect doc with the view*/
   connect(doc, SIGNAL(documentChanged()), this, SLOT(slotDocumentChanged()));
        
+       m_doc = doc;
        
        m_LeftSplit = new QSplitter(QSplitter::Vertical, this);
        m_RightSplit = new QSplitter(QSplitter::Vertical, this);
        
        m_LeftSplit = new QSplitter(QSplitter::Vertical, this);
        m_RightSplit = new QSplitter(QSplitter::Vertical, this);
@@ -67,6 +74,8 @@ BSView::~BSView()
 {
 }
 
 {
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
 void BSView::addBattle(QString name)
 {
        QListViewItem* battle = new QListViewItem(m_NumberView, name);
 void BSView::addBattle(QString name)
 {
        QListViewItem* battle = new QListViewItem(m_NumberView, name);
@@ -75,12 +84,37 @@ void BSView::addBattle(QString name)
        (void) new QListViewItem(def, tr("Home Planet"), "","","1");
 }
 
        (void) new QListViewItem(def, tr("Home Planet"), "","","1");
 }
 
+///////////////////////////////////////////////////////////////////////////////
+//
+/***This function clears the listview and then iterates through the battles
+ * and recreates the listview hierarchy.
+ */
 void BSView::slotDocumentChanged()
 {
 void BSView::slotDocumentChanged()
 {
-  //TODO update the view
+       m_NumberView->clear();
+       
+       map<QString, map<QString, map<QString, Fleet> > >& battles = m_doc->Battles();  
+
+       for (map<QString, map<QString, map<QString, Fleet> > >::iterator i = battles.begin(); i != battles.end(); i++)
+       {
+               QString b = (*i).first;
+               QListViewItem* battle = new QListViewItem(m_NumberView, b);
 
 
+               for (map<QString, map<QString, Fleet> >::iterator j = battles[b].begin(); j != battles[b].end(); j++)
+               {
+                       QString g = (*j).first;
+                       QListViewItem* group = new QListViewItem(battle, g);
+
+                       for (map<QString, Fleet>::iterator k = battles[b][g].begin(); k != battles[b][g].end(); k++)
+                       {                               
+                               (void) new QListViewItem(group, (*k).first);
+                       }
+               }
+       }
 }
 }
-/** No descriptions */
+
+//////////////////////////////////////////////////////////////////////////////
+//
 void BSView::slotFleetSelection(QListViewItem *lvi)
 {
        //cout << lvi->parent()->text(2).toLocal8bit() << endl;
 void BSView::slotFleetSelection(QListViewItem *lvi)
 {
        //cout << lvi->parent()->text(2).toLocal8bit() << endl;
@@ -95,7 +129,7 @@ void BSView::slotFleetSelection(QListViewItem *lvi)
        else if (lvi->parent()->parent() == '\0')
        {
                        m_FleetView->slotHomePlanet(false);
        else if (lvi->parent()->parent() == '\0')
        {
                        m_FleetView->slotHomePlanet(false);
-               if (lvi->text(3) == "1")
+               if (lvi->text(0) == tr("Friendly"))
                {
                        m_FleetView->slotAttacker(false);
                }
                {
                        m_FleetView->slotAttacker(false);
                }
@@ -108,11 +142,11 @@ void BSView::slotFleetSelection(QListViewItem *lvi)
        }
        else
        {
        }
        else
        {
-               if (lvi->parent()->text(3) == "1")
+               if (lvi->parent()->text(0) == tr("Friendly"))
                {
                        m_FleetView->slotAttacker(false);
                        m_FleetView->slotHomePlanet(false);
                {
                        m_FleetView->slotAttacker(false);
                        m_FleetView->slotHomePlanet(false);
-                       if (lvi->text(3) == "1")
+                       if (lvi->text(0) == tr("Home Planet"))
                        {
                                m_FleetView->slotHomePlanet(true);
                        }
                        {
                                m_FleetView->slotHomePlanet(true);
                        }
index da4f562ed2a301affd152dac8d1cc61bb75a253f..86f277ede218543f1f20c33c5d074bd1a6ab4f9a 100644 (file)
@@ -62,6 +62,7 @@ class BSView : public QSplitter
        TickView                *m_TickView;
        QWidgetStack    *m_FleetViews;
        FleetViewBase   *m_FleetView;
        TickView                *m_TickView;
        QWidgetStack    *m_FleetViews;
        FleetViewBase   *m_FleetView;
+       BSDoc                   *m_doc;
   
 public slots: // Public slots
   /** No descriptions */
   
 public slots: // Public slots
   /** No descriptions */
index b562b8150186def125235ef19275ef646f15a86e..4989573d87f069b3e3bd6e27c4b009e9a0e7268c 100644 (file)
@@ -67,4 +67,20 @@ string Fleet::Race()
        return m_sRace;
 }
 
        return m_sRace;
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+/** This function iterates through m_Fleet and adds all numbers together to
+ * produce a total.
+ */
+int Fleet::NumberOfShips()
+{
+       int total = 0;
+
+       for (map<string, vector<int> >::iterator i = m_Fleet.begin(); i != m_Fleet.end(); i++)
+       {
+               total += m_Fleet[(*i).first][0];
+       }
+
+       return total;
+}
 
 
index 88c78842b92c90452a026d556d25c4f96a56b4c9..0d81fd2b5de4637c15d5970385ee77d29a10f495 100644 (file)
@@ -60,6 +60,10 @@ public:
         */
        std::string Race();
 
         */
        std::string Race();
 
+       /**Returns the total number of ships in this fleet
+        */
+       int NumberOfShips();
+
 
 protected:
        std::string     m_sName;
 
 protected:
        std::string     m_sName;
index f2714b5aa841fbb08669b31807f664ad02d05485..fa0d859239421cae44553de64c051fa872ab6ee5 100644 (file)
@@ -25,7 +25,7 @@
             <x>0</x>
             <y>0</y>
             <width>726</width>
             <x>0</x>
             <y>0</y>
             <width>726</width>
-            <height>30</height>
+            <height>29</height>
         </rect>
     </property>
     <item text="&amp;File" name="fileMenu">
         </rect>
     </property>
     <item text="&amp;File" name="fileMenu">
@@ -33,7 +33,6 @@
         <action name="fileOpenAction"/>
         <action name="fileSaveAction"/>
         <action name="fileSaveAsAction"/>
         <action name="fileOpenAction"/>
         <action name="fileSaveAction"/>
         <action name="fileSaveAsAction"/>
-        <action name="KulSak"/>
         <separator/>
         <action name="filePrintAction"/>
         <separator/>
         <separator/>
         <action name="filePrintAction"/>
         <separator/>
@@ -55,6 +54,9 @@
         <separator/>
         <action name="helpAboutAction"/>
     </item>
         <separator/>
         <action name="helpAboutAction"/>
     </item>
+    <item text="Battle" name="PopupMenu">
+        <action name="battleNewAction"/>
+    </item>
 </menubar>
 <toolbars>
     <toolbar dock="2">
 </menubar>
 <toolbars>
     <toolbar dock="2">
@@ -84,7 +86,7 @@
             <string>&amp;New</string>
         </property>
         <property name="accel">
             <string>&amp;New</string>
         </property>
         <property name="accel">
-            <number>4194382</number>
+            <number>0</number>
         </property>
     </action>
     <action>
         </property>
     </action>
     <action>
     </action>
     <action>
         <property name="name">
     </action>
     <action>
         <property name="name">
-            <cstring>KulSak</cstring>
+            <cstring>battleNewAction</cstring>
         </property>
         <property name="text">
         </property>
         <property name="text">
-            <string>Kul sak</string>
+            <string>New</string>
         </property>
         <property name="accel">
         </property>
         <property name="accel">
-            <number>0</number>
+            <number>4194382</number>
         </property>
     </action>
 </actions>
         </property>
     </action>
 </actions>
         <receiver>BSAppBase</receiver>
         <slot>editCut()</slot>
     </connection>
         <receiver>BSAppBase</receiver>
         <slot>editCut()</slot>
     </connection>
-    <connection>
-        <sender>editCopyAction</sender>
-        <signal>activated()</signal>
-        <receiver>BSAppBase</receiver>
-        <slot>editCopy()</slot>
-    </connection>
     <connection>
         <sender>editPasteAction</sender>
         <signal>activated()</signal>
     <connection>
         <sender>editPasteAction</sender>
         <signal>activated()</signal>
         <receiver>BSAppBase</receiver>
         <slot>helpAbout()</slot>
     </connection>
         <receiver>BSAppBase</receiver>
         <slot>helpAbout()</slot>
     </connection>
+    <connection>
+        <sender>battleNewAction</sender>
+        <signal>activated()</signal>
+        <receiver>BSAppBase</receiver>
+        <slot>battleNew()</slot>
+    </connection>
 </connections>
 <includes>
 </connections>
 <includes>
+    <include location="local" impldecl="in implementation">../bsdoc.h</include>
+    <include location="local" impldecl="in implementation">../bsview.h</include>
+    <include location="global" impldecl="in implementation">qinputdialog.h</include>
     <include location="local" impldecl="in implementation">bsappbase.ui.h</include>
 </includes>
     <include location="local" impldecl="in implementation">bsappbase.ui.h</include>
 </includes>
+<forwards>
+    <forward>class BSDoc</forward>
+    <forward>class BSView</forward>
+</forwards>
+<variables>
+    <variable>BSDoc* doc</variable>
+    <variable>BSView* view</variable>
+</variables>
 <slots>
     <slot>fileNew()</slot>
     <slot>fileOpen()</slot>
 <slots>
     <slot>fileNew()</slot>
     <slot>fileOpen()</slot>
     <slot>editUndo()</slot>
     <slot>editRedo()</slot>
     <slot>editCut()</slot>
     <slot>editUndo()</slot>
     <slot>editRedo()</slot>
     <slot>editCut()</slot>
-    <slot>editCopy()</slot>
+    <slot>init()</slot>
     <slot>editPaste()</slot>
     <slot>editFind()</slot>
     <slot>helpIndex()</slot>
     <slot>helpContents()</slot>
     <slot>helpAbout()</slot>
     <slot>editPaste()</slot>
     <slot>editFind()</slot>
     <slot>helpIndex()</slot>
     <slot>helpContents()</slot>
     <slot>helpAbout()</slot>
+    <slot>battleNew()</slot>
 </slots>
 <layoutdefaults spacing="6" margin="11"/>
 </UI>
 </slots>
 <layoutdefaults spacing="6" margin="11"/>
 </UI>
index 4d70a19dde91d1c83cf471d0f84e9f694de94417..e7257447f284070aea24529ba78c00b8e8f2ed8f 100644 (file)
@@ -6,6 +6,7 @@
 ** a constructor, and a destroy() slot in place of a destructor.
 *****************************************************************************/
 
 ** a constructor, and a destroy() slot in place of a destructor.
 *****************************************************************************/
 
+           
 
 void BSAppBase::fileNew()
 {
 
 void BSAppBase::fileNew()
 {
@@ -52,9 +53,11 @@ void BSAppBase::editCut()
 
 }
 
 
 }
 
-void BSAppBase::editCopy()
+void BSAppBase::init()
 {
 {
-
+    doc = new BSDoc();
+    view = new BSView(this,doc);
+    setCentralWidget(view);
 }
 
 void BSAppBase::editPaste()
 }
 
 void BSAppBase::editPaste()
@@ -80,4 +83,19 @@ void BSAppBase::helpContents()
 void BSAppBase::helpAbout()
 {
 
 void BSAppBase::helpAbout()
 {
 
+}
+
+void BSAppBase::battleNew()
+{
+    bool ok = FALSE;
+  QString text = QInputDialog::getText(
+            tr( "Harvalen's Battlesystem" ),
+            tr( "Please enter the name of the battle (for example coords)" ),
+            QLineEdit::Normal, QString::null, &ok, this );
+  if ( ok && !text.isEmpty() )
+      doc->newBattle(text);
+  else
+       {
+      // user entered nothing or pressed Cancel
+       }
 }
\ No newline at end of file
 }
\ No newline at end of file