ManaPlus
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

#include <windowmenu.h>

Inheritance diagram for WindowMenu:
Container ConfigListener ActionListener SelectionListener MouseListener BasicContainer2 BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 WindowMenu (const Widget2 *const widget)
 
 ~WindowMenu ()
 
void action (const ActionEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
std::map< std::string, ButtonInfo * > & getButtonNames ()
 
std::vector< Button * > & getButtons ()
 
std::vector< ButtonText * > & getButtonTexts ()
 
void showButton (const std::string &name, const Visible visible)
 
void loadButtons ()
 
void saveButtons () const
 
void optionChanged (const std::string &name)
 
- Public Member Functions inherited from Container
 Container (const Widget2 *const widget)
 
 ~Container ()
 
bool safeRemove (Widget *const widget)
 
void removeControls ()
 
- 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)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
- 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)
 
Rect getChildrenArea ()
 
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 ()
 
virtual void postInit ()
 
- 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 ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from SelectionListener
virtual ~SelectionListener ()
 
virtual void valueChanged (const SelectionEvent &event)
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
virtual void mouseDragged (MouseEvent &event)
 

Protected Member Functions

void drawChildren (Graphics *const graphics)
 
void safeDrawChildren (Graphics *const graphics)
 
- Protected Member Functions inherited from BasicContainer
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 ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from SelectionListener
 SelectionListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 

Private Member Functions

void addButton (const char *const text, const std::string &description, int &x, int &h, const InputActionT key, const Visible visible)
 
void updateButtons ()
 

Private Attributes

SkinmSkin
 
int mPadding
 
int mSpacing
 
std::vector< Button * > mButtons
 
std::vector< ButtonText * > mButtonTexts
 
std::map< std::string, ButtonInfo * > mButtonNames
 
bool mHaveMouse
 
int mAutoHide
 
bool mSmallWindow
 

Additional Inherited Members

- 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)
 
- 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 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

The window menu. Allows showing and hiding many of the different windows used in the game.

Definition at line 47 of file windowmenu.h.

Constructor & Destructor Documentation

◆ WindowMenu()

WindowMenu::WindowMenu ( const Widget2 *const  widget)
explicit

Definition at line 49 of file windowmenu.cpp.

References _, addButton(), Configuration::addListener(), Widget::addMouseListener(), config, Configuration::getIntValue(), SkillDialog::hasSkills(), loadButtons(), mainGraphics, mAutoHide, mPadding, mSpacing, Graphics::mWidth, N_, Widget::setDimension(), Widget::setFocusable(), Widget::setVisible(), InputAction::SHOW_WINDOWS, skillDialog, Visible_false, Visible_true, InputAction::WINDOW_BANK, InputAction::WINDOW_CART, InputAction::WINDOW_CHAT, InputAction::WINDOW_DEBUG, InputAction::WINDOW_DIDYOUKNOW, InputAction::WINDOW_DROP, InputAction::WINDOW_EMOTE_SHORTCUT, InputAction::WINDOW_EQUIPMENT, InputAction::WINDOW_HELP, InputAction::WINDOW_INVENTORY, InputAction::WINDOW_KILLS, InputAction::WINDOW_MAIL, InputAction::WINDOW_MINIMAP, InputAction::WINDOW_ONLINE, InputAction::WINDOW_OUTFIT, InputAction::WINDOW_QUESTS, InputAction::WINDOW_SERVER_INFO, InputAction::WINDOW_SETUP, InputAction::WINDOW_SHOP, InputAction::WINDOW_SHORTCUT, InputAction::WINDOW_SKILL, InputAction::WINDOW_SOCIAL, InputAction::WINDOW_SPELLS, InputAction::WINDOW_STATUS, InputAction::WINDOW_UPDATER, and x.

