File indexing completed on 2022-09-27 13:19:26

0001 /*
0002     SPDX-FileCopyrightText: 1998-2001 Andreas Zehender <az@azweb.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "playerinfo.h"
0008 
0009 #include <QIcon>
0010 #include <KLocalizedString>
0011 #include <QStandardPaths>
0012 
0013 
0014 QPixmap* PlayerInfo::pplayer[6];
0015 
0016 void PlayerInfo::loadPixmaps()
0017 {
0018     pplayer[0] = new QPixmap(QIcon::fromTheme( QStringLiteral( "battery-discharging-100" )).pixmap(32,32));
0019     pplayer[1] = new QPixmap(QIcon::fromTheme( QStringLiteral( "battery-discharging-080" )).pixmap(32,32));
0020     pplayer[2] = new QPixmap(QIcon::fromTheme( QStringLiteral( "battery-discharging-060" )).pixmap(32,32));
0021     pplayer[3] = new QPixmap(QIcon::fromTheme( QStringLiteral( "battery-discharging-040" )).pixmap(32,32));
0022     pplayer[4] = new QPixmap(QIcon::fromTheme( QStringLiteral( "battery-discharging-020" )).pixmap(32,32));
0023     pplayer[5] = new QPixmap(QIcon::fromTheme( QStringLiteral( "battery-discharging-000" )).pixmap(32,32));
0024 }
0025 
0026 PlayerInfo::PlayerInfo(int pnr,QWidget *parent)
0027       :QFrame(parent),
0028        lplayer(this),lenergy(this),lwins(this),
0029        hitpoints(2,this),energy(2,this),wins(2,this)
0030 {
0031    setFixedWidth(45);
0032    QString str;
0033 //   int i;
0034 
0035    QPalette palette;
0036 
0037    lplayer.setFrameStyle(NoFrame);
0038    lplayer.setContentsMargins(0, 0, 0, 0);
0039    lplayer.setToolTip(i18n("Hit points"));
0040    lenergy.setFrameStyle(NoFrame);
0041    lenergy.setContentsMargins(0, 0, 0, 0);
0042    lenergy.setToolTip(i18n("Energy"));
0043    lwins.setFrameStyle(NoFrame);
0044    lwins.setContentsMargins(0, 0, 0, 0);
0045    lwins.setToolTip(i18n("Wins"));
0046 
0047    lplayer.setGeometry(5,5,35,35);
0048    lplayer.setIndent(0);
0049    lenergy.setGeometry(5,80,32,32);
0050    lenergy.setIndent(0);
0051    lwins.setGeometry(5,152,35,35);
0052    lwins.setIndent(0);
0053 
0054 /*   for(i=0;i<4;i++)
0055    {
0056       str = QString::fromLatin1("sprites/playerinfo/ship%1%2.png")
0057         .arg(pnr+1)
0058         .arg(i);
0059       pix[i]=new QPixmap(QStandardPaths::locate(QStandardPaths::AppDataLocation, str));
0060    }*/
0061 
0062    lplayer.setPixmap(*(pplayer[0]));
0063    currentPixmap=0;
0064    //lenergy.setPixmap(QPixmap(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sprites/playerinfo/energy.png")));
0065    lenergy.setPixmap(QIcon::fromTheme( QStringLiteral( "battery" )).pixmap(32,32));;
0066    lwins.setPixmap(QPixmap(QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral( "sprites/playerinfo/win.png" ))));
0067 
0068    hitpoints.setGeometry(9,45,26,26);
0069    energy.setGeometry(9,120,26,26);
0070    wins.setGeometry(9,195,26,26);
0071    hitpoints.setFrameStyle(NoFrame);
0072    hitpoints.setToolTip(i18n("Hit points"));
0073    hitpoints.setSegmentStyle(QLCDNumber::Flat);
0074    energy.setFrameStyle(NoFrame);
0075    energy.setToolTip(i18n("Energy"));
0076    energy.setSegmentStyle(QLCDNumber::Flat);
0077    wins.setFrameStyle(NoFrame);
0078    wins.setToolTip(i18n("Wins"));
0079    wins.setSegmentStyle(QLCDNumber::Flat);
0080    if (pnr==0)
0081    {
0082       palette.setColor(hitpoints.foregroundRole(), QColor(251,37,37));
0083    } else
0084    {
0085       palette.setColor(hitpoints.foregroundRole(), QColor(61,23,233));
0086    }
0087    hitpoints.setPalette(palette);
0088    energy.setPalette(palette);
0089    wins.setPalette(palette);
0090 }
0091 
0092 void PlayerInfo::setHitpoints(int h)
0093 {
0094    int p = 5-((h+19)/20);
0095    hitpoints.display(h);
0096    if(p!=currentPixmap)
0097    {
0098       lplayer.setPixmap(*(pplayer[p]));
0099       currentPixmap=p;
0100    }
0101 }
0102 
0103 void PlayerInfo::setEnergy(int e)
0104 {
0105    energy.display(e);
0106 }
0107 
0108 void PlayerInfo::setWins(int w)
0109 {
0110    // if the LCD range overflows, adjust its range
0111    if (wins.checkOverflow(w))
0112    {
0113       wins.setDigitCount(wins.digitCount()+1);
0114    }
0115    // if the LCD is set to 0 (start new game), also reset the range
0116    if (w==0)
0117    {
0118       wins.setDigitCount(2);
0119    }
0120    wins.display(w);
0121 }
0122 
0123