ManaPlus
Public Member Functions | Private Attributes
KillStats Class Reference

#include <killstats.h>

Inheritance diagram for KillStats:
Window ActionListener AttributeListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 KillStats ()
 
void action (const ActionEvent &event)
 
void gainXp (int64_t Xp)
 
void recalcStats ()
 
void update ()
 
void resetTimes ()
 
void attributeChanged (const AttributesT id, const int64_t oldVal, const int64_t newVal)
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~Window ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void setLocationHorisontallyRelativeTo (const Widget *const widget)
 
void setLocationRelativeTo (const ImagePosition::Type &position, int offsetX, int offsetY)
 
void setResizable (const bool resize)
 
void redraw ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void setCloseButton (const bool flag)
 
bool getCloseButton () const
 
void setAllowClose (const bool b)
 
bool getAlowClose () const
 
bool isResizable () const
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
void setShowTitle (bool flag)
 
void setStickyButton (const bool flag)
 
void setSticky (const bool sticky)
 
bool isSticky () const
 
void setStickyButtonLock (const bool sticky)
 
bool isStickyButtonLock () const
 
virtual void setVisible (Visible visible)
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
void postInit ()
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void updateResizeHandler (MouseEvent &event)
 
void setWindowName (const std::string &name)
 
const std::string & getWindowName () const
 
void loadWindowState ()
 
void saveWindowState ()
 
void setDefaultSize (const int defaultX, const int defaultY, int defaultWidth, int defaultHeight)
 
void setDefaultSize ()
 
void setDefaultSize (const int defaultWidth, const int defaultHeight, const ImagePosition::Type &position, const int offsetx, const int offsetY)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
virtual void close ()
 
void setModal (const Modal modal)
 
Rect getWindowArea () const
 
bool isResizeAllowed (const MouseEvent &event) const
 
void setCaptionFont (Font *font)
 
void enableVisibleSound (bool b)
 
bool isWindowVisible () const
 
void setPadding (int padding)
 
int getPadding () const
 
void setTitleBarHeight (unsigned int height)
 
unsigned int getTitleBarHeight () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void setAlignment (Graphics::Alignment alignment)
 
Graphics::Alignment getAlignment () const
 
void setMovable (Move movable)
 
bool isMovable () const
 
Rect getChildrenArea ()
 
virtual void resizeToContent ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget * > &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from AttributeListener
 AttributeListener ()
 
virtual ~ AttributeListener ()
 

Private Attributes

time_t mKillTimer
 
ButtonmResetButton
 
ButtonmTimerButton
 
LabelmLine1
 
LabelmLine2
 
LabelmLine3
 
LabelmLine4
 
LabelmLine5
 
LabelmLine6
 
LabelmLine7
 
LabelmExpSpeed1Label
 
LabelmExpTime1Label
 
LabelmExpSpeed5Label
 
LabelmExpTime5Label
 
LabelmExpSpeed15Label
 
LabelmExpTime15Label
 
LabelmLastKillExpLabel
 
int mKillCounter
 
int64_t mExpCounter
 
int mKillTCounter
 
int64_t mExpTCounter
 
time_t m1minExpTime
 
int64_t m1minExpNum
 
int m1minSpeed
 
time_t m5minExpTime
 
int64_t m5minExpNum
 
int m5minSpeed
 
time_t m15minExpTime
 
int64_t m15minExpNum
 
int m15minSpeed
 

Additional Inherited Members

- Static Public Member Functions inherited from Window
static void setWindowContainer (WindowContainer *const windowContainer)
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Static Public Member Functions inherited from AttributeListener
static void distributeEvent (const AttributesT id, const int64_t oldVal, const int64_t newVal)
 
static void addListener (AttributeListener *const listener)
 
static void removeListener (const AttributeListener *const listener)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Window
bool canMove () const
 
int getOption (const std::string &name, const int def) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Attributes inherited from Window
std::string mCaption
 
Graphics::Alignment mAlignment
 
int mPadding
 
unsigned int mTitleBarHeight
 
Move mMovable
 
int mDragOffsetX
 
int mDragOffsetY
 
bool mMoved
 
SkinmSkin
 
int mDefaultX
 
int mDefaultY
 
int mDefaultWidth
 
