File indexing completed on 2025-02-09 04:37:00
0001 /* This file is part of KsirK. 0002 Copyright (C) 2008 Guillaume Pelouas <pelouas@hotmail.fr> 0003 0004 KsirK is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, either version 2 0007 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA 0018 */ 0019 0020 /* begin : Thu Nov 21 2007 */ 0021 0022 0023 #include "fightArena.h" 0024 #include "GameLogic/player.h" 0025 0026 namespace Ksirk 0027 { 0028 using namespace GameLogic; 0029 0030 FightArena::FightArena(QWidget* parent, unsigned int mapW, unsigned int mapH, 0031 QGraphicsScene* sceneArena,ONU* onuObject, GameAutomaton* automaton): 0032 QGraphicsView(parent), 0033 m_scene(sceneArena), 0034 m_onu(onuObject), 0035 m_automaton(automaton) 0036 { 0037 qCDebug(KSIRK_LOG); 0038 0039 setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); 0040 setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); 0041 setCacheMode(QGraphicsView::CacheBackground); 0042 setMinimumSize(200,100); 0043 setMaximumSize(mapW,mapH); 0044 updateGeometry(); 0045 0046 // create the first country of the arena 0047 m_countryAttack = new Country(automaton, 0048 "", 0049 QPointF(0,0), 0050 QPointF(0,0), 0051 QPointF(0,0), 0052 QPointF(0,0), 0053 QPointF(0,0), 0054 QPointF(0,0)); 0055 // create the second country of the arena 0056 m_countryDefense = new Country(automaton, 0057 "", 0058 QPointF(0,0), 0059 QPointF(0,0), 0060 QPointF(0,0), 0061 QPointF(0,0), 0062 QPointF(0,0), 0063 QPointF(0,0)); 0064 // make the two arena countrys neighbours 0065 QList<Country*> arenaAttackNeighbours; 0066 arenaAttackNeighbours.insert(arenaAttackNeighbours.begin(), m_countryDefense); 0067 m_countryAttack->neighbours(arenaAttackNeighbours); 0068 QList<Country*> arenaDefenseNeighbours; 0069 arenaDefenseNeighbours.insert(arenaDefenseNeighbours.begin(), m_countryAttack); 0070 m_countryDefense->neighbours(arenaDefenseNeighbours); 0071 0072 0073 // search the background image for the arena 0074 KConfig config(onuObject->getConfigFileName()); 0075 KConfigGroup onugroup = config.group(QStringLiteral("onu")); 0076 QString skin = onugroup.readEntry("skinpath"); 0077 QString imageFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, skin + "/Images/arena.svg"); 0078 // create the background image 0079 m_bgImage = new QPixmap(imageFileName); 0080 } 0081 0082 FightArena::~FightArena() 0083 { 0084 qCDebug(KSIRK_LOG); 0085 delete m_countryAttack; m_countryAttack = nullptr; 0086 delete m_countryDefense; m_countryDefense= nullptr; 0087 delete m_bgImage; m_bgImage = nullptr; 0088 } 0089 0090 QSize FightArena::sizeHint() const 0091 { 0092 return QSize(m_mapW, m_mapH); 0093 } 0094 0095 /** 0096 * Init the arena with the two countries engaged 0097 * @param countryA attacker country 0098 * @param countryD defender country 0099 */ 0100 void FightArena::initFightArena (Country* countryA, Country* countryD, BackGnd* bg) 0101 { 0102 qCDebug(KSIRK_LOG); 0103 // new size 0104 int width = m_automaton->game()->centralWidget()->width(); 0105 int height = m_automaton->game()->centralWidget()->height(); 0106 0107 // resize the background image 0108 QPixmap pix; 0109 pix = m_bgImage->scaled(width,height); 0110 // and put the image 0111 bg->setPixmap(pix); 0112 0113 // resize the widget 0114 m_scene->setSceneRect ( 0, 0, width, height); 0115 setMaximumSize(width, height); 0116 0117 // new zoom 0118 double newZ = height/280; 0119 m_onu->setZoomArena(newZ); 0120 0121 qCDebug(KSIRK_LOG) << "Hi"; 0122 // re-place the anchor point of the two countries 0123 m_countryAttack->anchorPoint(QPointF((width/4)/newZ,(height/2)/newZ)); 0124 m_countryAttack->centralPoint(QPointF((width/4)/newZ,(height/2)/newZ)); 0125 m_countryAttack->pointFlag(QPointF((width/7)/newZ,(height/7)/newZ)); 0126 m_countryAttack->pointCannon(QPointF((2*width/18)/newZ,(height/2)/newZ)); 0127 m_countryAttack->pointCavalry(QPointF((4*width/18)/newZ,(2*height/5)/newZ)); 0128 m_countryAttack->pointInfantry(QPointF((6*width/18)/newZ,(3*height/5)/newZ)); 0129 0130 m_countryDefense->anchorPoint(QPointF((3*width/4)/newZ,(height/2)/newZ)); 0131 m_countryDefense->centralPoint(QPointF((3*width/4)/newZ,(height/2)/newZ)); 0132 m_countryDefense->pointFlag(QPointF((6*width/7)/newZ,(height/7)/newZ)); 0133 m_countryDefense->pointCannon(QPointF((16*width/18)/newZ,(height/2)/newZ)); 0134 m_countryDefense->pointCavalry(QPointF((14*width/18)/newZ,(3*height/5)/newZ)); 0135 m_countryDefense->pointInfantry(QPointF((12*width/18)/newZ,(2*height/5)/newZ)); 0136 0137 qCDebug(KSIRK_LOG) << "Ho"; 0138 // create the arena countries with the originals 0139 m_countryAttack->copyForArena(countryA); 0140 m_countryDefense->copyForArena(countryD); 0141 0142 qCDebug(KSIRK_LOG) << "Done"; 0143 } 0144 0145 } 0146 0147 #include "moc_fightArena.cpp"