PageRenderTime 105ms CodeModel.GetById 40ms app.highlight 30ms RepoModel.GetById 31ms app.codeStats 0ms

/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
 28#include "llviewerprecompiledheaders.h"
 29
 30#include "llfloatertelehub.h"
 31
 32#include "message.h"
 33#include "llfontgl.h"
 34
 35#include "llagent.h"
 36#include "llfloaterreg.h"
 37#include "llfloatertools.h"
 38#include "llscrolllistctrl.h"
 39#include "llselectmgr.h"
 40#include "lltoolcomp.h"
 41#include "lltoolmgr.h"
 42#include "llviewerobject.h"
 43#include "llviewerobjectlist.h"
 44#include "lluictrlfactory.h"
 45
 46LLFloaterTelehub::LLFloaterTelehub(const LLSD& key)
 47:	LLFloater(key),
 48	mTelehubObjectID(),
 49	mTelehubObjectName(),
 50	mTelehubPos(),
 51	mTelehubRot(),
 52	mNumSpawn(0)
 53{
 54}
 55
 56BOOL LLFloaterTelehub::postBuild()
 57{
 58	gMessageSystem->setHandlerFunc("TelehubInfo", processTelehubInfo);
 59
 60	getChild<LLUICtrl>("connect_btn")->setCommitCallback(boost::bind(&LLFloaterTelehub::onClickConnect, this));
 61	getChild<LLUICtrl>("disconnect_btn")->setCommitCallback(boost::bind(&LLFloaterTelehub::onClickDisconnect, this));
 62	getChild<LLUICtrl>("add_spawn_point_btn")->setCommitCallback(boost::bind(&LLFloaterTelehub::onClickAddSpawnPoint, this));
 63	getChild<LLUICtrl>("remove_spawn_point_btn")->setCommitCallback(boost::bind(&LLFloaterTelehub::onClickRemoveSpawnPoint, this));
 64
 65	LLScrollListCtrl* list = getChild<LLScrollListCtrl>("spawn_points_list");
 66	if (list)
 67	{
 68		// otherwise you can't walk with arrow keys while floater is up
 69		list->setAllowKeyboardMovement(FALSE);
 70	}
 71
 72	return TRUE;
 73}
 74void LLFloaterTelehub::onOpen(const LLSD& key)
 75{
 76	// Show tools floater by selecting translate (select) tool
 77	LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
 78	LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolCompTranslate::getInstance() );
 79
 80	sendTelehubInfoRequest();
 81	
 82	mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
 83}
 84
 85LLFloaterTelehub::~LLFloaterTelehub()
 86{
 87	// no longer interested in this message
 88	gMessageSystem->setHandlerFunc("TelehubInfo", NULL);
 89}
 90
 91void LLFloaterTelehub::draw()
 92{
 93	if (!isMinimized())
 94	{
 95		refresh();
 96	}
 97	LLFloater::draw();
 98}
 99
