scriptconsolegeneraltab.c 25 KB

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