49  :
50  Container(widget),
54  MouseListener(),
55  mSkin(theme != nullptr ? theme->load("windowmenu.xml", "",
56  true, Theme::getThemePath()) : nullptr),
57  mPadding(mSkin != nullptr ? mSkin->getPadding() : 1),
58  mSpacing(mSkin != nullptr ? mSkin->getOption("spacing", 3) : 3),
59  mButtons(),
60  mButtonTexts(),
61  mButtonNames(),
62  mHaveMouse(false),
63  mAutoHide(1),
65 {
66  int x = mPadding;
67  int h = 0;
68 
69  setFocusable(false);
70  // TRANSLATORS: short button name for who is online window.
71  addButton(N_("ONL"),
72  // TRANSLATORS: long button name for who is online window.
73  _("Who is online"), x, h, InputAction::WINDOW_ONLINE,
74  Visible_true);
75  // TRANSLATORS: short button name for help window.
76  addButton(N_("HLP"),
77  // TRANSLATORS: long button name for help window.
78  _("Help"), x, h, InputAction::WINDOW_HELP,
79  Visible_true);
80  // TRANSLATORS: short button name for quests window.
81  addButton(N_("QE"),
82  // TRANSLATORS: long button name for quests window.
83  _("Quests"), x, h, InputAction::WINDOW_QUESTS,
84  Visible_true);
85  // TRANSLATORS: short button name for kill stats window.
86  addButton(N_("KS"),
87  // TRANSLATORS: long button name for kill stats window.
88  _("Kill stats"), x, h, InputAction::WINDOW_KILLS,
89  Visible_true);
90  addButton(":-)",
91  // TRANSLATORS: long button name for emotes window.
92  _("Smilies"), x, h, InputAction::WINDOW_EMOTE_SHORTCUT,
93  Visible_true);
94  // TRANSLATORS: short button name for chat window.
95  addButton(N_("CH"),
96  // TRANSLATORS: longt button name for chat window.
97  _("Chat"), x, h, InputAction::WINDOW_CHAT,
98 #ifdef ANDROID
99  Visible_true);
100 #else // ANDROID
101  Visible_false);
102 #endif // ANDROID
103 
104  // TRANSLATORS: short button name for status window.
105  addButton(N_("STA"),
106  // TRANSLATORS: long button name for status window.
107  _("Status"), x, h, InputAction::WINDOW_STATUS,
108  Visible_true);
109  // TRANSLATORS: short button name for equipment window.
110  addButton(N_("EQU"),
111  // TRANSLATORS: long button name for equipment window.
112  _("Equipment"), x, h, InputAction::WINDOW_EQUIPMENT,
113  Visible_true);
114  // TRANSLATORS: short button name for inventory window.
115  addButton(N_("INV"),
116  // TRANSLATORS: long button name for inventory window.
117  _("Inventory"), x, h, InputAction::WINDOW_INVENTORY,
118  Visible_true);
119  // TRANSLATORS: short button name for cart window.
120  addButton(N_("CA"),
121  // TRANSLATORS: long button name for cart window.
122  _("Cart"), x, h, InputAction::WINDOW_CART,
123  Visible_true);
124  // TRANSLATORS: short button name for map window.
125  addButton(N_("MAP"),
126  // TRANSLATORS: long button name for map window.
127  _("Map"), x, h, InputAction::WINDOW_MINIMAP,
128  Visible_false);
129 
130  if (skillDialog->hasSkills())
131  {
132  // TRANSLATORS: short button name for skills window.
133  addButton(N_("SKI"),
134  // TRANSLATORS: long button name for skills window.
135  _("Skills"), x, h, InputAction::WINDOW_SKILL,
136  Visible_true);
137  }
138 
139  // TRANSLATORS: short button name for social window.
140  addButton(N_("SOC"),
141  // TRANSLATORS: long button name for social window.
142  _("Social"), x, h, InputAction::WINDOW_SOCIAL,
143  Visible_true);
144  // TRANSLATORS: short button name for shortcuts window.
145  addButton(N_("SH"),
146  // TRANSLATORS: long button name for shortcuts window.
147  _("Shortcuts"), x, h, InputAction::WINDOW_SHORTCUT,
148  Visible_true);
149  // TRANSLATORS: short button name for spells window.
150  addButton(N_("SP"),
151  // TRANSLATORS: long button name for spells window.
152  _("Spells"), x, h, InputAction::WINDOW_SPELLS,
153  Visible_true);
154  // TRANSLATORS: short button name for drops window.
155  addButton(N_("DR"),
156  // TRANSLATORS: long button name for drops window.
157  _("Drop"), x, h, InputAction::WINDOW_DROP,
158  Visible_false);
159  // TRANSLATORS: short button name for did you know window.
160  addButton(N_("YK"),
161  // TRANSLATORS: long button name for did you know window.
162  _("Did you know"), x, h, InputAction::WINDOW_DIDYOUKNOW,
163  Visible_false);
164  // TRANSLATORS: short button name for shop window.
165  addButton(N_("SHP"),
166  // TRANSLATORS: long button name for shop window.
167  _("Shop"), x, h, InputAction::WINDOW_SHOP,
168  Visible_false);
169  // TRANSLATORS: short button name for outfits window.
170  addButton(N_("OU"),
171  // TRANSLATORS: long button name for outfits window.
172  _("Outfits"), x, h, InputAction::WINDOW_OUTFIT,
173  Visible_false);
174  // TRANSLATORS: short button name for updates window.
175  addButton(N_("UP"),
176  // TRANSLATORS: long button name for updates window.
177  _("Updates"), x, h, InputAction::WINDOW_UPDATER,
178  Visible_false);
179  // TRANSLATORS: short button name for bank window.
180  addButton(N_("BA"),
181  // TRANSLATORS: long button name for bank window.
182  _("Bank"), x, h, InputAction::WINDOW_BANK,
183  Visible_true);
184  // TRANSLATORS: short button name for mail window.
185  addButton(N_("MA"),
186  // TRANSLATORS: long button name for mail window.
187  _("Mail"), x, h, InputAction::WINDOW_MAIL,
188  Visible_true);
189  // TRANSLATORS: short button name for server info window.
190  addButton(N_("SI"),
191  // TRANSLATORS: long button name for server info window.
192  _("Server info"), x, h, InputAction::WINDOW_SERVER_INFO,
193  Visible_true);
194  // TRANSLATORS: short button name for debug window.
195  addButton(N_("DBG"),
196  // TRANSLATORS: long button name for debug window.
197  _("Debug"), x, h, InputAction::WINDOW_DEBUG,
198 #ifdef ANDROID
199  Visible_true);
200 #else // ANDROID
201  Visible_false);
202 #endif // ANDROID
203 
204  // TRANSLATORS: short button name for windows list menu.
205  addButton(N_("WIN"),
206  // TRANSLATORS: long button name for windows list menu.
207  _("Windows"), x, h, InputAction::SHOW_WINDOWS,
208  Visible_false);
209  // TRANSLATORS: short button name for setup window.
210  addButton(N_("SET"),
211  // TRANSLATORS: long button name for setup window.
212  _("Setup"), x, h, InputAction::WINDOW_SETUP,
213  Visible_true);
214 
215  x += mPadding - mSpacing;
216  if (mainGraphics != nullptr)
217  setDimension(Rect(mainGraphics->mWidth - x, 0, x, h));
218 
219  loadButtons();
220 
221  addMouseListener(this);
223 
224  config.addListener("autohideButtons", this);
225  mAutoHide = config.getIntValue("autohideButtons");
226 }
#define _(s)
Definition: gettext.h:34
std::vector< ButtonText * > mButtonTexts
Definition: windowmenu.h:109
const bool Visible_true
Definition: visible.h:29
bool mSmallWindow
Definition: windowmenu.h:113
#define N_(s)
Definition: gettext.h:35
void setVisible(Visible visible)
Definition: widget.cpp:224
int mAutoHide
Definition: windowmenu.h:112
Definition: rect.h:72
int mWidth
Definition: graphics.h:483
int mSpacing
Definition: windowmenu.h:107
Configuration config
static std::string getThemePath()
Definition: theme.h:66
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
int getIntValue(const std::string &key) const
int getWidth() const
Definition: graphics.cpp:642
void addListener(const std::string &key, ConfigListener *const listener)
int getOption(const std::string &name) const
Definition: skin.h:105
Container(const Widget2 *const widget)
Definition: container.cpp:29
void loadButtons()
Definition: windowmenu.cpp:401
int getPadding() const
Definition: skin.h:99
void addButton(const char *const text, const std::string &description, int &x, int &h, const InputActionT key, const Visible visible)
Definition: windowmenu.cpp:273
const bool Visible_false
Definition: visible.h:29
bool mHaveMouse
Definition: windowmenu.h:111
int mPadding
Definition: windowmenu.h:106
Graphics * mainGraphics
Definition: graphics.cpp:108
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
bool hasSkills() const
Definition: skilldialog.h:116
SkillDialog * skillDialog
Definition: skilldialog.cpp:65
Theme * theme
Definition: theme.cpp:61
void setFocusable(const bool focusable)
Definition: widget.cpp:191
Skin * mSkin
Definition: windowmenu.h:105
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:110
std::vector< Button * > mButtons
Definition: windowmenu.h:108

