llfloatertelehub.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /**
  2. * @file llfloatertelehub.cpp
  3. * @author James Cook
  4. * @brief LLFloaterTelehub class implementation
  5. *
  6. * $LicenseInfo:firstyear=2005&license=viewergpl$
  7. *
  8. * Copyright (c) 2005-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "llviewerprecompiledheaders.h"
  34. #include "llfloatertelehub.h"
  35. #include "llbutton.h"
  36. #include "llscrolllistctrl.h"
  37. #include "lluictrlfactory.h"
  38. #include "llmessage.h"
  39. #include "llagent.h"
  40. #include "llfloatertools.h"
  41. #include "llselectmgr.h"
  42. #include "lltoolcomp.h"
  43. #include "lltoolmgr.h"
  44. #include "llviewerobjectlist.h"
  45. LLFloaterTelehub::LLFloaterTelehub(const LLSD&)
  46. : mTelehubObjectID(),
  47. mTelehubObjectName(),
  48. mTelehubPos(),
  49. mTelehubRot(),
  50. mNumSpawn(0)
  51. {
  52. LLUICtrlFactory::getInstance()->buildFloater(this, "floater_telehub.xml");
  53. }
  54. LLFloaterTelehub::~LLFloaterTelehub()
  55. {
  56. // no longer interested in this message
  57. gMessageSystemp->setHandlerFunc("TelehubInfo", NULL);
  58. }
  59. bool LLFloaterTelehub::postBuild()
  60. {
  61. gMessageSystemp->setHandlerFunc("TelehubInfo", processTelehubInfo);
  62. mConnectBtn = getChild<LLButton>("connect_btn");
  63. mConnectBtn->setClickedCallback(onClickConnect, this);
  64. mDisconnectBtn = getChild<LLButton>("disconnect_btn");
  65. mDisconnectBtn->setClickedCallback(onClickDisconnect, this);
  66. mAddSpawnBtn = getChild<LLButton>("add_spawn_point_btn");
  67. mAddSpawnBtn->setClickedCallback(onClickAddSpawnPoint, this);
  68. mRemoveSpawnBtn = getChild<LLButton>("remove_spawn_point_btn");
  69. mRemoveSpawnBtn->setClickedCallback(onClickRemoveSpawnPoint, this);
  70. mSpawnPointsList = getChild<LLScrollListCtrl>("spawn_points_list");
  71. // otherwise you can't walk with arrow keys while floater is up:
  72. mSpawnPointsList->setAllowKeyboardMovement(false);
  73. mObjectSelection = gSelectMgr.getEditSelection();
  74. // Show tools floater by selecting translate (select) tool
  75. gToolMgr.setCurrentToolset(gBasicToolset);
  76. gToolMgr.getCurrentToolset()->selectTool(&gToolCompTranslate);
  77. // Find tools floater, glue to bottom
  78. if (gFloaterToolsp)
  79. {
  80. LLRect tools_rect = gFloaterToolsp->getRect();
  81. S32 our_width = getRect().getWidth();
  82. S32 our_height = getRect().getHeight();
  83. LLRect our_rect;
  84. our_rect.setLeftTopAndSize(tools_rect.mLeft, tools_rect.mBottom,
  85. our_width, our_height);
  86. setRect(our_rect);
  87. }
  88. sendTelehubInfoRequest();
  89. return true;
  90. }
  91. void LLFloaterTelehub::draw()
  92. {
  93. if (!isMinimized())
  94. {
  95. refresh();
  96. }
  97. LLFloater::draw();
  98. }
  99. // Per-frame updates, because we don't have a selection manager observer.
  100. void LLFloaterTelehub::refresh()
  101. {
  102. bool have_selection = mObjectSelection->getFirstRootObject(true) != NULL;
  103. bool all_volume = gSelectMgr.selectionAllPCode(LL_PCODE_VOLUME);
  104. mConnectBtn->setEnabled(have_selection && all_volume);
  105. bool have_telehub = mTelehubObjectID.notNull();
  106. mDisconnectBtn->setEnabled(have_telehub);
  107. bool space_avail = (mNumSpawn < MAX_SPAWNPOINTS_PER_TELEHUB);
  108. mAddSpawnBtn->setEnabled(have_selection && all_volume && space_avail);
  109. bool enable_remove = mSpawnPointsList->getFirstSelected() != NULL;
  110. mRemoveSpawnBtn->setEnabled(enable_remove);
  111. }
  112. void LLFloaterTelehub::unpackTelehubInfo(LLMessageSystem* msg)
  113. {
  114. msg->getUUID("TelehubBlock", "ObjectID", mTelehubObjectID);
  115. msg->getString("TelehubBlock", "ObjectName", mTelehubObjectName);
  116. msg->getVector3("TelehubBlock", "TelehubPos", mTelehubPos);
  117. msg->getQuat("TelehubBlock", "TelehubRot", mTelehubRot);
  118. mNumSpawn = msg->getNumberOfBlocks("SpawnPointBlock");
  119. for (S32 i = 0; i < mNumSpawn; ++i)
  120. {
  121. msg->getVector3("SpawnPointBlock", "SpawnPointPos",
  122. mSpawnPointPos[i], i);
  123. }
  124. // Update parts of the UI that change only when message received.
  125. if (mTelehubObjectID.isNull())
  126. {
  127. childSetVisible("status_text_connected", false);
  128. childSetVisible("status_text_not_connected", true);
  129. childSetVisible("help_text_connected", false);
  130. childSetVisible("help_text_not_connected", true);
  131. }
  132. else
  133. {
  134. childSetTextArg("status_text_connected", "[OBJECT]",
  135. mTelehubObjectName);
  136. childSetVisible("status_text_connected", true);
  137. childSetVisible("status_text_not_connected", false);
  138. childSetVisible("help_text_connected", true);
  139. childSetVisible("help_text_not_connected", false);
  140. }
  141. mSpawnPointsList->deleteAllItems();
  142. for (S32 i = 0; i < mNumSpawn; ++i)
  143. {
  144. std::string pos = llformat("%.1f, %.1f, %.1f",
  145. mSpawnPointPos[i].mV[VX],
  146. mSpawnPointPos[i].mV[VY],
  147. mSpawnPointPos[i].mV[VZ]);
  148. mSpawnPointsList->addSimpleElement(pos);
  149. }
  150. mSpawnPointsList->selectNthItem(mNumSpawn - 1);
  151. }
  152. // static
  153. void LLFloaterTelehub::addBeacons()
  154. {
  155. LLFloaterTelehub* self = findInstance();
  156. if (!self) return;
  157. // Find the telehub position, either our cached old position, or an updated
  158. // one based on the actual object position.
  159. LLVector3 hub_pos_region = self->mTelehubPos;
  160. LLQuaternion hub_rot = self->mTelehubRot;
  161. LLViewerObject* obj = gObjectList.findObject(self->mTelehubObjectID);
  162. if (obj)
  163. {
  164. hub_pos_region = obj->getPositionRegion();
  165. hub_rot = obj->getRotationRegion();
  166. }
  167. // Draw nice thick 3-pixel lines.
  168. gObjectList.addDebugBeacon(hub_pos_region, "", LLColor4::yellow,
  169. LLColor4::white, 4);
  170. S32 spawn_index = self->mSpawnPointsList->getFirstSelectedIndex();
  171. if (spawn_index >= 0)
  172. {
  173. LLVector3 spawn_pos = hub_pos_region +
  174. self->mSpawnPointPos[spawn_index] * hub_rot;
  175. gObjectList.addDebugBeacon(spawn_pos, "", LLColor4::orange,
  176. LLColor4::white, 4);
  177. }
  178. }
  179. void LLFloaterTelehub::sendTelehubInfoRequest()
  180. {
  181. gSelectMgr.sendGodlikeRequest("telehub", "info ui");
  182. }
  183. // static
  184. void LLFloaterTelehub::onClickConnect(void*)
  185. {
  186. gSelectMgr.sendGodlikeRequest("telehub", "connect");
  187. }
  188. // static
  189. void LLFloaterTelehub::onClickDisconnect(void*)
  190. {
  191. gSelectMgr.sendGodlikeRequest("telehub", "delete");
  192. }
  193. // static
  194. void LLFloaterTelehub::onClickAddSpawnPoint(void*)
  195. {
  196. gSelectMgr.sendGodlikeRequest("telehub", "spawnpoint add");
  197. gSelectMgr.deselectAll();
  198. }
  199. // static
  200. void LLFloaterTelehub::onClickRemoveSpawnPoint(void* data)
  201. {
  202. LLFloaterTelehub* self = (LLFloaterTelehub*)data;
  203. if (!self) return;
  204. S32 spawn_index = self->mSpawnPointsList->getFirstSelectedIndex();
  205. if (spawn_index < 0) return; // nothing selected
  206. LLMessageSystem* msg = gMessageSystemp;
  207. if (!msg) return;
  208. // Could be god or estate owner. If neither, server will reject message.
  209. if (gAgent.isGodlike())
  210. {
  211. msg->newMessage("GodlikeMessage");
  212. }
  213. else
  214. {
  215. msg->newMessage("EstateOwnerMessage");
  216. }
  217. msg->nextBlock("AgentData");
  218. msg->addUUID("AgentID", gAgentID);
  219. msg->addUUID("SessionID", gAgentSessionID);
  220. msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); // not used
  221. msg->nextBlock("MethodData");
  222. msg->addString("Method", "telehub");
  223. msg->addUUID("Invoice", LLUUID::null);
  224. msg->nextBlock("ParamList");
  225. msg->addString("Parameter", "spawnpoint remove");
  226. std::string buffer = llformat("%d", spawn_index);
  227. msg->nextBlock("ParamList");
  228. msg->addString("Parameter", buffer);
  229. gAgent.sendReliableMessage();
  230. }
  231. // static
  232. void LLFloaterTelehub::processTelehubInfo(LLMessageSystem* msg, void**)
  233. {
  234. LLFloaterTelehub* self = findInstance();
  235. if (self && msg)
  236. {
  237. self->unpackTelehubInfo(msg);
  238. }
  239. }