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

#include <emoteshortcut.h>

Public Member Functions

 EmoteShortcut ()
 
 ~EmoteShortcut ()
 
void load ()
 
unsigned char getEmote (const size_t index) const
 
unsigned char getEmoteSelected () const
 
void setEmote (const size_t index)
 
void setEmotes (const size_t index, const unsigned char emoteId)
 
void setEmoteSelected (const unsigned char emoteId)
 
bool isEmoteSelected () const
 
void removeEmote (const size_t index)
 
void useEmote (const size_t index) const
 
void useEmotePlayer (const size_t index) const
 

Static Public Member Functions

static unsigned int getEmoteCount ()
 

Private Member Functions

void save () const
 

Private Attributes

unsigned char mEmotes [SHORTCUT_EMOTES]
 
unsigned char mEmoteSelected
 

Detailed Description

The class which keeps track of the emote shortcuts.

Definition at line 35 of file emoteshortcut.h.

Constructor & Destructor Documentation

◆ EmoteShortcut()

EmoteShortcut::EmoteShortcut ( )

Constructor.

Definition at line 40 of file emoteshortcut.cpp.

40  :
42 {
43  for (int i = 0; i < SHORTCUT_EMOTES; i++)
44  mEmotes[i] = 0;
45 }
unsigned char mEmotes[SHORTCUT_EMOTES]
unsigned char mEmoteSelected
static const int SHORTCUT_EMOTES
Definition: emoteshortcut.h:25

References mEmotes, and SHORTCUT_EMOTES.

◆ ~EmoteShortcut()

EmoteShortcut::~EmoteShortcut ( )

Destructor.

Definition at line 47 of file emoteshortcut.cpp.

48 {
49  save();
50 }
void save() const

References save().

Member Function Documentation

◆ getEmote()

unsigned char EmoteShortcut::getEmote ( const size_t  index) const
inline

Returns the shortcut Emote ID specified by the index.

Parameters
indexIndex of the shortcut Emote.

Definition at line 60 of file emoteshortcut.h.

61  { return mEmotes[index]; }

References mEmotes.

Referenced by EmoteShortcutContainer::mousePressed(), and EmoteShortcutContainer::mouseReleased().

◆ getEmoteCount()

static unsigned int EmoteShortcut::getEmoteCount ( )
inlinestatic

Returns the amount of shortcut Emotes.

Definition at line 66 of file emoteshortcut.h.

67  { return SHORTCUT_EMOTES; }

References SHORTCUT_EMOTES.

◆ getEmoteSelected()

unsigned char EmoteShortcut::getEmoteSelected ( ) const
inline

Returns the emote ID that is currently selected.

Definition at line 72 of file emoteshortcut.h.

73  { return mEmoteSelected; }

References mEmoteSelected.

◆ isEmoteSelected()

bool EmoteShortcut::isEmoteSelected ( ) const
inline

A flag to check if the Emote is selected.

Definition at line 104 of file emoteshortcut.h.

105  { return mEmoteSelected != 0U; }

References mEmoteSelected.

Referenced by EmoteShortcutContainer::mousePressed(), and EmoteShortcutContainer::mouseReleased().

◆ load()

void EmoteShortcut::load ( )

Load the configuration information.

Definition at line 52 of file emoteshortcut.cpp.

53 {
54  for (unsigned char i = 0, j = 0,
55  fsz = CAST_U8(EmoteDB::getLast());
56  i <= fsz && j < SHORTCUT_EMOTES;
57  i++)
58  {
59  const EmoteSprite *const sprite = EmoteDB::getSprite(i, true);
60  if (sprite != nullptr)
61  {
62  mEmotes[j] = CAST_U8(i + 1);
63  j ++;
64  }
65  }
66 }
#define CAST_U8
Definition: cast.h:27
const int & getLast() A_CONST
Definition: emotedb.cpp:301
const EmoteSprite * getSprite(const int id, const bool allowNull)
Definition: emotedb.cpp:292

References CAST_U8, EmoteDB::getLast(), EmoteDB::getSprite(), mEmotes, and SHORTCUT_EMOTES.

Referenced by createGuiWindows().

◆ removeEmote()

void EmoteShortcut::removeEmote ( const size_t  index)
inline

Remove a Emote from the shortcut.

Definition at line 110 of file emoteshortcut.h.

111  { if (index < CAST_SIZE(SHORTCUT_EMOTES)) mEmotes[index] = 0; }
#define CAST_SIZE
Definition: cast.h:34

References CAST_SIZE, mEmotes, and SHORTCUT_EMOTES.

◆ save()

void EmoteShortcut::save ( ) const
private

Save the configuration information.

Definition at line 68 of file emoteshortcut.cpp.