◆ ~WindowMenu()

WindowMenu::~WindowMenu ( )

Definition at line 228 of file windowmenu.cpp.

References CHECKLISTENERS, config, delete_all(), FOR_EACH, mButtonNames, mButtons, mButtonTexts, mSkin, Widget::mVisible, Configuration::removeListener(), theme, Theme::unload(), and Visible_false.

229 {
230  config.removeListener("autohideButtons", this);
232 
233  for (std::map <std::string, ButtonInfo*>::iterator
234  it = mButtonNames.begin(),
235  it_fend = mButtonNames.end(); it != it_fend; ++it)
236  {
237  delete (*it).second;
238  }
239  mButtonNames.clear();
240  FOR_EACH (STD_VECTOR <Button*>::iterator, it, mButtons)
241  {
242  Button *const btn = *it;
243  if (btn == nullptr)
244  continue;
245  if (btn->mVisible == Visible_false)
246  delete btn;
247  }
249  mButtonTexts.clear();
250  if (mSkin != nullptr)
251  {
252  if (theme != nullptr)
253  theme->unload(mSkin);
254  mSkin = nullptr;
255  }
256 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void unload(Skin *const skin)
Definition: theme.cpp:249
std::vector< ButtonText * > mButtonTexts
Definition: windowmenu.h:109
Definition: button.h:94
Configuration config
Visible mVisible
Definition: widget.h:962
void delete_all(Container &c)
Definition: dtor.h:55
const bool Visible_false
Definition: visible.h:29
Theme * theme
Definition: theme.cpp:61
Skin * mSkin
Definition: windowmenu.h:105
#define CHECKLISTENERS
Definition: localconsts.h:305
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:110
std::vector< Button * > mButtons
Definition: windowmenu.h:108
void removeListener(const std::string &key, ConfigListener *const listener)

Member Function Documentation

◆ action()

void WindowMenu::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Implements ActionListener.

Definition at line 258 of file windowmenu.cpp.

References InputManager::executeAction(), Actions::info(), inputManager, ButtonInfo::key, and mButtonNames.

259 {
260  const std::string &eventId = event.getId();
261  const std::map <std::string, ButtonInfo*>::iterator
262  it = mButtonNames.find(eventId);
263  if (it == mButtonNames.end())
264  return;
265 
266  const ButtonInfo *const info = (*it).second;
267  if (info == nullptr)
268  return;
269 
271 }
bool info(InputEvent &event)
Definition: commands.cpp:56
InputManager inputManager
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:110
InputActionT key
Definition: buttoninfo.h:46
void executeAction(const InputActionT keyNum)

◆ addButton()

void WindowMenu::addButton ( const char *const  text,
const std::string &  description,
int &  x,
int &  h,
const InputActionT  key,
const Visible  visible 
)
inlineprivate

Definition at line 273 of file windowmenu.cpp.

References BasicContainer2::add(), CAST_S32, Widget::getHeight(), Widget::getWidth(), mButtonNames, mButtons, mButtonTexts, mPadding, mSpacing, Button::setDescription(), Widget::setFocusable(), Widget::setPosition(), Button::setTag(), and InputAction::SHOW_WINDOWS.

Referenced by getButtonTexts(), and WindowMenu().

279 {
280  Button *const btn = new Button(this, gettext(text), text, this);
281  btn->setPosition(x, mPadding);
282  btn->setDescription(description);
283  btn->setTag(CAST_S32(key));
284  add(btn);
285  btn->setFocusable(false);
286  x += btn->getWidth() + mSpacing;
287  h = btn->getHeight() + 2 * mPadding;
288  mButtons.push_back(btn);
289  mButtonNames[text] = new ButtonInfo(btn, key, visible);
290  if (key != InputAction::SHOW_WINDOWS)
291  mButtonTexts.push_back(new ButtonText(description, key));
292 }
int getWidth() const
Definition: widget.h:220
std::vector< ButtonText * > mButtonTexts
Definition: windowmenu.h:109
int mSpacing
Definition: windowmenu.h:107
Definition: button.h:94
#define CAST_S32
Definition: cast.h:29
virtual void add(Widget *const widget)
int mPadding
Definition: windowmenu.h:106
void setPosition(const int x, const int y)
Definition: widget.cpp:160
void setFocusable(const bool focusable)
Definition: widget.cpp:191
void setTag(int tag)
Definition: button.h:176
int getHeight() const
Definition: widget.h:239
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:110
void setDescription(const std::string &text)
Definition: button.h:167
std::vector< Button * > mButtons
Definition: windowmenu.h:108

◆ drawChildren()

void WindowMenu::drawChildren ( Graphics *const  graphics)
protectedvirtual

Draws the children widgets of the basic container.

Parameters
graphicsA graphics object to draw with.

Reimplemented from BasicContainer.

Definition at line 471 of file windowmenu.cpp.

References BasicContainer::drawChildren(), mainGraphics, mAutoHide, mHaveMouse, mSmallWindow, and Graphics::mWidth.

Referenced by getButtonTexts().

472 {
473  if (mHaveMouse ||
474  mAutoHide == 0 ||
475  (mAutoHide == 1 &&
476  mainGraphics != nullptr &&
477  (mSmallWindow || mainGraphics->mWidth > 800)))
478  {
479  Container::drawChildren(graphics);
480  }
481 }
bool mSmallWindow
Definition: windowmenu.h:113
int mAutoHide
Definition: windowmenu.h:112
int mWidth
Definition: graphics.h:483
bool mHaveMouse
Definition: windowmenu.h:111
Graphics * mainGraphics
Definition: graphics.cpp:108
virtual void drawChildren(Graphics *const graphics)

◆ getButtonNames()

std::map<std::string, ButtonInfo*>& WindowMenu::getButtonNames ( )
inline

Definition at line 68 of file windowmenu.h.

References mButtonNames.

69  { return mButtonNames; }
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:110

◆ getButtons()

std::vector<Button*>& WindowMenu::getButtons ( )
inline

Definition at line 71 of file windowmenu.h.

References mButtons.

Referenced by PopupMenu::showPopup().

72  { return mButtons; }
std::vector< Button * > mButtons
Definition: windowmenu.h:108

◆ getButtonTexts()

std::vector<ButtonText*>& WindowMenu::getButtonTexts ( )
inline

◆ loadButtons()

void WindowMenu::loadButtons ( )

Definition at line 401 of file windowmenu.cpp.

References ButtonInfo::button, config, fromBool, Widget::getActionEventId(), ConfigurationObject::getValue(), Actions::info(), mButtonNames, mSmallWindow, Widget::setVisible(), ServerCommandType::str, Catch::toString(), updateButtons(), ButtonInfo::visible, Visible_false, and Visible_true.

Referenced by getButtonTexts(), and WindowMenu().

402 {
403  if (!mSmallWindow)
404  {
405  if (config.getValue("windowmenu0", "").empty())
406  {
407  for (std::map <std::string, ButtonInfo*>::iterator
408  it = mButtonNames.begin(),
409  it_fend = mButtonNames.end(); it != it_fend; ++it)
410  {
411  const ButtonInfo *const info = (*it).second;
412  if (info == nullptr ||
413  info->button == nullptr ||
414  info->visible == Visible_true)
415  {
416  continue;
417  }
419  }
420  updateButtons();
421  return;
422  }
423 
424  for (int f = 0; f < 30; f ++)
425  {
426  const std::string str = config.getValue(
427  "windowmenu" + toString(f), "");
428  if (str.empty() || str == "SET")
429  continue;
430  const ButtonInfo *const info = mButtonNames[str];
431  if ((info == nullptr) || (info->button == nullptr))
432  continue;
434  }
435  }
436  else
437  {
438  for (std::map <std::string, ButtonInfo*>::iterator
439  it = mButtonNames.begin(),
440  it_fend = mButtonNames.end(); it != it_fend; ++it)
441  {
442  const ButtonInfo *const info = (*it).second;
443  if ((info == nullptr) || (info->button == nullptr))
444  continue;
445  Button *const button = info->button;
446  const std::string &str = button->getActionEventId();
447  button->setVisible(fromBool(
448  str == "SET" || str == "WIN", Visible));
449  }
450  }
451  updateButtons();
452 }
void updateButtons()
Definition: windowmenu.cpp:376
const bool Visible_true
Definition: visible.h:29
bool mSmallWindow
Definition: windowmenu.h:113
void setVisible(Visible visible)
Definition: widget.cpp:224
Definition: button.h:94
Configuration config
const std::string & getActionEventId() const
Definition: widget.h:604
const bool Visible_false
Definition: visible.h:29
#define fromBool(val, name)
Definition: booldefines.h:48
bool info(InputEvent &event)
Definition: commands.cpp:56
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
std::string getValue(const std::string &key, const std::string &deflt) const
Visible visible
Definition: buttoninfo.h:47
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:110
Button * button
Definition: buttoninfo.h:45

◆ mouseExited()

void WindowMenu::mouseExited ( MouseEvent event)
virtual

Called when the mouse has exited the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 355 of file windowmenu.cpp.

References Popup::hide(), mHaveMouse, and textPopup.

356 {
357  mHaveMouse = false;
358  if (textPopup == nullptr)
359  return;
360 
361  textPopup->hide();
362 }
void hide()
Definition: popup.cpp:262
bool mHaveMouse
Definition: windowmenu.h:111
TextPopup * textPopup
Definition: textpopup.cpp:32

◆ mouseMoved()

void WindowMenu::mouseMoved ( MouseEvent event)
virtual

Called when the mouse has moved in the widget area and no mouse button has been pressed (i.e no widget is being dragged).

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 316 of file windowmenu.cpp.

References _, Button::getDescription(), InputManager::getKeyValueString(), Event::getSource(), Button::getTag(), Popup::hide(), inputManager, Widget::mDimension, mHaveMouse, InputAction::NO_VALUE, TextPopup::show(), strprintf(), textPopup, x, Rect::x, y, and Rect::y.

317 {
318  mHaveMouse = true;
319 
320  if (textPopup == nullptr)
321  return;
322 
323  if (event.getSource() == this)
324  {
325  textPopup->hide();
326  return;
327  }
328 
329  const Button *const btn = dynamic_cast<const Button *>(
330  event.getSource());
331 
332  if (btn == nullptr)
333  {
334  textPopup->hide();
335  return;
336  }
337 
338  const int x = event.getX();
339  const int y = event.getY();
340  const InputActionT key = static_cast<InputActionT>(btn->getTag());
341  const Rect &rect = mDimension;
342  if (key != InputAction::NO_VALUE)
343  {
344  textPopup->show(x + rect.x, y + rect.y, btn->getDescription(),
345  // TRANSLATORS: short key name
347  key).c_str()));
348  }
349  else
350  {
351  textPopup->show(x + rect.x, y + rect.y, btn->getDescription());
352  }
353 }
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:56
#define _(s)
Definition: gettext.h:34
Definition: rect.h:72
Definition: button.h:94
int x
Definition: rect.h:208
void hide()
Definition: popup.cpp:262
std::string getDescription() const
Definition: button.h:170
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
std::string getKeyValueString(const InputActionT index) const
Widget * getSource() const
Definition: event.h:103
int y
Definition: rect.h:213
bool mHaveMouse
Definition: windowmenu.h:111
int getTag() const
Definition: button.h:179
InputAction ::T InputActionT
Definition: inputaction.h:714
InputManager inputManager
Rect mDimension
Definition: widget.h:1100
TextPopup * textPopup
Definition: textpopup.cpp:32