int mDefaultHeight
 
int mCaptionOffsetX
 
int mCaptionOffsetY
 
bool mShowTitle
 
bool mLastRedraw
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Definition at line 34 of file killstats.h.

Constructor & Destructor Documentation

◆ KillStats()

KillStats::KillStats ( )

Constructor.

Definition at line 47 of file killstats.cpp.

47  :
48  // TRANSLATORS: kill stats window name
49  Window(_("Kill stats"), Modal_false, nullptr, "killstats.xml"),
52  mKillTimer(0),
53  // TRANSLATORS: kill stats window button
54  mResetButton(new Button(this, _("Reset stats"), "reset",
55  BUTTON_SKIN, this)),
56  // TRANSLATORS: kill stats window button
57  mTimerButton(new Button(this, _("Reset timer"), "timer",
58  BUTTON_SKIN, this)),
59  mLine1(nullptr),
60  mLine2(nullptr),
61  mLine3(nullptr),
62  // TRANSLATORS: kill stats window label
63  mLine4(new Label(this, strprintf(_("Kills: %s, total exp: %s"),
64  "?", "?"))),
65  // TRANSLATORS: kill stats window label
66  mLine5(new Label(this, strprintf(_("Avg Exp: %s"), "?"))),
67  // TRANSLATORS: kill stats window label
68  mLine6(new Label(this, strprintf(_("No. of avg mob to next level: %s"),
69  "?"))),
70  // TRANSLATORS: kill stats window label
71  mLine7(new Label(this, strprintf(_("Kills/Min: %s, Exp/Min: %s"),
72  "?", "?"))),
73  mExpSpeed1Label(new Label(this, strprintf(ngettext(
74  // TRANSLATORS: kill stats window label
75  "Exp speed per %d min: %s", "Exp speed per %d min: %s", 1), 1, "?"))),
76  mExpTime1Label(new Label(this, strprintf(ngettext(
77  "Time for next level per %d min: %s",
78  "Time for next level per %d min: %s", 1), 1, "?"))),
79  mExpSpeed5Label(new Label(this, strprintf(ngettext(
80  "Exp speed per %d min: %s", "Exp speed per %d min: %s", 5), 5, "?"))),
81  mExpTime5Label(new Label(this, strprintf(ngettext(
82  "Time for next level per %d min: %s",
83  "Time for next level per %d min: %s", 5), 5, "?"))),
84  mExpSpeed15Label(new Label(this, strprintf(ngettext(
85  "Exp speed per %d min: %s", "Exp speed per %d min: %s", 15),
86  15, "?"))),
87  mExpTime15Label(new Label(this, strprintf(ngettext(
88  "Time for next level per %d min: %s",
89  "Time for next level per %d min: %s", 15), 15, "?"))),
90  // TRANSLATORS: kill stats window label
91  mLastKillExpLabel(new Label(this, strprintf("%s ?", _("Last kill exp:")))),
92  mKillCounter(0),
93  mExpCounter(0),
94  mKillTCounter(0),
95  mExpTCounter(0),
96  m1minExpTime(0),
97  m1minExpNum(0),
98  m1minSpeed(0),
99  m5minExpTime(0),
100  m5minExpNum(0),
101  m5minSpeed(0),
102  m15minExpTime(0),
103  m15minExpNum(0),
104  m15minSpeed(0)
105 {
106  setWindowName("Kill stats");
107  setCloseButton(true);
108  setResizable(true);
109  setSaveVisible(true);
110  setStickyButtonLock(true);
111  setDefaultSize(250, 250, 350, 300);
112 
113  if (setupWindow != nullptr)
115 
117  int64_t xpNextLevel(PlayerInfo::getAttribute64(
119 
120  if (xpNextLevel == 0)
121  xpNextLevel = 1;
122 
123  // TRANSLATORS: kill stats window label
124  mLine1 = new Label(this, strprintf(_("Level: %d at %f%%"),
125  localPlayer->getLevel(), static_cast<double>(xp)
126  / static_cast<double>(xpNextLevel) * 100.0));
127 
128  const std::string strXp = toString(CAST_U64(xp));
129  const std::string strXpNextLevel = toString(CAST_U64(xpNextLevel));
130  const std::string strXpLeft = toString(CAST_U64(xpNextLevel - xp));
131  const std::string strXpPercent = toString(CAST_U64(xpNextLevel / 100));
132  // TRANSLATORS: kill stats window label
133  mLine2 = new Label(this, strprintf(_("Exp: %s/%s Left: %s"),
134  strXp.c_str(),
135  strXpNextLevel.c_str(),
136  strXpLeft.c_str()));
137 
138  // TRANSLATORS: kill stats window label
139  mLine3 = new Label(this, strprintf(_("1%% = %s exp, avg mob for 1%%: %s"),
140  strXpPercent.c_str(),
141  "?"));
142 
143  place(0, 0, mLine1, 6, 1).setPadding(0);
144  place(0, 1, mLine2, 6, 1).setPadding(0);
145  place(0, 2, mLine3, 6, 1).setPadding(0);
146  place(0, 3, mLine4, 6, 1).setPadding(0);
147  place(0, 4, mLine5, 6, 1).setPadding(0);
148  place(0, 5, mLine6, 6, 1).setPadding(0);
149  place(0, 6, mLine7, 6, 1).setPadding(0);
150 
151  place(0, 7, mLastKillExpLabel, 6, 1).setPadding(0);
152  place(0, 8, mExpSpeed1Label, 6, 1).setPadding(0);
153  place(0, 9, mExpTime1Label, 6, 1).setPadding(0);
154  place(0, 10, mExpSpeed5Label, 6, 1).setPadding(0);
155  place(0, 11, mExpTime5Label, 6, 1).setPadding(0);
156  place(0, 12, mExpSpeed15Label, 6, 1).setPadding(0);
157  place(0, 13, mExpTime15Label, 6, 1).setPadding(0);
158 
159  place(5, 12, mTimerButton, 1, 1).setPadding(0);
160  place(5, 13, mResetButton, 1, 1).setPadding(0);
161 
162  loadWindowState();
163  enableVisibleSound(true);
164 }
const std::string BUTTON_SKIN
Definition: button.h:89
#define CAST_U64
Definition: cast.h:33
Definition: button.h:102
Label * mLine2
Definition: killstats.h:74
Label * mLine1
Definition: killstats.h:73
Label * mExpTime15Label
Definition: killstats.h:86
time_t mKillTimer
Definition: killstats.h:70
int m5minSpeed
Definition: killstats.h:101
Label * mLine6
Definition: killstats.h:78
int64_t mExpCounter
Definition: killstats.h:91
Label * mExpTime5Label
Definition: killstats.h:84
Button * mResetButton
Definition: killstats.h:71
int mKillTCounter
Definition: killstats.h:92
int64_t m5minExpNum
Definition: killstats.h:100
int m1minSpeed
Definition: killstats.h:97
time_t m15minExpTime
Definition: killstats.h:103
time_t m5minExpTime
Definition: killstats.h:99
Label * mLastKillExpLabel
Definition: killstats.h:88
time_t m1minExpTime
Definition: killstats.h:95
Button * mTimerButton
Definition: killstats.h:72
Label * mExpSpeed15Label
Definition: killstats.h:85
Label * mLine4
Definition: killstats.h:76
Label * mLine3
Definition: killstats.h:75
int64_t mExpTCounter
Definition: killstats.h:93
Label * mExpSpeed5Label
Definition: killstats.h:83
Label * mLine7
Definition: killstats.h:79
Label * mLine5
Definition: killstats.h:77
int64_t m15minExpNum
Definition: killstats.h:104
int64_t m1minExpNum
Definition: killstats.h:96
Label * mExpTime1Label
Definition: killstats.h:82
int mKillCounter
Definition: killstats.h:90
Label * mExpSpeed1Label
Definition: killstats.h:81
int m15minSpeed
Definition: killstats.h:105
Definition: label.h:91
LayoutCell & setPadding(int p)
Definition: layoutcell.h:60
int getLevel() const
void registerWindowForReset(Window *const window)
void setSaveVisible(const bool save)
Definition: window.h:300
void setResizable(const bool resize)
Definition: window.cpp:627
void setWindowName(const std::string &name)
Definition: window.h:355
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:109
void enableVisibleSound(bool b)
Definition: window.h:481
void setCloseButton(const bool flag)
Definition: window.cpp:749
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:772
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1384
void setDefaultSize()
Definition: window.cpp:1198
void loadWindowState()
Definition: window.cpp:1087
#define _(s)
Definition: gettext.h:35
LocalPlayer * localPlayer
const bool Modal_false
Definition: modal.h:30
@ PLAYER_EXP_NEEDED
Definition: attributes.h:37
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
int64_t getAttribute64(const AttributesT id)
Definition: playerinfo.cpp:94
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
std::string strprintf(const char *const format,...)

References _, CAST_U64, Window::enableVisibleSound(), PlayerInfo::getAttribute64(), LocalPlayer::getLevel(), Window::loadWindowState(), localPlayer, mExpSpeed15Label, mExpSpeed1Label, mExpSpeed5Label, mExpTime15Label, mExpTime1Label, mExpTime5Label, mLastKillExpLabel, mLine1, mLine2, mLine3, mLine4, mLine5, mLine6, mLine7, mResetButton, mTimerButton, Window::place(), Attributes::PLAYER_EXP, Attributes::PLAYER_EXP_NEEDED, SetupWindow::registerWindowForReset(), Window::setCloseButton(), Window::setDefaultSize(), LayoutCell::setPadding(), Window::setResizable(), Window::setSaveVisible(), Window::setStickyButtonLock(), setupWindow, Window::setWindowName(), strprintf(), and Catch::toString().

Member Function Documentation

◆ action()

void KillStats::action ( const ActionEvent event)
virtual

Stuff.

Implements ActionListener.

Definition at line 166 of file killstats.cpp.

167 {
168  const std::string &eventId = event.getId();
169  if (eventId == "reset")
170  {
171  mKillCounter = 0;
172  mExpCounter = 0;
173  const std::string strXpPercent = toString(CAST_U64(
175  mLine3->setCaption(strprintf("1%% = %s exp, avg mob for 1%%: %s",
176  strXpPercent.c_str(),
177  "?"));
178  // TRANSLATORS: kill stats window label
179  mLine4->setCaption(strprintf(_("Kills: %s, total exp: %s"), "?", "?"));
180  // TRANSLATORS: kill stats window label
181  mLine5->setCaption(strprintf(_("Avg Exp: %s"), "?"));
183  // TRANSLATORS: kill stats window label
184  _("No. of avg mob to next level: %s"), "?"));
185 
186  resetTimes();
187  }
188  else if (eventId == "timer")
189  {
190  mKillTimer = 0;
191  mKillTCounter = 0;
192  mExpTCounter = 0;
194  // TRANSLATORS: kill stats window label
195  _("Kills/Min: %s, Exp/Min: %s"), "?", "?"));
196 
197  resetTimes();
198  }
199 }
void resetTimes()
Definition: killstats.cpp:201
void setCaption(const std::string &caption)
Definition: label.cpp:264

