00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "playerbox.h"
00023
00024 #include "../animatedsprite.h"
00025 #include "../configuration.h"
00026 #include "../graphics.h"
00027 #include "../player.h"
00028
00029 #include "../resources/image.h"
00030 #include "../resources/resourcemanager.h"
00031
00032 #include "../utils/dtor.h"
00033
00034 int PlayerBox::instances = 0;
00035 float PlayerBox::mAlpha = 1.0;
00036 ImageRect PlayerBox::background;
00037
00038 PlayerBox::PlayerBox(const Player *player):
00039 mPlayer(player)
00040 {
00041 setFrameSize(2);
00042
00043 if (instances == 0)
00044 {
00045
00046 ResourceManager *resman = ResourceManager::getInstance();
00047 Image *textbox = resman->getImage("graphics/gui/deepbox.png");
00048 int bggridx[4] = {0, 3, 28, 31};
00049 int bggridy[4] = {0, 3, 28, 31};
00050 int a = 0, x, y;
00051
00052 for (y = 0; y < 3; y++) {
00053 for (x = 0; x < 3; x++) {
00054 background.grid[a] = textbox->getSubImage(
00055 bggridx[x], bggridy[y],
00056 bggridx[x + 1] - bggridx[x] + 1,
00057 bggridy[y + 1] - bggridy[y] + 1);
00058 background.grid[a]->setAlpha(config.getValue("guialpha", 0.8));
00059 a++;
00060 }
00061 }
00062
00063 textbox->decRef();
00064 }
00065
00066 instances++;
00067 }
00068
00069 PlayerBox::~PlayerBox()
00070 {
00071 instances--;
00072
00073 if (instances == 0)
00074 {
00075 for_each(background.grid, background.grid + 9, dtor<Image*>());
00076 }
00077 }
00078
00079 void PlayerBox::draw(gcn::Graphics *graphics)
00080 {
00081 if (mPlayer)
00082 {
00083
00084 const int bs = getFrameSize();
00085 #ifdef TMWSERV_SUPPORT
00086 const int x = getWidth() / 2 + bs;
00087 const int y = getHeight() - bs - 8;
00088 mPlayer->draw(static_cast<Graphics*>(graphics), x, y);
00089 #else
00090 const int x = getWidth() / 2 - 16 + bs;
00091 const int y = getHeight() / 2 + bs;
00092 for (int i = 0; i < Being::VECTOREND_SPRITE; i++)
00093 {
00094 if (mPlayer->getSprite(i))
00095 {
00096 mPlayer->getSprite(i)->draw(static_cast<Graphics*>(graphics), x, y);
00097 }
00098 }
00099 #endif
00100 }
00101
00102 if (config.getValue("guialpha", 0.8) != mAlpha)
00103 {
00104 for (int a = 0; a < 9; a++)
00105 {
00106 background.grid[a]->setAlpha(config.getValue("guialpha", 0.8));
00107 }
00108 }
00109 }
00110
00111 void PlayerBox::drawFrame(gcn::Graphics *graphics)
00112 {
00113 int w, h, bs;
00114 bs = getFrameSize();
00115 w = getWidth() + bs * 2;
00116 h = getHeight() + bs * 2;
00117
00118 static_cast<Graphics*>(graphics)->drawImageRect(0, 0, w, h, background);
00119 }