00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/popupmenu.h"
00023
00024 #include "gui/chat.h"
00025 #include "gui/inventorywindow.h"
00026 #include "gui/item_amount.h"
00027
00028 #include "gui/widgets/browserbox.h"
00029
00030 #include "being.h"
00031 #include "beingmanager.h"
00032 #include "floor_item.h"
00033 #include "graphics.h"
00034 #include "item.h"
00035 #include "localplayer.h"
00036 #include "npc.h"
00037 #include "player_relations.h"
00038
00039 #include "net/adminhandler.h"
00040 #include "net/net.h"
00041
00042 #include "resources/itemdb.h"
00043 #include "resources/iteminfo.h"
00044
00045 #include "utils/gettext.h"
00046 #include "utils/strprintf.h"
00047
00048 #include <cassert>
00049
00050 extern std::string tradePartnerName;
00051
00052 PopupMenu::PopupMenu():
00053 Popup("PopupMenu"),
00054 mBeingId(0),
00055 mFloorItem(NULL),
00056 mItem(NULL)
00057 {
00058 mBrowserBox = new BrowserBox;
00059 mBrowserBox->setPosition(4, 4);
00060 mBrowserBox->setHighlightMode(BrowserBox::BACKGROUND);
00061 mBrowserBox->setOpaque(false);
00062 mBrowserBox->setLinkHandler(this);
00063 add(mBrowserBox);
00064 }
00065
00066 void PopupMenu::showPopup(int x, int y, Being *being)
00067 {
00068 mBeingId = being->getId();
00069 mBrowserBox->clearRows();
00070
00071
00072 if (being->getType() != Being::UNKNOWN)
00073 mBrowserBox->addRow(_("@@name|Add name to chat@@"));
00074
00075 const std::string &name = being->getType() == Being::NPC ?
00076 being->getName().substr(0, being->getName().size()
00077 - 6) : being->getName();
00078
00079 switch (being->getType())
00080 {
00081 case Being::PLAYER:
00082 {
00083
00084
00085 mBrowserBox->addRow(strprintf(_("@@trade|Trade With %s@@"), name.c_str()));
00086 mBrowserBox->addRow(strprintf(_("@@attack|Attack %s@@"), name.c_str()));
00087
00088 mBrowserBox->addRow("##3---");
00089
00090 switch (player_relations.getRelation(name)) {
00091 case PlayerRelation::NEUTRAL:
00092 mBrowserBox->addRow(strprintf(_("@@friend|Befriend %s@@"), name.c_str()));
00093
00094 case PlayerRelation::FRIEND:
00095 mBrowserBox->addRow(strprintf(_("@@disregard|Disregard %s@@"), name.c_str()));
00096 mBrowserBox->addRow(strprintf(_("@@ignore|Ignore %s@@"), name.c_str()));
00097 break;
00098
00099 case PlayerRelation::DISREGARDED:
00100 mBrowserBox->addRow(strprintf(_("@@unignore|Un-Ignore %s@@"), name.c_str()));
00101 mBrowserBox->addRow(strprintf(_("@@ignore|Completely ignore %s@@"), name.c_str()));
00102 break;
00103
00104 case PlayerRelation::IGNORED:
00105 mBrowserBox->addRow(strprintf(_("@@unignore|Un-Ignore %s@@"), name.c_str()));
00106 break;
00107 }
00108
00109
00110
00111 mBrowserBox->addRow(strprintf(_("@@guild|Invite %s to join your guild@@"), name.c_str()));
00112 mBrowserBox->addRow(strprintf(_("@@party|Invite %s to join your party@@"), name.c_str()));
00113
00114
00115
00116
00117 }
00118 break;
00119
00120 case Being::NPC:
00121
00122
00123 mBrowserBox->addRow(strprintf(_("@@talk|Talk To %s@@"), name.c_str()));
00124 break;
00125
00126 case Being::MONSTER:
00127
00128 mBrowserBox->addRow(strprintf(_("@@attack|Attack %s@@"), name.c_str()));
00129 break;
00130
00131
00132
00133
00134
00135 default:
00136
00137 return;
00138 }
00139
00140
00141 mBrowserBox->addRow("##3---");
00142 mBrowserBox->addRow(_("@@cancel|Cancel@@"));
00143
00144 showPopup(x, y);
00145 }
00146
00147 void PopupMenu::showPopup(int x, int y, FloorItem *floorItem)
00148 {
00149 mFloorItem = floorItem;
00150 mItem = floorItem->getItem();
00151 mBrowserBox->clearRows();
00152
00153
00154 std::string name = ItemDB::get(mFloorItem->getItemId()).getName();
00155 mBrowserBox->addRow(strprintf(_("@@pickup|Pick up %s@@"), name.c_str()));
00156 mBrowserBox->addRow(_("@@chat|Add to chat@@"));
00157
00158
00159 mBrowserBox->addRow("##3---");
00160 mBrowserBox->addRow(_("@@cancel|Cancel@@"));
00161
00162 showPopup(x, y);
00163 }
00164
00165 void PopupMenu::handleLink(const std::string &link)
00166 {
00167 Being *being = beingManager->findBeing(mBeingId);
00168
00169
00170 if (link == "talk" &&
00171 being &&
00172 being->getType() == Being::NPC &&
00173 current_npc == 0)
00174 {
00175 dynamic_cast<NPC*>(being)->talk();
00176 }
00177
00178
00179 else if (link == "trade" &&
00180 being &&
00181 being->getType() == Being::PLAYER)
00182 {
00183 player_node->trade(being);
00184 tradePartnerName = being->getName();
00185 }
00186 #ifdef EATHENA_SUPPORT
00187
00188 else if (link == "attack" && being)
00189 {
00190 player_node->attack(being, true);
00191 }
00192 #endif
00193 else if (link == "unignore" &&
00194 being &&
00195 being->getType() == Being::PLAYER)
00196 {
00197 player_relations.setRelation(being->getName(), PlayerRelation::NEUTRAL);
00198 }
00199
00200 else if (link == "ignore" &&
00201 being &&
00202 being->getType() == Being::PLAYER)
00203 {
00204 player_relations.setRelation(being->getName(), PlayerRelation::IGNORED);
00205 }
00206
00207 else if (link == "disregard" &&
00208 being &&
00209 being->getType() == Being::PLAYER)
00210 {
00211 player_relations.setRelation(being->getName(), PlayerRelation::DISREGARDED);
00212 }
00213
00214 else if (link == "friend" &&
00215 being &&
00216 being->getType() == Being::PLAYER)
00217 {
00218 player_relations.setRelation(being->getName(), PlayerRelation::FRIEND);
00219 }
00220 #ifdef TMWSERV_SUPPORT
00221
00222 else if (link == "guild" &&
00223 being != NULL &&
00224 being->getType() == Being::PLAYER)
00225 {
00226 player_node->inviteToGuild(being);
00227 }
00228 #endif
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 else if ((link == "pickup") && mFloorItem)
00247 {
00248 player_node->pickUp(mFloorItem);
00249 }
00250
00251
00252 else if (link == "look")
00253 {
00254 }
00255
00256 else if (link == "use")
00257 {
00258 assert(mItem);
00259 if (mItem->isEquipment())
00260 {
00261 #ifdef TMWSERV_SUPPORT
00262 player_node->equipItem(mItem);
00263 #else
00264 if (mItem->isEquipped())
00265 player_node->unequipItem(mItem);
00266 else
00267 player_node->equipItem(mItem);
00268 #endif
00269 }
00270 else
00271 {
00272 player_node->useItem(mItem);
00273 }
00274 }
00275
00276 else if (link == "chat")
00277 {
00278 chatWindow->addItemText(mItem->getInfo().getName());
00279 }
00280
00281 else if (link == "split")
00282 {
00283 new ItemAmountWindow(ItemAmountWindow::ItemSplit,
00284 inventoryWindow, mItem);
00285 }
00286
00287 else if (link == "drop")
00288 {
00289 new ItemAmountWindow(ItemAmountWindow::ItemDrop,
00290 inventoryWindow, mItem);
00291 }
00292
00293 else if (link == "party" && being && being->getType() == Being::PLAYER)
00294 {
00295 player_node->inviteToParty(dynamic_cast<Player*>(being));
00296 }
00297
00298 else if (link == "name" && being)
00299 {
00300 const std::string &name = being->getType() == Being::NPC ?
00301 being->getName().substr(0,
00302 being->getName().size() - 6) : being->getName();
00303 chatWindow->addInputText(name);
00304 }
00305
00306 else if (link == "admin-kick" &&
00307 being &&
00308 (being->getType() == Being::PLAYER ||
00309 being->getType() == Being::MONSTER))
00310 {
00311 Net::getAdminHandler()->kick(being->getId());
00312 }
00313
00314
00315 else if (link != "cancel")
00316 {
00317 std::cout << link << std::endl;
00318 }
00319
00320 setVisible(false);
00321
00322 mBeingId = 0;
00323 mFloorItem = NULL;
00324 mItem = NULL;
00325 }
00326
00327 void PopupMenu::showPopup(int x, int y, Item *item)
00328 {
00329 assert(item);
00330 mItem = item;
00331 mBrowserBox->clearRows();
00332
00333 if (item->isEquipment())
00334 {
00335 #ifdef TMWSERV_SUPPORT
00336 mBrowserBox->addRow(_("@@use|Equip@@"));
00337 #else
00338 if (item->isEquipped())
00339 mBrowserBox->addRow(_("@@use|Unequip@@"));
00340 else
00341 mBrowserBox->addRow(_("@@use|Equip@@"));
00342 #endif
00343 }
00344 else
00345 mBrowserBox->addRow(_("@@use|Use@@"));
00346
00347 mBrowserBox->addRow(_("@@drop|Drop@@"));
00348 #ifdef TMWSERV_SUPPORT
00349 if (!item->isEquipment())
00350 mBrowserBox->addRow(_("@@split|Split@@"));
00351 #endif
00352 mBrowserBox->addRow(_("@@chat|Add to chat@@"));
00353 mBrowserBox->addRow("##3---");
00354 mBrowserBox->addRow(_("@@cancel|Cancel@@"));
00355
00356 showPopup(x, y);
00357 }
00358
00359 void PopupMenu::showPopup(int x, int y)
00360 {
00361 setContentSize(mBrowserBox->getWidth() + 8, mBrowserBox->getHeight() + 8);
00362 if (graphics->getWidth() < (x + getWidth() + 5))
00363 x = graphics->getWidth() - getWidth();
00364 if (graphics->getHeight() < (y + getHeight() + 5))
00365 y = graphics->getHeight() - getHeight();
00366 setPosition(x, y);
00367 setVisible(true);
00368 requestMoveToTop();
00369 }