References _, CAST_U64, PlayerInfo::getAttribute64(), mExpCounter, mExpTCounter, mKillCounter, mKillTCounter, mKillTimer, mLine3, mLine4, mLine5, mLine6, mLine7, Attributes::PLAYER_EXP_NEEDED, resetTimes(), Label::setCaption(), strprintf(), and Catch::toString().

◆ attributeChanged()

void KillStats::attributeChanged ( const AttributesT  id,
const int64_t  oldVal,
const int64_t  newVal 
)
virtual

Implements AttributeListener.

Definition at line 437 of file killstats.cpp.

440 {
441  PRAGMA45(GCC diagnostic push)
442  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
443  switch (id)
444  {
447  gainXp(newVal - oldVal);
448  break;
450  {
451  const std::string strXpPercent = toString(CAST_U64(
454  mKillCounter = 0;
455  mKillTCounter = 0;
456  mExpCounter = 0;
457  mExpTCounter = 0;
458  mLine3->setCaption(strprintf("1%% = %s exp, avg mob for 1%%: %s",
459  strXpPercent.c_str(),
460  "?"));
462  // TRANSLATORS: kill stats window label
463  _("Kills: %s, total exp: %s"), "?", "?"));
464  // TRANSLATORS: kill stats window label
465  mLine5->setCaption(strprintf(_("Avg Exp: %s"), "?"));
467  // TRANSLATORS: kill stats window label
468  _("No. of avg mob to next level: %s"), "?"));
470  // TRANSLATORS: kill stats window label
471  _("Kills/Min: %s, Exp/Min: %s"), "?", "?"));
472 
473  resetTimes();
474  update();
475  break;
476  }
477  default:
478  break;
479  }
480  PRAGMA45(GCC diagnostic pop)
481 }
void update()
Definition: killstats.cpp:365
void gainXp(int64_t Xp)
Definition: killstats.cpp:214
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wredundant-decls") PRAGMA45(GCC diagnostic pop) class TestMain
@ PLAYER_BASE_LEVEL
Definition: attributes.h:31
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:102

