summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-18 18:10:34 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-18 18:12:01 +0300
commitcc16bd52b4bfd5b542deddfcb131f0a1ca15b2e0 (patch)
treeedb2a4a75e478cefd282909d1708dfc2d04816a5 /src
parent9d18345d84b0c294b0fe7743cb263259f8cc9447 (diff)
downloadplus-cc16bd52b4bfd5b542deddfcb131f0a1ca15b2e0.tar.gz
plus-cc16bd52b4bfd5b542deddfcb131f0a1ca15b2e0.tar.bz2
plus-cc16bd52b4bfd5b542deddfcb131f0a1ca15b2e0.tar.xz
plus-cc16bd52b4bfd5b542deddfcb131f0a1ca15b2e0.zip
Draw cool down bar in skills window.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp3
-rw-r--r--src/gui/widgets/skillinfo.cpp1
-rw-r--r--src/gui/widgets/skillinfo.h1
-rw-r--r--src/gui/widgets/skilllistbox.h39
-rw-r--r--src/gui/windows/skilldialog.cpp40
-rw-r--r--src/gui/windows/skilldialog.h5
6 files changed, 79 insertions, 10 deletions
diff --git a/src/game.cpp b/src/game.cpp
index ca778a071..de6282cdc 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -616,6 +616,9 @@ void Game::slowLogic()
DelayedManager::delayedLoad();
if (guildManager)
guildManager->slowLogic();
+ if (skillDialog)
+ skillDialog->slowLogic();
+
PacketCounters::update();
// Handle network stuff
diff --git a/src/gui/widgets/skillinfo.cpp b/src/gui/widgets/skillinfo.cpp
index feb4d7023..63849ac20 100644
--- a/src/gui/widgets/skillinfo.cpp
+++ b/src/gui/widgets/skillinfo.cpp
@@ -52,6 +52,7 @@ SkillInfo::SkillInfo() :
sp(0),
duration(0),
durationTime(0),
+ cooldown(0),
type(SkillType::Unknown),
modifiable(false),
visible(false)
diff --git a/src/gui/widgets/skillinfo.h b/src/gui/widgets/skillinfo.h
index fcca73dce..439608c17 100644
--- a/src/gui/widgets/skillinfo.h
+++ b/src/gui/widgets/skillinfo.h
@@ -59,6 +59,7 @@ struct SkillInfo final
int sp;
int duration;
int durationTime;
+ int cooldown;
SkillType::SkillType type;
bool modifiable;
bool visible;
diff --git a/src/gui/widgets/skilllistbox.h b/src/gui/widgets/skilllistbox.h
index 5ae389d83..d92758849 100644
--- a/src/gui/widgets/skilllistbox.h
+++ b/src/gui/widgets/skilllistbox.h
@@ -58,6 +58,7 @@ class SkillListBox final : public ListBox
mPopup(new SkillPopup),
mTextColor(getThemeColor(Theme::TEXT)),
mTextColor2(getThemeColor(Theme::TEXT_OUTLINE)),
+ mCooldownColor(getThemeColor(Theme::SKILL_COOLDOWN)),
mTextPadding(mSkin ? mSkin->getOption("textPadding", 34) : 34),
mSpacing(mSkin ? mSkin->getOption("spacing", 0) : 0),
mSkillClicked(false)
@@ -101,20 +102,40 @@ class SkillListBox final : public ListBox
mHighlightColor.a = static_cast<int>(mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
+ const int width1 = getWidth();
+ const int usableWidth = width1 - 2 * mPadding;
+
// Draw filled rectangle around the selected list element
if (mSelected >= 0)
{
graphics->fillRectangle(Rect(mPadding, getRowHeight()
- * mSelected + mPadding, getWidth() - 2 * mPadding,
+ * mSelected + mPadding, usableWidth,
getRowHeight()));
}
// Draw the list elements
- graphics->setColorAll(mTextColor, mTextColor2);
Font *const font = getFont();
const int space = font->getHeight() + mSpacing;
- const int width2 = getWidth() - mPadding;
- for (int i = 0, y = 1;
+ const int width2 = width1 - mPadding;
+
+ graphics->setColor(mCooldownColor);
+ for (int i = 0, y = 1 + mPadding;
+ i < model->getNumberOfElements();
+ ++i, y += getRowHeight())
+ {
+ SkillInfo *const e = model->getSkillAt(i);
+ if (e)
+ {
+ if (e->cooldown)
+ {
+ graphics->fillRectangle(Rect(mPadding, y,
+ usableWidth * 100 / e->cooldown, 10));
+ }
+ }
+ }
+
+ graphics->setColorAll(mTextColor, mTextColor2);
+ for (int i = 0, y = 1 + mPadding;
i < model->getNumberOfElements();
++i, y += getRowHeight())
{
@@ -122,14 +143,13 @@ class SkillListBox final : public ListBox
if (e)
{
const SkillData *const data = e->data;
- const int yPad = y + mPadding;
const std::string &description = data->description;
- graphics->drawImage(data->icon, mPadding, yPad);
- font->drawString(graphics, data->name, mTextPadding, yPad);
+ graphics->drawImage(data->icon, mPadding, y);
+ font->drawString(graphics, data->name, mTextPadding, y);
if (!description.empty())
{
font->drawString(graphics, description,
- mTextPadding, yPad + space);
+ mTextPadding, y + space);
}
if (e->skillLevelWidth < 0)
@@ -139,7 +159,7 @@ class SkillListBox final : public ListBox
}
font->drawString(graphics, e->skillLevel, width2
- - e->skillLevelWidth, yPad);
+ - e->skillLevelWidth, y);
}
}
}
@@ -221,6 +241,7 @@ class SkillListBox final : public ListBox
SkillPopup *mPopup;
Color mTextColor;
Color mTextColor2;
+ Color mCooldownColor;
int mTextPadding;
int mSpacing;
bool mSkillClicked;
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index 073cf11bd..ee82445f7 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -62,6 +62,7 @@ SkillDialog::SkillDialog() :
Window(_("Skills"), false, nullptr, "skills.xml"),
ActionListener(),
mSkills(),
+ mDurations(),
mTabs(new TabbedArea(this)),
mDeleteTabs(),
mPointsLabel(new Label(this, "0")),
@@ -197,6 +198,7 @@ void SkillDialog::clearSkills()
delete_all(mSkills);
mSkills.clear();
+ mDurations.clear();
}
void SkillDialog::hideSkills()
@@ -433,8 +435,9 @@ void SkillDialog::setSkillDuration(const int id, const int duration)
SkillInfo *const info = (*it).second;
if (info)
{
- info->duration = duration / 10;
+ info->duration = duration;
info->durationTime = tick_time;
+ addSkillDuration(info);
}
}
}
@@ -542,3 +545,38 @@ void SkillDialog::useSkill(const SkillInfo *const info)
}
}
}
+
+void SkillDialog::addSkillDuration(SkillInfo *const skill)
+{
+ FOR_EACH (std::vector<SkillInfo*>::const_iterator, it, mDurations)
+ {
+ if ((*it)->id == skill->id)
+ return;
+ }
+ mDurations.push_back(skill);
+}
+
+void SkillDialog::slowLogic()
+{
+ FOR_EACH (std::vector<SkillInfo*>::const_iterator, it, mDurations)
+ {
+ SkillInfo *const skill = *it;
+ if (skill)
+ {
+ const int time = get_elapsed_time(skill->durationTime);
+ if (time >= skill->duration)
+ {
+ it = mDurations.erase(it);
+ skill->cooldown = 0;
+ skill->duration = 0;
+ skill->durationTime = 0;
+ if (it != mDurations.begin())
+ -- it;
+ }
+ else if (time)
+ {
+ skill->cooldown = skill->duration * 100 / time;
+ }
+ }
+ }
+}
diff --git a/src/gui/windows/skilldialog.h b/src/gui/windows/skilldialog.h
index b01adcabd..fd9bca7c2 100644
--- a/src/gui/windows/skilldialog.h
+++ b/src/gui/windows/skilldialog.h
@@ -110,11 +110,16 @@ class SkillDialog final : public Window,
void playUpdateEffect(const int id) const;
+ void slowLogic();
+
static void useSkill(const SkillInfo *const info);
private:
+ void addSkillDuration(SkillInfo *const skill);
+
typedef std::map<int, SkillInfo*> SkillMap;
SkillMap mSkills;
+ std::vector<SkillInfo*> mDurations;
TabbedArea *mTabs;
std::list<Tab*> mDeleteTabs;
Label *mPointsLabel;