llfloaterevent.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:9k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloaterevent.cpp
  3.  * @brief Display for events in the finder
  4.  *
  5.  * $LicenseInfo:firstyear=2004&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2004-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaterevent.h"
  34. #include "message.h"
  35. #include "llnotificationsutil.h"
  36. #include "llui.h"
  37. #include "llagent.h"
  38. #include "llviewerwindow.h"
  39. #include "llbutton.h"
  40. #include "llcachename.h"
  41. #include "llcommandhandler.h" // secondlife:///app/chat/ support
  42. #include "lleventflags.h"
  43. #include "lleventnotifier.h"
  44. #include "llexpandabletextbox.h"
  45. #include "llfloater.h"
  46. #include "llfloaterreg.h"
  47. #include "llfloaterworldmap.h"
  48. #include "llinventorymodel.h"
  49. #include "llsecondlifeurls.h"
  50. #include "llslurl.h"
  51. #include "lltextbox.h"
  52. #include "lltexteditor.h"
  53. #include "lluiconstants.h"
  54. #include "llviewercontrol.h"
  55. #include "llweb.h"
  56. #include "llworldmap.h"
  57. #include "lluictrlfactory.h"
  58. #include "lltrans.h"
  59. class LLEventHandler : public LLCommandHandler
  60. {
  61. public:
  62. // requires trusted browser to trigger
  63. LLEventHandler() : LLCommandHandler("event", UNTRUSTED_THROTTLE) { }
  64. bool handle(const LLSD& params, const LLSD& query_map,
  65. LLMediaCtrl* web)
  66. {
  67. if (params.size() < 1)
  68. {
  69. return false;
  70. }
  71. LLFloaterEvent* floater = LLFloaterReg::getTypedInstance<LLFloaterEvent>("event");
  72. if (floater)
  73. {
  74. floater->setEventID(params[0].asInteger());
  75. LLFloaterReg::showTypedInstance<LLFloaterEvent>("event");
  76. return true;
  77. }
  78. return false;
  79. }
  80. };
  81. LLEventHandler gEventHandler;
  82. LLFloaterEvent::LLFloaterEvent(const LLSD& key)
  83. : LLFloater(key),
  84.   mEventID(0)
  85. {
  86. }
  87. LLFloaterEvent::~LLFloaterEvent()
  88. {
  89. }
  90. BOOL LLFloaterEvent::postBuild()
  91. {
  92. mTBName = getChild<LLTextBox>("event_name");
  93. mTBCategory = getChild<LLTextBox>("event_category");
  94. mTBDate = getChild<LLTextBox>("event_date");
  95. mTBDuration = getChild<LLTextBox>("event_duration");
  96. mTBDesc = getChild<LLExpandableTextBox>("event_desc");
  97. mTBDesc->setEnabled(FALSE);
  98. mTBRunBy = getChild<LLTextBox>("event_runby");
  99. mTBLocation = getChild<LLTextBox>("event_location");
  100. mTBCover = getChild<LLTextBox>("event_cover");
  101. mTeleportBtn = getChild<LLButton>( "teleport_btn");
  102. mTeleportBtn->setClickedCallback(onClickTeleport, this);
  103. mMapBtn = getChild<LLButton>( "map_btn");
  104. mMapBtn->setClickedCallback(onClickMap, this);
  105. mNotifyBtn = getChild<LLButton>( "notify_btn");
  106. mNotifyBtn->setClickedCallback(onClickNotify, this);
  107. mCreateEventBtn = getChild<LLButton>( "create_event_btn");
  108. mCreateEventBtn->setClickedCallback(onClickCreateEvent, this);
  109. mGodDeleteEventBtn = getChild<LLButton>( "god_delete_event_btn");
  110. mGodDeleteEventBtn->setClickedCallback(boost::bind(&LLFloaterEvent::onClickDeleteEvent, this));
  111. return TRUE;
  112. }
  113. void LLFloaterEvent::setEventID(const U32 event_id)
  114. {
  115. mEventID = event_id;
  116. // Should reset all of the panel state here
  117. resetInfo();
  118. if (event_id != 0)
  119. {
  120. sendEventInfoRequest();
  121. }
  122. }
  123. void LLFloaterEvent::onClickDeleteEvent()
  124. {
  125. LLMessageSystem* msg = gMessageSystem;
  126. msg->newMessageFast(_PREHASH_EventGodDelete);
  127. msg->nextBlockFast(_PREHASH_AgentData);
  128. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  129. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  130. msg->nextBlockFast(_PREHASH_EventData);
  131. msg->addU32Fast(_PREHASH_EventID, mEventID);
  132. gAgent.sendReliableMessage();
  133. }
  134. void LLFloaterEvent::sendEventInfoRequest()
  135. {
  136. LLMessageSystem *msg = gMessageSystem;
  137. msg->newMessageFast(_PREHASH_EventInfoRequest);
  138. msg->nextBlockFast(_PREHASH_AgentData);
  139. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
  140. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
  141. msg->nextBlockFast(_PREHASH_EventData);
  142. msg->addU32Fast(_PREHASH_EventID, mEventID);
  143. gAgent.sendReliableMessage();
  144. }
  145. //static 
  146. void LLFloaterEvent::processEventInfoReply(LLMessageSystem *msg, void **)
  147. {
  148. // extract the agent id
  149. LLUUID agent_id;
  150. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id );
  151. LLFloaterEvent* floater = LLFloaterReg::getTypedInstance<LLFloaterEvent>("event");
  152. if(floater)
  153. {
  154. floater->mEventInfo.unpack(msg);
  155. floater->mTBName->setText(floater->mEventInfo.mName);
  156. floater->mTBCategory->setText(floater->mEventInfo.mCategoryStr);
  157. floater->mTBDate->setText(floater->mEventInfo.mTimeStr);
  158. floater->mTBDesc->setText(floater->mEventInfo.mDesc);
  159. floater->mTBRunBy->setText(LLSLURL::buildCommand("agent", floater->mEventInfo.mRunByID, "inspect"));
  160. floater->mTBDuration->setText(llformat("%d:%.2d", floater->mEventInfo.mDuration / 60, floater->mEventInfo.mDuration % 60));
  161. if (!floater->mEventInfo.mHasCover)
  162. {
  163. floater->mTBCover->setText(floater->getString("none"));
  164. }
  165. else
  166. {
  167. floater->mTBCover->setText(llformat("%d", floater->mEventInfo.mCover));
  168. }
  169. F32 global_x = (F32)floater->mEventInfo.mPosGlobal.mdV[VX];
  170. F32 global_y = (F32)floater->mEventInfo.mPosGlobal.mdV[VY];
  171. S32 region_x = llround(global_x) % REGION_WIDTH_UNITS;
  172. S32 region_y = llround(global_y) % REGION_WIDTH_UNITS;
  173. S32 region_z = llround((F32)floater->mEventInfo.mPosGlobal.mdV[VZ]);
  174. std::string desc = floater->mEventInfo.mSimName + llformat(" (%d, %d, %d)", region_x, region_y, region_z);
  175. floater->mTBLocation->setText(desc);
  176. if (floater->mEventInfo.mEventFlags & EVENT_FLAG_MATURE)
  177. {
  178. floater->childSetVisible("event_mature_yes", TRUE);
  179. floater->childSetVisible("event_mature_no", FALSE);
  180. }
  181. else
  182. {
  183. floater->childSetVisible("event_mature_yes", FALSE);
  184. floater->childSetVisible("event_mature_no", TRUE);
  185. }
  186. if (floater->mEventInfo.mUnixTime < time_corrected())
  187. {
  188. floater->mNotifyBtn->setEnabled(FALSE);
  189. }
  190. else
  191. {
  192. floater->mNotifyBtn->setEnabled(TRUE);
  193. }
  194. if (gEventNotifier.hasNotification(floater->mEventInfo.mID))
  195. {
  196. floater->mNotifyBtn->setLabel(floater->getString("dont_notify"));
  197. }
  198. else
  199. {
  200. floater->mNotifyBtn->setLabel(floater->getString("notify"));
  201. }
  202. floater->mMapBtn->setEnabled(TRUE);
  203. floater->mTeleportBtn->setEnabled(TRUE);
  204. }
  205. }
  206. void LLFloaterEvent::draw()
  207. {
  208. mGodDeleteEventBtn->setVisible(gAgent.isGodlike());
  209. LLPanel::draw();
  210. }
  211. void LLFloaterEvent::resetInfo()
  212. {
  213. mTBName->setText(LLStringUtil::null);
  214. mTBCategory->setText(LLStringUtil::null);
  215. mTBDate->setText(LLStringUtil::null);
  216. mTBDesc->setText(LLStringUtil::null);
  217. mTBDuration->setText(LLStringUtil::null);
  218. mTBCover->setText(LLStringUtil::null);
  219. mTBLocation->setText(LLStringUtil::null);
  220. mTBRunBy->setText(LLStringUtil::null);
  221. mNotifyBtn->setEnabled(FALSE);
  222. mMapBtn->setEnabled(FALSE);
  223. mTeleportBtn->setEnabled(FALSE);
  224. }
  225. // static
  226. void LLFloaterEvent::onClickTeleport(void* data)
  227. {
  228. LLFloaterEvent* self = (LLFloaterEvent*)data;
  229. LLFloaterWorldMap* worldmap_instance = LLFloaterWorldMap::getInstance();
  230. if (!self->mEventInfo.mPosGlobal.isExactlyZero()&&worldmap_instance)
  231. {
  232. gAgent.teleportViaLocation(self->mEventInfo.mPosGlobal);
  233. worldmap_instance->trackLocation(self->mEventInfo.mPosGlobal);
  234. }
  235. }
  236. // static
  237. void LLFloaterEvent::onClickMap(void* data)
  238. {
  239. LLFloaterEvent* self = (LLFloaterEvent*)data;
  240. LLFloaterWorldMap* worldmap_instance = LLFloaterWorldMap::getInstance();
  241. if (!self->mEventInfo.mPosGlobal.isExactlyZero()&&worldmap_instance)
  242. {
  243. worldmap_instance->trackLocation(self->mEventInfo.mPosGlobal);
  244. LLFloaterReg::showInstance("world_map", "center");
  245. }
  246. }
  247. // static
  248. void LLFloaterEvent::onClickCreateEvent(void* data)
  249. {
  250. LLNotificationsUtil::add("PromptGoToEventsPage");//, LLSD(), LLSD(), callbackCreateEventWebPage); 
  251. }
  252. // static
  253. void LLFloaterEvent::onClickNotify(void *data)
  254. {
  255. LLFloaterEvent* self = (LLFloaterEvent*)data;
  256. if (!gEventNotifier.hasNotification(self->mEventID))
  257. {
  258. gEventNotifier.add(self->mEventInfo);
  259. self->mNotifyBtn->setLabel(self->getString("dont_notify"));
  260. }
  261. else
  262. {
  263. gEventNotifier.remove(self->mEventInfo.mID);
  264. self->mNotifyBtn->setLabel(self->getString("notify"));
  265. }
  266. }