References _, CAST_U64, gainXp(), PlayerInfo::getAttribute(), mExpCounter, mExpTCounter, mKillCounter, mKillTCounter, mLine3, mLine4, mLine5, mLine6, mLine7, Attributes::PLAYER_BASE_LEVEL, Attributes::PLAYER_EXP, Attributes::PLAYER_EXP_NEEDED, PRAGMA45(), resetTimes(), Label::setCaption(), strprintf(), Catch::toString(), and update().

◆ gainXp()

void KillStats::gainXp ( int64_t  Xp)

Definition at line 214 of file killstats.cpp.

215 {
216  const int64_t expNeed = PlayerInfo::getAttribute64(
218  if (xp == expNeed)
219  xp = 0;
220  else if (xp == 0)
221  return;
222 
223  mKillCounter++;
224  mKillTCounter++;
225 
226  mExpCounter = mExpCounter + xp;
227  mExpTCounter = mExpTCounter + xp;
228  if (mKillCounter == 0)
229  mKillCounter = 1;
230 
231  const float AvgExp = static_cast<float>(mExpCounter)
232  / static_cast<float>(mKillCounter);
233  int64_t xpNextLevel(expNeed);
234 
235  if (mKillTimer == 0)
237 
238  if (xpNextLevel == 0)
239  xpNextLevel = 1;
240 
241  double timeDiff = difftime(cur_time, mKillTimer) / 60;
242 
243  if (timeDiff <= 0.01)
244  timeDiff = 1;
245 
247  // TRANSLATORS: kill stats window label
248  mLine1->setCaption(strprintf(_("Level: %d at %f%%"),
249  localPlayer->getLevel(), static_cast<double>(exp)
250  / static_cast<double>(xpNextLevel) * 100.0));
251 
252  const std::string strXp = toString(CAST_U64(exp));
253  const std::string strXpNextLevel = toString(CAST_U64(xpNextLevel));
254  const std::string strXpLeft = toString(CAST_U64(xpNextLevel - exp));
255  const std::string strXpPercent = toString(CAST_U64(xpNextLevel / 100));
256  // TRANSLATORS: kill stats window label
257  mLine2->setCaption(strprintf(_("Exp: %s/%s Left: %s"),
258  strXp.c_str(),
259  strXpNextLevel.c_str(),
260  strXpLeft.c_str()));
261 
262  if (AvgExp >= -0.001F && AvgExp <= 0.001F)
263  {
264  // TRANSLATORS: kill stats window label
265  mLine3->setCaption(strprintf(_("1%% = %s exp, avg mob for 1%%: %s"),
266  strXpPercent.c_str(),
267  "?"));
268 
269  // TRANSLATORS: kill stats window label
270  mLine5->setCaption(strprintf(_("Avg Exp: %s"),
271  toString(AvgExp).c_str()));
272 
274  // TRANSLATORS: kill stats window label
275  _("No. of avg mob to next level: %s"), "?"));
276  }
277  else
278  {
279  // TRANSLATORS: kill stats window label
280  mLine3->setCaption(strprintf(_("1%% = %s exp, avg mob for 1%%: %s"),
281  strXpPercent.c_str(), toString((static_cast<float>(
282  xpNextLevel) / 100) / AvgExp).c_str()));
283 
284  // TRANSLATORS: kill stats window label
285  mLine5->setCaption(strprintf(_("Avg Exp: %s"),
286  toString(AvgExp).c_str()));
287 
288  // TRANSLATORS: kill stats window label
289  mLine6->setCaption(strprintf(_("No. of avg mob to next level: %s"),
290  toString(static_cast<float>(xpNextLevel - exp) / AvgExp).c_str()));
291  }
292  // TRANSLATORS: kill stats window label
293  mLine4->setCaption(strprintf(_("Kills: %s, total exp: %s"),
294  toString(mKillCounter).c_str(),
295  toString(CAST_U64(mExpCounter)).c_str()));
296 
297  // TRANSLATORS: kill stats window label
298  mLine7->setCaption(strprintf(_("Kills/Min: %s, Exp/Min: %s"),
299  toString(mKillTCounter / timeDiff).c_str(),
300  toString(CAST_U64(mExpTCounter / timeDiff)).c_str()));
301 
303  // TRANSLATORS: kill stats window label
304  _("Last kill exp:"),
305  strXp.c_str()));
306 
307  recalcStats();
308  update();
309 }
volatile time_t cur_time
Definition: timer.cpp:58
void recalcStats()
Definition: killstats.cpp:311

