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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file lloverlaybar.cpp
  3.  * @brief LLOverlayBar class implementation
  4.  *
  5.  * $LicenseInfo:firstyear=2002&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2002-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. // Temporary buttons that appear at the bottom of the screen when you
  33. // are in a mode.
  34. #include "llviewerprecompiledheaders.h"
  35. #include "lloverlaybar.h"
  36. #include "llaudioengine.h"
  37. #include "llrender.h"
  38. #include "llagent.h"
  39. #include "llbutton.h"
  40. #include "llfocusmgr.h"
  41. #include "llimview.h"
  42. #include "llmediaremotectrl.h"
  43. #include "llparcel.h"
  44. #include "lltextbox.h"
  45. #include "llui.h"
  46. #include "llviewercontrol.h"
  47. #include "llviewertexturelist.h"
  48. #include "llviewerjoystick.h"
  49. #include "llviewermedia.h"
  50. #include "llviewermenu.h" // handle_reset_view()
  51. #include "llviewermedia.h"
  52. #include "llviewerparcelmedia.h"
  53. #include "llviewerparcelmgr.h"
  54. #include "lluictrlfactory.h"
  55. #include "llviewerwindow.h"
  56. #include "llvoiceclient.h"
  57. #include "llvoavatarself.h"
  58. #include "llvoiceremotectrl.h"
  59. #include "llmediactrl.h"
  60. #include "llselectmgr.h"
  61. //
  62. // Globals
  63. //
  64. LLOverlayBar *gOverlayBar = NULL;
  65. extern S32 MENU_BAR_HEIGHT;
  66. //
  67. // Functions
  68. //
  69. void* LLOverlayBar::createMediaRemote(void* userdata)
  70. {
  71. LLOverlayBar *self = (LLOverlayBar*)userdata;
  72. self->mMediaRemote =  new LLMediaRemoteCtrl ();
  73. return self->mMediaRemote;
  74. }
  75. void* LLOverlayBar::createVoiceRemote(void* userdata)
  76. {
  77. LLOverlayBar *self = (LLOverlayBar*)userdata;
  78. self->mVoiceRemote = new LLVoiceRemoteCtrl();
  79. return self->mVoiceRemote;
  80. }
  81. LLOverlayBar::LLOverlayBar()
  82. : LLPanel(),
  83. mMediaRemote(NULL),
  84. mVoiceRemote(NULL),
  85. mMusicState(STOPPED)
  86. {
  87. setMouseOpaque(FALSE);
  88. setIsChrome(TRUE);
  89. mBuilt = false;
  90. mFactoryMap["media_remote"] = LLCallbackMap(LLOverlayBar::createMediaRemote, this);
  91. mFactoryMap["voice_remote"] = LLCallbackMap(LLOverlayBar::createVoiceRemote, this);
  92. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_overlaybar.xml");
  93. }
  94. BOOL LLOverlayBar::postBuild()
  95. {
  96. childSetAction("Set Not Busy",onClickSetNotBusy,this);
  97. childSetAction("Mouselook",onClickMouselook,this);
  98. childSetAction("Stand Up",onClickStandUp,this);
  99.   childSetAction("Flycam",onClickFlycam,this);
  100. childSetVisible("chat_bar", gSavedSettings.getBOOL("ChatVisible"));
  101. mVoiceRemote->expandOrCollapse();
  102. mMediaRemote->expandOrCollapse();
  103. setFocusRoot(TRUE);
  104. mBuilt = true;
  105. layoutButtons();
  106. return TRUE;
  107. }
  108. LLOverlayBar::~LLOverlayBar()
  109. {
  110. // LLView destructor cleans up children
  111. }
  112. // virtual
  113. void LLOverlayBar::reshape(S32 width, S32 height, BOOL called_from_parent)
  114. {
  115. LLView::reshape(width, height, called_from_parent);
  116. if (mBuilt) 
  117. {
  118. layoutButtons();
  119. }
  120. }
  121. void LLOverlayBar::layoutButtons()
  122. {
  123. LLView* state_buttons_panel = getChildView("state_buttons");
  124. if (state_buttons_panel->getVisible())
  125. {
  126. LLViewQuery query;
  127. LLWidgetTypeFilter<LLButton> widget_filter;
  128. query.addPreFilter(LLEnabledFilter::getInstance());
  129. query.addPreFilter(&widget_filter);
  130. child_list_t button_list = query(state_buttons_panel);
  131. const S32 MAX_BAR_WIDTH = 600;
  132. S32 bar_width = llclamp(state_buttons_panel->getRect().getWidth(), 0, MAX_BAR_WIDTH);
  133. // calculate button widths
  134. const S32 MAX_BUTTON_WIDTH = 150;
  135. const S32 STATUS_BAR_PAD = 10;
  136. S32 segment_width = llclamp(lltrunc((F32)(bar_width) / (F32)button_list.size()), 0, MAX_BUTTON_WIDTH);
  137. S32 btn_width = segment_width - STATUS_BAR_PAD;
  138. // Evenly space all buttons, starting from left
  139. S32 left = 0;
  140. S32 bottom = 1;
  141. for (child_list_reverse_iter_t child_iter = button_list.rbegin();
  142. child_iter != button_list.rend(); ++child_iter)
  143. {
  144. LLView *view = *child_iter;
  145. LLRect r = view->getRect();
  146. r.setOriginAndSize(left, bottom, btn_width, r.getHeight());
  147. view->setRect(r);
  148. left += segment_width;
  149. }
  150. }
  151. }
  152. // Per-frame updates of visibility
  153. void LLOverlayBar::refresh()
  154. {
  155. BOOL buttons_changed = FALSE;
  156. BOOL im_received = gIMMgr->getIMReceived();
  157. LLButton* button = getChild<LLButton>("IM Received");
  158. if (button && button->getVisible() != im_received)
  159. {
  160. button->setVisible(im_received);
  161. sendChildToFront(button);
  162. moveChildToBackOfTabGroup(button);
  163. buttons_changed = TRUE;
  164. }
  165. BOOL busy = gAgent.getBusy();
  166. button = getChild<LLButton>("Set Not Busy");
  167. if (button && button->getVisible() != busy)
  168. {
  169. button->setVisible(busy);
  170. sendChildToFront(button);
  171. moveChildToBackOfTabGroup(button);
  172. buttons_changed = TRUE;
  173. }
  174. BOOL flycam = LLViewerJoystick::getInstance()->getOverrideCamera();
  175. button = getChild<LLButton>("Flycam");
  176. if (button && button->getVisible() != flycam)
  177. {
  178. button->setVisible(flycam);
  179. sendChildToFront(button);
  180. moveChildToBackOfTabGroup(button);
  181. buttons_changed = TRUE;
  182. }
  183. BOOL mouselook_grabbed;
  184. mouselook_grabbed = gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_DOWN_INDEX)
  185. || gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_UP_INDEX);
  186. button = getChild<LLButton>("Mouselook");
  187. if (button && button->getVisible() != mouselook_grabbed)
  188. {
  189. button->setVisible(mouselook_grabbed);
  190. sendChildToFront(button);
  191. moveChildToBackOfTabGroup(button);
  192. buttons_changed = TRUE;
  193. }
  194. BOOL sitting = FALSE;
  195. if (gAgent.getAvatarObject())
  196. {
  197. sitting = gAgent.getAvatarObject()->isSitting();
  198. }
  199. button = getChild<LLButton>("Stand Up");
  200. if (button && button->getVisible() != sitting)
  201. {
  202. button->setVisible(sitting);
  203. sendChildToFront(button);
  204. moveChildToBackOfTabGroup(button);
  205. buttons_changed = TRUE;
  206. }
  207. moveChildToBackOfTabGroup(mMediaRemote);
  208. moveChildToBackOfTabGroup(mVoiceRemote);
  209. // turn off the whole bar in mouselook
  210. if (gAgent.cameraMouselook())
  211. {
  212. childSetVisible("media_remote_container", FALSE);
  213. childSetVisible("voice_remote_container", FALSE);
  214. childSetVisible("state_buttons", FALSE);
  215. }
  216. else
  217. {
  218. // update "remotes"
  219. childSetVisible("media_remote_container", TRUE);
  220. childSetVisible("voice_remote_container", LLVoiceClient::voiceEnabled());
  221. childSetVisible("state_buttons", TRUE);
  222. }
  223. // always let user toggle into and out of chatbar
  224. childSetVisible("chat_bar", gSavedSettings.getBOOL("ChatVisible"));
  225. if (buttons_changed)
  226. {
  227. layoutButtons();
  228. }
  229. }
  230. //-----------------------------------------------------------------------
  231. // Static functions
  232. //-----------------------------------------------------------------------
  233. // static
  234. void LLOverlayBar::onClickSetNotBusy(void*)
  235. {
  236. gAgent.clearBusy();
  237. }
  238. // static
  239. void LLOverlayBar::onClickFlycam(void*)
  240. {
  241. LLViewerJoystick::getInstance()->toggleFlycam();
  242. }
  243. // static
  244. void LLOverlayBar::onClickResetView(void* data)
  245. {
  246. handle_reset_view();
  247. }
  248. //static
  249. void LLOverlayBar::onClickMouselook(void*)
  250. {
  251. gAgent.changeCameraToMouselook();
  252. }
  253. //static
  254. void LLOverlayBar::onClickStandUp(void*)
  255. {
  256. LLSelectMgr::getInstance()->deselectAllForStandingUp();
  257. gAgent.setControlFlags(AGENT_CONTROL_STAND_UP);
  258. }
  259. ////////////////////////////////////////////////////////////////////////////////
  260. // static media helpers
  261. // *TODO: Move this into an audio manager abstraction
  262. //static
  263. void LLOverlayBar::mediaStop(void*)
  264. {
  265. if (!gOverlayBar)
  266. {
  267. // return;
  268. }
  269. LLViewerParcelMedia::stop();
  270. }
  271. //static
  272. void LLOverlayBar::toggleMediaPlay(void*)
  273. {
  274. if (!gOverlayBar)
  275. {
  276. // return;
  277. }
  278. if (LLViewerParcelMedia::getStatus() == LLViewerMediaImpl::MEDIA_PAUSED)
  279. {
  280. LLViewerParcelMedia::start();
  281. }
  282. else if(LLViewerParcelMedia::getStatus() == LLViewerMediaImpl::MEDIA_PLAYING)
  283. {
  284. LLViewerParcelMedia::pause();
  285. }
  286. else
  287. {
  288. LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  289. if (parcel)
  290. {
  291. LLViewerParcelMedia::play(parcel);
  292. }
  293. }
  294. }
  295. //static
  296. void LLOverlayBar::toggleMusicPlay(void*)
  297. {
  298. if (gAudiop->isInternetStreamPlaying() != 1)
  299. {
  300. if (gAudiop)
  301. {
  302. LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  303. if ( parcel )
  304. {
  305. // this doesn't work properly when crossing parcel boundaries - even when the 
  306. // stream is stopped, it doesn't return the right thing - commenting out for now.
  307. //  if ( gAudiop->isInternetStreamPlaying() == 0 )
  308. {
  309. gAudiop->startInternetStream(parcel->getMusicURL());
  310. }
  311. }
  312. }
  313. }
  314. //else
  315. //{
  316. // gOverlayBar->mMusicState = PAUSED; // desired state
  317. // if (gAudiop)
  318. // {
  319. // gAudiop->pauseInternetStream(1);
  320. // }
  321. //}
  322. else
  323. {
  324. if (gAudiop)
  325. {
  326. gAudiop->stopInternetStream();
  327. }
  328. }
  329. }