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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloaterjoystick.cpp
  3.  * @brief Joystick preferences panel
  4.  *
  5.  * $LicenseInfo:firstyear=2007&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2007-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. // file include
  34. #include "llfloaterjoystick.h"
  35. // linden library includes
  36. #include "llerror.h"
  37. #include "llrect.h"
  38. #include "llstring.h"
  39. // project includes
  40. #include "lluictrlfactory.h"
  41. #include "llviewercontrol.h"
  42. #include "llappviewer.h"
  43. #include "llviewerjoystick.h"
  44. #include "llcheckboxctrl.h"
  45. LLFloaterJoystick::LLFloaterJoystick(const LLSD& data)
  46. : LLFloater(data)
  47. {
  48. //Called from floater reg: LLUICtrlFactory::getInstance()->buildFloater(this, "floater_joystick.xml");
  49. initFromSettings();
  50. }
  51. void LLFloaterJoystick::draw()
  52. {
  53. bool joystick_inited = LLViewerJoystick::getInstance()->isJoystickInitialized();
  54. childSetEnabled("enable_joystick", joystick_inited);
  55. childSetEnabled("joystick_type", joystick_inited);
  56. std::string desc = LLViewerJoystick::getInstance()->getDescription();
  57. if (desc.empty()) desc = getString("NoDevice");
  58. childSetText("joystick_type", desc);
  59. LLViewerJoystick* joystick(LLViewerJoystick::getInstance());
  60. for (U32 i = 0; i < 6; i++)
  61. {
  62. F32 value = joystick->getJoystickAxis(i);
  63. mAxisStats[i]->addValue(value * gFrameIntervalSeconds);
  64. if (mAxisStatsBar[i])
  65. {
  66. F32 minbar, maxbar;
  67. mAxisStatsBar[i]->getRange(minbar, maxbar);
  68. if (llabs(value) > maxbar)
  69. {
  70. F32 range = llabs(value);
  71. mAxisStatsBar[i]->setRange(-range, range, range * 0.25f, range * 0.5f);
  72. }
  73. }
  74. }
  75. LLFloater::draw();
  76. }
  77. BOOL LLFloaterJoystick::postBuild()
  78. {
  79. center();
  80. F32 range = gSavedSettings.getBOOL("Cursor3D") ? 128.f : 2.f;
  81. for (U32 i = 0; i < 6; i++)
  82. {
  83. mAxisStats[i] = new LLStat(4);
  84. std::string axisname = llformat("axis%d", i);
  85. mAxisStatsBar[i] = getChild<LLStatBar>(axisname);
  86. if (mAxisStatsBar[i])
  87. {
  88. mAxisStatsBar[i]->setStat(mAxisStats[i]);
  89. mAxisStatsBar[i]->setRange(-range, range, range * 0.25f, range * 0.5f);
  90. }
  91. }
  92. mCheckJoystickEnabled = getChild<LLCheckBoxCtrl>("enable_joystick");
  93. childSetCommitCallback("enable_joystick",onCommitJoystickEnabled,this);
  94. mCheckFlycamEnabled = getChild<LLCheckBoxCtrl>("JoystickFlycamEnabled");
  95. childSetCommitCallback("JoystickFlycamEnabled",onCommitJoystickEnabled,this);
  96. childSetAction("SpaceNavigatorDefaults", onClickRestoreSNDefaults, this);
  97. childSetAction("cancel_btn", onClickCancel, this);
  98. childSetAction("ok_btn", onClickOK, this);
  99. refresh();
  100. return TRUE;
  101. }
  102. LLFloaterJoystick::~LLFloaterJoystick()
  103. {
  104. // Children all cleaned up by default view destructor.
  105. }
  106. void LLFloaterJoystick::apply()
  107. {
  108. }
  109. void LLFloaterJoystick::initFromSettings()
  110. {
  111. mJoystickEnabled = gSavedSettings.getBOOL("JoystickEnabled");
  112. mJoystickAxis[0] = gSavedSettings.getS32("JoystickAxis0");
  113. mJoystickAxis[1] = gSavedSettings.getS32("JoystickAxis1");
  114. mJoystickAxis[2] = gSavedSettings.getS32("JoystickAxis2");
  115. mJoystickAxis[3] = gSavedSettings.getS32("JoystickAxis3");
  116. mJoystickAxis[4] = gSavedSettings.getS32("JoystickAxis4");
  117. mJoystickAxis[5] = gSavedSettings.getS32("JoystickAxis5");
  118. mJoystickAxis[6] = gSavedSettings.getS32("JoystickAxis6");
  119. m3DCursor = gSavedSettings.getBOOL("Cursor3D");
  120. mAutoLeveling = gSavedSettings.getBOOL("AutoLeveling");
  121. mZoomDirect  = gSavedSettings.getBOOL("ZoomDirect");
  122. mAvatarEnabled = gSavedSettings.getBOOL("JoystickAvatarEnabled");
  123. mBuildEnabled = gSavedSettings.getBOOL("JoystickBuildEnabled");
  124. mFlycamEnabled = gSavedSettings.getBOOL("JoystickFlycamEnabled");
  125. mAvatarAxisScale[0] = gSavedSettings.getF32("AvatarAxisScale0");
  126. mAvatarAxisScale[1] = gSavedSettings.getF32("AvatarAxisScale1");
  127. mAvatarAxisScale[2] = gSavedSettings.getF32("AvatarAxisScale2");
  128. mAvatarAxisScale[3] = gSavedSettings.getF32("AvatarAxisScale3");
  129. mAvatarAxisScale[4] = gSavedSettings.getF32("AvatarAxisScale4");
  130. mAvatarAxisScale[5] = gSavedSettings.getF32("AvatarAxisScale5");
  131. mBuildAxisScale[0] = gSavedSettings.getF32("BuildAxisScale0");
  132. mBuildAxisScale[1] = gSavedSettings.getF32("BuildAxisScale1");
  133. mBuildAxisScale[2] = gSavedSettings.getF32("BuildAxisScale2");
  134. mBuildAxisScale[3] = gSavedSettings.getF32("BuildAxisScale3");
  135. mBuildAxisScale[4] = gSavedSettings.getF32("BuildAxisScale4");
  136. mBuildAxisScale[5] = gSavedSettings.getF32("BuildAxisScale5");
  137. mFlycamAxisScale[0] = gSavedSettings.getF32("FlycamAxisScale0");
  138. mFlycamAxisScale[1] = gSavedSettings.getF32("FlycamAxisScale1");
  139. mFlycamAxisScale[2] = gSavedSettings.getF32("FlycamAxisScale2");
  140. mFlycamAxisScale[3] = gSavedSettings.getF32("FlycamAxisScale3");
  141. mFlycamAxisScale[4] = gSavedSettings.getF32("FlycamAxisScale4");
  142. mFlycamAxisScale[5] = gSavedSettings.getF32("FlycamAxisScale5");
  143. mFlycamAxisScale[6] = gSavedSettings.getF32("FlycamAxisScale6");
  144. mAvatarAxisDeadZone[0] = gSavedSettings.getF32("AvatarAxisDeadZone0");
  145. mAvatarAxisDeadZone[1] = gSavedSettings.getF32("AvatarAxisDeadZone1");
  146. mAvatarAxisDeadZone[2] = gSavedSettings.getF32("AvatarAxisDeadZone2");
  147. mAvatarAxisDeadZone[3] = gSavedSettings.getF32("AvatarAxisDeadZone3");
  148. mAvatarAxisDeadZone[4] = gSavedSettings.getF32("AvatarAxisDeadZone4");
  149. mAvatarAxisDeadZone[5] = gSavedSettings.getF32("AvatarAxisDeadZone5");
  150. mBuildAxisDeadZone[0] = gSavedSettings.getF32("BuildAxisDeadZone0");
  151. mBuildAxisDeadZone[1] = gSavedSettings.getF32("BuildAxisDeadZone1");
  152. mBuildAxisDeadZone[2] = gSavedSettings.getF32("BuildAxisDeadZone2");
  153. mBuildAxisDeadZone[3] = gSavedSettings.getF32("BuildAxisDeadZone3");
  154. mBuildAxisDeadZone[4] = gSavedSettings.getF32("BuildAxisDeadZone4");
  155. mBuildAxisDeadZone[5] = gSavedSettings.getF32("BuildAxisDeadZone5");
  156. mFlycamAxisDeadZone[0] = gSavedSettings.getF32("FlycamAxisDeadZone0");
  157. mFlycamAxisDeadZone[1] = gSavedSettings.getF32("FlycamAxisDeadZone1");
  158. mFlycamAxisDeadZone[2] = gSavedSettings.getF32("FlycamAxisDeadZone2");
  159. mFlycamAxisDeadZone[3] = gSavedSettings.getF32("FlycamAxisDeadZone3");
  160. mFlycamAxisDeadZone[4] = gSavedSettings.getF32("FlycamAxisDeadZone4");
  161. mFlycamAxisDeadZone[5] = gSavedSettings.getF32("FlycamAxisDeadZone5");
  162. mFlycamAxisDeadZone[6] = gSavedSettings.getF32("FlycamAxisDeadZone6");
  163. mAvatarFeathering = gSavedSettings.getF32("AvatarFeathering");
  164. mBuildFeathering = gSavedSettings.getF32("BuildFeathering");
  165. mFlycamFeathering = gSavedSettings.getF32("FlycamFeathering");
  166. }
  167. void LLFloaterJoystick::refresh()
  168. {
  169. LLFloater::refresh();
  170. initFromSettings();
  171. }
  172. void LLFloaterJoystick::cancel()
  173. {
  174. gSavedSettings.setBOOL("JoystickEnabled", mJoystickEnabled);
  175. gSavedSettings.setS32("JoystickAxis0", mJoystickAxis[0]);
  176. gSavedSettings.setS32("JoystickAxis1", mJoystickAxis[1]);
  177. gSavedSettings.setS32("JoystickAxis2", mJoystickAxis[2]);
  178. gSavedSettings.setS32("JoystickAxis3", mJoystickAxis[3]);
  179. gSavedSettings.setS32("JoystickAxis4", mJoystickAxis[4]);
  180. gSavedSettings.setS32("JoystickAxis5", mJoystickAxis[5]);
  181. gSavedSettings.setS32("JoystickAxis6", mJoystickAxis[6]);
  182. gSavedSettings.setBOOL("Cursor3D", m3DCursor);
  183. gSavedSettings.setBOOL("AutoLeveling", mAutoLeveling);
  184. gSavedSettings.setBOOL("ZoomDirect", mZoomDirect );
  185. gSavedSettings.setBOOL("JoystickAvatarEnabled", mAvatarEnabled);
  186. gSavedSettings.setBOOL("JoystickBuildEnabled", mBuildEnabled);
  187. gSavedSettings.setBOOL("JoystickFlycamEnabled", mFlycamEnabled);
  188. gSavedSettings.setF32("AvatarAxisScale0", mAvatarAxisScale[0]);
  189. gSavedSettings.setF32("AvatarAxisScale1", mAvatarAxisScale[1]);
  190. gSavedSettings.setF32("AvatarAxisScale2", mAvatarAxisScale[2]);
  191. gSavedSettings.setF32("AvatarAxisScale3", mAvatarAxisScale[3]);
  192. gSavedSettings.setF32("AvatarAxisScale4", mAvatarAxisScale[4]);
  193. gSavedSettings.setF32("AvatarAxisScale5", mAvatarAxisScale[5]);
  194. gSavedSettings.setF32("BuildAxisScale0", mBuildAxisScale[0]);
  195. gSavedSettings.setF32("BuildAxisScale1", mBuildAxisScale[1]);
  196. gSavedSettings.setF32("BuildAxisScale2", mBuildAxisScale[2]);
  197. gSavedSettings.setF32("BuildAxisScale3", mBuildAxisScale[3]);
  198. gSavedSettings.setF32("BuildAxisScale4", mBuildAxisScale[4]);
  199. gSavedSettings.setF32("BuildAxisScale5", mBuildAxisScale[5]);
  200. gSavedSettings.setF32("FlycamAxisScale0", mFlycamAxisScale[0]);
  201. gSavedSettings.setF32("FlycamAxisScale1", mFlycamAxisScale[1]);
  202. gSavedSettings.setF32("FlycamAxisScale2", mFlycamAxisScale[2]);
  203. gSavedSettings.setF32("FlycamAxisScale3", mFlycamAxisScale[3]);
  204. gSavedSettings.setF32("FlycamAxisScale4", mFlycamAxisScale[4]);
  205. gSavedSettings.setF32("FlycamAxisScale5", mFlycamAxisScale[5]);
  206. gSavedSettings.setF32("FlycamAxisScale6", mFlycamAxisScale[6]);
  207. gSavedSettings.setF32("AvatarAxisDeadZone0", mAvatarAxisDeadZone[0]);
  208. gSavedSettings.setF32("AvatarAxisDeadZone1", mAvatarAxisDeadZone[1]);
  209. gSavedSettings.setF32("AvatarAxisDeadZone2", mAvatarAxisDeadZone[2]);
  210. gSavedSettings.setF32("AvatarAxisDeadZone3", mAvatarAxisDeadZone[3]);
  211. gSavedSettings.setF32("AvatarAxisDeadZone4", mAvatarAxisDeadZone[4]);
  212. gSavedSettings.setF32("AvatarAxisDeadZone5", mAvatarAxisDeadZone[5]);
  213. gSavedSettings.setF32("BuildAxisDeadZone0", mBuildAxisDeadZone[0]);
  214. gSavedSettings.setF32("BuildAxisDeadZone1", mBuildAxisDeadZone[1]);
  215. gSavedSettings.setF32("BuildAxisDeadZone2", mBuildAxisDeadZone[2]);
  216. gSavedSettings.setF32("BuildAxisDeadZone3", mBuildAxisDeadZone[3]);
  217. gSavedSettings.setF32("BuildAxisDeadZone4", mBuildAxisDeadZone[4]);
  218. gSavedSettings.setF32("BuildAxisDeadZone5", mBuildAxisDeadZone[5]);
  219. gSavedSettings.setF32("FlycamAxisDeadZone0", mFlycamAxisDeadZone[0]);
  220. gSavedSettings.setF32("FlycamAxisDeadZone1", mFlycamAxisDeadZone[1]);
  221. gSavedSettings.setF32("FlycamAxisDeadZone2", mFlycamAxisDeadZone[2]);
  222. gSavedSettings.setF32("FlycamAxisDeadZone3", mFlycamAxisDeadZone[3]);
  223. gSavedSettings.setF32("FlycamAxisDeadZone4", mFlycamAxisDeadZone[4]);
  224. gSavedSettings.setF32("FlycamAxisDeadZone5", mFlycamAxisDeadZone[5]);
  225. gSavedSettings.setF32("FlycamAxisDeadZone6", mFlycamAxisDeadZone[6]);
  226. gSavedSettings.setF32("AvatarFeathering", mAvatarFeathering);
  227. gSavedSettings.setF32("BuildFeathering", mBuildFeathering);
  228. gSavedSettings.setF32("FlycamFeathering", mFlycamFeathering);
  229. }
  230. void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel)
  231. {
  232. LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel;
  233. BOOL joystick_enabled = self->mCheckJoystickEnabled->get();
  234. BOOL flycam_enabled = self->mCheckFlycamEnabled->get();
  235. if (!joystick_enabled || !flycam_enabled)
  236. {
  237. // Turn off flycam
  238. LLViewerJoystick* joystick(LLViewerJoystick::getInstance());
  239. if (joystick->getOverrideCamera())
  240. {
  241. joystick->toggleFlycam();
  242. }
  243. }
  244. }
  245. void LLFloaterJoystick::onClickRestoreSNDefaults(void *joy_panel)
  246. {
  247. setSNDefaults();
  248. }
  249. void LLFloaterJoystick::onClickCancel(void *joy_panel)
  250. {
  251. if (joy_panel)
  252. {
  253. LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel;
  254. if (self)
  255. {
  256. self->cancel();
  257. self->closeFloater();
  258. }
  259. }
  260. }
  261. void LLFloaterJoystick::onClickOK(void *joy_panel)
  262. {
  263. if (joy_panel)
  264. {
  265. LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel;
  266. if (self)
  267. {
  268. self->closeFloater();
  269. }
  270. }
  271. }
  272. void LLFloaterJoystick::setSNDefaults()
  273. {
  274. LLViewerJoystick::getInstance()->setSNDefaults();
  275. }