References _, CAST_U64, cur_time, PlayerInfo::getAttribute64(), LocalPlayer::getLevel(), localPlayer, mExpCounter, mExpTCounter, mKillCounter, mKillTCounter, mKillTimer, mLastKillExpLabel, mLine1, mLine2, mLine3, mLine4, mLine5, mLine6, mLine7, Attributes::PLAYER_EXP, Attributes::PLAYER_EXP_NEEDED, recalcStats(), Label::setCaption(), strprintf(), Catch::toString(), and update().

Referenced by attributeChanged().

◆ recalcStats()

void KillStats::recalcStats ( )

Recalc stats if needed

Definition at line 311 of file killstats.cpp.

312 {
313  BLOCK_START("KillStats::recalcStats")
314  const time_t curTime = cur_time;
315 
316  // Need Update Exp Counter
317  if (curTime - m1minExpTime > 60)
318  {
319  const int64_t newExp = PlayerInfo::getAttribute(
321  if (m1minExpTime != 0)
322  m1minSpeed = CAST_S32(newExp - m1minExpNum);
323  else
324  m1minSpeed = 0;
325  m1minExpTime = curTime;
326  m1minExpNum = newExp;
327  }
328 
329  if (curTime != 0 && mLastHost == 0xFF6B66 && cur_time > 1)
330  {
331  const int newExp = PlayerInfo::getAttribute(
333  if (m1minExpTime != 0)
334  m1minSpeed = CAST_S32(newExp - m1minExpNum);
335  mStatsReUpdated = true;
336  m1minExpNum = newExp;
337  }
338 
339  if (curTime - m5minExpTime > 60*5)
340  {
341  const int64_t newExp = PlayerInfo::getAttribute(
343  if (m5minExpTime != 0)
344  m5minSpeed = CAST_S32(newExp - m5minExpNum);
345  else
346  m5minSpeed = 0;
347  m5minExpTime = curTime;
348  m5minExpNum = newExp;
349  }
350 
351  if (curTime - m15minExpTime > 60*15)
352  {
353  const int64_t newExp = PlayerInfo::getAttribute(
355  if (m15minExpTime != 0)
356  m15minSpeed = CAST_S32(newExp - m15minExpNum);
357  else
358  m15minSpeed = 0;
359  m15minExpTime = curTime;
360  m15minExpNum = newExp;
361  }
362  BLOCK_END("KillStats::recalcStats")
363 }
#define CAST_S32
Definition: cast.h:30
unsigned int mLastHost
Definition: client.cpp:136
bool mStatsReUpdated
Definition: game.cpp:161
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References BLOCK_END, BLOCK_START, CAST_S32, cur_time, PlayerInfo::getAttribute(), m15minExpNum, m15minExpTime, m15minSpeed, m1minExpNum, m1minExpTime, m1minSpeed, m5minExpNum, m5minExpTime, m5minSpeed, mLastHost, mStatsReUpdated, Attributes::PLAYER_EXP, and Attributes::PLAYER_EXP_NEEDED.

Referenced by gainXp(), and Game::slowLogic().

◆ resetTimes()

void KillStats::resetTimes ( )

Definition at line 201 of file killstats.cpp.

202 {
203  m1minExpTime = 0;
204  m1minExpNum = 0;
205  m1minSpeed = 0;
206  m5minExpTime = 0;
207  m5minExpNum = 0;
208  m5minSpeed = 0;
209  m15minExpTime = 0;
210  m15minExpNum = 0;
211  m15minSpeed = 0;
212 }

References m15minExpNum, m15minExpTime, m15minSpeed, m1minExpNum, m1minExpTime, m1minSpeed, m5minExpNum, m5minExpTime, and m5minSpeed.

Referenced by action(), and attributeChanged().

◆ update()

void KillStats::update ( )

Updates this dialog

Definition at line 365 of file killstats.cpp.

366 {
367  BLOCK_START("KillStats::update")
368 
369  mExpSpeed1Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s",
370  "Exp speed per %d min: %s", 1),
371  1,
372  toString(m1minSpeed).c_str()));
373 
374  if (m1minSpeed != 0)
375  {
376  // TRANSLATORS: kill stats window label
377  mExpTime1Label->setCaption(strprintf(_(" Time for next level: %s"),
378  toString(static_cast<float>((PlayerInfo::getAttribute(
381  static_cast<float>(m1minSpeed))).c_str()));
382  }
383  else
384  {
386  // TRANSLATORS: kill stats window label
387  _(" Time for next level: %s"), "?"));
388  }
390 
391  mExpSpeed5Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s",
392  "Exp speed per %d min: %s", 5),
393  5,
394  toString(m5minSpeed / 5).c_str()));
396 
397  if (m5minSpeed != 0)
398  {
399  // TRANSLATORS: kill stats window label
400  mExpTime5Label->setCaption(strprintf(_(" Time for next level: %s"),
401  toString(static_cast<float>((PlayerInfo::getAttribute(
403  Attributes::PLAYER_EXP)) / m5minSpeed * 5)).c_str()));
404  }
405  else
406  {
408  // TRANSLATORS: kill stats window label
409  _(" Time for next level: %s"), "?"));
410  }
412 
413 
414  mExpSpeed15Label->setCaption(strprintf(ngettext("Exp speed per %d min: %s",
415  "Exp speed per %d min: %s", 15), 15, toString(
416  m15minSpeed / 15).c_str()));
418 
419  if (m15minSpeed != 0)
420  {
421  // TRANSLATORS: kill stats window label
422  mExpTime15Label->setCaption(strprintf(_(" Time for next level: %s"),
423  toString(static_cast<float>((PlayerInfo::getAttribute(
425  Attributes::PLAYER_EXP)) / m15minSpeed * 15)).c_str()));
426  }
427  else
428  {
430  // TRANSLATORS: kill stats window label
431  _(" Time for next level: %s"), "?"));
432  }
433 
434  BLOCK_END("KillStats::update")
435 }
void adjustSize()
Definition: label.cpp:200
void setCaption(const std::string &caption)
Definition: window.h:531