100// Per-frame updates, because we don't have a selection manager observer.
101void LLFloaterTelehub::refresh()
102{
103	const BOOL children_ok = TRUE;
104	LLViewerObject* object = mObjectSelection->getFirstRootObject(children_ok);
105	
106	BOOL have_selection = (object != NULL);
107	BOOL all_volume = LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME );
108	getChildView("connect_btn")->setEnabled(have_selection && all_volume);
109
110	BOOL have_telehub = mTelehubObjectID.notNull();
111	getChildView("disconnect_btn")->setEnabled(have_telehub);
112
113	BOOL space_avail = (mNumSpawn < MAX_SPAWNPOINTS_PER_TELEHUB);
114	getChildView("add_spawn_point_btn")->setEnabled(have_selection && all_volume && space_avail);
115
116	LLScrollListCtrl* list = getChild<LLScrollListCtrl>("spawn_points_list");
117	if (list)
118	{
119		BOOL enable_remove = (list->getFirstSelected() != NULL);
120		getChildView("remove_spawn_point_btn")->setEnabled(enable_remove);
121	}
122}
123
124// static
125BOOL LLFloaterTelehub::renderBeacons()
126{
127	// only render if we've got a telehub
128	LLFloaterTelehub* floater = LLFloaterReg::findTypedInstance<LLFloaterTelehub>("telehubs");
129	return floater && floater->mTelehubObjectID.notNull();
130}
131
132// static
133void LLFloaterTelehub::addBeacons()
134{
135	LLFloaterTelehub* floater = LLFloaterReg::findTypedInstance<LLFloaterTelehub>("telehubs");
136	if (!floater)
137		return;
138	
139	// Find the telehub position, either our cached old position, or
140	// an updated one based on the actual object position.
141	LLVector3 hub_pos_region = floater->mTelehubPos;
142	LLQuaternion hub_rot = floater->mTelehubRot;
143	LLViewerObject* obj = gObjectList.findObject(floater->mTelehubObjectID);
144	if (obj)
145	{
146		hub_pos_region = obj->getPositionRegion();
147		hub_rot = obj->getRotationRegion();
148	}
149	// Draw nice thick 3-pixel lines.
150	gObjectList.addDebugBeacon(hub_pos_region, "", LLColor4::yellow, LLColor4::white, 4);
151
152	LLScrollListCtrl* list = floater->getChild<LLScrollListCtrl>("spawn_points_list");
153	if (list)
154	{
155		S32 spawn_index = list->getFirstSelectedIndex();
156		if (spawn_index >= 0)
157		{
158			LLVector3 spawn_pos = hub_pos_region  + (floater->mSpawnPointPos[spawn_index] * hub_rot);
159			gObjectList.addDebugBeacon(spawn_pos, "", LLColor4::orange, LLColor4::white, 4);
160		}
161	}
162}
163
164void LLFloaterTelehub::sendTelehubInfoRequest()
165{
166	LLSelectMgr::getInstance()->sendGodlikeRequest("telehub", "info ui");
167}
168
169void LLFloaterTelehub::onClickConnect()
170{
171	LLSelectMgr::getInstance()->sendGodlikeRequest("telehub", "connect");
172}
173
174void LLFloaterTelehub::onClickDisconnect()
175{
176	LLSelectMgr::getInstance()->sendGodlikeRequest("telehub", "delete");
177}
178
179void LLFloaterTelehub::onClickAddSpawnPoint()
180{
181	LLSelectMgr::getInstance()->sendGodlikeRequest("telehub", "spawnpoint add");
182	LLSelectMgr::getInstance()->deselectAll();
183}
184
185void LLFloaterTelehub::onClickRemoveSpawnPoint()
186{
187	LLScrollListCtrl* list = getChild<LLScrollListCtrl>("spawn_points_list");
188	if (!list)
189		return;
190
191	S32 spawn_index = list->getFirstSelectedIndex();
192	if (spawn_index < 0) return;  // nothing selected
193
194	LLMessageSystem* msg = gMessageSystem;
195
196	// Could be god or estate owner.  If neither, server will reject message.
197	if (gAgent.isGodlike())
198	{
199		msg->newMessage("GodlikeMessage");
200	}
201	else
202	{
203		msg->newMessage("EstateOwnerMessage");
204	}
205	msg->nextBlock("AgentData");
206	msg->addUUID("AgentID", gAgent.getID());
207	msg->addUUID("SessionID", gAgent.getSessionID());
208	msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
209	msg->nextBlock("MethodData");
210	msg->addString("Method", "telehub");
211	msg->addUUID("Invoice", LLUUID::null);
212
213	msg->nextBlock("ParamList");
214	msg->addString("Parameter", "spawnpoint remove");
215
216	std::string buffer;
217	buffer = llformat("%d", spawn_index);
218	msg->nextBlock("ParamList");
219	msg->addString("Parameter", buffer);
220
221	gAgent.sendReliableMessage();
222}
223
224// static 
225void LLFloaterTelehub::processTelehubInfo(LLMessageSystem* msg, void**)
226{
227	LLFloaterTelehub* floater = LLFloaterReg::findTypedInstance<LLFloaterTelehub>("telehubs");
228	if (floater)
229	{
230		floater->unpackTelehubInfo(msg);
231	}
232}
233
234void LLFloaterTelehub::unpackTelehubInfo(LLMessageSystem* msg)
235{
236	msg->getUUID("TelehubBlock", "ObjectID", mTelehubObjectID);
237	msg->getString("TelehubBlock", "ObjectName", mTelehubObjectName);
238	msg->getVector3("TelehubBlock", "TelehubPos", mTelehubPos);
239	msg->getQuat("TelehubBlock", "TelehubRot", mTelehubRot);
240
241	mNumSpawn = msg->getNumberOfBlocks("SpawnPointBlock");
242	for (S32 i = 0; i < mNumSpawn; i++)
243	{
244		msg->getVector3("SpawnPointBlock", "SpawnPointPos", mSpawnPointPos[i], i);
245	}
246
247	// Update parts of the UI that change only when message received.
248
249	if (mTelehubObjectID.isNull())
250	{
251		getChildView("status_text_connected")->setVisible( false);
252		getChildView("status_text_not_connected")->setVisible( true);
253		getChildView("help_text_connected")->setVisible( false);
254		getChildView("help_text_not_connected")->setVisible( true);
255	}
256	else
257	{
258		getChild<LLUICtrl>("status_text_connected")->setTextArg("[OBJECT]", mTelehubObjectName);
259		getChildView("status_text_connected")->setVisible( true);
260		getChildView("status_text_not_connected")->setVisible( false);
261		getChildView("help_text_connected")->setVisible( true);
262		getChildView("help_text_not_connected")->setVisible( false);
263	}
264
265	LLScrollListCtrl* list = getChild<LLScrollListCtrl>("spawn_points_list");
266	if (list)
267	{
268		list->deleteAllItems();
269		for (S32 i = 0; i < mNumSpawn; i++)
270		{
271			std::string pos = llformat("%.1f, %.1f, %.1f", 
272									mSpawnPointPos[i].mV[VX],
273									mSpawnPointPos[i].mV[VY],
274									mSpawnPointPos[i].mV[VZ]);
275			list->addSimpleElement(pos);
276		}
277		list->selectNthItem(mNumSpawn - 1);
278	}
279}