◆ mousePressed()

void WindowMenu::mousePressed ( MouseEvent event)
virtual

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 294 of file windowmenu.cpp.

References MouseEvent::getButton(), MouseEvent::getX(), Widget::getX(), Widget::getY(), mSmallWindow, popupManager, popupMenu, MouseButton::RIGHT, and PopupMenu::showPopup().

295 {
296  if (popupManager == nullptr)
297  return;
298 
299  if (event.getButton() == MouseButton::RIGHT)
300  {
301  if (mSmallWindow)
302  return;
303 
304  event.consume();
305  Button *const btn = dynamic_cast<Button*>(event.getSource());
306  if (btn == nullptr)
307  return;
308  if (popupMenu != nullptr)
309  {
310  popupMenu->showPopup(getX() + event.getX(),
311  getY() + event.getY(), btn);
312  }
313  }
314 }
bool mSmallWindow
Definition: windowmenu.h:113
int getY() const
Definition: widget.h:287
MouseButtonT getButton() const
Definition: mouseevent.h:115
Definition: button.h:94
PopupManager * popupManager
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
int getX() const
Definition: widget.h:268
int getX() const
Definition: mouseevent.h:126
void showPopup(const int x, const int y, const Being *const being)
Definition: popupmenu.cpp:202

◆ optionChanged()

