scriptconsolegeneraltab.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. class ScriptConsoleGeneralTab : ScriptConsoleTabBase
  2. {
  3. static int m_ObjectsScope = 2;
  4. static protected vector m_LastEditPos = vector.Zero;
  5. static protected vector m_LastEditDir = vector.Zero;
  6. protected static float DEBUG_MAP_ZOOM = 1;
  7. protected static bool SHOW_OTHERS = 0;
  8. protected const string NUMERIC_LETTERS = "0123456789.-";
  9. protected vector m_MapPos;
  10. protected bool m_PlayerPosRefreshBlocked;
  11. protected ref array<ref RemotePlayerStatDebug> m_PlayerDebugStats = new array<ref RemotePlayerStatDebug>;
  12. protected MissionGameplay m_MissionGameplay;
  13. protected PluginDeveloper m_Developer;
  14. protected SliderWidget m_TimeSlider;
  15. protected ref Timer m_LateInit = new Timer();
  16. protected bool m_UpdatePlayerPositions;
  17. protected bool m_InitialOpen = true;
  18. //-------------------------------- WIDGETS ---------------------------------------
  19. protected EditBoxWidget m_TeleportHeading;
  20. protected EditBoxWidget m_TeleportXYZ;
  21. protected EditBoxWidget m_DateYear;
  22. protected EditBoxWidget m_DateMonth;
  23. protected EditBoxWidget m_DateDay;
  24. protected EditBoxWidget m_DateHour;
  25. protected EditBoxWidget m_DateMinute;
  26. protected ButtonWidget m_LocationAddButton;
  27. protected ButtonWidget m_LocationRemoveButton;
  28. protected ButtonWidget m_TeleportButton;
  29. protected ButtonWidget m_ButtonCopyPos;
  30. protected ButtonWidget m_DiagDrawButton;
  31. protected ButtonWidget m_DiagToggleButton;
  32. protected CheckBoxWidget m_LogsEnabled;
  33. protected CheckBoxWidget m_HudDCharStats;
  34. protected CheckBoxWidget m_HudDCharLevels;
  35. protected CheckBoxWidget m_HudDCharStomach;
  36. protected CheckBoxWidget m_HudDCharModifiers;
  37. protected CheckBoxWidget m_HudDCharAgents;
  38. protected CheckBoxWidget m_HudDCharDebug;
  39. protected CheckBoxWidget m_HudDFreeCamCross;
  40. protected CheckBoxWidget m_HudDVersion;
  41. protected CheckBoxWidget m_HudDHealth;
  42. protected CheckBoxWidget m_HudDHorticulture;
  43. protected CheckBoxWidget m_ShowOthers;
  44. protected CheckBoxWidget m_HudDTemperature;
  45. protected MapWidget m_DebugMapWidget;
  46. protected TextWidget m_PlayerCurPos;
  47. protected TextWidget m_PlayerCurDir;
  48. protected TextWidget m_MouseCurPos;
  49. protected TextWidget m_PlayerMouseDiff;
  50. protected TextWidget m_CameraCurPos;
  51. protected TextWidget m_CameraCurDir;
  52. protected TextListboxWidget m_DiagToggleTextListbox;
  53. protected TextListboxWidget m_PositionsListbox;
  54. protected TextListboxWidget m_DiagDrawmodeTextListbox;
  55. protected TextListboxWidget m_HelpTextListboxWidget;
  56. protected FreeDebugCamera m_FreeDebugCamera;
  57. //-----------------------------------------------------------------------------------
  58. void ScriptConsoleGeneralTab(Widget root, ScriptConsole console, Widget button, ScriptConsoleTabBase parent = null)
  59. {
  60. m_MissionGameplay = MissionGameplay.Cast(GetGame().GetMission());
  61. m_DiagToggleTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("DiagToggle"));
  62. m_DiagToggleButton = ButtonWidget.Cast(root.FindAnyWidget("DiagToggleButton"));
  63. m_DiagDrawmodeTextListbox = TextListboxWidget.Cast(root.FindAnyWidget("DiagDrawmode"));
  64. m_DiagDrawButton = ButtonWidget.Cast(root.FindAnyWidget("DiagDrawButton"));
  65. m_DebugMapWidget = MapWidget.Cast(root.FindAnyWidget("MapWidget"));
  66. m_PositionsListbox = TextListboxWidget.Cast(root.FindAnyWidget("PositionsList"));
  67. m_TeleportButton = ButtonWidget.Cast(root.FindAnyWidget("ButtonTeleport"));
  68. m_ButtonCopyPos = ButtonWidget.Cast(root.FindAnyWidget("Button_CopyPos"));
  69. m_TeleportHeading = EditBoxWidget.Cast(root.FindAnyWidget("TeleportHeading"));
  70. m_TeleportXYZ = EditBoxWidget.Cast(root.FindAnyWidget("TeleportXYZ"));
  71. m_PlayerCurPos = TextWidget.Cast(root.FindAnyWidget("PlayerPosLabel"));
  72. m_PlayerCurDir = TextWidget.Cast(root.FindAnyWidget("PlayerDirLabel"));
  73. m_PlayerMouseDiff = TextWidget.Cast(root.FindAnyWidget("PlayerMouseDiff"));
  74. m_MouseCurPos = TextWidget.Cast(root.FindAnyWidget("MousePosLabel"));
  75. m_CameraCurPos = TextWidget.Cast(root.FindAnyWidget("CameraPosLabel"));
  76. m_CameraCurDir = TextWidget.Cast(root.FindAnyWidget("CameraDirLabel"));
  77. m_LogsEnabled = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_LogsEnabled"));
  78. m_HudDCharStats = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_CharacterStats"));
  79. m_HudDCharLevels = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_CharacterLevels"));
  80. m_HudDCharStomach = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_CharacterStomach"));
  81. m_HudDCharModifiers = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_CharacterModifiers"));
  82. m_HudDCharAgents = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_CharacterAgents"));
  83. m_HudDCharDebug = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_CharacterDebug"));
  84. m_HudDFreeCamCross = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_FreeCamCross"));
  85. m_HudDTemperature = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_Temp"));
  86. m_HudDVersion = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_Version"));
  87. m_HudDHealth = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_Health"));
  88. m_HudDHorticulture = CheckBoxWidget.Cast(root.FindAnyWidget("cbx_Horticulture"));
  89. m_LocationAddButton = ButtonWidget.Cast(root.FindAnyWidget("AddButton"));
  90. //m_LocationAddButton.SetHandler(ToolTipEventHandler.GetInstance());
  91. m_LocationRemoveButton = ButtonWidget.Cast(root.FindAnyWidget("RemoveButton"));
  92. m_TimeSlider = SliderWidget.Cast(root.FindAnyWidget("TimeSlider"));
  93. m_DateYear = EditBoxWidget.Cast(root.FindAnyWidget("DateYear"));
  94. m_DateMonth = EditBoxWidget.Cast(root.FindAnyWidget("DateMonth"));
  95. m_DateDay = EditBoxWidget.Cast(root.FindAnyWidget("DateDay"));
  96. m_DateHour = EditBoxWidget.Cast(root.FindAnyWidget("DateHour"));
  97. m_DateMinute = EditBoxWidget.Cast(root.FindAnyWidget("DateMinute"));
  98. m_ShowOthers = CheckBoxWidget.Cast(root.FindAnyWidget("ShowOthersCheckbox"));
  99. m_HelpTextListboxWidget = TextListboxWidget.Cast(root.FindAnyWidget("HelpTextListboxWidget"));
  100. m_Developer = PluginDeveloper.Cast(GetPlugin(PluginDeveloper));
  101. m_FreeDebugCamera = FreeDebugCamera.GetInstance();
  102. Init();
  103. LateInit();
  104. }
  105. void ~ScriptConsoleGeneralTab()
  106. {
  107. DEBUG_MAP_ZOOM = m_DebugMapWidget.GetScale();
  108. PluginRemotePlayerDebugClient plugin_remote_client = PluginRemotePlayerDebugClient.Cast(GetPlugin(PluginRemotePlayerDebugClient));
  109. if (SHOW_OTHERS && plugin_remote_client && GetGame().GetPlayer())
  110. plugin_remote_client.RequestPlayerInfo(PlayerBase.Cast(GetGame().GetPlayer()), 0);
  111. }
  112. protected void Init()
  113. {
  114. // Update checkbox Character Values
  115. m_HudDCharStats.SetChecked(m_ConfigDebugProfile.GetCharacterStatsVisible());
  116. m_HudDCharLevels.SetChecked(m_ConfigDebugProfile.GetCharacterLevelsVisible());
  117. m_HudDCharStomach.SetChecked(m_ConfigDebugProfile.GetCharacterStomachVisible());
  118. m_HudDCharModifiers.SetChecked(m_ConfigDebugProfile.GetCharacterModifiersVisible());
  119. m_HudDCharAgents.SetChecked(m_ConfigDebugProfile.GetCharacterAgentsVisible());
  120. m_HudDCharDebug.SetChecked(m_ConfigDebugProfile.GetCharacterDebugVisible());
  121. m_HudDFreeCamCross.SetChecked(m_ConfigDebugProfile.GetFreeCameraCrosshairVisible());
  122. m_HudDVersion.SetChecked(m_ConfigDebugProfile.GetVersionVisible());
  123. m_HudDTemperature.SetChecked(m_ConfigDebugProfile.GetTempVisible());
  124. m_HudDHealth.SetChecked(m_ConfigDebugProfile.GetHealthVisible());
  125. m_HudDHorticulture.SetChecked(m_ConfigDebugProfile.GetHorticultureVisible());
  126. m_LogsEnabled.SetChecked(m_ConfigDebugProfile.GetLogsEnabled());
  127. TStringArray diag_names = new TStringArray;
  128. GetGame().GetDiagModeNames(diag_names);
  129. int i;
  130. for (i = 0; i < diag_names.Count(); i++)
  131. {
  132. m_DiagToggleTextListbox.AddItem(diag_names.Get(i), NULL, 0);
  133. }
  134. GetGame().GetDiagDrawModeNames(diag_names);
  135. for (i = 0; i < diag_names.Count(); i++)
  136. {
  137. m_DiagDrawmodeTextListbox.AddItem(diag_names.Get(i), NULL, 0);
  138. }
  139. RefreshLocations();
  140. UpdateHudDebugSetting();
  141. if (GetGame().GetPlayer())
  142. {
  143. m_DebugMapWidget.SetScale(DEBUG_MAP_ZOOM);
  144. m_DebugMapWidget.SetMapPos(GetGame().GetPlayer().GetWorldPosition());
  145. }
  146. if (m_LastEditPos != vector.Zero)
  147. m_TeleportXYZ.SetText(m_LastEditPos.ToString(true));
  148. if (m_LastEditDir != vector.Zero)
  149. m_TeleportHeading.SetText(m_LastEditDir.ToString(true));
  150. m_LateInit.Run(0.05, this, "LateInit", null, false);
  151. int year,month,day,hour,minute;
  152. GetGame().GetWorld().GetDate(year,month, day, hour, minute);
  153. RefreshDateWidgets(year,month, day, hour, minute);
  154. }
  155. void RefreshDateWidgets(int year, int month, int day, int hour, int minute)
  156. {
  157. float time01 = Math.InverseLerp(0,60*24 - 1, (hour * 60) + minute);
  158. m_DateYear.SetText(year.ToString());
  159. m_DateMonth.SetText(month.ToString());
  160. m_DateDay.SetText(day.ToString());
  161. m_DateHour.SetText(hour.ToString());
  162. m_DateMinute.SetText(minute.ToString());
  163. m_TimeSlider.SetCurrent(time01 * 100);
  164. }
  165. bool IsLocationNameAvailable(string name)
  166. {
  167. int count = m_PositionsListbox.GetNumItems();
  168. for (int i = 0; i < count; i++)
  169. {
  170. LocationParams data;
  171. m_PositionsListbox.GetItemData(i,0,data);
  172. if (data.param1 == name)
  173. return false;
  174. }
  175. return true;
  176. }
  177. void LateInit()
  178. {
  179. m_ShowOthers.SetChecked(SHOW_OTHERS);
  180. if (m_ConfigDebugProfile)
  181. {
  182. int prevRow = m_ConfigDebugProfile.GetSpawnLocIndex();
  183. if (prevRow < m_PositionsListbox.GetNumItems())
  184. m_PositionsListbox.SelectRow(prevRow);
  185. }
  186. PluginRemotePlayerDebugClient plugin_remote_client = PluginRemotePlayerDebugClient.Cast(GetPlugin(PluginRemotePlayerDebugClient));
  187. if (SHOW_OTHERS && plugin_remote_client && GetGame().GetPlayer())
  188. {
  189. plugin_remote_client.RequestPlayerInfo(PlayerBase.Cast(GetGame().GetPlayer()), 1);
  190. m_UpdatePlayerPositions = 1;
  191. }
  192. }
  193. void Teleport(PlayerBase player, vector position)
  194. {
  195. if (position[1] == 0)
  196. position[1] = GetGame().SurfaceY(position[0], position[2]);
  197. m_Developer.Teleport(player, position);
  198. }
  199. void ProcessTeleportText(PlayerBase player)
  200. {
  201. bool doTeleport, doSetDir;
  202. vector pos, dir;
  203. string text = m_TeleportXYZ.GetText();
  204. string textDir = m_TeleportHeading.GetText();
  205. array<float> numbersPos = TextToNumbersArray(text);
  206. if (numbersPos.Count() != 0)
  207. {
  208. if (numbersPos.Count() == 1)
  209. {
  210. pos = vector.Zero;
  211. }
  212. else if (numbersPos.Count() == 2)
  213. {
  214. pos = Vector(numbersPos[0], GetGame().SurfaceY(numbersPos[0], numbersPos[1]), numbersPos[1]);
  215. }
  216. else if (numbersPos.Count() <= 5)
  217. {
  218. pos = Vector(numbersPos[0], numbersPos[1], numbersPos[2]);
  219. }
  220. else if (numbersPos.Count() > 5)
  221. {
  222. pos = Vector(numbersPos[0], numbersPos[1], numbersPos[2]);
  223. dir = Vector(numbersPos[3], numbersPos[4], numbersPos[5]);
  224. Teleport(player, pos);
  225. m_LastEditPos = pos;
  226. m_TeleportXYZ.SetText(m_LastEditPos.ToString());
  227. m_Developer.SetDirection(player, dir);
  228. m_LastEditDir = dir;
  229. m_TeleportHeading.SetText(m_LastEditDir.ToString());
  230. return;
  231. }
  232. doTeleport = true;
  233. }
  234. else
  235. m_LastEditPos = vector.Zero;
  236. array<float> numbersDir = TextToNumbersArray(textDir);
  237. if (numbersDir.Count() != 0)
  238. {
  239. if (numbersDir.Count() == 1)
  240. {
  241. dir = vector.Zero;
  242. }
  243. else if (numbersDir.Count() == 2)
  244. {
  245. dir = Vector(numbersDir[0], 0, numbersDir[1]);
  246. }
  247. else if (numbersDir.Count() <= 5)
  248. {
  249. dir = Vector(numbersDir[0], numbersDir[1], numbersDir[2]);
  250. }
  251. else if (numbersDir.Count() > 5)
  252. {
  253. pos = Vector(numbersDir[0], numbersDir[1], numbersDir[2]);
  254. dir = Vector(numbersDir[3], numbersDir[4], numbersDir[5]);
  255. Teleport(player, pos);
  256. m_LastEditPos = pos;
  257. m_TeleportXYZ.SetText(m_LastEditPos.ToString());
  258. m_Developer.SetDirection(player, dir);
  259. m_LastEditDir = dir;
  260. m_TeleportHeading.SetText(m_LastEditDir.ToString());
  261. return;
  262. }
  263. doSetDir = true;
  264. }
  265. else
  266. m_LastEditDir = vector.Zero;
  267. if (doTeleport)
  268. {
  269. Teleport(player, pos);
  270. m_LastEditPos = pos;
  271. }
  272. if (doSetDir)
  273. {
  274. m_Developer.SetDirection(player, dir);
  275. m_LastEditDir = dir;
  276. }
  277. }
  278. array<float> TextToNumbersArray(string text)
  279. {
  280. array<float> numbers = new array<float>();
  281. int length = text.Length();
  282. int numberStart = -1;
  283. int numberLen;
  284. for (int i = 0; i < length; i++) // find numbers and move them to array
  285. {
  286. string letter = text.Get(i);
  287. if (numberStart == -1 && NUMERIC_LETTERS.Contains(letter) && letter != ".") // search for number
  288. numberStart = i;
  289. if (numberStart != -1 && (!NUMERIC_LETTERS.Contains(letter) || (letter == "-" && numberStart != i))) // search for number end
  290. {
  291. numberLen = i - numberStart;
  292. numbers.Insert(text.Substring(numberStart, numberLen).ToFloat());
  293. numberStart = -1;
  294. }
  295. else if (numberStart != -1 && (i + 1 == length)) // last letter
  296. {
  297. numberLen = i - numberStart + 1;
  298. numbers.Insert(text.Substring(numberStart, numberLen).ToFloat());
  299. numberStart = -1;
  300. }
  301. }
  302. return numbers;
  303. }
  304. void RefreshLocations()
  305. {
  306. m_PositionsListbox.ClearItems();
  307. array<ref LocationParams> locData = new array<ref LocationParams>;
  308. m_ConfigDebugProfile.GetLocationsData(locData,true);
  309. m_ConfigDebugProfileFixed.GetLocationsData(locData,false);
  310. foreach (LocationParams dta: locData)
  311. {
  312. string name = dta.param1;
  313. if (!dta.param2)
  314. {
  315. name = "[" + name + "]";
  316. }
  317. m_PositionsListbox.AddItem(name,dta,0);
  318. }
  319. }
  320. string GetCurrentLocationName()
  321. {
  322. string name;
  323. LocationParams prms;
  324. GetCurrentPositionData(prms);
  325. if (prms)
  326. name =prms.param1;
  327. return name;
  328. }
  329. vector GetCurrentLocationPos()
  330. {
  331. LocationParams prms;
  332. GetCurrentPositionData(prms);
  333. if (prms)
  334. return prms.param3;
  335. else
  336. return vector.Zero;
  337. }
  338. void GetCurrentPositionData(out LocationParams data)
  339. {
  340. if (m_PositionsListbox.GetSelectedRow() != -1)
  341. {
  342. m_PositionsListbox.GetItemData(m_PositionsListbox.GetSelectedRow(), 0, data);
  343. }
  344. }
  345. bool IsCurrentPositionCustom()
  346. {
  347. LocationParams prms;
  348. GetCurrentPositionData(prms);
  349. if (prms)
  350. return prms.param2;
  351. else
  352. return false;
  353. }
  354. int GetCurrentPositionIndex()
  355. {
  356. return m_PositionsListbox.GetSelectedRow();
  357. }
  358. bool IsCurrentPositionValid()
  359. {
  360. return (m_PositionsListbox.GetSelectedRow() != -1);
  361. }
  362. void UpdateHudDebugSetting();
  363. void RefreshPlayerPosEditBoxes()
  364. {
  365. if (!GetGame().GetPlayer())
  366. {
  367. return;
  368. }
  369. vector playerPos = GetGame().GetPlayer().GetPosition();
  370. SetMapPos(playerPos);
  371. vector playerDir = GetGame().GetPlayer().GetDirection();
  372. SetDir(playerDir);
  373. }
  374. void UpdateTime(bool slider_used)
  375. {
  376. Param5<int,int,int,int,int> p5 = new Param5<int,int,int,int,int>(0,0,0,0,0);
  377. int year, month, day, hour, minute;
  378. year = m_DateYear.GetText().ToInt();
  379. month = m_DateMonth.GetText().ToInt();
  380. day = m_DateDay.GetText().ToInt();
  381. if (slider_used)
  382. {
  383. int time_minutes = Math.Lerp(0, (24*60) - 1, m_TimeSlider.GetCurrent()/100);
  384. hour = time_minutes / 60;
  385. minute = time_minutes % 60;
  386. }
  387. else
  388. {
  389. hour = m_DateHour.GetText().ToInt();
  390. minute = m_DateMinute.GetText().ToInt();
  391. }
  392. p5.param1 = year;
  393. p5.param2 = month;
  394. p5.param3 = day;
  395. p5.param4 = hour;
  396. p5.param5 = minute;
  397. RefreshDateWidgets(year, month, day, hour, minute);
  398. GetGame().GetWorld().SetDate(year, month, day, hour, minute);
  399. g_Game.GetMission().GetOnTimeChanged().Invoke();
  400. if (GetGame().GetPlayer())
  401. {
  402. GetGame().GetPlayer().RPCSingleParam(ERPCs.DEV_RPC_SET_TIME, p5, true);
  403. }
  404. }
  405. void UpdateMousePos()
  406. {
  407. int x,y;
  408. GetMousePos(x,y);
  409. vector mousePos, worldPos;
  410. mousePos[0] = x;
  411. mousePos[1] = y;
  412. worldPos = m_DebugMapWidget.ScreenToMap(mousePos);
  413. worldPos[1] = GetGame().SurfaceY(worldPos[0], worldPos[2]);
  414. if (m_MouseCurPos)
  415. {
  416. m_MouseCurPos.SetText("Mouse: "+ MiscGameplayFunctions.TruncateToS(worldPos[0]) +", "+ MiscGameplayFunctions.TruncateToS(worldPos[1]) +", "+ MiscGameplayFunctions.TruncateToS(worldPos[2]));
  417. }
  418. if (m_PlayerMouseDiff && GetGame().GetPlayer())
  419. {
  420. vector playerPos = GetGame().GetPlayer().GetWorldPosition();
  421. //playerPos[1] = 0;
  422. float dst = (worldPos - playerPos).Length();
  423. m_PlayerMouseDiff.SetText("Distance: " + MiscGameplayFunctions.TruncateToS(dst));
  424. }
  425. }
  426. void SetMapPos(vector pos)
  427. {
  428. m_MapPos = pos;
  429. m_PlayerCurPos.SetText("Position: "+ MiscGameplayFunctions.TruncateToS(pos[0]) +", "+ MiscGameplayFunctions.TruncateToS(pos[1]) +", "+ MiscGameplayFunctions.TruncateToS(pos[2]));
  430. }
  431. void SetMapCameraPos(vector pos)
  432. {
  433. m_CameraCurPos.SetText("Camera Position: "+ MiscGameplayFunctions.TruncateToS(pos[0]) +", "+ MiscGameplayFunctions.TruncateToS(pos[1]) +", "+ MiscGameplayFunctions.TruncateToS(pos[2]));
  434. }
  435. void SetDir(vector dir)
  436. {
  437. m_PlayerCurDir.SetText("Direction: "+ MiscGameplayFunctions.TruncateToS(dir[0]) +", "+ MiscGameplayFunctions.TruncateToS(dir[1]) +", "+ MiscGameplayFunctions.TruncateToS(dir[2]));
  438. }
  439. void SetCameraDir(vector dir)
  440. {
  441. m_CameraCurDir.SetText("Camera Direction: "+ MiscGameplayFunctions.TruncateToS(dir[0]) +", "+ MiscGameplayFunctions.TruncateToS(dir[1]) +", "+ MiscGameplayFunctions.TruncateToS(dir[2]));
  442. }
  443. vector GetMapPos()
  444. {
  445. return m_MapPos;
  446. }
  447. override bool OnMouseButtonDown(Widget w, int x, int y, int button)
  448. {
  449. super.OnMouseButtonDown(w,x,y,button);
  450. if (w == m_DebugMapWidget)
  451. {
  452. if (button == 0)
  453. {
  454. if (m_FreeDebugCamera && m_FreeDebugCamera.IsActive())
  455. {
  456. SetMapCameraPos(m_FreeDebugCamera.GetWorldPosition());
  457. SetCameraDir(m_FreeDebugCamera.GetDirection());
  458. }
  459. else
  460. {
  461. m_PlayerPosRefreshBlocked = true;
  462. int mouseX, mouseY;
  463. GetMousePos(mouseX,mouseY);
  464. vector mousePos, worldPos;
  465. mousePos[0] = mouseX;
  466. mousePos[1] = mouseY;
  467. worldPos = m_DebugMapWidget.ScreenToMap(mousePos);
  468. worldPos[1] = GetGame().SurfaceY(worldPos[0], worldPos[2]);
  469. SetMapPos(worldPos);
  470. }
  471. }
  472. else if (button == 1 && GetGame().GetPlayer())
  473. {
  474. if (m_FreeDebugCamera && m_FreeDebugCamera.IsActive())
  475. SetMapCameraPos(m_FreeDebugCamera.GetWorldPosition());
  476. else
  477. SetMapPos(GetGame().GetPlayer().GetWorldPosition());
  478. }
  479. }
  480. return true;
  481. }
  482. override bool OnKeyDown(Widget w, int x, int y, int key)
  483. {
  484. super.OnKeyDown(w, x, y, key);
  485. return false;
  486. }
  487. override bool OnChange(Widget w, int x, int y, bool finished)
  488. {
  489. super.OnChange(w, x, y, finished);
  490. if (w == m_ShowOthers && GetGame().GetPlayer())
  491. {
  492. PluginRemotePlayerDebugClient plugin_remote_client = PluginRemotePlayerDebugClient.Cast(GetPlugin(PluginRemotePlayerDebugClient));
  493. if (m_ShowOthers.IsChecked())
  494. {
  495. plugin_remote_client.RequestPlayerInfo(PlayerBase.Cast(GetGame().GetPlayer()), 1);
  496. m_UpdatePlayerPositions = 1;
  497. SHOW_OTHERS = true;
  498. }
  499. else
  500. {
  501. plugin_remote_client.RequestPlayerInfo(PlayerBase.Cast(GetGame().GetPlayer()), 0);
  502. m_UpdatePlayerPositions = 0;
  503. SHOW_OTHERS = false;
  504. }
  505. return true;
  506. }
  507. else if (w == m_TimeSlider || w == m_DateDay || w == m_DateYear || w == m_DateMonth || w == m_DateHour || w == m_DateMinute)
  508. {
  509. UpdateTime(w == m_TimeSlider);
  510. return true;
  511. }
  512. return false;
  513. }
  514. override bool OnItemSelected(Widget w, int x, int y, int row, int column, int oldRow, int oldColumn)
  515. {
  516. super.OnItemSelected(w, x, y, row, column, oldRow, oldColumn);
  517. if (w == m_PositionsListbox)
  518. {
  519. if (m_InitialOpen)
  520. {
  521. m_InitialOpen = false;
  522. return true;
  523. }
  524. vector position = GetCurrentLocationPos();
  525. m_TeleportXYZ.SetText(position.ToString());
  526. if (IsCurrentPositionValid())
  527. {
  528. m_ConfigDebugProfile.SetSpawnLocIndex(GetCurrentPositionIndex());
  529. }
  530. return true;
  531. }
  532. return false;
  533. }
  534. override bool OnDoubleClick(Widget w, int x, int y, int button)
  535. {
  536. super.OnDoubleClick(w, x, y, button);
  537. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  538. if (w == m_DebugMapWidget)
  539. {
  540. vector screen_to_map = m_DebugMapWidget.ScreenToMap(Vector(x,y, 0));
  541. float pos_y_a = GetGame().SurfaceY(screen_to_map[0], screen_to_map[2]);
  542. float pos_y_b = GetGame().SurfaceRoadY(screen_to_map[0], screen_to_map[2]);
  543. float pos_y = Math.Max(pos_y_a, pos_y_b);
  544. screen_to_map[1] = pos_y;
  545. if (m_FreeDebugCamera && m_FreeDebugCamera.IsActive())
  546. {
  547. vector camPos = m_FreeDebugCamera.GetPosition();
  548. float camPosY = camPos[1];
  549. screen_to_map[1] = camPosY;
  550. m_FreeDebugCamera.SetPosition(screen_to_map);
  551. }
  552. else
  553. {
  554. m_Developer.Teleport(player, screen_to_map);
  555. }
  556. return true;
  557. }
  558. if (w == m_PositionsListbox)
  559. {
  560. vector position = GetCurrentLocationPos();
  561. if (m_FreeDebugCamera && m_FreeDebugCamera.IsActive())
  562. {
  563. m_FreeDebugCamera.SetPosition(position);
  564. }
  565. else
  566. {
  567. Teleport(player, position);
  568. }
  569. return true;
  570. }
  571. if (w == m_TeleportHeading)
  572. {
  573. EditBoxWidget.Cast(w).SetText("");
  574. return true;
  575. }
  576. if (w == m_TeleportXYZ)
  577. {
  578. EditBoxWidget.Cast(w).SetText("");
  579. return true;
  580. }
  581. return false;
  582. }
  583. override bool OnClick(Widget w, int x, int y, int button)
  584. {
  585. super.OnClick(w, x, y, button);
  586. int i;
  587. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  588. PluginDeveloper module_dev = PluginDeveloper.Cast(GetPlugin(PluginDeveloper));
  589. if (w == m_PositionsListbox)
  590. {
  591. vector position = GetCurrentLocationPos();
  592. if (IsCurrentPositionValid())
  593. {
  594. m_ConfigDebugProfile.SetSpawnLocIndex(GetCurrentPositionIndex());
  595. }
  596. return true;
  597. }
  598. else if (w == m_TeleportButton)
  599. {
  600. ProcessTeleportText(player);
  601. return true;
  602. }
  603. else if (w == m_ButtonCopyPos)
  604. {
  605. if (m_IsShiftDown)
  606. {
  607. GetGame().CopyToClipboard(GetMapPos().ToString(false));
  608. return true;
  609. }
  610. GetGame().CopyToClipboard(GetMapPos().ToString() + " " + GetGame().GetPlayer().GetDirection().ToString());
  611. return true;
  612. }
  613. else if (w == m_LogsEnabled)
  614. {
  615. //Log("m_LogsEnabled: "+ToString(m_LogsEnabled.IsChecked()));
  616. if (m_ConfigDebugProfile)
  617. {
  618. m_ConfigDebugProfile.SetLogsEnabled(m_LogsEnabled.IsChecked());
  619. LogManager.SetLogsEnabled(m_LogsEnabled.IsChecked());
  620. }
  621. return true;
  622. }
  623. else if (w == m_HudDCharStats)
  624. {
  625. if (m_ConfigDebugProfile)
  626. {
  627. m_ConfigDebugProfile.SetCharacterStatsVisible(m_HudDCharStats.IsChecked());
  628. }
  629. // Refresh UI by new settings
  630. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  631. return true;
  632. }
  633. else if (w == m_HudDCharLevels)
  634. {
  635. if (m_ConfigDebugProfile)
  636. {
  637. m_ConfigDebugProfile.SetCharacterLevelsVisible(m_HudDCharLevels.IsChecked());
  638. }
  639. // Refresh UI by new settings
  640. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  641. return true;
  642. }
  643. else if (w == m_HudDCharStomach)
  644. {
  645. if (m_ConfigDebugProfile)
  646. {
  647. m_ConfigDebugProfile.SetCharacterStomachVisible(m_HudDCharStomach.IsChecked());
  648. }
  649. // Refresh UI by new settings
  650. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  651. return true;
  652. }
  653. else if (w == m_HudDVersion)
  654. {
  655. if (m_ConfigDebugProfile)
  656. {
  657. m_ConfigDebugProfile.SetVersionVisible(m_HudDVersion.IsChecked());
  658. }
  659. // Refresh UI by new settings
  660. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  661. return true;
  662. }
  663. else if (w == m_HudDTemperature)
  664. {
  665. if (m_ConfigDebugProfile)
  666. {
  667. m_ConfigDebugProfile.SetTempVisible(m_HudDTemperature.IsChecked());
  668. }
  669. // Refresh UI by new settings
  670. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  671. return true;
  672. }
  673. else if (w == m_HudDHealth)
  674. {
  675. if (m_ConfigDebugProfile)
  676. {
  677. m_ConfigDebugProfile.SetHealthVisible(m_HudDHealth.IsChecked());
  678. }
  679. // Refresh UI by new settings
  680. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  681. return true;
  682. }
  683. else if (w == m_HudDHorticulture)
  684. {
  685. if (m_ConfigDebugProfile)
  686. {
  687. m_ConfigDebugProfile.SetHorticultureVisible(m_HudDHorticulture.IsChecked());
  688. }
  689. // Refresh UI by new settings
  690. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  691. return true;
  692. }
  693. else if (w == m_HudDCharModifiers)
  694. {
  695. if (m_ConfigDebugProfile)
  696. {
  697. m_ConfigDebugProfile.SetCharacterModifiersVisible(m_HudDCharModifiers.IsChecked());
  698. }
  699. // Refresh UI by new settings
  700. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  701. return true;
  702. }
  703. else if (w == m_HudDCharAgents)
  704. {
  705. if (m_ConfigDebugProfile)
  706. {
  707. m_ConfigDebugProfile.SetCharacterAgentsVisible(m_HudDCharAgents.IsChecked());
  708. }
  709. // Refresh UI by new settings
  710. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  711. return true;
  712. }
  713. else if (w == m_HudDCharDebug)
  714. {
  715. if (m_ConfigDebugProfile)
  716. {
  717. m_ConfigDebugProfile.SetCharacterDebugVisible(m_HudDCharDebug.IsChecked());
  718. }
  719. // Refresh UI by new settings
  720. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  721. return true;
  722. }
  723. else if (w == m_HudDFreeCamCross)
  724. {
  725. if (m_ConfigDebugProfile)
  726. {
  727. m_ConfigDebugProfile.SetFreeCameraCrosshairVisible(m_HudDFreeCamCross.IsChecked());
  728. }
  729. // Refresh UI by new settings
  730. m_MissionGameplay.GetHudDebug().RefreshByLocalProfile();
  731. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(GetGame().GetMission().RefreshCrosshairVisibility);
  732. return true;
  733. }
  734. else if (w == m_DiagToggleButton)
  735. {
  736. int toggle_row_index = m_DiagToggleTextListbox.GetSelectedRow();
  737. bool toggle_state = GetGame().GetDiagModeEnable(toggle_row_index);
  738. GetGame().SetDiagModeEnable(toggle_row_index, !toggle_state);
  739. return true;
  740. }
  741. else if (w == m_DiagDrawButton)
  742. {
  743. int draw_row_index = m_DiagDrawmodeTextListbox.GetSelectedRow();
  744. GetGame().SetDiagDrawMode(draw_row_index);
  745. return true;
  746. }
  747. // TOUCHED THIS
  748. else if (w == m_LocationAddButton)
  749. {
  750. ScriptConsoleAddLocation menu = ScriptConsoleAddLocation.Cast(g_Game.GetUIManager().EnterScriptedMenu(MENU_LOC_ADD, m_ScriptConsole));
  751. menu.SetPosition(GetMapPos());
  752. return true;
  753. }
  754. else if (w == m_LocationRemoveButton)
  755. {
  756. m_ConfigDebugProfile.CustomLocationsRemove(GetCurrentLocationName());
  757. RefreshLocations();
  758. return true;
  759. }
  760. return false;
  761. }
  762. override void OnRPCEx(int rpc_type, ParamsReadContext ctx)
  763. {
  764. super.OnRPCEx(rpc_type, ctx);
  765. #ifdef DIAG_DEVELOPER
  766. switch (rpc_type)
  767. {
  768. case ERPCs.DEV_PLAYER_DEBUG_DATA:
  769. {
  770. ctx.Read(m_PlayerDebugStats);
  771. break;
  772. }
  773. }
  774. #endif
  775. }
  776. override void Update(float timeslice)
  777. {
  778. super.Update(timeslice);
  779. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  780. m_DebugMapWidget.ClearUserMarks();
  781. if (m_UpdatePlayerPositions)
  782. {
  783. foreach (RemotePlayerStatDebug rpd: m_PlayerDebugStats)
  784. {
  785. if (rpd.m_Player != player)
  786. {
  787. vector dir = rpd.m_Pos - player.GetWorldPosition();
  788. dir[1] = 0;
  789. string dist = ((int)dir.Length()).ToString();
  790. string text = rpd.m_Name + " " +dist +"m.";
  791. m_DebugMapWidget.AddUserMark(rpd.m_Pos, text , COLOR_BLUE,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
  792. }
  793. }
  794. }
  795. if (player)
  796. {
  797. vector playerPos = player.GetWorldPosition();
  798. m_DebugMapWidget.AddUserMark(playerPos,"You", COLOR_RED,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
  799. if (playerPos != GetMapPos())
  800. m_DebugMapWidget.AddUserMark(GetMapPos(),"Pos", COLOR_BLUE,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
  801. }
  802. if (m_FreeDebugCamera && m_FreeDebugCamera.IsActive())
  803. {
  804. vector cameraPos = m_FreeDebugCamera.GetWorldPosition();
  805. m_DebugMapWidget.AddUserMark(cameraPos,"Camera", COLOR_GREEN,"\\dz\\gear\\navigation\\data\\map_tree_ca.paa");
  806. }
  807. UpdateMousePos();
  808. if (!m_PlayerPosRefreshBlocked)
  809. RefreshPlayerPosEditBoxes();
  810. foreach (MapMarker marker: ScriptConsole.m_MarkedEntities)
  811. {
  812. m_DebugMapWidget.AddUserMark(marker.GetMarkerPos(),marker.GetMarkerText(), marker.GetMarkerColor(), MapMarkerTypes.GetMarkerTypeFromID(marker.GetMarkerIcon()));
  813. }
  814. }
  815. }