References _, Label::adjustSize(), BLOCK_END, BLOCK_START, PlayerInfo::getAttribute(), m15minSpeed, m1minSpeed, m5minSpeed, mExpSpeed15Label, mExpSpeed1Label, mExpSpeed5Label, mExpTime15Label, mExpTime1Label, mExpTime5Label, Attributes::PLAYER_EXP, Attributes::PLAYER_EXP_NEEDED, Label::setCaption(), strprintf(), and Catch::toString().

Referenced by attributeChanged(), gainXp(), and Game::slowLogic().

Field Documentation

◆ m15minExpNum

int64_t KillStats::m15minExpNum
private

Definition at line 104 of file killstats.h.

Referenced by recalcStats(), and resetTimes().

◆ m15minExpTime

time_t KillStats::m15minExpTime
private

Definition at line 103 of file killstats.h.

Referenced by recalcStats(), and resetTimes().

◆ m15minSpeed

int KillStats::m15minSpeed
private

Definition at line 105 of file killstats.h.

Referenced by recalcStats(), resetTimes(), and update().

◆ m1minExpNum

int64_t KillStats::m1minExpNum
private

Definition at line 96 of file killstats.h.

Referenced by recalcStats(), and resetTimes().

◆ m1minExpTime

time_t KillStats::m1minExpTime
private