69 {
70  for (int i = 0; i < SHORTCUT_EMOTES; i++)
71  {
72  const unsigned char emoteId = mEmotes[i] != 0U ? mEmotes[i]
73  : CAST_U8(0);
74  serverConfig.setValue("emoteshortcut" + toString(i),
75  CAST_U32(emoteId));
76  }
77 }
#define CAST_U32
Definition: cast.h:31
void setValue(const std::string &key, const std::string &value)
Configuration serverConfig
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774

References CAST_U32, CAST_U8, mEmotes, serverConfig, Configuration::setValue(), SHORTCUT_EMOTES, and Catch::toString().

Referenced by ~EmoteShortcut().

◆ setEmote()

void EmoteShortcut::setEmote ( const size_t  index)
inline

Adds the selected emote ID to the emotes specified by the index.

Parameters
indexIndex of the emotes.

Definition at line 80 of file emoteshortcut.h.

81  { mEmotes[index] = mEmoteSelected; }

References mEmotes, and mEmoteSelected.

Referenced by EmoteShortcutContainer::mousePressed().

◆ setEmotes()

void EmoteShortcut::setEmotes ( const size_t  index,
const unsigned char  emoteId 
)
inline

Adds a emoticon to the emotes store specified by the index.

Parameters
indexIndex of the emote.
emoteIdID of the emote.

Definition at line 89 of file emoteshortcut.h.

91  { mEmotes[index] = emoteId; }

References mEmotes.

Referenced by EmoteShortcutContainer::mouseReleased().

◆ setEmoteSelected()

void EmoteShortcut::setEmoteSelected ( const unsigned char  emoteId)
inline

Set the Emote that is selected.

Parameters
emoteIdThe ID of the emote that is to be assigned.

Definition at line 98 of file emoteshortcut.h.

99  { mEmoteSelected = emoteId; }

References mEmoteSelected.

Referenced by EmoteShortcutContainer::mousePressed(), and EmoteShortcutContainer::mouseReleased().

◆ useEmote()

void EmoteShortcut::useEmote ( const size_t  index) const

Try to use the Emote specified by the index.

Parameters
indexIndex of the emote shortcut.

Definition at line 88 of file emoteshortcut.cpp.

89 {
90  if (localPlayer == nullptr)
91  return;
92 
93  if (index <= CAST_SIZE(SHORTCUT_EMOTES))
94  {
95  if (mEmotes[index - 1] > 0)
96  {
97  const uint8_t emote = mEmotes[index - 1];
98  switch (settings.emoteType)
99  {
100  case EmoteType::Player:
101  default:
103  break;
104  case EmoteType::Pet:
106  break;
109  break;
112  break;
113  }
114  }
115  }
116 }
static bool emote(const uint8_t emotion)
virtual void emote(const uint8_t emoteId) const =0
virtual void emote(const uint8_t emoteId) const =0
virtual void emote(const uint8_t emoteId)=0
EmoteTypeT emoteType
Definition: settings.h:152
Net::HomunculusHandler * homunculusHandler
Definition: net.cpp:112
LocalPlayer * localPlayer
Net::MercenaryHandler * mercenaryHandler
Definition: net.cpp:118
bool emote(InputEvent &event)
Definition: actions.cpp:31
@ Mercenary
Definition: emotetype.h:31
@ Homunculus
Definition: emotetype.h:30
Net::PetHandler * petHandler
Definition: net.cpp:95
Settings settings
Definition: settings.cpp:32

References CAST_SIZE, Net::HomunculusHandler::emote(), Net::MercenaryHandler::emote(), Net::PetHandler::emote(), LocalPlayer::emote(), Actions::emote(), Settings::emoteType, EmoteType::Homunculus, homunculusHandler, localPlayer, mEmotes, EmoteType::Mercenary, mercenaryHandler, EmoteType::Pet, petHandler, EmoteType::Player, settings, and SHORTCUT_EMOTES.

Referenced by EmoteShortcutContainer::mouseReleased().

◆ useEmotePlayer()

void EmoteShortcut::useEmotePlayer ( const size_t  index) const

Definition at line 79 of file emoteshortcut.cpp.

80 {
81  if (index <= CAST_SIZE(SHORTCUT_EMOTES))
82  {
83  if (mEmotes[index - 1] > 0)
84  LocalPlayer::emote(mEmotes[index - 1]);
85  }
86 }

References CAST_SIZE, LocalPlayer::emote(), mEmotes, and SHORTCUT_EMOTES.

Field Documentation

◆ mEmotes

unsigned char EmoteShortcut::mEmotes[SHORTCUT_EMOTES]
private

◆ mEmoteSelected

unsigned char EmoteShortcut::mEmoteSelected
private

Definition at line 129 of file emoteshortcut.h.

Referenced by getEmoteSelected(), isEmoteSelected(), setEmote(), and setEmoteSelected().


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