ManaPlus
Functions | Variables
Ea::NpcRecv Namespace Reference

Functions

void processNpcChoice (Net::MessageIn &msg)
 
void processNpcMessage (Net::MessageIn &msg)
 
void processNpcClose (Net::MessageIn &msg)
 
void processNpcNext (Net::MessageIn &msg)
 
void processNpcIntInput (Net::MessageIn &msg)
 
void processNpcStrInput (Net::MessageIn &msg)
 
void processNpcCommand (Net::MessageIn &msg)
 
void processChangeTitle (Net::MessageIn &msg)
 

Variables

NpcDialogmDialog = 0
 
bool mRequestLang = false
 

Function Documentation

◆ processChangeTitle()

void Ea::NpcRecv::processChangeTitle ( Net::MessageIn msg)

Definition at line 235 of file npcrecv.cpp.

236 {
237  msg.readInt16("len");
239  mRequestLang = false;
240  if (mDialog != nullptr)
241  {
242  const std::string str = msg.readString(-1, "title");
243  mDialog->setCaption(str);
244  }
245 }
virtual BeingId getNpc(Net::MessageIn &msg, const NpcActionT action)=0
void setCaption(const std::string &caption)
Definition: window.h:531
bool msg(InputEvent &event)
Definition: chat.cpp:39
NpcDialog * mDialog
Definition: npcrecv.cpp:42
bool mRequestLang
Definition: npcrecv.cpp:43
Net::NpcHandler * npcHandler
Definition: net.cpp:93

References Net::NpcHandler::getNpc(), mDialog, mRequestLang, Actions::msg(), npcHandler, NpcAction::Other, and Window::setCaption().

◆ processNpcChoice()

void Ea::NpcRecv::processNpcChoice ( Net::MessageIn msg)

Definition at line 46 of file npcrecv.cpp.

47 {
48  msg.readInt16("len");
50  mRequestLang = false;
51 
52  if (mDialog != nullptr)
53  {
55  mDialog->parseListItems(msg.readString(msg.getLength() - 8,
56  "select items"));
57  }
58  else
59  {
60  msg.readString(msg.getLength() - 8, "select items");
61  }
62 }
void parseListItems(const std::string &itemString)
Definition: npcdialog.cpp:706
void choiceRequest()
Definition: npcdialog.cpp:686

References NpcDialog::choiceRequest(), Net::NpcHandler::getNpc(), mDialog, mRequestLang, Actions::msg(), npcHandler, NpcAction::Other, and NpcDialog::parseListItems().

◆ processNpcClose()

void Ea::NpcRecv::processNpcClose ( Net::MessageIn msg)

Definition at line 78 of file npcrecv.cpp.

79 {
80  // Show the close button
82  mRequestLang = false;
83  if (mDialog != nullptr)
85 }
void showCloseButton()
Definition: npcdialog.cpp:313

References NpcAction::Close, Net::NpcHandler::getNpc(), mDialog, mRequestLang, Actions::msg(), npcHandler, and NpcDialog::showCloseButton().

◆ processNpcCommand()

void Ea::NpcRecv::processNpcCommand ( Net::MessageIn msg)

Definition at line 120 of file npcrecv.cpp.

121 {
122  const BeingId npcId = npcHandler->getNpc(msg, NpcAction::Other);
123  mRequestLang = false;
124 
125  const int cmd = msg.readInt16("cmd");
126  const BeingId id = msg.readBeingId("id");
127  const int x = msg.readInt16("x");
128  const int y = msg.readInt16("y");
129  switch (cmd)
130  {
131  case 0:
132  mRequestLang = true;
133  break;
134 
135  case 1:
136  if (viewport != nullptr)
137  viewport->moveCameraToActor(npcId, 0, 0);
138  break;
139 
140  case 2:
141  if (viewport != nullptr)
142  {
143  if (id == BeingId_zero)
145  else
146  viewport->moveCameraToActor(id, x, y);
147  }
148  break;
149 
150  case 3:
151  if (viewport != nullptr)
153  break;
154 
155  case 4:
156  if (viewport != nullptr)
157  {
159  }
160  break;
161  case 5: // close dialog
162  if (mDialog != nullptr)
164  npcHandler->closeDialog(npcId);
165  break;
166  case 6: // show avatar
167  if (mDialog != nullptr)
168  {
170  }
171  break;
172  case 7: // set avatar direction
173  if (mDialog != nullptr)
174  {
177  CAST_U8(id)));
178  }
179  break;
180  case 8: // set avatar action
181  if (mDialog != nullptr)
182  mDialog->setAvatarAction(toInt(id, int));
183  break;
184  case 9: // clear npc dialog
185  if (mDialog != nullptr)
186  mDialog->clearRows();
187  break;
188  case 10: // send selected item id
189  {
190  int invSize = toInt(id, int);
191  if (invSize == 0)
192  invSize = 1;
193  if (mDialog != nullptr)
194  mDialog->itemRequest(invSize);
195  break;
196  }
197  case 11: // send selected item index
198  {
199  int invSize = toInt(id, int);
200  if (invSize == 0)
201  invSize = 1;
202  if (mDialog != nullptr)
203  mDialog->itemIndexRequest(invSize);
204  break;
205  }
206  case 12: // send complex items
207  {
208  int invSize = toInt(id, int);
209  if (invSize == 0)
210  invSize = 1;
211  if (mDialog != nullptr)
212  mDialog->itemCraftRequest(invSize);
213  break;
214  }
215  case 14:
216  {
217  const NpcDialogs::iterator it = NpcDialog::mNpcDialogs.find(npcId);
218  if (it != NpcDialog::mNpcDialogs.end())
219  {
220  NpcDialog *const dialog = (*it).second;
221  if (dialog != nullptr)
222  dialog->close();
223  if (dialog == Ea::NpcRecv::mDialog)
224  Ea::NpcRecv::mDialog = nullptr;
225  NpcDialog::mNpcDialogs.erase(it);
226  }
227  break;
228  }
229  default:
231  break;
232  }
233 }
int BeingId
Definition: beingid.h:30
const BeingId BeingId_zero
Definition: beingid.h:30
int BeingTypeId
Definition: beingtypeid.h:30
#define CAST_U8
Definition: cast.h:27
static uint8_t fromServerDirection(const uint8_t serverDir)
Definition: messagein.cpp:266
virtual void closeDialog(const BeingId npcId)=0
void itemRequest(const int size)
Definition: npcdialog.cpp:791
void itemCraftRequest(const int size)
Definition: npcdialog.cpp:807
void itemIndexRequest(const int size)
Definition: npcdialog.cpp:799
void setAvatarAction(const int actionId)
Definition: npcdialog.cpp:1184
void showAvatar(const BeingTypeId avatarId)
Definition: npcdialog.cpp:1130
void setAvatarDirection(const uint8_t direction)
Definition: npcdialog.cpp:1177
static NpcDialogs mNpcDialogs
Definition: npcdialog.h:242
void clearRows()
Definition: npcdialog.cpp:1212
void restoreCamera()
Definition: npcdialog.cpp:1115
void moveCameraToActor(const BeingId actorId, const int x, const int y)
Definition: viewport.cpp:1077
void moveCameraRelative(const int x, const int y)
Definition: viewport.cpp:1103
void returnCamera()
Definition: viewport.cpp:1111
void moveCameraToPosition(const int x, const int y)
Definition: viewport.cpp:1092
virtual void close()
Definition: window.cpp:902
Viewport * viewport
Definition: viewport.cpp:36
#define toInt(val, name)
Definition: intdefines.h:47
#define fromInt(val, name)
Definition: intdefines.h:46
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:59

