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 40 of file minimap.h.

Constructor & Destructor Documentation

◆ Minimap()

Minimap::Minimap ( )

Definition at line 64 of file minimap.cpp.

64  :
65  // TRANSLATORS: mini map window name
66  Window(_("Map"), Modal_false, nullptr, "map.xml"),
67  mWidthProportion(0.5),
68  mHeightProportion(0.5),
69  mMapImage(nullptr),
70  mMapOriginX(0),
71  mMapOriginY(0),
72  mCustomMapImage(false),
73  mAutoResize(config.getBoolValue("autoresizeminimaps"))
74 {
75  setWindowName("Minimap");
76  mShow = config.getValueBool(getWindowName() + "Show", true);
77 
78  config.addListener("autoresizeminimaps", this);
79 
80  setDefaultSize(5, 25, 100, 100);
81  // set this to false as the minimap window size is changed
82  // depending on the map size
83  setResizable(true);
84  if (setupWindow != nullptr)
86 
87  setDefaultVisible(true);
88  setSaveVisible(true);
89 
90  setStickyButton(true);
91  setSticky(false);
92 
95  enableVisibleSound(true);
96 }

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

Member Function Documentation

◆ deleteMapImage()

void Minimap::deleteMapImage ( )
private

Definition at line 106 of file minimap.cpp.

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

References Image::decRef(), 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 253 of file minimap.cpp.

254 {
255  BLOCK_START("Minimap::draw")
256 
257  Window::draw(graphics);
258  draw2(graphics);
259 }

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

◆ draw2()

void Minimap::draw2 ( Graphics *const  graphics)

Definition at line 269 of file minimap.cpp.

