missionloader.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. class JsonMissionLoaderData
  2. {
  3. ref TStringArray MissionPaths;
  4. static JsonMissionLoaderData GetData()
  5. {
  6. JsonMissionLoaderData data;
  7. string path;
  8. string errorMessage;
  9. if (GetCLIParam("missionLoaderPath", path) == false)
  10. {
  11. path = CFG_FILE_MISSION_LIST;
  12. }
  13. if (!FileExist(path))
  14. {
  15. DayZGame dzg = GetDayZGame();
  16. data = new JsonMissionLoaderData();
  17. data.MissionPaths = {dzg.GetMissionFolderPath()};
  18. if (!JsonFileLoader<JsonMissionLoaderData>.SaveFile(path, data, errorMessage))
  19. ErrorEx(errorMessage);
  20. }
  21. else
  22. {
  23. if (!JsonFileLoader<JsonMissionLoaderData>.LoadFile(path, data, errorMessage))
  24. ErrorEx(errorMessage);
  25. }
  26. return data;
  27. }
  28. }
  29. class MissionLoader : UIScriptedMenu
  30. {
  31. protected TextListboxWidget m_WgtLstMsnList;
  32. protected ButtonWidget m_WgtBtnMsnPlay;
  33. protected ButtonWidget m_WgtBtnMsnClose;
  34. protected ref TStringArray m_ListMissionsNames;
  35. protected ref JsonMissionLoaderData m_MissionData;
  36. override Widget Init()
  37. {
  38. m_MissionData = JsonMissionLoaderData.GetData();
  39. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_mission_loader.layout");
  40. m_WgtLstMsnList = TextListboxWidget.Cast( layoutRoot.FindAnyWidget("wgt_lst_missions") );
  41. m_WgtBtnMsnPlay = ButtonWidget.Cast( layoutRoot.FindAnyWidget("wgt_btn_mission_play") );
  42. m_WgtBtnMsnClose = ButtonWidget.Cast( layoutRoot.FindAnyWidget("wgt_btn_mission_close") );
  43. foreach (string path:m_MissionData.MissionPaths)
  44. {
  45. m_WgtLstMsnList.AddItem(path, NULL, 0);
  46. }
  47. return layoutRoot;
  48. }
  49. override bool OnClick(Widget w, int x, int y, int button)
  50. {
  51. super.OnClick(w, x, y, button);
  52. if ( w == m_WgtBtnMsnClose )
  53. {
  54. Close();
  55. return true;
  56. }
  57. else if ( w == m_WgtBtnMsnPlay )
  58. {
  59. int rowIndex = m_WgtLstMsnList.GetSelectedRow();
  60. string missionPath = m_MissionData.MissionPaths.Get(rowIndex);
  61. GetGame().PlayMission(missionPath);
  62. return true;
  63. }
  64. return false;
  65. }
  66. override bool OnDoubleClick(Widget w, int x, int y, int button)
  67. {
  68. super.OnClick(w, x, y, button);
  69. if (w == m_WgtLstMsnList)
  70. {
  71. int rowIndex = m_WgtLstMsnList.GetSelectedRow();
  72. string missionPath = m_MissionData.MissionPaths.Get(rowIndex);
  73. GetGame().PlayMission(missionPath);
  74. }
  75. return false;
  76. }
  77. override bool OnKeyDown(Widget w, int x, int y, int key)
  78. {
  79. super.OnKeyDown(w,x,y,key);
  80. switch (key)
  81. {
  82. case KeyCode.KC_ESCAPE:
  83. {
  84. Close();
  85. return true;
  86. }
  87. }
  88. return false;
  89. }
  90. }