ManaPlus
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

#include <minimap.h>

Inheritance diagram for Minimap:
Window ConfigListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 Minimap ()
 
 ~Minimap ()
 
void setMap (const Map *const map)
 
void toggle ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void draw2 (Graphics *const graphics)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void screenToMap (int &x, int &y)
 
void optionChanged (const std::string &name)
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~Window ()
 
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 mouseDragged (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 ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 

Private Member Functions

void deleteMapImage ()
 

Private Attributes

float mWidthProportion
 
float mHeightProportion
 
ImagemMapImage
 
int mMapOriginX
 
int mMapOriginY
 
bool mCustomMapImage
 
bool mAutoResize
 

Static Private Attributes

static bool mShow = true
 

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

Minimap window. Shows a minimap image and the name of the current map.

The name of the map is defined by the map property "name". The minimap image is defined by the map property "minimap". The path to the image should be given relative to the root of the client data.

Definition at line 41 of file minimap.h.

Constructor & Destructor Documentation

◆ Minimap()

Minimap::Minimap ( )

Definition at line 65 of file minimap.cpp.

65  :
66  // TRANSLATORS: mini map window name
67  Window(_("Map"), Modal_false, nullptr, "map.xml"),
68  mWidthProportion(0.5),
69  mHeightProportion(0.5),
70  mMapImage(nullptr),
71  mMapOriginX(0),
72  mMapOriginY(0),
73  mCustomMapImage(false),
74  mAutoResize(config.getBoolValue("autoresizeminimaps"))
75 {
76  setWindowName("Minimap");
77  mShow = config.getValueBool(getWindowName() + "Show", true);
78 
79  config.addListener("autoresizeminimaps", this);
80 
81  setDefaultSize(5, 25, 100, 100);
82  // set this to false as the minimap window size is changed
83  // depending on the map size
84  setResizable(true);
85  if (setupWindow != nullptr)
87 
88  setDefaultVisible(true);
89  setSaveVisible(true);
90 
91  setStickyButton(true);
92  setSticky(false);
93 
96  enableVisibleSound(true);
97 }
#define fromBool(val, name)
Definition: booldefines.h:49
bool getValueBool(const std::string &key, const bool deflt) const
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
int mMapOriginY
Definition: minimap.h:88
static bool mShow
Definition: minimap.h:91
int mMapOriginX
Definition: minimap.h:87
Image * mMapImage
Definition: minimap.h:86
bool mCustomMapImage
Definition: minimap.h:89
float mHeightProportion
Definition: minimap.h:85
bool mAutoResize
Definition: minimap.h:90
float mWidthProportion
Definition: minimap.h:84
void registerWindowForReset(Window *const window)
void setSaveVisible(const bool save)
Definition: window.h:300
void setResizable(const bool resize)
Definition: window.cpp:627
virtual void setVisible(Visible visible)
Definition: window.cpp:778
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
bool isSticky() const
Definition: window.h:253
void setSticky(const bool sticky)
Definition: window.cpp:766
void enableVisibleSound(bool b)
Definition: window.h:481
const std::string & getWindowName() const
Definition: window.h:361
void setDefaultVisible(const bool save)
Definition: window.h:288
void setDefaultSize()
Definition: window.cpp:1198
void loadWindowState()
Definition: window.cpp:1087
void setStickyButton(const bool flag)
Definition: window.cpp:761
Configuration config
#define _(s)
Definition: gettext.h:35
const bool Modal_false
Definition: modal.h:30
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
bool Visible
Definition: visible.h:30

References Configuration::addListener(), config, Window::enableVisibleSound(), fromBool, ConfigurationObject::getValueBool(), Window::getWindowName(), Window::isSticky(), Window::loadWindowState(), mShow, SetupWindow::registerWindowForReset(), Window::setDefaultSize(), Window::setDefaultVisible(), Window::setResizable(), Window::setSaveVisible(), Window::setSticky(), Window::setStickyButton(), setupWindow, Window::setVisible(), and Window::setWindowName().

◆ ~Minimap()

Minimap::~Minimap ( )

Definition at line 99 of file minimap.cpp.

100 {
101  config.setValue(getWindowName() + "Show", mShow);
102  config.removeListeners(this);
104  deleteMapImage();
105 }
void setValue(const std::string &key, const std::string &value)
void removeListeners(ConfigListener *const listener)
void deleteMapImage()
Definition: minimap.cpp:107
#define CHECKLISTENERS
Definition: localconsts.h:277

References CHECKLISTENERS, config, deleteMapImage(), Window::getWindowName(), mShow, Configuration::removeListeners(), and Configuration::setValue().

Member Function Documentation

◆ deleteMapImage()

void Minimap::deleteMapImage ( )
private

Definition at line 107 of file minimap.cpp.

108 {
109  if (mMapImage != nullptr)
110  {
111  if (mCustomMapImage)
112  delete mMapImage;
113  else
114  mMapImage->decRef();
115  mMapImage = nullptr;
116  }
117 }

References mCustomMapImage, and mMapImage.

Referenced by setMap(), and ~Minimap().

◆ draw()

void Minimap::draw ( Graphics *const  graphics)
virtual

Draws the minimap.

Reimplemented from Window.

Definition at line 254 of file minimap.cpp.

255 {
256  BLOCK_START("Minimap::draw")
257 
258  Window::draw(graphics);
259  draw2(graphics);
260 }
void draw2(Graphics *const graphics)
Definition: minimap.cpp:270
void draw(Graphics *const graphics)
Definition: minimap.cpp:254
Definition: window.h:102
#define BLOCK_START(name)
Definition: perfomance.h:79

References BLOCK_START, Window::draw(), and draw2().

◆ draw2()

void Minimap::draw2 ( Graphics *const  graphics)

Definition at line 270 of file minimap.cpp.

271 {
272  if (userPalette == nullptr ||
273  localPlayer == nullptr ||
274  viewport == nullptr)
275  {
276  BLOCK_END("Minimap::draw")
277  return;
278  }
279 
280  const Rect a = getChildrenArea();
281 
282  graphics->pushClipArea(a);
283 
284  if (actorManager == nullptr)
285  {
286  BLOCK_END("Minimap::draw")
287  return;
288  }
289 
290  mMapOriginX = 0;
291  mMapOriginY = 0;
292 
293  if (mMapImage != nullptr)
294  {
295  const SDL_Rect &rect = mMapImage->mBounds;
296  const int w = rect.w;
297  const int h = rect.h;
298  if (w > a.width || h > a.height)
299  {
300  mMapOriginX = (a.width / 2) - (localPlayer->mPixelX +
302 
303  mMapOriginY = (a.height / 2) - (localPlayer->mPixelY +
305 
306  const int minOriginX = a.width - w;
307  const int minOriginY = a.height - h;
308 
309  if (mMapOriginX < minOriginX)
310  mMapOriginX = minOriginX;
311  if (mMapOriginY < minOriginY)
312  mMapOriginY = minOriginY;
313  if (mMapOriginX > 0)
314  mMapOriginX = 0;
315  if (mMapOriginY > 0)
316  mMapOriginY = 0;
317  }
318 
320  }
321 
322  const ActorSprites &actors = actorManager->getAll();
323  FOR_EACH (ActorSpritesConstIterator, it, actors)
324  {
325  if (((*it) == nullptr) || (*it)->getType() == ActorType::FloorItem)
326  continue;
327 
328  const Being *const being = static_cast<const Being *>(*it);
329  if (being == nullptr)
330  continue;
331 
332  int dotSize = 2;
334 
335  if (being == localPlayer)
336  {
337  type = UserColorId::SELF;
338  dotSize = 3;
339  }
340  else if (being->isGM())
341  {
342  type = UserColorId::GM;
343  }
344  else if (being->getGuild() == localPlayer->getGuild()
345  || being->getGuildName() == localPlayer->getGuildName())
346  {
347  type = UserColorId::GUILD;
348  }
349  else
350  {
351  switch (being->getType())
352  {
353  case ActorType::Monster:
354  type = UserColorId::MONSTER;
355  break;
356 
357  case ActorType::Npc:
358  type = UserColorId::NPC;
359  break;
360 
361  case ActorType::Portal:
363  break;
364 
365  case ActorType::Pet:
366  type = UserColorId::PET;
367  break;
369  type = UserColorId::MERCENARY;
370  break;
371 
374  break;
375 
377  type = UserColorId::SKILLUNIT;
378  break;
379  case ActorType::Avatar:
380  case ActorType::Unknown:
381  case ActorType::Player:
384  default:
385  continue;
386  }
387  }
388 
389  if (userPalette != nullptr)
390  graphics->setColor(userPalette->getColor(type, 255U));
391 
392  const int offsetHeight = CAST_S32(static_cast<float>(
393  dotSize - 1) * mHeightProportion);
394  const int offsetWidth = CAST_S32(static_cast<float>(
395  dotSize - 1) * mWidthProportion);
396  graphics->fillRectangle(Rect(
397  (being->mPixelX * mWidthProportion) / 32
398  + mMapOriginX - offsetWidth,
399  (being->mPixelY * mHeightProportion) / 32
400  + mMapOriginY - offsetHeight, dotSize, dotSize));
401  }
402 
403  if (localPlayer->isInParty())
404  {
405  const Party *const party = localPlayer->getParty();
406  if (party != nullptr)
407  {
408  const PartyMember *const m = party->getMember(
409  localPlayer->getName());
410  const Party::MemberList *const members = party->getMembers();
411  if (m != nullptr)
412  {
413  const std::string curMap = m->getMap();
414  Party::MemberList::const_iterator it = members->begin();
415  const Party::MemberList::const_iterator
416  it_end = members->end();
417  while (it != it_end)
418  {
419  const PartyMember *const member = *it;
420  if ((member != nullptr) && member->getMap() == curMap
421  && member->getOnline() && member != m)
422  {
423  if (userPalette != nullptr)
424  {
425  graphics->setColor(userPalette->getColor(
426  UserColorId::PARTY, 255U));
427  }
428 
429  const int offsetHeight = CAST_S32(
431  const int offsetWidth = CAST_S32(
433 
434  graphics->fillRectangle(Rect(
435  CAST_S32(member->getX()
436  * mWidthProportion) + mMapOriginX - offsetWidth,
437  CAST_S32(member->getY()
438  * mHeightProportion) + mMapOriginY - offsetHeight,
439  2, 2));
440  }
441  ++ it;
442  }
443  }
444  }
445  }
446 
447  const int gw = graphics->getWidth();
448  const int gh = graphics->getHeight();
449  int x = (localPlayer->mPixelX - (gw / 2)
451  * mWidthProportion / 32 + mMapOriginX;
452  int y = (localPlayer->mPixelY - (gh / 2)
455 
456  const int w = CAST_S32(static_cast<float>(
457  gw) * mWidthProportion / 32);
458  const int h = CAST_S32(static_cast<float>(
459  gh) * mHeightProportion / 32);
460 
461  if (w <= a.width)
462  {
463  if (x < 0 && (w != 0))
464  x = 0;
465  if (x + w > a.width)
466  x = a.width - w;
467  }
468  if (h <= a.height)
469  {
470  if (y < 0 && (h != 0))
471  y = 0;
472  if (y + h > a.height)
473  y = a.height - h;
474  }
475 
476  graphics->setColor(userPalette->getColor(UserColorId::PC, 255U));
477  graphics->drawRectangle(Rect(x, y, w, h));
478  graphics->popClipArea();
479  BLOCK_END("Minimap::draw")
480 }
ActorManager * actorManager
std::set< ActorSprite * > ActorSprites
Definition: actormanager.h:57
ActorSprites::const_iterator ActorSpritesConstIterator
Definition: actormanager.h:61
#define CAST_S32
Definition: cast.h:30
const ActorSprites & getAll() const A_CONST
int mPixelX
Definition: actor.h:133
int mPixelY
Definition: actor.h:134
std::string getMap() const
Definition: avatar.h:120
bool getOnline() const
Definition: avatar.h:81
int getY() const
Definition: avatar.h:132
int getX() const
Definition: avatar.h:126
Definition: being.h:96
Party * getParty() const
Definition: being.h:330
const Guild * getGuild(const std::string &guildName) const
Definition: being.cpp:1258
bool isGM() const
Definition: being.h:659
const std::string & getName() const
Definition: being.h:232
const std::string & getGuildName() const
Definition: being.h:259
bool isInParty() const
Definition: being.h:321
ActorTypeT getType() const
Definition: being.h:116
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
virtual void popClipArea()
Definition: graphics.cpp:739
virtual void fillRectangle(const Rect &rectangle)=0
int getHeight() const
Definition: graphics.cpp:648
virtual void setColor(const Color &color)
Definition: graphics.h:320
virtual void drawRectangle(const Rect &rectangle)=0
int getWidth() const
Definition: graphics.cpp:643
Definition: party.h:63
std::vector< PartyMember * > MemberList
Definition: party.h:157
Definition: rect.h:74
const Color & getColor(UserColorIdT type, const unsigned int alpha)
Definition: userpalette.h:160
int getCameraRelativeY() const
Definition: viewport.h:143
int getCameraRelativeX() const
Definition: viewport.h:140
Rect getChildrenArea()
Definition: window.cpp:1473
Viewport * viewport
Definition: viewport.cpp:36
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
if(!vert) return
void pushClipArea(const Rect &restrict area) restrict2 override final
LocalPlayer * localPlayer
uint32_t party
@ Mercenary
Definition: actortype.h:38
@ Homunculus
Definition: actortype.h:39
@ SkillUnit
Definition: actortype.h:40
@ Elemental
Definition: actortype.h:41
@ FloorItem
Definition: actortype.h:34
@ PORTAL_HIGHLIGHT
Definition: usercolorid.h:79
#define BLOCK_END(name)
Definition: perfomance.h:80
UserColorId ::T UserColorIdT
Definition: usercolorid.h:99
UserPalette * userPalette
Definition: userpalette.cpp:34

References actorManager, ActorType::Avatar, BLOCK_END, CAST_S32, Graphics::drawImage(), Graphics::drawRectangle(), ActorType::Elemental, Graphics::fillRectangle(), ActorType::FloorItem, FOR_EACH, ActorManager::getAll(), Viewport::getCameraRelativeX(), Viewport::getCameraRelativeY(), Window::getChildrenArea(), UserPalette::getColor(), Being::getGuild(), Being::getGuildName(), Graphics::getHeight(), Avatar::getMap(), Being::getName(), Avatar::getOnline(), Being::getParty(), Being::getType(), Graphics::getWidth(), Avatar::getX(), Avatar::getY(), UserColorId::GM, UserColorId::GUILD, Rect::height, ActorType::Homunculus, UserColorId::HOMUNCULUS, Being::isGM(), Being::isInParty(), localPlayer, ActorType::Mercenary, UserColorId::MERCENARY, mHeightProportion, mMapImage, mMapOriginX, mMapOriginY, ActorType::Monster, UserColorId::MONSTER, Actor::mPixelX, Actor::mPixelY, mWidthProportion, ActorType::Npc, UserColorId::NPC, UserColorId::PARTY, party, UserColorId::PC, ActorType::Pet, UserColorId::PET, ActorType::Player, Graphics::popClipArea(), ActorType::Portal, UserColorId::PORTAL_HIGHLIGHT, Graphics::pushClipArea(), UserColorId::SELF, Graphics::setColor(), ActorType::SkillUnit, UserColorId::SKILLUNIT, ActorType::Unknown, userPalette, viewport, Rect::width, x, and y.

Referenced by draw(), and safeDraw().

◆ mouseExited()

void Minimap::mouseExited ( MouseEvent event)
virtual

When the mouse leaves the window this ensures that the custom cursor is restored back to it's standard image.

Reimplemented from Window.

Definition at line 525 of file minimap.cpp.

526 {
527  Window::mouseExited(event);
528  textPopup->hide();
529 }
void hide()
Definition: popup.cpp:265
void mouseExited(MouseEvent &event)
Definition: window.cpp:924
TextPopup * textPopup
Definition: textpopup.cpp:33

References Popup::hide(), Window::mouseExited(), and textPopup.

◆ mouseMoved()

void Minimap::mouseMoved ( MouseEvent event)
virtual

Implements custom cursor image changing context, based on mouse relative position.

Reimplemented from Window.

Definition at line 516 of file minimap.cpp.

517 {
518  Window::mouseMoved(event);
519  const int x = event.getX();
520  const int y = event.getY();
521  const Rect &rect = mDimension;
522  textPopup->show(x + rect.x, y + rect.y, mCaption);
523 }
int y
Definition: rect.h:214
int x
Definition: rect.h:209
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:57
Rect mDimension
Definition: widget.h:1101
void mouseMoved(MouseEvent &event)
Definition: window.cpp:967
std::string mCaption
Definition: window.h:608

References Window::mCaption, Widget::mDimension, Window::mouseMoved(), TextPopup::show(), textPopup, Rect::x, x, Rect::y, and y.

◆ mousePressed()

void Minimap::mousePressed ( MouseEvent event)
virtual

Starts window resizing when appropriate.

Reimplemented from Window.

Definition at line 482 of file minimap.cpp.

483 {
484  if (event.getButton() == MouseButton::RIGHT)
485  return;
486  Window::mousePressed(event);
487 }
MouseButtonT getButton() const
Definition: mouseevent.h:116
void mousePressed(MouseEvent &event)
Definition: window.cpp:836

References MouseEvent::getButton(), Window::mousePressed(), and MouseButton::RIGHT.

◆ mouseReleased()

void Minimap::mouseReleased ( MouseEvent event)
virtual

When the mouse button has been let go, this ensures that the mouse custom cursor is restored back to it's standard image.

Reimplemented from Window.

Definition at line 489 of file minimap.cpp.

490 {
491  Window::mouseReleased(event);
492 
493  if ((localPlayer == nullptr) || (popupManager == nullptr))
494  return;
495 
496  if (event.getButton() == MouseButton::LEFT)
497  {
498  int x = event.getX();
499  int y = event.getY();
500  screenToMap(x, y);
501 
503  }
504  else if (event.getButton() == MouseButton::RIGHT)
505  {
506  int x = event.getX();
507  int y = event.getY();
508  screenToMap(x, y);
510  viewport->mMouseY,
511  x, y,
512  true);
513  }
514 }
bool navigateTo(const int x, const int y)
void screenToMap(int &x, int &y)
Definition: minimap.cpp:531
void showMapPopup(const int x, const int y, const int x2, const int y2, const bool isMinimap)
Definition: popupmenu.cpp:805
int mMouseX
Definition: viewport.h:154
int mMouseY
Definition: viewport.h:155
void mouseReleased(MouseEvent &event)
Definition: window.cpp:907
PopupManager * popupManager
PopupMenu * popupMenu
Definition: popupmenu.cpp:103

References MouseEvent::getButton(), MouseButton::LEFT, localPlayer, Viewport::mMouseX, Viewport::mMouseY, Window::mouseReleased(), LocalPlayer::navigateTo(), popupManager, popupMenu, MouseButton::RIGHT, screenToMap(), PopupMenu::showMapPopup(), viewport, x, and y.

◆ optionChanged()

void Minimap::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 538 of file minimap.cpp.

539 {
540  if (name == "autoresizeminimaps")
541  mAutoResize = config.getBoolValue("autoresizeminimaps");
542 }

References config, Configuration::getBoolValue(), and mAutoResize.

◆ safeDraw()

void Minimap::safeDraw ( Graphics *const  graphics)
virtual

Reimplemented from Window.

Definition at line 262 of file minimap.cpp.

263 {
264  BLOCK_START("Minimap::draw")
265 
266  Window::safeDraw(graphics);
267  draw2(graphics);
268 }
void safeDraw(Graphics *const graphics)
Definition: minimap.cpp:262

References BLOCK_START, draw2(), and Window::safeDraw().

◆ screenToMap()

void Minimap::screenToMap ( int &  x,
int &  y 
)

Definition at line 531 of file minimap.cpp.

532 {
533  const Rect a = getChildrenArea();
536 }

References Window::getChildrenArea(), mHeightProportion, mMapOriginX, mMapOriginY, mWidthProportion, Rect::x, x, Rect::y, and y.

Referenced by mouseReleased().

◆ setMap()

void Minimap::setMap ( const Map *const  map)

Sets the map image that should be displayed.

< Surface is in system memory

Definition at line 119 of file minimap.cpp.

120 {
121  BLOCK_START("Minimap::setMap")
122  std::string caption;
123 
124  if (map != nullptr)
125  caption = map->getName();
126 
127  if (caption.empty())
128  {
129  // TRANSLATORS: mini map window name
130  caption = _("Map");
131  }
132 
133  setCaption(caption);
134  deleteMapImage();
135 
136  if (map != nullptr)
137  {
138  if (config.getBoolValue("showExtMinimaps"))
139  {
140  SDL_Surface *const surface = MSDL_CreateRGBSurface(SDL_SWSURFACE,
141  map->getWidth(), map->getHeight(), 32,
142  0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000);
143  if (surface == nullptr)
144  {
145  if (!isSticky())
147  BLOCK_END("Minimap::setMap")
148  return;
149  }
150 
151  // I'm not sure if the locks are necessary since it's a SWSURFACE
152  SDL_LockSurface(surface);
153  int* data = static_cast<int*>(surface->pixels);
154  if (data == nullptr)
155  {
156  if (!isSticky())
158  BLOCK_END("Minimap::setMap")
159  return;
160  }
161  const int size = surface->h * surface->w;
162  const int mask = (BlockMask::WALL |
163  BlockMask::AIR |
164  BlockMask::WATER |
166 
167  for (int ptr = 0; ptr < size; ptr ++)
168  {
169  *(data ++) = (map->mMetaTiles[ptr].blockmask & mask) != 0 ?
170  0x0 : 0x00ffffff;
171  }
172 
173  SDL_UnlockSurface(surface);
174 
175  mMapImage = imageHelper->loadSurface(surface);
176  mMapImage->setAlpha(settings.guiAlpha);
177  mCustomMapImage = true;
178  MSDL_FreeSurface(surface);
179  }
180  else
181  {
182  std::string tempname = pathJoin(paths.getStringValue("minimaps"),
183  map->getFilename()).append(".png");
184 
185  std::string minimapName = map->getProperty("minimap",
186  std::string());
187 
188  if (minimapName.empty() && VirtFs::exists(tempname))
189  minimapName = tempname;
190 
191  if (minimapName.empty())
192  {
193  tempname = pathJoin("graphics/minimaps",
194  map->getFilename()).append(".png");
195  if (VirtFs::exists(tempname))
196  minimapName = STD_MOVE(tempname);
197  }
198 
199  if (!minimapName.empty())
200  mMapImage = Loader::getImage(minimapName);
201  else
202  mMapImage = nullptr;
203  mCustomMapImage = false;
204  }
205  }
206 
207  if ((mMapImage != nullptr) && (map != nullptr))
208  {
209  const int width = mMapImage->mBounds.w + 2 * getPadding();
210  const int height = mMapImage->mBounds.h
212  const int mapWidth = mMapImage->mBounds.w < 100 ? width : 100;
213  const int mapHeight = mMapImage->mBounds.h < 100 ? height : 100;
214  const int minWidth = mapWidth > 310 ? 310 : mapWidth;
215  const int minHeight = mapHeight > 220 ? 220 : mapHeight;
216 
217  setMinWidth(minWidth);
218  setMinHeight(minHeight);
219 
220  mWidthProportion = static_cast<float>(
221  mMapImage->mBounds.w) / static_cast<float>(map->getWidth());
222  mHeightProportion = static_cast<float>(
223  mMapImage->mBounds.h) / static_cast<float>(map->getHeight());
224 
225  setMaxWidth(width);
226  setMaxHeight(height);
227  if (mAutoResize)
228  {
229  setWidth(width);
230  setHeight(height);
231  }
232 
233  const Rect &rect = mDimension;
234  setDefaultSize(rect.x, rect.y, rect.width, rect.height);
236 
237  if (mShow)
239  }
240  else
241  {
242  if (!isSticky())
244  }
245  BLOCK_END("Minimap::setMap")
246 }
std::string getStringValue(const std::string &key) const
virtual Image * loadSurface(SDL_Surface *const)
Definition: imagehelper.h:73
const std::string getFilename() const
Definition: map.cpp:848
int getHeight() const
Definition: map.h:172
MetaTile *const mMetaTiles
Definition: map.h:417
int getWidth() const
Definition: map.h:166
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:59
int width
Definition: rect.h:219
int height
Definition: rect.h:224
float guiAlpha
Definition: settings.h:131
void setWidth(const int width)
Definition: widget.cpp:133
void setHeight(const int height)
Definition: widget.cpp:140
void setMaxWidth(const int width)
Definition: window.cpp:617
unsigned int getTitleBarHeight() const
Definition: window.h:522
virtual void resetToDefaultSize()
Definition: window.cpp:1259
void setCaption(const std::string &caption)
Definition: window.h:531
void setMinHeight(const int height)
Definition: window.cpp:604
void setMaxHeight(const int height)
Definition: window.cpp:622
void setMinWidth(const int width)
Definition: window.cpp:591
int getPadding() const
Definition: window.h:504
Configuration paths
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
Definition: debug.h:55
#define MSDL_FreeSurface(surface)
Definition: debug.h:54
ImageHelper * imageHelper
Definition: imagehelper.cpp:44
uint32_t data
@ PLAYERWALL
Definition: blockmask.h:36
int size()
Definition: emotedb.cpp:306
const std::string & getName(const int id)
Definition: groupdb.cpp:344
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:86
bool exists(std::string name)
Definition: fs.cpp:124
std::string empty
Definition: podict.cpp:26
Settings settings
Definition: settings.cpp:32
#define STD_MOVE(var)
Definition: stdmove.h:28
std::string pathJoin(std::string str1, const std::string &str2)
unsigned char blockmask
Definition: metatile.h:52
const bool Visible_false
Definition: visible.h:30
const bool Visible_true
Definition: visible.h:30

References _, BlockMask::AIR, BLOCK_END, BLOCK_START, MetaTile::blockmask, config, data, deleteMapImage(), VirtFs::exists(), Configuration::getBoolValue(), Map::getFilename(), Map::getHeight(), Loader::getImage(), Map::getName(), Window::getPadding(), Properties::getProperty(), Configuration::getStringValue(), Window::getTitleBarHeight(), Map::getWidth(), Settings::guiAlpha, Rect::height, imageHelper, Window::isSticky(), ImageHelper::loadSurface(), mAutoResize, mCustomMapImage, Widget::mDimension, mHeightProportion, mMapImage, Map::mMetaTiles, MSDL_CreateRGBSurface, MSDL_FreeSurface, mShow, mWidthProportion, pathJoin(), paths, BlockMask::PLAYERWALL, Window::resetToDefaultSize(), Window::setCaption(), Window::setDefaultSize(), Widget::setHeight(), Window::setMaxHeight(), Window::setMaxWidth(), Window::setMinHeight(), Window::setMinWidth(), settings, Window::setVisible(), Widget::setWidth(), EmoteDB::size(), STD_MOVE, Visible_false, Visible_true, BlockMask::WALL, BlockMask::WATER, Rect::width, Rect::x, and Rect::y.

Referenced by Game::changeMap().

◆ toggle()

void Minimap::toggle ( )

Toggles the displaying of the minimap.

Definition at line 248 of file minimap.cpp.

249 {
252 }
bool isWindowVisible() const
Definition: window.h:484

References fromBool, Window::isSticky(), Window::isWindowVisible(), mShow, and Window::setVisible().

Field Documentation

◆ mAutoResize

bool Minimap::mAutoResize
private

Definition at line 90 of file minimap.h.

Referenced by optionChanged(), and setMap().

◆ mCustomMapImage

bool Minimap::mCustomMapImage
private

Definition at line 89 of file minimap.h.

Referenced by deleteMapImage(), and setMap().

◆ mHeightProportion

float Minimap::mHeightProportion
private

Definition at line 85 of file minimap.h.

Referenced by draw2(), screenToMap(), and setMap().

◆ mMapImage

Image* Minimap::mMapImage
private

Definition at line 86 of file minimap.h.

Referenced by deleteMapImage(), draw2(), and setMap().

◆ mMapOriginX

int Minimap::mMapOriginX
private

Definition at line 87 of file minimap.h.

Referenced by draw2(), and screenToMap().

◆ mMapOriginY

int Minimap::mMapOriginY
private

Definition at line 88 of file minimap.h.

Referenced by draw2(), and screenToMap().

◆ mShow

bool Minimap::mShow = true
staticprivate

Definition at line 91 of file minimap.h.

Referenced by Minimap(), setMap(), toggle(), and ~Minimap().

◆ mWidthProportion

float Minimap::mWidthProportion
private

Definition at line 84 of file minimap.h.

Referenced by draw2(), screenToMap(), and setMap().


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