References BeingId_zero, CAST_U8, NpcDialog::clearRows(), Window::close(), Net::NpcHandler::closeDialog(), fromInt, Net::MessageIn::fromServerDirection(), Net::NpcHandler::getNpc(), NpcDialog::itemCraftRequest(), NpcDialog::itemIndexRequest(), NpcDialog::itemRequest(), mDialog, NpcDialog::mNpcDialogs, Viewport::moveCameraRelative(), Viewport::moveCameraToActor(), Viewport::moveCameraToPosition(), mRequestLang, Actions::msg(), npcHandler, NpcAction::Other, NpcDialog::restoreCamera(), Viewport::returnCamera(), NpcDialog::setAvatarAction(), NpcDialog::setAvatarDirection(), NpcDialog::showAvatar(), toInt, UNIMPLEMENTEDPACKETFIELD, viewport, x, and y.

◆ processNpcIntInput()

void Ea::NpcRecv::processNpcIntInput ( Net::MessageIn msg)

Definition at line 96 of file npcrecv.cpp.

97 {
98  // Request for an integer
100  mRequestLang = false;
101  if (mDialog != nullptr)
102  mDialog->integerRequest(0, 0, 2147483647);
103 }
void integerRequest(const int defaultValue, const int min, const int max)
Definition: npcdialog.cpp:779

References Net::NpcHandler::getNpc(), NpcDialog::integerRequest(), mDialog, mRequestLang, Actions::msg(), npcHandler, and NpcAction::Other.

◆ processNpcMessage()

void Ea::NpcRecv::processNpcMessage ( Net::MessageIn msg)

Definition at line 64 of file npcrecv.cpp.

65 {
66  msg.readInt16("len");
68  mRequestLang = false;
69 
70  const std::string message = msg.readString(msg.getLength() - 8, "message");
71  // ignore future legacy npc commands.
72  if (message.size() > 3 && message.substr(0, 3) == "###")
73  return;
74  if (mDialog != nullptr)
75  mDialog->addText(message, true);
76 }
void addText(const std::string &string, const bool save)
Definition: npcdialog.cpp:291

References NpcDialog::addText(), Net::NpcHandler::getNpc(), mDialog, mRequestLang, Actions::msg(), npcHandler, and NpcAction::Other.

◆ processNpcNext()

void Ea::NpcRecv::processNpcNext ( Net::MessageIn msg)

Definition at line 87 of file npcrecv.cpp.

88 {
89  // Show the next button
91  mRequestLang = false;
92  if (mDialog != nullptr)
94 }
void showNextButton()
Definition: npcdialog.cpp:307

References Net::NpcHandler::getNpc(), mDialog, mRequestLang, Actions::msg(), NpcAction::Next, npcHandler, and NpcDialog::showNextButton().

◆ processNpcStrInput()

void Ea::NpcRecv::processNpcStrInput ( Net::MessageIn msg)

Definition at line 105 of file npcrecv.cpp.

106 {
107  // Request for a string
109  if (mRequestLang)
110  {
111  mRequestLang = false;
113  }
114  else if (mDialog != nullptr)
115  {
116  mDialog->textRequest(std::string());
117  }
118 }
virtual void stringInput(const BeingId npcId, const std::string &value) const =0
void textRequest(const std::string &defaultText)
Definition: npcdialog.cpp:747
std::string getLangSimple()
Definition: langs.cpp:85

References getLangSimple(), Net::NpcHandler::getNpc(), mDialog, mRequestLang, Actions::msg(), npcHandler, NpcAction::Other, Net::NpcHandler::stringInput(), and NpcDialog::textRequest().

Variable Documentation

◆ mDialog

NpcDialog * Ea::NpcRecv::mDialog = 0

◆ mRequestLang

bool Ea::NpcRecv::mRequestLang = false