49#include <guichan/font.hpp>
53#define SKILLS_FILE "skills.xml"
79 if (!iconPath.empty())
106 {
mSkills.push_back(std::move(info)); }
109 std::vector<std::unique_ptr<SkillInfo>>
mSkills;
122 const int selected = getSelected();
123 if (selected < 0 || selected > mListModel->getNumberOfElements())
126 return static_cast<SkillModel*
>(mListModel)->getSkillAt(selected);
129 void draw(gcn::Graphics *gcnGraphics)
override
134 auto *model =
static_cast<SkillModel *
>(mListModel);
150 for (
int i = 0, y = 1;
151 i < model->getNumberOfElements();
223 if (
event.getId() ==
"inc")
226 if (
SkillInfo *info = tab->getSelectedInfo())
229 else if (
event.getId() ==
"close")
245 return std::string();
255 skill.second->update();
271 it->second->update();
277 for (
auto &tab :
mTabs)
295 if (!root || root.
name() !=
"skills")
301 auto model = std::make_unique<SkillModel>();
302 auto skill = std::make_unique<SkillInfo>();
304 skill->name =
"basic";
305 skill->setIcon(std::string());
306 skill->modifiable =
true;
307 skill->visible =
true;
308 skill->model = model.get();
313 model->addSkill(std::move(skill));
314 model->updateVisibilities();
317 auto scroll = std::make_unique<ScrollArea>(listbox);
318 scroll->setOpaque(
false);
319 scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
320 scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
322 auto tab = std::make_unique<SkillTab>(
"Skills", listbox);
325 mTabs.push_back(std::move(tab));
336 if (set.name() ==
"set" ||
337 set.name() ==
"skill-set")
340 setName = set.getProperty(
"name",
strprintf(
_(
"Skill Set %d"), setCount));
342 auto model = std::make_unique<SkillModel>();
344 for (
auto node : set.children())
346 if (node.name() ==
"skill")
348 int id = atoi(node.getProperty(
"id",
"-1").c_str());
349 std::string name = node.getProperty(
"name",
strprintf(
_(
"Skill %d"),
id));
350 std::string icon = node.getProperty(
"icon",
"");
352 auto skill = std::make_unique<SkillInfo>();
355 skill->setIcon(icon);
356 skill->modifiable =
false;
357 skill->visible =
false;
358 skill->model = model.get();
363 model->addSkill(std::move(skill));
367 model->updateVisibilities();
370 auto scroll = std::make_unique<ScrollArea>(listbox);
371 scroll->setOpaque(
false);
372 scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
373 scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
375 auto tab = std::make_unique<SkillTab>(setName, listbox);
379 mTabs.push_back(std::move(tab));
395 info.modifiable = modifiable;
416 if (!
modifiable && baseLevel == 0 && effLevel == 0 && exp.second == 0)
427 bool updateVisibility = !
visible;
430 if (effLevel != baseLevel)
433 effLevel - baseLevel);
450 progress = exp.second != 0 ? (float) exp.first / exp.second : 0;
461 if (updateVisibility)
482 const gcn::Rectangle rect(33, y + 15, width - 33, 17);
std::string getStringValue(const std::string &key) const
void listen(Event::Channel channel)
A central point of control for graphics.
gcn::Font * getFont() const
void drawText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, const gcn::Color &color, gcn::Font *font, bool outline=false, bool shadow=false, const std::optional< gcn::Color > &outlineColor={}, const std::optional< gcn::Color > &shadowColor={})
void setColor(const gcn::Color &color) override
bool drawImage(const Image *image, int x, int y)
Blits an image onto the screen.
Theme * getTheme() const
The global GUI theme.
A list box, meant to be used inside a scroll area.
virtual void increaseSkill(int skillId)=0
A class for loading and managing resources.
static ResourceManager * getInstance()
Returns an instance of the class, creating one if it does not already exist.
ResourceRef< Image > getImage(const std::string &idPath)
Loads the Image resource found at the given identifier path.
Automatically counting Resource reference.
void registerWindowForReset(Window *window)
Enables the Reset Windows button.
std::vector< std::unique_ptr< SkillModel > > mSkillModels
std::map< int, SkillInfo * > mSkills
std::vector< std::unique_ptr< gcn::Widget > > mTabWidgets
void event(Event::Channel channel, const Event &event) override
void setModifiable(int id, bool modifiable)
void action(const gcn::ActionEvent &event) override
Called when receiving actions from widget.
void update()
Update other parts of the display.
std::vector< std::unique_ptr< Tab > > mTabs
void draw(gcn::Graphics *gcnGraphics) override
unsigned int getRowHeight() const override
SkillListBox(SkillModel *model)
SkillInfo * getSelectedInfo()
std::vector< std::unique_ptr< SkillInfo > > mSkills
void updateVisibilities()
SkillInfo * getSkillAt(int i) const
int getNumberOfElements() override
void addSkill(std::unique_ptr< SkillInfo > info)
std::string getElementAt(int i) override
std::vector< SkillInfo * > mVisibleSkills
SkillTab(const std::string &name, SkillListBox *listBox)
SkillInfo * getSelectedInfo()
A tab, the same as the Guichan tab in 0.8, but extended to allow transparency.
void setCaption(const std::string &caption)
Sets the caption of the tab.
A tabbed area, the same as the guichan tabbed area in 0.8, but extended.
void addTab(gcn::Tab *tab, gcn::Widget *widget) override
Add a tab.
void removeTab(gcn::Tab *tab) override
Override the remove tab function as it's broken in guichan 0.8.
int getGuiAlpha() const
Get the current GUI alpha value.
static const gcn::Color & getThemeColor(int type)
Gets the color associated with the type in the default palette (0).
static ResourceRef< Image > getImageFromTheme(const std::string &path)
void drawProgressBar(Graphics *graphics, const gcn::Rectangle &area, const gcn::Color &color, float progress, const std::string &text=std::string(), ProgressPalette progressType=ProgressPalette::THEME_PROG_END) const
static gcn::Color getProgressColor(int type, float progress)
void center()
Positions the window in the center of it's parent.
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
void setMinHeight(int height)
Sets the minimum height of the window.
void setWindowName(const std::string &name)
Sets the name of the window.
void setResizable(bool resize)
Sets whether or not the window can be resized.
void setSaveVisible(bool save)
Sets whether the window will save it's visibility.
LayoutCell & place(int x, int y, gcn::Widget *, int w=1, int h=1)
Adds a widget to the window and sets it at given cell.
void setCloseButton(bool flag)
Sets whether or not the window has a close button.
void setDefaultSize()
Set the default win pos and size to the current ones.
void loadWindowState()
Reads the position (and the size for resizable windows) in the configuration based on the given strin...
void setMinWidth(int width)
Sets the minimum width of the window.
A helper class for parsing an XML document, which also cleans it up again (RAII).
Node rootNode() const
Returns the root node of the document (or NULL if there was a load error).
std::string_view name() const
Children children() const
Configuration paths
XML default paths information reader.
void info(const char *log_text,...) LOG_PRINTF_ATTR
ServerType getNetworkType()
PlayerHandler * getPlayerHandler()
int getStatBase(int id)
Returns the base value of the given stat.
int getStatEffective(int id)
Returns the current effective value of the given stat.
int getAttribute(int id)
Returns the value of the given attribute.
std::pair< int, int > getStatExperience(int id)
Returns the experience of the given stat.
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.
ResourceRef< Image > icon
void setIcon(const std::string &iconPath)
void draw(Graphics *graphics, int y, int width)
WindowContainer * windowContainer