huddebug.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. // *************************************************************************************
  2. // ! PluginDayzPlayerDebugUI
  3. // *************************************************************************************
  4. class HudDebugEventHandler extends ScriptedWidgetEventHandler
  5. {
  6. HudDebug m_HudDebug;
  7. void HudDebugEventHandler( HudDebug hud_debug )
  8. {
  9. m_HudDebug = hud_debug;
  10. }
  11. HudDebug GetHudDebug()
  12. {
  13. return m_HudDebug;
  14. }
  15. override bool OnClick( Widget w, int x, int y, int button )
  16. {
  17. super.OnClick( w, x, y, button );
  18. return GetHudDebug().OnClick( w, x, y, button );
  19. }
  20. override bool OnFocus(Widget w, int x, int y)
  21. {
  22. //Print("OnFocus");
  23. return true;
  24. }
  25. override bool OnFocusLost(Widget w, int x, int y)
  26. {
  27. //Print("OnFocusLost");
  28. return true;
  29. }
  30. /*
  31. override bool OnMouseEnter(Widget w, int x, int y)
  32. {
  33. Print("OnMouseEnter");
  34. return true;
  35. }
  36. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  37. {
  38. Print("OnMouseLeaves");
  39. return true;
  40. }*/
  41. override bool OnMouseButtonDown(Widget w, int x, int y, int button)
  42. {
  43. //Print("OnMouseButtonDown");
  44. return true;
  45. }
  46. override bool OnSelect(Widget w, int x, int y)
  47. {
  48. //Print("OnSelect");
  49. return true;
  50. }
  51. override bool OnItemSelected(Widget w, int x, int y, int row, int column, int oldRow, int oldColumn)
  52. {
  53. //Print("OnItemSelected");
  54. return true;
  55. }
  56. override bool OnModalResult(Widget w, int x, int y, int code, int result)
  57. {
  58. //Print("OnModalResult");
  59. return true;
  60. }
  61. override bool OnChange(Widget w, int x, int y, bool finished)
  62. {
  63. //Print("OnChange " + finished);
  64. super.OnChange( w, x, y, finished );
  65. return GetHudDebug().OnChange( w, x, y, finished );
  66. }
  67. }
  68. class HudDebug extends Hud
  69. {
  70. static const int HUD_WIN_UNDEFINED = 0;
  71. static const int HUD_WIN_CHAR_STATS = 1;
  72. static const int HUD_WIN_CHAR_MODIFIERS = 2;
  73. static const int HUD_WIN_CHAR_AGENTS = 3;
  74. static const int HUD_WIN_CHAR_DEBUG = 4;
  75. static const int HUD_WIN_CHAR_LEVELS = 5;
  76. static const int HUD_WIN_CHAR_STOMACH = 6;
  77. static const int HUD_WIN_VERSION = 7;
  78. static const int HUD_WIN_TEMPERATURE = 8;
  79. static const int HUD_WIN_HEALTH = 9;
  80. static const int HUD_WIN_HORTICULTURE = 10;
  81. Widget m_WgtRoot;
  82. Widget m_Crosshair;
  83. ref array<ref HudDebugWinBase> m_Panels;
  84. ref Timer m_TimerUpdate;
  85. ref HudDebugEventHandler m_HudDebugHandler;
  86. ref HudDebugWinCharModifiers m_WinCharModifiers;
  87. ref HudDebugWinCharStats m_WinCharStats;
  88. ref HudDebugWinCharAgents m_WinCharAgents;
  89. ref HudDebugWinHealth m_WinHealth;
  90. ref HudDebugWinHorticulture m_WinHorticulture;
  91. //============================================
  92. // HudDebug
  93. //============================================
  94. void HudDebug()
  95. {
  96. }
  97. //============================================
  98. // ~HudDebug
  99. //============================================
  100. void ~HudDebug()
  101. {
  102. delete m_WgtRoot;
  103. m_TimerUpdate.Stop();
  104. }
  105. //============================================
  106. // Init
  107. //============================================
  108. override void Init( Widget hud_panel_widget )
  109. {
  110. m_WgtRoot = hud_panel_widget;
  111. m_WgtRoot.Show( true );
  112. // Crosshair widget root
  113. m_Crosshair = m_WgtRoot.FindAnyWidget( "wdw_Crosshair" );
  114. m_Panels = new array<ref HudDebugWinBase>;
  115. // Register Window Character Stats
  116. m_WinCharStats = new HudDebugWinCharStats( m_WgtRoot.FindAnyWidget( "wdw_CharacterStats" ) );
  117. m_Panels.Insert( m_WinCharStats );
  118. // Register Window Character Stats
  119. HudDebugWinCharLevels win_char_levels = new HudDebugWinCharLevels( m_WgtRoot.FindAnyWidget( "wdw_CharacterLevels" ) );
  120. m_Panels.Insert( win_char_levels );
  121. // Register Window Chracter Modifiers
  122. m_WinCharModifiers = new HudDebugWinCharModifiers( m_WgtRoot.FindAnyWidget( "wdw_CharacterModifiers" ) );
  123. m_Panels.Insert( m_WinCharModifiers );
  124. // Register Window Chracter Agents
  125. m_WinCharAgents = new HudDebugWinCharAgents( m_WgtRoot.FindAnyWidget( "wdw_CharacterAgents" ) );
  126. m_Panels.Insert( m_WinCharAgents );
  127. // Register Window Chracter Debug
  128. HudDebugWinCharDebug win_char_debug = new HudDebugWinCharDebug( m_WgtRoot.FindAnyWidget( "wdw_CharacterDebug" ) );
  129. m_Panels.Insert( win_char_debug );
  130. // Register Window Chracter Debug
  131. HudDebugWinCharStomach win_char_stomach = new HudDebugWinCharStomach( m_WgtRoot.FindAnyWidget( "wdw_CharacterStomach" ) );
  132. m_Panels.Insert( win_char_stomach );
  133. // Register Window Version
  134. HudDebugWinVersion win_version = new HudDebugWinVersion( m_WgtRoot.FindAnyWidget( "wdw_Version" ) );
  135. m_Panels.Insert( win_version );
  136. // Register Window Temperature
  137. HudDebugWinTemperature win_temp = new HudDebugWinTemperature( m_WgtRoot.FindAnyWidget( "wdw_Temp" ) );
  138. m_Panels.Insert( win_temp );
  139. // Register Window Character Health
  140. m_WinHealth = new HudDebugWinHealth( m_WgtRoot.FindAnyWidget( "wdw_Health" ) );
  141. m_Panels.Insert( m_WinHealth );
  142. m_WinHorticulture = new HudDebugWinHorticulture( m_WgtRoot.FindAnyWidget( "wdw_Horticulture" ) );
  143. m_Panels.Insert( m_WinHorticulture );
  144. RefreshByLocalProfile();
  145. RefreshCrosshairVisibility();
  146. m_TimerUpdate = new Timer();
  147. m_TimerUpdate.Run( 1.0, this, "Update", NULL, true );
  148. //set ui event handler
  149. m_HudDebugHandler = new HudDebugEventHandler( this );
  150. m_WgtRoot.SetHandler( m_HudDebugHandler );
  151. }
  152. //============================================
  153. // Update
  154. //============================================
  155. override void Update( float timeslice )
  156. {
  157. for ( int i = 0; i < m_Panels.Count(); ++i )
  158. {
  159. if ( m_Panels.Get( i ).IsVisible() )
  160. {
  161. m_Panels.Get( i ).Update();
  162. }
  163. }
  164. }
  165. //============================================
  166. // SetPanetVisible
  167. //============================================
  168. void SetPanelVisible(int panel_type, bool visible)
  169. {
  170. if ( visible )
  171. {
  172. PanelShow( panel_type );
  173. }
  174. else
  175. {
  176. PanelHide( panel_type );
  177. }
  178. }
  179. //============================================
  180. // PanelShow
  181. //============================================
  182. void PanelShow(int panel_type)
  183. {
  184. for ( int i = 0; i < m_Panels.Count(); ++i )
  185. {
  186. HudDebugWinBase panel = m_Panels.Get( i );
  187. if ( panel.GetType() == panel_type )
  188. {
  189. panel.Show();
  190. }
  191. }
  192. }
  193. //============================================
  194. // PanelHide
  195. //============================================
  196. void PanelHide(int panel_type)
  197. {
  198. for ( int i = 0; i < m_Panels.Count(); ++i )
  199. {
  200. HudDebugWinBase panel = m_Panels.Get( i );
  201. if ( panel.GetType() == panel_type )
  202. {
  203. panel.Hide();
  204. }
  205. }
  206. }
  207. //============================================
  208. // RefreshCrosshairVisibility
  209. //============================================
  210. void RefreshCrosshairVisibility()
  211. {
  212. PluginConfigDebugProfile module_cfg_profile = PluginConfigDebugProfile.Cast( GetPlugin( PluginConfigDebugProfile ) );
  213. if ( module_cfg_profile )
  214. {
  215. PluginDeveloper modul_dev = PluginDeveloper.Cast( GetPlugin( PluginDeveloper ) );
  216. if ( modul_dev.IsEnabledFreeCamera() )
  217. {
  218. m_Crosshair.Show( module_cfg_profile.GetFreeCameraCrosshairVisible() );
  219. }
  220. else
  221. {
  222. m_Crosshair.Show( false );
  223. }
  224. }
  225. }
  226. //============================================
  227. // HideCrosshairVisibility
  228. //============================================
  229. void HideCrosshairVisibility()
  230. {
  231. PluginConfigDebugProfile module_cfg_profile = PluginConfigDebugProfile.Cast( GetPlugin( PluginConfigDebugProfile ) );
  232. if ( module_cfg_profile )
  233. {
  234. PluginDeveloper modul_dev = PluginDeveloper.Cast( GetPlugin( PluginDeveloper ) );
  235. if ( modul_dev.IsEnabledFreeCamera() )
  236. {
  237. m_Crosshair.Show( false );
  238. }
  239. }
  240. }
  241. //============================================
  242. // RefreshByLocalProfile
  243. //============================================
  244. void RefreshByLocalProfile()
  245. {
  246. PluginConfigDebugProfile module_cfg_profile = PluginConfigDebugProfile.Cast( GetPlugin( PluginConfigDebugProfile ) );
  247. if ( module_cfg_profile )
  248. {
  249. SetPanelVisible( HudDebug.HUD_WIN_CHAR_STATS, module_cfg_profile.GetCharacterStatsVisible() );
  250. SetPanelVisible( HudDebug.HUD_WIN_CHAR_LEVELS, module_cfg_profile.GetCharacterLevelsVisible() );
  251. SetPanelVisible( HudDebug.HUD_WIN_CHAR_MODIFIERS, module_cfg_profile.GetCharacterModifiersVisible() );
  252. SetPanelVisible( HudDebug.HUD_WIN_CHAR_AGENTS, module_cfg_profile.GetCharacterAgentsVisible() );
  253. SetPanelVisible( HudDebug.HUD_WIN_CHAR_DEBUG, module_cfg_profile.GetCharacterDebugVisible() );
  254. SetPanelVisible( HudDebug.HUD_WIN_CHAR_STOMACH, module_cfg_profile.GetCharacterStomachVisible() );
  255. SetPanelVisible( HudDebug.HUD_WIN_VERSION, module_cfg_profile.GetVersionVisible() );
  256. SetPanelVisible( HudDebug.HUD_WIN_TEMPERATURE, module_cfg_profile.GetTempVisible() );
  257. SetPanelVisible( HudDebug.HUD_WIN_HEALTH, module_cfg_profile.GetHealthVisible() );
  258. SetPanelVisible( HudDebug.HUD_WIN_HORTICULTURE, module_cfg_profile.GetHorticultureVisible() );
  259. }
  260. }
  261. //============================================
  262. // IsInitialized
  263. //============================================
  264. bool IsInitialized()
  265. {
  266. if ( m_WgtRoot == NULL )
  267. {
  268. return false;
  269. }
  270. return false;
  271. }
  272. //============================================
  273. // OnClick
  274. //============================================
  275. bool OnClick( Widget w, int x, int y, int button )
  276. {
  277. //send OnClick to HudDebugWinCharModifiers
  278. if ( m_WinCharModifiers )
  279. {
  280. if (m_WinCharModifiers.OnClick( w, x, y, button ))
  281. return true;
  282. }
  283. if ( m_WinCharAgents )
  284. {
  285. if (m_WinCharAgents.OnClick( w, x, y, button ))
  286. return true;
  287. }
  288. if ( m_WinCharStats )
  289. {
  290. if (m_WinCharStats.OnClick( w, x, y, button ))
  291. return true;
  292. }
  293. if ( m_WinHealth )
  294. {
  295. if (m_WinHealth.OnClick( w, x, y, button ))
  296. return true;
  297. }
  298. if ( m_WinHorticulture )
  299. {
  300. if (m_WinHorticulture.OnClick( w, x, y, button ))
  301. return true;
  302. }
  303. return false;
  304. }
  305. bool OnChange(Widget w, int x, int y, bool finished)
  306. {
  307. if ( m_WinCharStats )
  308. {
  309. if (m_WinCharStats.OnChange( w, x, y, finished ))
  310. return true;
  311. }
  312. return false;
  313. }
  314. }