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

游戏引擎

开发平台:

C++ Builder

  1. /* @file llvoiceremotectrl.cpp
  2.  * @brief A remote control for voice chat
  3.  *
  4.  * $LicenseInfo:firstyear=2005&license=viewergpl$
  5.  * 
  6.  * Copyright (c) 2005-2010, Linden Research, Inc.
  7.  * 
  8.  * Second Life Viewer Source Code
  9.  * The source code in this file ("Source Code") is provided by Linden Lab
  10.  * to you under the terms of the GNU General Public License, version 2.0
  11.  * ("GPL"), unless you have obtained a separate licensing agreement
  12.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  13.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15.  * 
  16.  * There are special exceptions to the terms and conditions of the GPL as
  17.  * it is applied to this Source Code. View the full text of the exception
  18.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  19.  * online at
  20.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21.  * 
  22.  * By copying, modifying or distributing this software, you acknowledge
  23.  * that you have read and understood your obligations described above,
  24.  * and agree to abide by those obligations.
  25.  * 
  26.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28.  * COMPLETENESS OR PERFORMANCE.
  29.  * $/LicenseInfo$
  30.  */
  31. #include "llviewerprecompiledheaders.h"
  32. #include "llvoiceremotectrl.h"
  33. #include "llagent.h"
  34. #include "llui.h"
  35. #include "llbutton.h"
  36. #include "lluictrlfactory.h"
  37. #include "llviewercontrol.h"
  38. #include "llvoicechannel.h"
  39. #include "llvoiceclient.h"
  40. #include "llfloaterchatterbox.h"
  41. #include "llfloaterreg.h"
  42. #include "lliconctrl.h"
  43. #include "lloverlaybar.h"
  44. #include "lltextbox.h"
  45. LLVoiceRemoteCtrl::LLVoiceRemoteCtrl ()
  46.   : LLPanel()
  47. {
  48. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_voice_remote.xml");
  49. setIsChrome(TRUE);
  50. setFocusRoot(TRUE);
  51. mCommitCallbackRegistrar.add("VoiceRemote.Lock",     boost::bind(&LLVoiceRemoteCtrl::onBtnLock, this));
  52. mCommitCallbackRegistrar.add("VoiceRemote.Popup",    boost::bind(&LLVoiceRemoteCtrl::onClickPopupBtn, this));
  53. }
  54. LLVoiceRemoteCtrl::~LLVoiceRemoteCtrl()
  55. {
  56. }
  57. void LLVoiceRemoteCtrl::expandOrCollapse()
  58. {
  59. deleteAllChildren();
  60. if (gSavedSettings.getBOOL("ShowVoiceChannelPopup"))
  61. {
  62. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_voice_remote_expanded.xml");
  63. }
  64. else
  65. {
  66. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_voice_remote.xml");
  67. }
  68. }
  69. BOOL LLVoiceRemoteCtrl::postBuild()
  70. {
  71. mTalkBtn = getChild<LLButton>("push_to_talk");
  72. mTalkBtn->setClickedCallback(onBtnTalkClicked, this);
  73. mTalkBtn->setHeldDownCallback(onBtnTalkHeld, this);
  74. mTalkBtn->setMouseUpCallback(onBtnTalkReleased, this);
  75. mTalkLockBtn = getChild<LLButton>("ptt_lock");
  76. mSpeakersBtn = getChild<LLButton>("speakers_btn");
  77. //childSetAction("end_call_btn", onClickEndCall, this);  not in use
  78. return TRUE;
  79. }
  80. void LLVoiceRemoteCtrl::draw()
  81. {
  82. BOOL voice_active = FALSE;
  83. LLVoiceChannel* channelp = LLVoiceChannel::getCurrentVoiceChannel();
  84. if (channelp)
  85. {
  86. voice_active = channelp->isActive();
  87. }
  88. mTalkBtn->setEnabled(voice_active);
  89. mTalkLockBtn->setEnabled(voice_active);
  90. // propagate ptt state to button display,
  91. if (!mTalkBtn->hasMouseCapture())
  92. {
  93. // not in push to talk mode, or push to talk is active means I'm talking
  94. mTalkBtn->setToggleState(!gSavedSettings.getBOOL("PTTCurrentlyEnabled") || gVoiceClient->getUserPTTState());
  95. }
  96. mSpeakersBtn->setToggleState(LLFloaterReg::instanceVisible("active_speakers",LLSD()));
  97. mTalkLockBtn->setToggleState(!gSavedSettings.getBOOL("PTTCurrentlyEnabled"));
  98. std::string talk_blip_image;
  99. if (gVoiceClient->getIsSpeaking(gAgent.getID()))
  100. {
  101. F32 voice_power = gVoiceClient->getCurrentPower(gAgent.getID());
  102. if (voice_power > LLVoiceClient::OVERDRIVEN_POWER_LEVEL)
  103. {
  104. talk_blip_image = "icn_voice_ptt-on-lvl3.tga";
  105. }
  106. else
  107. {
  108. F32 power = gVoiceClient->getCurrentPower(gAgent.getID());
  109. S32 icon_image_idx = llmin(2, llfloor((power / LLVoiceClient::OVERDRIVEN_POWER_LEVEL) * 3.f));
  110. switch(icon_image_idx)
  111. {
  112. case 0:
  113. talk_blip_image = "icn_voice_ptt-on.tga";
  114. break;
  115. case 1:
  116. talk_blip_image = "icn_voice_ptt-on-lvl1.tga";
  117. break;
  118. case 2:
  119. talk_blip_image = "icn_voice_ptt-on-lvl2.tga";
  120. break;
  121. }
  122. }
  123. }
  124. else
  125. {
  126. talk_blip_image = "icn_voice_ptt-off.tga";
  127. }
  128. LLIconCtrl* icon = getChild<LLIconCtrl>("voice_volume");
  129. if (icon)
  130. {
  131. icon->setValue(talk_blip_image);
  132. }
  133. LLFloater* voice_floater = LLFloaterChatterBox::getCurrentVoiceFloater();
  134. std::string active_channel_name;
  135. if (voice_floater)
  136. {
  137. active_channel_name = voice_floater->getShortTitle();
  138. }
  139. LLVoiceChannel* current_channel = LLVoiceChannel::getCurrentVoiceChannel();
  140. //childSetEnabled("end_call_btn", LLVoiceClient::voiceEnabled() 
  141. // && current_channel
  142. // && current_channel->isActive()
  143. // && current_channel != LLVoiceChannelProximal::getInstance());
  144. childSetValue("channel_label", active_channel_name);
  145. childSetToolTip("voice_channel_bg", active_channel_name);
  146. if (current_channel)
  147. {
  148. if (voice_floater)
  149. {
  150. childSetValue("voice_channel_icon", voice_floater->getString("voice_icon"));
  151. }
  152. LLButton* voice_channel_bg = getChild<LLButton>("voice_channel_bg", FALSE);
  153. LLColor4 bg_color;
  154. if (current_channel->isActive())
  155. {
  156. bg_color = lerp(LLColor4::green, LLColor4::white, 0.7f);
  157. }
  158. else if (current_channel->getState() == LLVoiceChannel::STATE_ERROR)
  159. {
  160. bg_color = lerp(LLColor4::red, LLColor4::white, 0.7f);
  161. }
  162. else // active, but not connected
  163. {
  164. bg_color = lerp(LLColor4::yellow, LLColor4::white, 0.7f);
  165. }
  166. voice_channel_bg->setImageColor(bg_color);
  167. }
  168. LLButton* expand_button = getChild<LLButton>("show_channel");
  169. if (expand_button)
  170. {
  171. if (expand_button->getToggleState())
  172. {
  173. expand_button->setImageOverlay(std::string("arrow_down.tga"));
  174. }
  175. else
  176. {
  177. expand_button->setImageOverlay(std::string("arrow_up.tga"));
  178. }
  179. }
  180. LLPanel::draw();
  181. }
  182. void LLVoiceRemoteCtrl::onBtnTalkClicked(void *user_data)
  183. {
  184. // when in toggle mode, clicking talk button turns mic on/off
  185. if (gSavedSettings.getBOOL("PushToTalkToggle"))
  186. {
  187. gVoiceClient->toggleUserPTTState();
  188. }
  189. }
  190. void LLVoiceRemoteCtrl::onBtnTalkHeld(void *user_data)
  191. {
  192. // when not in toggle mode, holding down talk button turns on mic
  193. if (!gSavedSettings.getBOOL("PushToTalkToggle"))
  194. {
  195. gVoiceClient->setUserPTTState(true);
  196. }
  197. }
  198. void LLVoiceRemoteCtrl::onBtnTalkReleased(void* user_data)
  199. {
  200. // when not in toggle mode, releasing talk button turns off mic
  201. if (!gSavedSettings.getBOOL("PushToTalkToggle"))
  202. {
  203. gVoiceClient->setUserPTTState(false);
  204. }
  205. }
  206. void LLVoiceRemoteCtrl::onBtnLock()
  207. {
  208. gSavedSettings.setBOOL("PTTCurrentlyEnabled",mTalkLockBtn->getToggleState());
  209. }
  210. void LLVoiceRemoteCtrl::onClickPopupBtn()
  211. {
  212.     expandOrCollapse();
  213. gOverlayBar->layoutButtons();
  214. }
  215. //static
  216. void LLVoiceRemoteCtrl::onClickEndCall(void* user_data)
  217. {
  218. LLVoiceChannel* current_channel = LLVoiceChannel::getCurrentVoiceChannel();
  219. if (current_channel && current_channel != LLVoiceChannelProximal::getInstance())
  220. {
  221. current_channel->deactivate();
  222. }
  223. }