void WindowMenu::optionChanged ( const std::string &  name)
virtual

Called when an option changed. The config listener will have to be registered to the option name first.

Implements ConfigListener.

Definition at line 495 of file windowmenu.cpp.

References BLOCK_END, BLOCK_START, config, Configuration::getIntValue(), BasicContainer::logicChildren(), and mAutoHide.

Referenced by getButtonTexts().

496 {
497  if (name == "autohideButtons")
498  mAutoHide = config.getIntValue("autohideButtons");
499 }
int mAutoHide
Definition: windowmenu.h:112
Configuration config
int getIntValue(const std::string &key) const

◆ safeDrawChildren()

void WindowMenu::safeDrawChildren ( Graphics *const  graphics)
protectedvirtual

Reimplemented from BasicContainer.

Definition at line 483 of file windowmenu.cpp.

References mainGraphics, mAutoHide, mHaveMouse, mSmallWindow, Graphics::mWidth, and BasicContainer::safeDrawChildren().

Referenced by getButtonTexts().

484 {
485  if (mHaveMouse ||
486  mAutoHide == 0 ||
487  (mAutoHide == 1 &&
488  mainGraphics != nullptr &&
489  (mSmallWindow || mainGraphics->mWidth > 800)))
490  {
491  Container::safeDrawChildren(graphics);
492  }
493 }
bool mSmallWindow
Definition: windowmenu.h:113
int mAutoHide
Definition: windowmenu.h:112
int mWidth
Definition: graphics.h:483
bool mHaveMouse
Definition: windowmenu.h:111
Graphics * mainGraphics
Definition: graphics.cpp:108
virtual void safeDrawChildren(Graphics *const graphics)