Definition at line 95 of file killstats.h.

Referenced by recalcStats(), and resetTimes().

◆ m1minSpeed

int KillStats::m1minSpeed
private

Definition at line 97 of file killstats.h.

Referenced by recalcStats(), resetTimes(), and update().

◆ m5minExpNum

int64_t KillStats::m5minExpNum
private

Definition at line 100 of file killstats.h.

Referenced by recalcStats(), and resetTimes().

◆ m5minExpTime

time_t KillStats::m5minExpTime
private

Definition at line 99 of file killstats.h.

Referenced by recalcStats(), and resetTimes().

◆ m5minSpeed

int KillStats::m5minSpeed
private

Definition at line 101 of file killstats.h.

Referenced by recalcStats(), resetTimes(), and update().

◆ mExpCounter

int64_t KillStats::mExpCounter
private

Session Exp counter.

Definition at line 91 of file killstats.h.

Referenced by action(), attributeChanged(), and gainXp().

◆ mExpSpeed15Label

Label* KillStats::mExpSpeed15Label
private

Definition at line 85 of file killstats.h.

Referenced by KillStats(), and update().

◆ mExpSpeed1Label

Label* KillStats::mExpSpeed1Label
private

Definition at line 81 of file killstats.h.

Referenced by KillStats(), and update().

