plugindayzinfecteddebug.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. // *************************************************************************************
  2. // ! PluginDayZInfectedDebugUIHandler
  3. // *************************************************************************************
  4. class PluginDayZInfectedDebugUIHandler extends ScriptedWidgetEventHandler
  5. {
  6. override bool OnClick(Widget w, int x, int y, int button)
  7. {
  8. super.OnClick(w, x, y, button);
  9. return m_pPluginInfectedDebug.OnClick(w, x, y, button);
  10. }
  11. override bool OnChange(Widget w, int x, int y, bool finished)
  12. {
  13. super.OnChange(w, x, y, finished);
  14. return m_pPluginInfectedDebug.OnChange(w, x, y, finished);
  15. }
  16. PluginDayZInfectedDebug m_pPluginInfectedDebug;
  17. }
  18. // *************************************************************************************
  19. // ! PluginDayZInfectedDebugAttackDesc
  20. // *************************************************************************************
  21. class PluginDayZInfectedDebugAttackDesc
  22. {
  23. void PluginDayZInfectedDebugAttackDesc(string pName, int pValue)
  24. {
  25. name = pName;
  26. animValue = pValue;
  27. }
  28. string name;
  29. int animValue;
  30. }
  31. // *************************************************************************************
  32. // ! PluginDayZInfectedDebug
  33. // *************************************************************************************
  34. class PluginDayZInfectedDebug extends PluginBase
  35. {
  36. int m_CurrentMode = 0;
  37. bool m_HasFocus = false;
  38. bool m_IsActive = false;
  39. //! main controls
  40. Widget m_MainWnd;
  41. ButtonWidget m_SpawnEntityButton;
  42. ButtonWidget m_CardMovementButton;
  43. ButtonWidget m_CardFightButton;
  44. Widget m_CardMovementFrame;
  45. Widget m_CardFightFrame;
  46. TextWidget m_StatusText;
  47. //! movement card
  48. XComboBoxWidget m_StanceCB;
  49. XComboBoxWidget m_MindStateCB;
  50. EditBoxWidget m_MovementSpeedEB;
  51. ButtonWidget m_StartTurnButton;
  52. XComboBoxWidget m_TurnTypeCB;
  53. EditBoxWidget m_TurnDirectionEB;
  54. XComboBoxWidget m_VaultingCB;
  55. ButtonWidget m_StartVaultButton;
  56. ButtonWidget m_KnucleOutButton;
  57. XComboBoxWidget m_CrawlingTypeCB;
  58. ButtonWidget m_StartCrawlingButton;
  59. //! fight card
  60. EditBoxWidget m_HitDirEB;
  61. XComboBoxWidget m_HitTypeCB;
  62. XComboBoxWidget m_HitBodyPartCB;
  63. ButtonWidget m_StartHitButton;
  64. XComboBoxWidget m_DeathTypeCB;
  65. ButtonWidget m_StartDeathButton;
  66. XComboBoxWidget m_AttackTypeCB;
  67. XComboBoxWidget m_AttackDirCB;
  68. ButtonWidget m_StartAttackButton;
  69. //! controlled instance
  70. DayZInfected m_ControlledInfected;
  71. //! command handler values
  72. bool m_CH_DoTurn = false;
  73. bool m_CH_DoVault = false;
  74. bool m_CH_DoKnucleOut = false;
  75. bool m_CH_GoToCrawl = false;
  76. bool m_CH_DoHit = false;
  77. bool m_CH_StartDeath = false;
  78. bool m_CH_DoAttack = false;
  79. ref PluginDayZInfectedDebugUIHandler m_pUIHandler;
  80. ref array<ref PluginDayZInfectedDebugAttackDesc> m_AttackDescriptors = new array<ref PluginDayZInfectedDebugAttackDesc>;
  81. private ref array<Shape> m_DebugShapes = new array<Shape>();
  82. //! status refresh timer
  83. ref Timer m_TickTimer;
  84. void PluginDayZInfectedDebug()
  85. {
  86. #ifndef NO_GUI
  87. CreateModuleWidgets();
  88. #endif
  89. }
  90. void ~PluginDayZInfectedDebug()
  91. {
  92. #ifndef NO_GUI
  93. DestroyModuleWidgets();
  94. #endif
  95. }
  96. //!
  97. void ToggleDebugWindowEvent()
  98. {
  99. m_CurrentMode++;
  100. if (m_CurrentMode > 2)
  101. {
  102. m_CurrentMode = 0;
  103. }
  104. ToggleDebugWindowSetMode(m_CurrentMode);
  105. }
  106. //!
  107. void ToggleDebugWindowSetMode(int pMode)
  108. {
  109. switch (pMode)
  110. {
  111. case 0: Hide(); ReleaseFocus(); CleanupDebugShapes(m_DebugShapes); break;
  112. case 1: Show(); ReleaseFocus(); break;
  113. case 2: Show(); CaptureFocus(); break;
  114. }
  115. }
  116. //!
  117. void CaptureFocus()
  118. {
  119. if (!m_HasFocus)
  120. {
  121. GetGame().GetInput().ChangeGameFocus(1);
  122. GetGame().GetUIManager().ShowUICursor(true);
  123. m_HasFocus = true;
  124. }
  125. }
  126. //!
  127. void ReleaseFocus()
  128. {
  129. if (m_HasFocus)
  130. {
  131. GetGame().GetInput().ChangeGameFocus(-1);
  132. GetGame().GetUIManager().ShowUICursor(false);
  133. m_HasFocus = false;
  134. }
  135. }
  136. //!
  137. void Show()
  138. {
  139. ShowWidgets(true);
  140. m_IsActive = true;
  141. GetUApi().ActivateExclude("menu");
  142. GetUApi().UpdateControls();
  143. if (!m_TickTimer)
  144. {
  145. m_TickTimer = new Timer();
  146. m_TickTimer.Run(0.1, this, "Tick", NULL, true);
  147. }
  148. }
  149. //!
  150. void Hide()
  151. {
  152. ShowWidgets(false);
  153. m_IsActive = false;
  154. GetUApi().UpdateControls();
  155. m_TickTimer = NULL;
  156. }
  157. //!
  158. void ShowWidgets(bool show)
  159. {
  160. if(m_MainWnd)
  161. {
  162. m_MainWnd.Show(show);
  163. }
  164. }
  165. override void OnUpdate(float delta_time)
  166. {
  167. super.OnUpdate(delta_time);
  168. CleanupDebugShapes(m_DebugShapes);
  169. if (m_IsActive)
  170. {
  171. if (!m_ControlledInfected)
  172. return;
  173. m_DebugShapes.Insert(Debug.DrawSphere(m_ControlledInfected.GetPosition() + "0 2 0", 0.25, FadeColors.RED));
  174. }
  175. }
  176. //!
  177. void CreateModuleWidgets()
  178. {
  179. if (!m_pUIHandler)
  180. {
  181. m_pUIHandler = new PluginDayZInfectedDebugUIHandler();
  182. m_pUIHandler.m_pPluginInfectedDebug = this;
  183. }
  184. if (!m_MainWnd)
  185. {
  186. m_MainWnd = GetGame().GetWorkspace().CreateWidgets("gui/layouts/debug/day_z_infecteddebug.layout");
  187. m_MainWnd.SetHandler(m_pUIHandler);
  188. m_MainWnd.Show(false);
  189. }
  190. //! main controls
  191. m_SpawnEntityButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("SpawnEntityButton") );
  192. m_CardMovementButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("CardMovementButton") );
  193. m_CardFightButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("CardFightButton") );
  194. m_CardMovementFrame = m_MainWnd.FindAnyWidget("CardMovementFrame");
  195. m_CardFightFrame = m_MainWnd.FindAnyWidget("CardFightFrame");
  196. m_StatusText = TextWidget.Cast( m_MainWnd.FindAnyWidget("StatusText") );
  197. //! movement card
  198. m_StanceCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("StanceCB") );
  199. m_MindStateCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("MindStateCB") );
  200. m_MovementSpeedEB = EditBoxWidget.Cast( m_MainWnd.FindAnyWidget("MovementSpeedEB") );
  201. m_StartTurnButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("StartTurnButton") );
  202. m_TurnTypeCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("TurnTypeCB") );
  203. m_TurnDirectionEB = EditBoxWidget.Cast( m_MainWnd.FindAnyWidget("TurnDirectionEB") );
  204. m_VaultingCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("TurnTypeCB") );
  205. m_StartVaultButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("StartVaultButton") );
  206. m_KnucleOutButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("KnucleOutButton") );
  207. m_CrawlingTypeCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("TurnTypeCB") );
  208. m_StartCrawlingButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("StartCrawlingButton") );
  209. //! fight card
  210. m_HitDirEB = EditBoxWidget.Cast( m_MainWnd.FindAnyWidget("HitDirEB") );
  211. m_HitTypeCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("HitTypeCB") );
  212. m_HitBodyPartCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("HitBodyPartCB") );
  213. m_StartHitButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("StartHitButton") );
  214. m_DeathTypeCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("DeathTypeCB") );
  215. m_StartDeathButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("StartDeathButton") );
  216. m_AttackTypeCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("AttackTypeCB") );
  217. m_AttackDirCB = XComboBoxWidget.Cast( m_MainWnd.FindAnyWidget("AttackDirCB") );
  218. m_StartAttackButton = ButtonWidget.Cast( m_MainWnd.FindAnyWidget("StartAttackButton") );
  219. //! fill some controls
  220. InitAttacks();
  221. ShowCard(0);
  222. }
  223. //!
  224. void DestroyModuleWidgets()
  225. {
  226. delete m_MainWnd;
  227. }
  228. //!
  229. void ShowCard(int pCard)
  230. {
  231. m_CardMovementFrame.Show(pCard == 0);
  232. m_CardFightFrame.Show(pCard == 1);
  233. }
  234. //! buttons clicks
  235. bool OnClick(Widget w, int x, int y, int button)
  236. {
  237. if (w == m_SpawnEntityButton)
  238. {
  239. ResetValues();
  240. SpawnNewInfectedEntity();
  241. return true;
  242. }
  243. if (w == m_CardMovementButton)
  244. {
  245. ShowCard(0);
  246. return true;
  247. }
  248. else if (w == m_CardFightButton)
  249. {
  250. ShowCard(1);
  251. return true;
  252. }
  253. else if (w == m_StartTurnButton)
  254. {
  255. m_CH_DoTurn = true;
  256. return true;
  257. }
  258. else if (w == m_StartVaultButton)
  259. {
  260. m_CH_DoVault = true;
  261. return true;
  262. }
  263. else if (w == m_KnucleOutButton)
  264. {
  265. m_CH_DoKnucleOut = true;
  266. return true;
  267. }
  268. else if (w == m_StartCrawlingButton)
  269. {
  270. m_CH_GoToCrawl = true;
  271. return true;
  272. }
  273. else if (w == m_StartHitButton)
  274. {
  275. m_CH_DoHit = true;
  276. return true;
  277. }
  278. else if (w == m_StartDeathButton)
  279. {
  280. m_CH_StartDeath = true;
  281. return true;
  282. }
  283. else if (w == m_StartAttackButton)
  284. {
  285. m_CH_DoAttack = true;
  286. return true;
  287. }
  288. return false;
  289. }
  290. //!
  291. bool OnChange(Widget w, int x, int y, bool finished)
  292. {
  293. return false;
  294. }
  295. //!
  296. void ResetValues()
  297. {
  298. m_CH_DoTurn = false;
  299. m_CH_DoVault = false;
  300. m_CH_DoKnucleOut = false;
  301. m_CH_GoToCrawl = false;
  302. m_CH_DoHit = false;
  303. m_CH_StartDeath = false;
  304. m_CH_DoAttack = false;
  305. m_MovementSpeedEB.SetText("0");
  306. m_MainWnd.Update();
  307. }
  308. //!
  309. void SpawnNewInfectedEntity()
  310. {
  311. m_ControlledInfected = DayZInfected.Cast(GetGame().CreateObjectEx("ZmbF_JournalistNormal_Blue", GetGame().GetPlayer().GetPosition(), ECE_PLACE_ON_SURFACE|ECE_INITAI|ECE_EQUIP_ATTACHMENTS));
  312. m_ControlledInfected.GetAIAgent().SetKeepInIdle(true);
  313. }
  314. protected void PossesInfected()
  315. {
  316. ResetValues();
  317. FreeDebugCamera.GetInstance().SetActive(true);
  318. m_ControlledInfected = DayZInfected.Cast(FreeDebugCamera.GetInstance().GetCrosshairObject());
  319. FreeDebugCamera.GetInstance().SetActive(false);
  320. }
  321. //!
  322. void CommandHandler(DayZInfected infected)
  323. {
  324. if( infected != m_ControlledInfected )
  325. return;
  326. infected.GetInputController().OverrideMovementSpeed(true, m_MovementSpeedEB.GetText().ToFloat());
  327. DayZInfectedCommandMove moveCommand = infected.GetCommand_Move();
  328. if( moveCommand )
  329. {
  330. moveCommand.SetStanceVariation(m_StanceCB.GetCurrentItem());
  331. moveCommand.SetIdleState(m_MindStateCB.GetCurrentItem());
  332. }
  333. if( m_CH_DoTurn )
  334. {
  335. moveCommand.StartTurn(m_TurnDirectionEB.GetText().ToFloat(), m_TurnTypeCB.GetCurrentItem());
  336. m_CH_DoTurn = false;
  337. }
  338. if( m_CH_DoVault )
  339. {
  340. infected.StartCommand_Vault(m_VaultingCB.GetCurrentItem());
  341. m_CH_DoVault = false;
  342. }
  343. if( m_CH_DoKnucleOut )
  344. {
  345. infected.StartCommand_Vault(-1);
  346. m_CH_DoKnucleOut = false;
  347. }
  348. if( m_CH_GoToCrawl )
  349. {
  350. infected.StartCommand_Crawl(m_CrawlingTypeCB.GetCurrentItem());
  351. m_CH_GoToCrawl = false;
  352. }
  353. if( m_CH_DoHit )
  354. {
  355. float hitDir = m_HitDirEB.GetText().ToFloat();
  356. int bodyPart = m_HitBodyPartCB.GetCurrentItem();
  357. bool heavyHit = m_HitTypeCB.GetCurrentItem() == 1;
  358. infected.StartCommand_Hit(heavyHit, bodyPart, hitDir);
  359. m_CH_DoHit = false;
  360. }
  361. if( m_CH_StartDeath )
  362. {
  363. int deathType = m_DeathTypeCB.GetCurrentItem();
  364. float deathDir = m_HitDirEB.GetText().ToFloat();
  365. infected.StartCommand_Death(deathType, deathDir);
  366. m_CH_StartDeath = false;
  367. }
  368. if( m_CH_DoAttack )
  369. {
  370. float attackDir = m_AttackDirCB.GetCurrentItem();
  371. int attackType = m_AttackDescriptors.Get(m_AttackTypeCB.GetCurrentItem()).animValue;
  372. infected.StartCommand_Attack(null, attackType, attackDir);
  373. m_CH_DoAttack = false;
  374. }
  375. }
  376. //!
  377. void Tick()
  378. {
  379. if( !m_ControlledInfected )
  380. return;
  381. }
  382. //!
  383. void InitAttacks()
  384. {
  385. m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Attack Left Light", 0));
  386. m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Attack Right Light", 1));
  387. m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Attack Left Heavy", 2));
  388. m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Attack Right Heavy", 3));
  389. m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Crawl Attack", 7));
  390. //m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Crawl Attack Combo", 8));
  391. //m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Door Push Attack", 9));
  392. //m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Door Head Attack", 10));
  393. //m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Door Shoulder Attack", 11));
  394. //m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Door LR Attack", 12));
  395. //m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Door Kick Attack", 13));
  396. //m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Door Charge R", 14));
  397. //m_AttackDescriptors.Insert(new PluginDayZInfectedDebugAttackDesc("Door Charge L", 15));
  398. for( int i = 0; i < m_AttackDescriptors.Count(); ++i )
  399. {
  400. m_AttackTypeCB.AddItem(m_AttackDescriptors.Get(i).name);
  401. }
  402. }
  403. private void CleanupDebugShapes(array<Shape> shapesArr)
  404. {
  405. for ( int it = 0; it < shapesArr.Count(); ++it )
  406. {
  407. Debug.RemoveShape( shapesArr[it] );
  408. }
  409. shapesArr.Clear();
  410. }
  411. }