◆ saveButtons()

void WindowMenu::saveButtons ( ) const

Definition at line 454 of file windowmenu.cpp.

References config, ConfigurationObject::deleteKey(), FOR_EACH, Widget::getActionEventId(), mButtons, Widget::mVisible, Configuration::setValue(), Catch::toString(), and Visible_false.

Referenced by getButtonTexts(), and showButton().

455 {
456  int i = 0;
457  FOR_EACH (STD_VECTOR <Button*>::const_iterator, it, mButtons)
458  {
459  const Button *const btn = *it;
460  if ((btn != nullptr) && btn->mVisible == Visible_false)
461  {
462  config.setValue("windowmenu" + toString(i),
463  btn->getActionEventId());
464  i ++;
465  }
466  }
467  for (int f = i; f < 30; f ++)
468  config.deleteKey("windowmenu" + toString(f));
469 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Definition: button.h:94
Configuration config
const std::string & getActionEventId() const
Definition: widget.h:604
Visible mVisible
Definition: widget.h:962
const bool Visible_false
Definition: visible.h:29
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void deleteKey(const std::string &key)
void setValue(const std::string &key, const std::string &value)
std::vector< Button * > mButtons
Definition: windowmenu.h:108

◆ showButton()

void WindowMenu::showButton ( const std::string &  name,
const Visible  visible 
)

Definition at line 364 of file windowmenu.cpp.

References ButtonInfo::button, Actions::info(), mButtonNames, saveButtons(), Widget::setVisible(), and updateButtons().

Referenced by getButtonTexts(), and PopupMenu::handleLink().

366 {
367  const ButtonInfo *const info = mButtonNames[name];
368  if ((info == nullptr) || (info->button == nullptr))
369  return;
370 
371  info->button->setVisible(visible);
372  updateButtons();
373  saveButtons();
374 }
void updateButtons()
Definition: windowmenu.cpp:376
void setVisible(Visible visible)
Definition: widget.cpp:224
void saveButtons() const
Definition: windowmenu.cpp:454
bool info(InputEvent &event)
Definition: commands.cpp:56
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:110
Button * button
Definition: buttoninfo.h:45

◆ updateButtons()

void WindowMenu::updateButtons ( )
private

Definition at line 376 of file windowmenu.cpp.

References BasicContainer2::add(), FOR_EACH, Widget::getHeight(), Widget::getWidth(), mainGraphics, mButtons, mPadding, mSpacing, Widget::mVisible, Graphics::mWidth, Container::safeRemove(), Widget::setDimension(), Widget::setPosition(), Visible_true, and x.

Referenced by getButtonTexts(), loadButtons(), and showButton().

377 {
378  int x = mPadding;
379  int h = 0;
380  FOR_EACH (STD_VECTOR <Button*>::const_iterator, it, mButtons)
381  safeRemove(*it);
382  const int pad2 = 2 * mPadding;
383  FOR_EACH (STD_VECTOR <Button*>::iterator, it, mButtons)
384  {
385  Button *const btn = *it;
386  if (btn == nullptr)
387  continue;
388  if (btn->mVisible == Visible_true)
389  {
390  btn->setPosition(x, mPadding);
391  add(btn);
392  x += btn->getWidth() + mSpacing;
393  h = btn->getHeight() + pad2;
394  }
395  }
396  x += mPadding - mSpacing;
397  if (mainGraphics != nullptr)
398  setDimension(Rect(mainGraphics->mWidth - x, 0, x, h));
399 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
int getWidth() const
Definition: widget.h:220
const bool Visible_true
Definition: visible.h:29
Definition: rect.h:72
int mWidth
Definition: graphics.h:483
int mSpacing
Definition: windowmenu.h:107
Definition: button.h:94
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
bool safeRemove(Widget *const widget)
Definition: container.cpp:48
Visible mVisible
Definition: widget.h:962
virtual void add(Widget *const widget)
int mPadding
Definition: windowmenu.h:106
Graphics * mainGraphics
Definition: graphics.cpp:108
void setPosition(const int x, const int y)
Definition: widget.cpp:160
int getHeight() const
Definition: widget.h:239
std::vector< Button * > mButtons
Definition: windowmenu.h:108

Field Documentation

◆ mAutoHide

int WindowMenu::mAutoHide
private

Definition at line 112 of file windowmenu.h.

Referenced by drawChildren(), optionChanged(), safeDrawChildren(), and WindowMenu().

◆ mButtonNames

std::map<std::string, ButtonInfo*> WindowMenu::mButtonNames
private

Definition at line 110 of file windowmenu.h.

Referenced by action(), addButton(), getButtonNames(), loadButtons(), showButton(), and ~WindowMenu().

◆ mButtons

std::vector<Button*> WindowMenu::mButtons
private

Definition at line 108 of file windowmenu.h.

Referenced by addButton(), getButtons(), saveButtons(), updateButtons(), and ~WindowMenu().

◆ mButtonTexts

std::vector<ButtonText*> WindowMenu::mButtonTexts
private

Definition at line 109 of file windowmenu.h.

Referenced by addButton(), getButtonTexts(), and ~WindowMenu().

◆ mHaveMouse

bool WindowMenu::mHaveMouse
private

Definition at line 111 of file windowmenu.h.

Referenced by drawChildren(), mouseExited(), mouseMoved(), and safeDrawChildren().

◆ mPadding

int WindowMenu::mPadding
private

Definition at line 106 of file windowmenu.h.

Referenced by addButton(), updateButtons(), and WindowMenu().

◆ mSkin

Skin* WindowMenu::mSkin
private

Definition at line 105 of file windowmenu.h.

Referenced by ~WindowMenu().

◆ mSmallWindow

bool WindowMenu::mSmallWindow
private

Definition at line 113 of file windowmenu.h.

Referenced by drawChildren(), loadButtons(), mousePressed(), and safeDrawChildren().

◆ mSpacing

int WindowMenu::mSpacing
private

Definition at line 107 of file windowmenu.h.

Referenced by addButton(), updateButtons(), and WindowMenu().


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