◆ mExpSpeed5Label

Label* KillStats::mExpSpeed5Label
private

Definition at line 83 of file killstats.h.

Referenced by KillStats(), and update().

◆ mExpTCounter

int64_t KillStats::mExpTCounter
private

Timer Exp counter.

Definition at line 93 of file killstats.h.

Referenced by action(), attributeChanged(), and gainXp().

◆ mExpTime15Label

Label* KillStats::mExpTime15Label
private

Definition at line 86 of file killstats.h.

Referenced by KillStats(), and update().

◆ mExpTime1Label

Label* KillStats::mExpTime1Label
private

Definition at line 82 of file killstats.h.

Referenced by KillStats(), and update().

◆ mExpTime5Label

Label* KillStats::mExpTime5Label
private

Definition at line 84 of file killstats.h.

Referenced by KillStats(), and update().

◆ mKillCounter

int KillStats::mKillCounter
private

Session Kill counter.

Definition at line 90 of file killstats.h.

Referenced by action(), attributeChanged(), and gainXp().

◆ mKillTCounter

int KillStats::mKillTCounter
private

Timer Kill counter.

Definition at line 92 of file killstats.h.

Referenced by action(), attributeChanged(), and gainXp().

◆ mKillTimer

time_t KillStats::mKillTimer
private

Timer for kill stats.

Definition at line 70 of file killstats.h.

Referenced by action(), and gainXp().

◆ mLastKillExpLabel

Label* KillStats::mLastKillExpLabel
private

Definition at line 88 of file killstats.h.

Referenced by gainXp(), and KillStats().

◆ mLine1

Label* KillStats::mLine1
private

Definition at line 73 of file killstats.h.

Referenced by gainXp(), and KillStats().

◆ mLine2

Label* KillStats::mLine2
private

Definition at line 74 of file killstats.h.

Referenced by gainXp(), and KillStats().

◆ mLine3

Label* KillStats::mLine3
private

Definition at line 75 of file killstats.h.

Referenced by action(), attributeChanged(), gainXp(), and KillStats().

◆ mLine4

Label* KillStats::mLine4
private

Definition at line 76 of file killstats.h.

Referenced by action(), attributeChanged(), gainXp(), and KillStats().

◆ mLine5

Label* KillStats::mLine5
private

Definition at line 77 of file killstats.h.

Referenced by action(), attributeChanged(), gainXp(), and KillStats().

◆ mLine6

Label* KillStats::mLine6
private

Definition at line 78 of file killstats.h.

Referenced by action(), attributeChanged(), gainXp(), and KillStats().

◆ mLine7

Label* KillStats::mLine7
private

Definition at line 79 of file killstats.h.

Referenced by action(), attributeChanged(), gainXp(), and KillStats().

◆ mResetButton

Button* KillStats::mResetButton
private

Definition at line 71 of file killstats.h.

Referenced by KillStats().

◆ mTimerButton

Button* KillStats::mTimerButton
private

Definition at line 72 of file killstats.h.

Referenced by KillStats().


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