00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/palette.h"
00023 #include "gui/shop.h"
00024 #include "gui/shoplistbox.h"
00025
00026 #include "configuration.h"
00027 #include "graphics.h"
00028 #include "shopitem.h"
00029
00030 #include <guichan/font.hpp>
00031 #include <guichan/listmodel.hpp>
00032
00033 const int ITEM_ICON_SIZE = 32;
00034
00035 float ShopListBox::mAlpha = 1.0;
00036
00037 ShopListBox::ShopListBox(gcn::ListModel *listModel):
00038 ListBox(listModel),
00039 mPlayerMoney(0)
00040 {
00041 mRowHeight = getFont()->getHeight();
00042 mPriceCheck = true;
00043 }
00044
00045 ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel):
00046 ListBox(listModel),
00047 mPlayerMoney(0),
00048 mShopItems(shopListModel)
00049 {
00050 mRowHeight = std::max(getFont()->getHeight(), ITEM_ICON_SIZE);
00051 mPriceCheck = true;
00052 }
00053
00054 void ShopListBox::setPlayersMoney(int money)
00055 {
00056 mPlayerMoney = money;
00057 }
00058
00059 void ShopListBox::draw(gcn::Graphics *gcnGraphics)
00060 {
00061 if (!mListModel)
00062 return;
00063
00064 if (config.getValue("guialpha", 0.8) != mAlpha)
00065 mAlpha = config.getValue("guialpha", 0.8);
00066
00067 int alpha = (int)(mAlpha * 255.0f);
00068 const gcn::Color* highlightColor =
00069 &guiPalette->getColor(Palette::HIGHLIGHT, alpha);
00070
00071 Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
00072
00073 graphics->setFont(getFont());
00074
00075
00076 for (int i = 0, y = 0;
00077 i < mListModel->getNumberOfElements();
00078 ++i, y += mRowHeight)
00079 {
00080 gcn::Color temp;
00081 const gcn::Color* backgroundColor =
00082 &guiPalette->getColor(Palette::BACKGROUND, alpha);
00083
00084 if (mShopItems &&
00085 mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck)
00086 if (i != mSelected)
00087 backgroundColor = &guiPalette->getColor(Palette::SHOP_WARNING,
00088 alpha);
00089 else
00090 {
00091 temp = guiPalette->getColor(Palette::SHOP_WARNING, alpha);
00092 temp.r = (temp.r + highlightColor->r) / 2;
00093 temp.g = (temp.g + highlightColor->g) / 2;
00094 temp.b = (temp.g + highlightColor->b) / 2;
00095 backgroundColor = &temp;
00096 }
00097 else if (i == mSelected)
00098 backgroundColor = highlightColor;
00099
00100 graphics->setColor(*backgroundColor);
00101 graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight));
00102
00103 if (mShopItems)
00104 {
00105 Image *icon = mShopItems->at(i)->getImage();
00106 if (icon)
00107 {
00108 graphics->drawImage(icon, 1, y);
00109 }
00110 }
00111 graphics->setColor(guiPalette->getColor(Palette::TEXT));
00112 graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5,
00113 y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2);
00114 }
00115 }
00116
00117 void ShopListBox::adjustSize()
00118 {
00119 if (mListModel)
00120 {
00121 setHeight(mRowHeight * mListModel->getNumberOfElements());
00122 }
00123 }
00124
00125 void ShopListBox::setPriceCheck(bool check)
00126 {
00127 mPriceCheck = check;
00128 }