ManaPlus
renamelistener.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
22 
23 #include "gui/viewport.h"
24 
26 #include "gui/windows/textdialog.h"
27 
28 #include "resources/map/map.h"
29 #include "resources/map/mapitem.h"
31 
32 #include "debug.h"
33 
36  mMapItemX(0),
37  mMapItemY(0),
39 {
40 }
41 
42 void RenameListener::setMapItem(const MapItem *const mapItem)
43 {
44  if (mapItem != nullptr)
45  {
46  mMapItemX = mapItem->getX();
47  mMapItemY = mapItem->getY();
48  }
49  else
50  {
51  mMapItemX = 0;
52  mMapItemY = 0;
53  }
54 }
55 
57 {
58  if (event.getId() == "ok" && (viewport != nullptr) && (mDialog != nullptr))
59  {
60  const Map *const map = viewport->getMap();
61  if (map == nullptr)
62  return;
63 
64  const SpecialLayer *const sl = map->getSpecialLayer();
65  MapItem *item = nullptr;
66  if (sl != nullptr)
67  {
68  item = sl->getTile(mMapItemX, mMapItemY);
69  if (item != nullptr)
70  item->setComment(mDialog->getText());
71  }
72  item = map->findPortalXY(mMapItemX, mMapItemY);
73  if (item != nullptr)
74  item->setComment(mDialog->getText());
75 
76  if (socialWindow != nullptr)
78  }
79  mDialog = nullptr;
80 }
RenameListener::mMapItemY
int mMapItemY
Definition: renamelistener.h:47
SpecialLayer::getTile
MapItem * getTile(const int x, const int y) const
Definition: speciallayer.cpp:56
Ea::NpcRecv::mDialog
NpcDialog * mDialog
Definition: npcrecv.cpp:41
MapItem::getX
int getX() const
Definition: mapitem.h:61
Map::getSpecialLayer
SpecialLayer * getSpecialLayer() const
Definition: map.h:240
ActionEvent
Definition: actionevent.h:96
RenameListener::setMapItem
void setMapItem(const MapItem *const mapItem)
Definition: renamelistener.cpp:42
renamelistener.h
TextDialog::getText
const std::string & getText() const
Definition: textdialog.cpp:123
MapItem
Definition: mapitem.h:31
RenameListener::mDialog
TextDialog * mDialog
Definition: renamelistener.h:48
MapItem::setComment
void setComment(const std::string &comment)
Definition: mapitem.h:70
socialWindow
SocialWindow * socialWindow
Definition: socialwindow.cpp:48
MapItem::getY
int getY() const
Definition: mapitem.h:64
ActionListener
Definition: actionlistener.h:77
nullptr
#define nullptr
Definition: localconsts.h:44
mapitem.h
speciallayer.h
viewport
Viewport * viewport
Definition: viewport.cpp:35
ActionEvent::getId
const std::string & getId() const
Definition: actionevent.h:121
SocialWindow::updatePortalNames
void updatePortalNames()
Definition: socialwindow.cpp:548
Viewport::getMap
Map * getMap() const
Definition: viewport.h:134
SpecialLayer
Definition: speciallayer.h:33
RenameListener::action
void action(const ActionEvent &event)
Definition: renamelistener.cpp:56
Map::findPortalXY
MapItem * findPortalXY(const int x, const int y) const
Definition: map.cpp:1337
socialwindow.h
Map
Definition: map.h:71
RenameListener::RenameListener
RenameListener()
Definition: renamelistener.cpp:34
RenameListener::mMapItemX
int mMapItemX
Definition: renamelistener.h:46
debug.h
textdialog.h