ManaPlus
Public Member Functions | Static Public Member Functions | Private Attributes
SpellShortcut Class Reference

#include <spellshortcut.h>

Public Member Functions

 SpellShortcut ()
 
 ~SpellShortcut ()
 
void load ()
 
void setItemSelected (const int itemId)
 
bool isItemSelected () const
 
int getSelectedItem () const
 
int getItem (const size_t index) const
 

Static Public Member Functions

static unsigned int getSpellsCount ()
 

Private Attributes

int mItems [SPELLS_SIZE]
 
int mItemSelected
 

Detailed Description

The class which keeps track of the item shortcuts.

Definition at line 31 of file spellshortcut.h.

Constructor & Destructor Documentation

◆ SpellShortcut()

SpellShortcut::SpellShortcut ( )

Constructor.

Definition at line 32 of file spellshortcut.cpp.

32  :
33  mItemSelected(-1)
34 {
35  load();
36 }

References load().

◆ ~SpellShortcut()

SpellShortcut::~SpellShortcut ( )

Destructor.

Definition at line 38 of file spellshortcut.cpp.

39 {
40 }

Member Function Documentation

◆ getItem()

int SpellShortcut::getItem ( const size_t  index) const
inline

Returns the shortcut item ID specified by the index.

Parameters
indexIndex of the shortcut item.

Definition at line 78 of file spellshortcut.h.

79  { return mItems[index]; }
int mItems[SPELLS_SIZE]
Definition: spellshortcut.h:82

References mItems.

Referenced by SpellShortcutContainer::getItemByIndex().

◆ getSelectedItem()

int SpellShortcut::getSelectedItem ( ) const
inline

Returns selected shortcut item ID.

Definition at line 70 of file spellshortcut.h.

71  { return mItemSelected; }

References mItemSelected.

Referenced by SpellShortcutContainer::draw(), SpellShortcutContainer::mouseReleased(), and SpellShortcutContainer::safeDraw().

◆ getSpellsCount()

unsigned int SpellShortcut::getSpellsCount ( )
static

Definition at line 60 of file spellshortcut.cpp.

61 {
62  return SPELL_SHORTCUT_ITEMS;
63 }
const unsigned int SPELL_SHORTCUT_ITEMS
Definition: spells.h:28

References SPELL_SHORTCUT_ITEMS.

Referenced by SpellShortcutContainer::SpellShortcutContainer().

◆ isItemSelected()

bool SpellShortcut::isItemSelected ( ) const
inline

A flag to check if the item is selected.

Definition at line 64 of file spellshortcut.h.

65  { return mItemSelected > -1; }

References mItemSelected.

◆ load()

void SpellShortcut::load ( )

Load the configuration information.

Definition at line 42 of file spellshortcut.cpp.

43 {
44  for (unsigned f = 0; f < SPELLS_SIZE; f ++)
45  mItems[f] = -1;
46 
47  if (spellManager == nullptr)
48  return;
49 
50  const STD_VECTOR<TextCommand*> &spells = spellManager->getAll();
51  unsigned k = 0;
52 
53  for (STD_VECTOR<TextCommand*>::const_iterator i = spells.begin(),
54  i_end = spells.end(); i != i_end && k < SPELLS_SIZE; ++i)
55  {
56  mItems[k++] = (*i)->getId();
57  }
58 }
const std::vector< TextCommand * > & getAll() const A_CONST
SpellManager * spellManager
const unsigned int SPELLS_SIZE
Definition: spells.h:30

References SpellManager::getAll(), mItems, spellManager, and SPELLS_SIZE.

Referenced by SpellShortcut().

◆ setItemSelected()

void SpellShortcut::setItemSelected ( const int  itemId)
inline

Set the item that is selected.

Parameters
itemIdThe ID of the item that is to be assigned.

Definition at line 58 of file spellshortcut.h.

59  { mItemSelected = itemId; }

References mItemSelected.

Referenced by ItemShortcutContainer::mousePressed(), and SpellShortcutContainer::mouseReleased().

Field Documentation

◆ mItems

int SpellShortcut::mItems[SPELLS_SIZE]
private

Definition at line 82 of file spellshortcut.h.

Referenced by getItem(), and load().

◆ mItemSelected

int SpellShortcut::mItemSelected
private

The item held by cursor.

Definition at line 83 of file spellshortcut.h.

Referenced by getSelectedItem(), isItemSelected(), and setItemSelected().


The documentation for this class was generated from the following files: