[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/games/granatier/src
From:       Mathias Kraus <k.hias () gmx ! de>
Date:       2009-10-04 12:10:20
Message-ID: 1254658220.062109.13651.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1031216 by mkraus:

show the name of the arena

 M  +10 -0     arena.cpp  
 M  +17 -1     arena.h  
 M  +5 -2      game.cpp  
 M  +36 -18    gamescene.cpp  
 M  +5 -2      gamescene.h  


--- trunk/playground/games/granatier/src/arena.cpp #1031215:1031216
@@ -48,6 +48,16 @@
     }
 }
 
+QString Arena::getName () const
+{
+    return m_strArenaName;
+}
+    
+void Arena::setName (const QString p_strArenaName)
+{
+    m_strArenaName = p_strArenaName;
+}
+
 void Arena::setCellType(const int p_row, const int p_column, const Cell::Type \
p_type)  {
     if (p_row < 0 || p_row >= m_nbRows || p_column < 0 || p_column >= m_nbColumns)
--- trunk/playground/games/granatier/src/arena.h #1031215:1031216
@@ -29,6 +29,7 @@
 
 class QPoint;
 class QPointF;
+class QString;
 
 /**
  * @brief This class represents the Arena of the game.
@@ -39,6 +40,9 @@
 
 private:
     /** The number of rows of the Arena */
+    QString m_strArenaName;
+    
+    /** The number of rows of the Arena */
     int m_nbRows;
     
     /** The number of columns of the Arena */
@@ -68,8 +72,20 @@
       * @param p_nbColumns the number of columns
       */
     void init(const int p_nbRows, const int p_nbColumns);
-
+    
     /**
+      * Returns the Arean name.
+      * @return the Arena name
+      */
+    QString getName () const;
+    
+    /**
+      * Sets the Arena name
+      * @param p_strArenaName the Arena name
+      */
+    void setName (const QString p_strArenaName);
+    
+    /**
       * Sets the CellType of the Cell whose coordinates are given in parameters.
       * @param p_row the Cell row
       * @param p_column the Cell column
--- trunk/playground/games/granatier/src/game.cpp #1031215:1031216
@@ -137,8 +137,8 @@
     QString filePath = KStandardDirs::locate("appdata", Settings::self()->arena());
     KConfig arenaConfig(filePath, KConfig::SimpleConfig);
     KConfigGroup group = arenaConfig.group("Arena");
-    QString arenaName = group.readEntry("FileName");
-    QFile arenaXmlFile(KStandardDirs::locate("appdata", \
QString("arenas/%1").arg(arenaName))); +    QString arenaFileName = \
group.readEntry("FileName"); +    QFile arenaXmlFile(KStandardDirs::locate("appdata", \
                QString("arenas/%1").arg(arenaFileName)));
     //QFile arenaXmlFile(KStandardDirs::locate("appdata", "arenas/granatier.xml"));
     QXmlInputSource source(&arenaXmlFile);
     // Create the XML file reader
@@ -147,6 +147,9 @@
     // Parse the XML file
     reader.parse(source);
     
+    QString arenaName = group.readEntry("Name");
+    m_arena->setName(arenaName);
+    
     //create the block items
     for (int i = 0; i < m_arena->getNbRows(); ++i)
     {
--- trunk/playground/games/granatier/src/gamescene.cpp #1031215:1031216
@@ -126,20 +126,25 @@
     }
 
     // The remaining time
-    m_remainingTime = new QGraphicsTextItem(i18n("0:00"));
-    m_remainingTime->setFont(QFont("Helvetica", 15, QFont::Bold, false));
-    m_remainingTime->setDefaultTextColor(QColor("#FFFF00"));
-    m_remainingTime->setZValue(0);
+    m_remainingTimeLabel = new QGraphicsTextItem(i18n("0:00"));
+    m_remainingTimeLabel->setFont(QFont("Helvetica", 15, QFont::Bold, false));
+    m_remainingTimeLabel->setDefaultTextColor(QColor("#FFFF00"));
+    m_remainingTimeLabel->setZValue(0);
     
+    m_arenaNameLabel = new QGraphicsTextItem(i18n("Arena Name"));
+    m_arenaNameLabel->setFont(QFont("Helvetica", 15, QFont::Bold, false));
+    m_arenaNameLabel->setDefaultTextColor(QColor("#FFFF00"));
+    m_arenaNameLabel->setZValue(0);
+    
     // Display each PlayerItem
     for (int i = 0; i < m_playerItems.size(); i++)
     {
         addItem(m_playerItems[i]);
     }
     
-    setSceneRect(0, -m_remainingTime->boundingRect().height(),
+    setSceneRect(0, -m_remainingTimeLabel->boundingRect().height(),
                  m_game->getArena()->getNbColumns()*Cell::SIZE,
-                 m_game->getArena()->getNbRows()*Cell::SIZE + \
m_remainingTime->boundingRect().height()); +                 \
m_game->getArena()->getNbRows()*Cell::SIZE + \
m_remainingTimeLabel->boundingRect().height());  
     // create the info overlay
     m_infoOverlay = new InfoOverlay(m_game, m_rendererScoreItems, this);
@@ -289,15 +294,22 @@
         }
     }
     
-    if (!items().contains(m_remainingTime))
+    if (!items().contains(m_remainingTimeLabel))
     {
-        addItem(m_remainingTime);
+        addItem(m_remainingTimeLabel);
     }
-    m_remainingTime->setDefaultTextColor(QColor("#FFFF00"));
+    m_remainingTimeLabel->setDefaultTextColor(QColor("#FFFF00"));
     int nTime = m_game->getRemainingTime();
-    m_remainingTime->setPlainText(QString("%1:%2").arg(nTime/60).arg(nTime%60, 2, \
                10, QChar('0')));
-    m_remainingTime->setPos((width() - m_remainingTime->boundingRect().width()), - \
m_remainingTime->boundingRect().height()); +    \
m_remainingTimeLabel->setPlainText(QString("%1:%2").arg(nTime/60).arg(nTime%60, 2, \
10, QChar('0'))); +    m_remainingTimeLabel->setPos((width() - \
m_remainingTimeLabel->boundingRect().width()), - \
m_remainingTimeLabel->boundingRect().height());  
+    if (!items().contains(m_arenaNameLabel))
+    {
+        addItem(m_arenaNameLabel);
+    }
+    m_arenaNameLabel->setPlainText(m_game->getArena()->getName());
+    m_arenaNameLabel->setPos(0, - m_arenaNameLabel->boundingRect().height());
+    
     m_infoOverlay->showGetReady();
 }
 
@@ -315,7 +327,8 @@
     }
     
     delete m_infoOverlay;
-    delete m_remainingTime;
+    delete m_remainingTimeLabel;
+    delete m_arenaNameLabel;
     
     delete m_cache;
     delete m_rendererSelectedTheme;
@@ -394,10 +407,15 @@
     
     m_infoOverlay->hideItems();
     
-    if(items().contains(m_remainingTime))
+    if(items().contains(m_remainingTimeLabel))
     {
-        removeItem(m_remainingTime);
+        removeItem(m_remainingTimeLabel);
     }
+    
+    if(items().contains(m_arenaNameLabel))
+    {
+        removeItem(m_arenaNameLabel);
+    }
 }
 
 void GameScene::showScore()
@@ -505,13 +523,13 @@
         int nTime = m_game->getRemainingTime();
         if(nTime > 0)
         {
-            m_remainingTime->setPlainText(QString("%1:%2").arg(nTime/60).arg(nTime%60, \
2, 10, QChar('0'))); +            \
m_remainingTimeLabel->setPlainText(QString("%1:%2").arg(nTime/60).arg(nTime%60, 2, \
10, QChar('0')));  }
         else
         {
-            m_remainingTime->setPlainText(i18n("Sudden Death"));
-            m_remainingTime->setDefaultTextColor(QColor("#FF0000"));
-            m_remainingTime->setPos((width() - \
m_remainingTime->boundingRect().width()), - \
m_remainingTime->boundingRect().height()); +            \
m_remainingTimeLabel->setPlainText(i18n("Sudden Death")); +            \
m_remainingTimeLabel->setDefaultTextColor(QColor("#FF0000")); +            \
m_remainingTimeLabel->setPos((width() - \
m_remainingTimeLabel->boundingRect().width()), - \
m_remainingTimeLabel->boundingRect().height());  }
     }
 }
--- trunk/playground/games/granatier/src/gamescene.h #1031215:1031216
@@ -67,8 +67,11 @@
     /** The overlay to show the score at the end of a round*/
     InfoOverlay* m_infoOverlay;
     
-    /** The labels to be displayed during the game */
-    QGraphicsTextItem* m_remainingTime;
+    /** The labels to displayed the arena name */
+    QGraphicsTextItem* m_arenaNameLabel;
+    
+    /** The labels to displayed the remaining time */
+    QGraphicsTextItem* m_remainingTimeLabel;
 
     /** The pixmap cache */
     KPixmapCache* m_cache; //TODO: check if the cache is used


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic