/indra/newview/llfloatertelehub.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 279 lines · 201 code · 39 blank · 39 comment · 21 complexity · 857aec5f6def70b6fe9106fe0dc6e8a2 MD5 · raw file

  1. /**
  2. * @file llfloatertelehub.cpp
  3. * @author James Cook
  4. * @brief LLFloaterTelehub class implementation
  5. *
  6. * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "llviewerprecompiledheaders.h"
  28. #include "llfloatertelehub.h"
  29. #include "message.h"
  30. #include "llfontgl.h"
  31. #include "llagent.h"
  32. #include "llfloaterreg.h"
  33. #include "llfloatertools.h"
  34. #include "llscrolllistctrl.h"
  35. #include "llselectmgr.h"
  36. #include "lltoolcomp.h"
  37. #include "lltoolmgr.h"
  38. #include "llviewerobject.h"
  39. #include "llviewerobjectlist.h"
  40. #include "lluictrlfactory.h"
  41. LLFloaterTelehub::LLFloaterTelehub(const LLSD& key)
  42. : LLFloater(key),
  43. mTelehubObjectID(),
  44. mTelehubObjectName(),
  45. mTelehubPos(),
  46. mTelehubRot(),
  47. mNumSpawn(0)
  48. {
  49. }
  50. BOOL LLFloaterTelehub::postBuild()
  51. {
  52. gMessageSystem->setHandlerFunc("TelehubInfo", processTelehubInfo);
  53. getChild<LLUICtrl>("connect_btn")->setCommitCallback(boost::bind(&LLFloaterTelehub::onClickConnect, this));
  54. getChild<LLUICtrl>("disconnect_btn")->setCommitCallback(boost::bind(&LLFloaterTelehub::onClickDisconnect, this));
  55. getChild<LLUICtrl>("add_spawn_point_btn")->setCommitCallback(boost::bind(&LLFloaterTelehub::onClickAddSpawnPoint, this));
  56. getChild<LLUICtrl>("remove_spawn_point_btn")->setCommitCallback(boost::bind(&LLFloaterTelehub::onClickRemoveSpawnPoint, this));
  57. LLScrollListCtrl* list = getChild<LLScrollListCtrl>("spawn_points_list");
  58. if (list)
  59. {
  60. // otherwise you can't walk with arrow keys while floater is up
  61. list->setAllowKeyboardMovement(FALSE);
  62. }
  63. return TRUE;
  64. }
  65. void LLFloaterTelehub::onOpen(const LLSD& key)
  66. {
  67. // Show tools floater by selecting translate (select) tool
  68. LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
  69. LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolCompTranslate::getInstance() );
  70. sendTelehubInfoRequest();
  71. mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
  72. }
  73. LLFloaterTelehub::~LLFloaterTelehub()
  74. {
  75. // no longer interested in this message
  76. gMessageSystem->setHandlerFunc("TelehubInfo", NULL);
  77. }
  78. void LLFloaterTelehub::draw()
  79. {
  80. if (!isMinimized())
  81. {
  82. refresh();
  83. }
  84. LLFloater::draw();
  85. }
  86. // Per-frame updates, because we don't have a selection manager observer.
  87. void LLFloaterTelehub::refresh()
  88. {
  89. const BOOL children_ok = TRUE;
  90. LLViewerObject* object = mObjectSelection->getFirstRootObject(children_ok);
  91. BOOL have_selection = (object != NULL);
  92. BOOL all_volume = LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME );
  93. getChildView("connect_btn")->setEnabled(have_selection && all_volume);
  94. BOOL have_telehub = mTelehubObjectID.notNull();
  95. getChildView("disconnect_btn")->setEnabled(have_telehub);
  96. BOOL space_avail = (mNumSpawn < MAX_SPAWNPOINTS_PER_TELEHUB);
  97. getChildView("add_spawn_point_btn")->setEnabled(have_selection && all_volume && space_avail);
  98. LLScrollListCtrl* list = getChild<LLScrollListCtrl>("spawn_points_list");
  99. if (list)
  100. {
  101. BOOL enable_remove = (list->getFirstSelected() != NULL);
  102. getChildView("remove_spawn_point_btn")->setEnabled(enable_remove);
  103. }
  104. }
  105. // static
  106. BOOL LLFloaterTelehub::renderBeacons()
  107. {
  108. // only render if we've got a telehub
  109. LLFloaterTelehub* floater = LLFloaterReg::findTypedInstance<LLFloaterTelehub>("telehubs");
  110. return floater && floater->mTelehubObjectID.notNull();
  111. }
  112. // static
  113. void LLFloaterTelehub::addBeacons()
  114. {
  115. LLFloaterTelehub* floater = LLFloaterReg::findTypedInstance<LLFloaterTelehub>("telehubs");
  116. if (!floater)
  117. return;
  118. // Find the telehub position, either our cached old position, or
  119. // an updated one based on the actual object position.
  120. LLVector3 hub_pos_region = floater->mTelehubPos;
  121. LLQuaternion hub_rot = floater->mTelehubRot;
  122. LLViewerObject* obj = gObjectList.findObject(floater->mTelehubObjectID);
  123. if (obj)
  124. {
  125. hub_pos_region = obj->getPositionRegion();
  126. hub_rot = obj->getRotationRegion();
  127. }
  128. // Draw nice thick 3-pixel lines.
  129. gObjectList.addDebugBeacon(hub_pos_region, "", LLColor4::yellow, LLColor4::white, 4);
  130. LLScrollListCtrl* list = floater->getChild<LLScrollListCtrl>("spawn_points_list");
  131. if (list)
  132. {
  133. S32 spawn_index = list->getFirstSelectedIndex();
  134. if (spawn_index >= 0)
  135. {
  136. LLVector3 spawn_pos = hub_pos_region + (floater->mSpawnPointPos[spawn_index] * hub_rot);
  137. gObjectList.addDebugBeacon(spawn_pos, "", LLColor4::orange, LLColor4::white, 4);
  138. }
  139. }
  140. }
  141. void LLFloaterTelehub::sendTelehubInfoRequest()
  142. {
  143. LLSelectMgr::getInstance()->sendGodlikeRequest("telehub", "info ui");
  144. }
  145. void LLFloaterTelehub::onClickConnect()
  146. {
  147. LLSelectMgr::getInstance()->sendGodlikeRequest("telehub", "connect");
  148. }
  149. void LLFloaterTelehub::onClickDisconnect()
  150. {
  151. LLSelectMgr::getInstance()->sendGodlikeRequest("telehub", "delete");
  152. }
  153. void LLFloaterTelehub::onClickAddSpawnPoint()
  154. {
  155. LLSelectMgr::getInstance()->sendGodlikeRequest("telehub", "spawnpoint add");
  156. LLSelectMgr::getInstance()->deselectAll();
  157. }
  158. void LLFloaterTelehub::onClickRemoveSpawnPoint()
  159. {
  160. LLScrollListCtrl* list = getChild<LLScrollListCtrl>("spawn_points_list");
  161. if (!list)
  162. return;
  163. S32 spawn_index = list->getFirstSelectedIndex();
  164. if (spawn_index < 0) return; // nothing selected
  165. LLMessageSystem* msg = gMessageSystem;
  166. // Could be god or estate owner. If neither, server will reject message.
  167. if (gAgent.isGodlike())
  168. {
  169. msg->newMessage("GodlikeMessage");
  170. }
  171. else
  172. {
  173. msg->newMessage("EstateOwnerMessage");
  174. }
  175. msg->nextBlock("AgentData");
  176. msg->addUUID("AgentID", gAgent.getID());
  177. msg->addUUID("SessionID", gAgent.getSessionID());
  178. msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
  179. msg->nextBlock("MethodData");
  180. msg->addString("Method", "telehub");
  181. msg->addUUID("Invoice", LLUUID::null);
  182. msg->nextBlock("ParamList");
  183. msg->addString("Parameter", "spawnpoint remove");
  184. std::string buffer;
  185. buffer = llformat("%d", spawn_index);
  186. msg->nextBlock("ParamList");
  187. msg->addString("Parameter", buffer);
  188. gAgent.sendReliableMessage();
  189. }
  190. // static
  191. void LLFloaterTelehub::processTelehubInfo(LLMessageSystem* msg, void**)
  192. {
  193. LLFloaterTelehub* floater = LLFloaterReg::findTypedInstance<LLFloaterTelehub>("telehubs");
  194. if (floater)
  195. {
  196. floater->unpackTelehubInfo(msg);
  197. }
  198. }
  199. void LLFloaterTelehub::unpackTelehubInfo(LLMessageSystem* msg)
  200. {
  201. msg->getUUID("TelehubBlock", "ObjectID", mTelehubObjectID);
  202. msg->getString("TelehubBlock", "ObjectName", mTelehubObjectName);
  203. msg->getVector3("TelehubBlock", "TelehubPos", mTelehubPos);
  204. msg->getQuat("TelehubBlock", "TelehubRot", mTelehubRot);
  205. mNumSpawn = msg->getNumberOfBlocks("SpawnPointBlock");
  206. for (S32 i = 0; i < mNumSpawn; i++)
  207. {
  208. msg->getVector3("SpawnPointBlock", "SpawnPointPos", mSpawnPointPos[i], i);
  209. }
  210. // Update parts of the UI that change only when message received.
  211. if (mTelehubObjectID.isNull())
  212. {
  213. getChildView("status_text_connected")->setVisible( false);
  214. getChildView("status_text_not_connected")->setVisible( true);
  215. getChildView("help_text_connected")->setVisible( false);
  216. getChildView("help_text_not_connected")->setVisible( true);
  217. }
  218. else
  219. {
  220. getChild<LLUICtrl>("status_text_connected")->setTextArg("[OBJECT]", mTelehubObjectName);
  221. getChildView("status_text_connected")->setVisible( true);
  222. getChildView("status_text_not_connected")->setVisible( false);
  223. getChildView("help_text_connected")->setVisible( true);
  224. getChildView("help_text_not_connected")->setVisible( false);
  225. }
  226. LLScrollListCtrl* list = getChild<LLScrollListCtrl>("spawn_points_list");
  227. if (list)
  228. {
  229. list->deleteAllItems();
  230. for (S32 i = 0; i < mNumSpawn; i++)
  231. {
  232. std::string pos = llformat("%.1f, %.1f, %.1f",
  233. mSpawnPointPos[i].mV[VX],
  234. mSpawnPointPos[i].mV[VY],
  235. mSpawnPointPos[i].mV[VZ]);
  236. list->addSimpleElement(pos);
  237. }
  238. list->selectNthItem(mNumSpawn - 1);
  239. }
  240. }