270 {
271  if (userPalette == nullptr ||
272  localPlayer == nullptr ||
273  viewport == nullptr)
274  {
275  BLOCK_END("Minimap::draw")
276  return;
277  }
278 
279  const Rect a = getChildrenArea();
280 
281  graphics->pushClipArea(a);
282 
283  if (actorManager == nullptr)
284  {
285  BLOCK_END("Minimap::draw")
286  return;
287  }
288 
289  mMapOriginX = 0;
290  mMapOriginY = 0;
291 
292  if (mMapImage != nullptr)
293  {
294  const SDL_Rect &rect = mMapImage->mBounds;
295  const int w = rect.w;
296  const int h = rect.h;
297  if (w > a.width || h > a.height)
298  {
299  mMapOriginX = (a.width / 2) - (localPlayer->mPixelX +
301 
302  mMapOriginY = (a.height / 2) - (localPlayer->mPixelY +
304 
305  const int minOriginX = a.width - w;
306  const int minOriginY = a.height - h;
307 
308  if (mMapOriginX < minOriginX)
309  mMapOriginX = minOriginX;
310  if (mMapOriginY < minOriginY)
311  mMapOriginY = minOriginY;
312  if (mMapOriginX > 0)
313  mMapOriginX = 0;
314  if (mMapOriginY > 0)
315  mMapOriginY = 0;
316  }
317 
319  }
320 
321  const ActorSprites &actors = actorManager->getAll();
322  FOR_EACH (ActorSpritesConstIterator, it, actors)
323  {
324  if (((*it) == nullptr) || (*it)->getType() == ActorType::FloorItem)
325  continue;
326 
327  const Being *const being = static_cast<const Being *>(*it);
328  if (being == nullptr)
329  continue;
330 
331  int dotSize = 2;
333 
334  if (being == localPlayer)
335  {
336  type = UserColorId::SELF;
337  dotSize = 3;
338  }
339  else if (being->isGM())
340  {
341  type = UserColorId::GM;
342  }
343  else if (being->getGuild() == localPlayer->getGuild()
344  || being->getGuildName() == localPlayer->getGuildName())
345  {
346  type = UserColorId::GUILD;
347  }
348  else
349  {
350  switch (being->getType())
351  {
352  case ActorType::Monster:
353  type = UserColorId::MONSTER;
354  break;
355 
356  case ActorType::Npc:
357  type = UserColorId::NPC;
358  break;
359 
360  case ActorType::Portal:
362  break;
363 
364  case ActorType::Pet:
365  type = UserColorId::PET;
366  break;
368  type = UserColorId::MERCENARY;
369  break;
370 
373  break;
374 
376  type = UserColorId::SKILLUNIT;
377  break;
378  case ActorType::Avatar:
379  case ActorType::Unknown:
380  case ActorType::Player:
383  default:
384  continue;
385  }
386  }
387 
388  if (userPalette != nullptr)
389  graphics->setColor(userPalette->getColor(type, 255U));
390 
391  const int offsetHeight = CAST_S32(static_cast<float>(
392  dotSize - 1) * mHeightProportion);
393  const int offsetWidth = CAST_S32(static_cast<float>(
394  dotSize - 1) * mWidthProportion);
395  graphics->fillRectangle(Rect(
396  (being->mPixelX * mWidthProportion) / 32
397  + mMapOriginX - offsetWidth,
398  (being->mPixelY * mHeightProportion) / 32
399  + mMapOriginY - offsetHeight, dotSize, dotSize));
400  }
401 
402  if (localPlayer->isInParty())
403  {
404  const Party *const party = localPlayer->getParty();
405  if (party != nullptr)
406  {
407  const PartyMember *const m = party->getMember(
408  localPlayer->getName());
409  const Party::MemberList *const members = party->getMembers();
410  if (m != nullptr)
411  {
412  const std::string curMap = m->getMap();
413  Party::MemberList::const_iterator it = members->begin();
414  const Party::MemberList::const_iterator
415  it_end = members->end();
416  while (it != it_end)
417  {
418  const PartyMember *const member = *it;
419  if ((member != nullptr) && member->getMap() == curMap
420  && member->getOnline() && member != m)
421  {
422  if (userPalette != nullptr)
423  {
424  graphics->setColor(userPalette->getColor(
425  UserColorId::PARTY, 255U));
426  }
427 
428  const int offsetHeight = CAST_S32(
430  const int offsetWidth = CAST_S32(
432 
433  graphics->fillRectangle(Rect(
434  CAST_S32(member->getX()
435  * mWidthProportion) + mMapOriginX - offsetWidth,
436  CAST_S32(member->getY()
437  * mHeightProportion) + mMapOriginY - offsetHeight,
438  2, 2));
439  }
440  ++ it;
441  }
442  }
443  }
444  }
445 
446  const int gw = graphics->getWidth();
447  const int gh = graphics->getHeight();
448  int x = (localPlayer->mPixelX - (gw / 2)
450  * mWidthProportion / 32 + mMapOriginX;
451  int y = (localPlayer->mPixelY - (gh / 2)
454 
455  const int w = CAST_S32(static_cast<float>(
456  gw) * mWidthProportion / 32);
457  const int h = CAST_S32(static_cast<float>(
458  gh) * mHeightProportion / 32);
459 
460  if (w <= a.width)
461  {
462  if (x < 0 && (w != 0))
463  x = 0;
464  if (x + w > a.width)
465  x = a.width - w;
466  }
467  if (h <= a.height)
468  {
469  if (y < 0 && (h != 0))
470  y = 0;
471  if (y + h > a.height)
472  y = a.height - h;
473  }
474 
475  graphics->setColor(userPalette->getColor(UserColorId::PC, 255U));
476  graphics->drawRectangle(Rect(x, y, w, h));
477  graphics->popClipArea();
478  BLOCK_END("Minimap::draw")
479 }

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, Image::mBounds, ActorType::Mercenary, UserColorId::MERCENARY, mHeightProportion, mMapImage, mMapOriginX, mMapOriginY, ActorType::Monster, UserColorId::MONSTER, Actor::mPixelX, Actor::mPixelY, mWidthProportion, ActorType::Npc, UserColorId::NPC, party, UserColorId::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 524 of file minimap.cpp.

525 {
526  Window::mouseExited(event);
527  textPopup->hide();
528 }

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 515 of file minimap.cpp.

516 {
517  Window::mouseMoved(event);
518  const int x = event.getX();
519  const int y = event.getY();
520  const Rect &rect = mDimension;
521  textPopup->show(x + rect.x, y + rect.y, mCaption);
522 }

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

◆ mousePressed()

void Minimap::mousePressed ( MouseEvent event)
virtual

Starts window resizing when appropriate.

Reimplemented from Window.

Definition at line 481 of file minimap.cpp.

482 {
483  if (event.getButton() == MouseButton::RIGHT)
484  return;
485  Window::mousePressed(event);
486 }

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 488 of file minimap.cpp.

489 {
490  Window::mouseReleased(event);
491 
492  if ((localPlayer == nullptr) || (popupManager == nullptr))
493  return;
494 
495  if (event.getButton() == MouseButton::LEFT)
496  {
497  int x = event.getX();
498  int y = event.getY();
499  screenToMap(x, y);
500 
502  }
503  else if (event.getButton() == MouseButton::RIGHT)
504  {
505  int x = event.getX();
506  int y = event.getY();
507  screenToMap(x, y);
509  viewport->mMouseY,
510  x, y,
511  true);
512  }
513 }

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 537 of file minimap.cpp.

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

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

◆ safeDraw()

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

Reimplemented from Window.

Definition at line 261 of file minimap.cpp.

262 {
263  BLOCK_START("Minimap::draw")
264 
265  Window::safeDraw(graphics);
266  draw2(graphics);
267 }

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

◆ screenToMap()

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

Definition at line 530 of file minimap.cpp.

531 {
532  const Rect a = getChildrenArea();
535 }

References Window::getChildrenArea(), mHeightProportion, mMapOriginX, mMapOriginY, mWidthProportion, x, Rect::x, y, and Rect::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 118 of file minimap.cpp.

119 {
120  BLOCK_START("Minimap::setMap")
121  std::string caption;
122 
123  if (map != nullptr)
124  caption = map->getName();
125 
126  if (caption.empty())
127  {
128  // TRANSLATORS: mini map window name
129  caption = _("Map");
130  }
131 
132  setCaption(caption);
133  deleteMapImage();
134 
135  if (map != nullptr)
136  {
137  if (config.getBoolValue("showExtMinimaps"))
138  {
139  SDL_Surface *const surface = MSDL_CreateRGBSurface(SDL_SWSURFACE,
140  map->getWidth(), map->getHeight(), 32,
141  0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000);
142  if (surface == nullptr)
143  {
144  if (!isSticky())
146  BLOCK_END("Minimap::setMap")
147  return;
148  }
149 
150  // I'm not sure if the locks are necessary since it's a SWSURFACE
151  SDL_LockSurface(surface);
152  int* data = static_cast<int*>(surface->pixels);
153  if (data == nullptr)
154  {
155  if (!isSticky())
157  BLOCK_END("Minimap::setMap")
158  return;
159  }
160  const int size = surface->h * surface->w;
161  const int mask = (BlockMask::WALL |
162  BlockMask::AIR |
163  BlockMask::WATER |
165 
166  for (int ptr = 0; ptr < size; ptr ++)
167  {
168  *(data ++) = (map->mMetaTiles[ptr].blockmask & mask) != 0 ?
169  0x0 : 0x00ffffff;
170  }
171 
172  SDL_UnlockSurface(surface);
173 
174  mMapImage = imageHelper->loadSurface(surface);
176  mCustomMapImage = true;
177  MSDL_FreeSurface(surface);
178  }
179  else
180  {
181  std::string tempname = pathJoin(paths.getStringValue("minimaps"),
182  map->getFilename()).append(".png");
183 
184  std::string minimapName = map->getProperty("minimap",
185  std::string());
186 
187  if (minimapName.empty() && VirtFs::exists(tempname))
188  minimapName = tempname;
189 
190  if (minimapName.empty())
191  {
192  tempname = pathJoin("graphics/minimaps",
193  map->getFilename()).append(".png");
194  if (VirtFs::exists(tempname))
195  minimapName = STD_MOVE(tempname);
196  }
197 
198  if (!minimapName.empty())
199  mMapImage = Loader::getImage(minimapName);
200  else
201  mMapImage = nullptr;
202  mCustomMapImage = false;
203  }
204  }
205 
206  if ((mMapImage != nullptr) && (map != nullptr))
207  {
208  const int width = mMapImage->mBounds.w + 2 * getPadding();
209  const int height = mMapImage->mBounds.h
211  const int mapWidth = mMapImage->mBounds.w < 100 ? width : 100;
212  const int mapHeight = mMapImage->mBounds.h < 100 ? height : 100;
213  const int minWidth = mapWidth > 310 ? 310 : mapWidth;
214  const int minHeight = mapHeight > 220 ? 220 : mapHeight;
215 
216  setMinWidth(minWidth);
217  setMinHeight(minHeight);
218 
219  mWidthProportion = static_cast<float>(
220  mMapImage->mBounds.w) / static_cast<float>(map->getWidth());
221  mHeightProportion = static_cast<float>(
222  mMapImage->mBounds.h) / static_cast<float>(map->getHeight());
223 
224  setMaxWidth(width);
225  setMaxHeight(height);
226  if (mAutoResize)
227  {
228  setWidth(width);
229  setHeight(height);
230  }
231 
232  const Rect &rect = mDimension;
233  setDefaultSize(rect.x, rect.y, rect.width, rect.height);
235 
236  if (mShow)
238  }
239  else
240  {
241  if (!isSticky())
243  }
244  BLOCK_END("Minimap::setMap")
245 }

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, Image::mBounds, mCustomMapImage, Widget::mDimension, mHeightProportion, mMapImage, Map::mMetaTiles, MSDL_CreateRGBSurface, MSDL_FreeSurface, mShow, mWidthProportion, pathJoin(), paths, BlockMask::PLAYERWALL, Window::resetToDefaultSize(), Image::setAlpha(), 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 247 of file minimap.cpp.

248 {
251 }

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

Field Documentation

◆ mAutoResize

bool Minimap::mAutoResize
private

Definition at line 89 of file minimap.h.

Referenced by optionChanged(), and setMap().

◆ mCustomMapImage

bool Minimap::mCustomMapImage
private

Definition at line 88 of file minimap.h.

Referenced by deleteMapImage(), and setMap().

◆ mHeightProportion

float Minimap::mHeightProportion
private

Definition at line 84 of file minimap.h.

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

◆ mMapImage

Image* Minimap::mMapImage
private

Definition at line 85 of file minimap.h.

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

◆ mMapOriginX

int Minimap::mMapOriginX
private

Definition at line 86 of file minimap.h.

Referenced by draw2(), and screenToMap().

◆ mMapOriginY

int Minimap::mMapOriginY
private

Definition at line 87 of file minimap.h.

Referenced by draw2(), and screenToMap().

◆ mShow

bool Minimap::mShow = true
staticprivate

Definition at line 90 of file minimap.h.

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

◆ mWidthProportion

float Minimap::mWidthProportion
private

Definition at line 83 of file minimap.h.

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


The documentation for this class was generated from the following files:
VirtFs::exists
bool exists(std::string name)
Definition: fs.cpp:123
Window::getChildrenArea
Rect getChildrenArea()
Definition: window.cpp:1472
Graphics::drawRectangle
virtual void drawRectangle(const Rect &rectangle)=0
Minimap::mCustomMapImage
bool mCustomMapImage
Definition: minimap.h:88
ActorType::Unknown
@ Unknown
Definition: actortype.h:29
ActorType::Elemental
@ Elemental
Definition: actortype.h:40
Window::mouseMoved
void mouseMoved(MouseEvent &event)
Definition: window.cpp:966
Avatar::getX
int getX() const
Definition: avatar.h:125
CHECKLISTENERS
#define CHECKLISTENERS
Definition: localconsts.h:276
Rect::height
int height
Definition: rect.h:223
Viewport::getCameraRelativeX
int getCameraRelativeX() const
Definition: viewport.h:139
Window::setStickyButton
void setStickyButton(const bool flag)
Definition: window.cpp:760
ActorType::Pet
@ Pet
Definition: actortype.h:36
Being::isGM
bool isGM() const
Definition: being.h:658
pushClipArea
void pushClipArea(const Rect &restrict area) restrict2 override final
Minimap::mAutoResize
bool mAutoResize
Definition: minimap.h:89
MouseButton::RIGHT
@ RIGHT
Definition: mousebutton.h:74
Window::setMinHeight
void setMinHeight(const int height)
Definition: window.cpp:603
Minimap::mShow
static bool mShow
Definition: minimap.h:90
Being::getParty
Party * getParty() const
Definition: being.h:329
Window::isWindowVisible
bool isWindowVisible() const
Definition: window.h:483
Map::getWidth
int getWidth() const
Definition: map.h:165
Window::setWindowName
void setWindowName(const std::string &name)
Definition: window.h:354
Minimap::deleteMapImage
void deleteMapImage()
Definition: minimap.cpp:106
Rect::y
int y
Definition: rect.h:213
Window::mCaption
std::string mCaption
Definition: window.h:607
Window
Definition: window.h:98
ActorType::Homunculus
@ Homunculus
Definition: actortype.h:38
paths
Configuration paths
Definition: configuration.cpp:55
settings
Settings settings
Definition: settings.cpp:31
imageHelper
ImageHelper * imageHelper
Definition: imagehelper.cpp:43
Being::getGuild
const Guild * getGuild(const std::string &guildName) const
Definition: being.cpp:1257
popupManager
PopupManager * popupManager
Definition: popupmanager.cpp:36
actorManager
ActorManager * actorManager
Definition: actormanager.cpp:80
Image::setAlpha
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
Window::mouseReleased
void mouseReleased(MouseEvent &event)
Definition: window.cpp:906
Minimap::mMapOriginX
int mMapOriginX
Definition: minimap.h:86
Window::setSticky
void setSticky(const bool sticky)
Definition: window.cpp:765
GroupDb::getName
const std::string & getName(const int id)
Definition: groupdb.cpp:343
UserColorId::PET
@ PET
Definition: usercolorid.h:44
PopupMenu::showMapPopup
void showMapPopup(const int x, const int y, const int x2, const int y2, const bool isMinimap)
Definition: popupmenu.cpp:804
Visible_true
const bool Visible_true
Definition: visible.h:29
UserColorIdT
UserColorId ::T UserColorIdT
Definition: usercolorid.h:98
Minimap::mHeightProportion
float mHeightProportion
Definition: minimap.h:84
Avatar::getOnline
bool getOnline() const
Definition: avatar.h:80
UserColorId::HOMUNCULUS
@ HOMUNCULUS
Definition: usercolorid.h:46
ActorType::Avatar
@ Avatar
Definition: actortype.h:35
BlockMask::WATER
@ WATER
Definition: blockmask.h:32
SetupWindow::registerWindowForReset
void registerWindowForReset(Window *const window)
Definition: setupwindow.cpp:272
Window::isSticky
bool isSticky() const
Definition: window.h:252
UserColorId::GM
@ GM
Definition: usercolorid.h:41
fromBool
#define fromBool(val, name)
Definition: booldefines.h:48
Window::resetToDefaultSize
virtual void resetToDefaultSize()
Definition: window.cpp:1258
Map::getFilename
const std::string getFilename() const
Definition: map.cpp:847
ActorSpritesConstIterator
ActorSprites::const_iterator ActorSpritesConstIterator
Definition: actormanager.h:60
pathJoin
std::string pathJoin(std::string str1, const std::string &str2)
Definition: stringutils.cpp:1036
MSDL_FreeSurface
#define MSDL_FreeSurface(surface)
Definition: debug.h:53
Minimap::mMapOriginY
int mMapOriginY
Definition: minimap.h:87
Viewport::mMouseY
int mMouseY
Definition: viewport.h:154
PartyMember
Definition: party.h:36
UserColorId::SELF
@ SELF
Definition: usercolorid.h:40
Window::Window
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
ActorType::Player
@ Player
Definition: actortype.h:30
bool
userPalette
UserPalette * userPalette
Definition: userpalette.cpp:33
UserColorId::NPC
@ NPC
Definition: usercolorid.h:42
ActorType::Mercenary
@ Mercenary
Definition: actortype.h:37
Configuration::addListener
void addListener(const std::string &key, ConfigListener *const listener)
Definition: configuration.cpp:905
Modal_false
const bool Modal_false
Definition: modal.h:29
Graphics::getWidth
int getWidth() const
Definition: graphics.cpp:642
Configuration::setValue
void setValue(const std::string &key, const std::string &value)
Definition: configuration.cpp:238
Minimap::mMapImage
Image * mMapImage
Definition: minimap.h:85
if
if(!vert) return
Widget::mDimension
Rect mDimension
Definition: widget.h:1100
Window::enableVisibleSound
void enableVisibleSound(bool b)
Definition: window.h:480
Window::getWindowName
const std::string & getWindowName() const
Definition: window.h:360
Being::isInParty
bool isInParty() const
Definition: being.h:320
Minimap::draw2
void draw2(Graphics *const graphics)
Definition: minimap.cpp:269
localPlayer
LocalPlayer * localPlayer
Definition: localplayer.cpp:108
Window::setDefaultSize
void setDefaultSize()
Definition: window.cpp:1197
Actor::mPixelY
int mPixelY
Definition: actor.h:133
Window::getPadding
int getPadding() const
Definition: window.h:503
Avatar::getY
int getY() const
Definition: avatar.h:131
UserColorId::MERCENARY
@ MERCENARY
Definition: usercolorid.h:45
Party::MemberList
std::vector< PartyMember * > MemberList
Definition: party.h:156
Being::getName
const std::string & getName() const
Definition: being.h:231
Settings::guiAlpha
float guiAlpha
Definition: settings.h:130
Rect::width
int width
Definition: rect.h:218
Widget::setWidth
void setWidth(const int width)
Definition: widget.cpp:132
UserColorId::SKILLUNIT
@ SKILLUNIT
Definition: usercolorid.h:47
Visible_false
const bool Visible_false
Definition: visible.h:29
data
uint32_t data
Definition: maptypeproperty2.h:3
Loader::getImage
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
Minimap::draw
void draw(Graphics *const graphics)
Definition: minimap.cpp:253
Window::getTitleBarHeight
unsigned int getTitleBarHeight() const
Definition: window.h:521
Widget::setHeight
void setHeight(const int height)
Definition: widget.cpp:139
Viewport::mMouseX
int mMouseX
Definition: viewport.h:153
UserColorId::PORTAL_HIGHLIGHT
@ PORTAL_HIGHLIGHT
Definition: usercolorid.h:78
BlockMask::WALL
@ WALL
Definition: blockmask.h:30
Popup::hide
void hide()
Definition: popup.cpp:264
Actor::mPixelX
int mPixelX
Definition: actor.h:132
x
x
Definition: graphics_calcImageRect.hpp:72
Party
Definition: party.h:61
Being
Definition: being.h:93
Window::setMaxHeight
void setMaxHeight(const int height)
Definition: window.cpp:621
Configuration::getStringValue
std::string getStringValue(const std::string &key) const
Definition: configuration.cpp:487
BlockMask
Definition: blockmask.h:26
popupMenu
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
Window::setDefaultVisible
void setDefaultVisible(const bool save)
Definition: window.h:287
ConfigurationObject::getValueBool
bool getValueBool(const std::string &key, const bool deflt) const
Definition: configuration.cpp:292
Window::mouseExited
void mouseExited(MouseEvent &event)
Definition: window.cpp:923
ActorSprites
std::set< ActorSprite * > ActorSprites
Definition: actormanager.h:56
ActorManager::getAll
const ActorSprites & getAll() const A_CONST
Definition: actormanager.cpp:940
Viewport::getCameraRelativeY
int getCameraRelativeY() const
Definition: viewport.h:142
Window::setMaxWidth
void setMaxWidth(const int width)
Definition: window.cpp:616
Window::loadWindowState
void loadWindowState()
Definition: window.cpp:1086
BlockMask::PLAYERWALL
@ PLAYERWALL
Definition: blockmask.h:35
textPopup
TextPopup * textPopup
Definition: textpopup.cpp:32
Properties::getProperty
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58
Minimap::mWidthProportion
float mWidthProportion
Definition: minimap.h:83
Window::setResizable
void setResizable(const bool resize)
Definition: window.cpp:626
MSDL_CreateRGBSurface
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
Definition: debug.h:54
viewport
Viewport * viewport
Definition: viewport.cpp:35
Image::mBounds
SDL_Rect mBounds
Definition: image.h:216
Avatar::getMap
std::string getMap() const
Definition: avatar.h:119
config
Configuration config
Definition: configuration.cpp:51
Window::setCaption
void setCaption(const std::string &caption)
Definition: window.h:530
Map::getHeight
int getHeight() const
Definition: map.h:171
MetaTile::blockmask
unsigned char blockmask
Definition: metatile.h:51
EmoteDB::size
int size()
Definition: emotedb.cpp:305
Graphics::setColor
virtual void setColor(const Color &color)
Definition: graphics.h:319
Minimap::safeDraw
void safeDraw(Graphics *const graphics)
Definition: minimap.cpp:261
ActorType::FloorItem
@ FloorItem
Definition: actortype.h:33
empty
std::string empty
Definition: podict.cpp:25
Being::getType
ActorTypeT getType() const
Definition: being.h:115
UserColorId::GUILD
@ GUILD
Definition: usercolorid.h:49
ActorType::Npc
@ Npc
Definition: actortype.h:31
ActorType::Monster
@ Monster
Definition: actortype.h:32
Configuration::removeListeners
void removeListeners(ConfigListener *const listener)
Definition: configuration.cpp:938
BlockMask::AIR
@ AIR
Definition: blockmask.h:31
std
Definition: mseprimitives.h:398
Rect
Definition: rect.h:72
setupWindow
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
STD_MOVE
#define STD_MOVE(var)
Definition: stdmove.h:27
UserPalette::getColor
const Color & getColor(UserColorIdT type, const unsigned int alpha)
Definition: userpalette.h:159
BLOCK_START
#define BLOCK_START(name)
Definition: perfomance.h:78
UserColorId::PARTY
@ PARTY
Definition: usercolorid.h:48
BLOCK_END
#define BLOCK_END(name)
Definition: perfomance.h:79
CAST_S32
#define CAST_S32
Definition: cast.h:29
LocalPlayer::navigateTo
bool navigateTo(const int x, const int y)
Definition: localplayer.cpp:2123
Graphics::drawImage
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Window::setSaveVisible
void setSaveVisible(const bool save)
Definition: window.h:299
Being::getGuildName
const std::string & getGuildName() const
Definition: being.h:258
party
uint32_t party
Definition: maptypeproperty2.h:4
ImageHelper::loadSurface
virtual Image * loadSurface(SDL_Surface *const)
Definition: imagehelper.h:72
Graphics::fillRectangle
virtual void fillRectangle(const Rect &rectangle)=0
Map::mMetaTiles
MetaTile *const mMetaTiles
Definition: map.h:416
UserColorId::MONSTER
@ MONSTER
Definition: usercolorid.h:43
_
#define _(s)
Definition: gettext.h:34
MouseEvent::getButton
MouseButtonT getButton() const
Definition: mouseevent.h:115
Window::setVisible
virtual void setVisible(Visible visible)
Definition: window.cpp:777
TextPopup::show
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:56
Minimap::screenToMap
void screenToMap(int &x, int &y)
Definition: minimap.cpp:530
Graphics::getHeight
int getHeight() const
Definition: graphics.cpp:647
ActorType::Portal
@ Portal
Definition: actortype.h:34
y
y
Definition: graphics_calcImageRect.hpp:72
Rect::x
int x
Definition: rect.h:208
Graphics::popClipArea
virtual void popClipArea()
Definition: graphics.cpp:738
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Image::decRef
void decRef()
Definition: image.cpp:522
Window::mousePressed
void mousePressed(MouseEvent &event)
Definition: window.cpp:835
Configuration::getBoolValue
bool getBoolValue(const std::string &key) const
Definition: configuration.cpp:596
Window::setMinWidth
void setMinWidth(const int width)
Definition: window.cpp:590
ActorType::SkillUnit
@ SkillUnit
Definition: actortype.h:39
MouseButton::LEFT
@ LEFT
Definition: mousebutton.h:73
UserColorId::PC
@ PC
Definition: usercolorid.h:39