File size: 2,496 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
class JsonMissionLoaderData
{
	ref TStringArray MissionPaths;

	static JsonMissionLoaderData GetData()
	{
		JsonMissionLoaderData data;
		
		string path;
		string errorMessage;

		if (GetCLIParam("missionLoaderPath", path) == false)
		{
			path = CFG_FILE_MISSION_LIST;
		}
		
		if (!FileExist(path))
		{
			DayZGame dzg = GetDayZGame();
			
			data = new JsonMissionLoaderData();
			data.MissionPaths = {dzg.GetMissionFolderPath()};
			if (!JsonFileLoader<JsonMissionLoaderData>.SaveFile(path, data, errorMessage))
				ErrorEx(errorMessage);
		}
		else
		{
			if (!JsonFileLoader<JsonMissionLoaderData>.LoadFile(path, data, errorMessage))
				ErrorEx(errorMessage);
		}

		return data;
	}
}

class MissionLoader : UIScriptedMenu
{
	
	protected TextListboxWidget			m_WgtLstMsnList;
	protected ButtonWidget				m_WgtBtnMsnPlay;
	protected ButtonWidget				m_WgtBtnMsnClose;
	protected ref TStringArray			m_ListMissionsNames;
	protected ref JsonMissionLoaderData m_MissionData;
	
	override Widget Init()
	{
		m_MissionData = JsonMissionLoaderData.GetData();
		
		layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_mission_loader.layout");	
		
		m_WgtLstMsnList = TextListboxWidget.Cast( layoutRoot.FindAnyWidget("wgt_lst_missions") );
		m_WgtBtnMsnPlay = ButtonWidget.Cast( layoutRoot.FindAnyWidget("wgt_btn_mission_play") );
		m_WgtBtnMsnClose = ButtonWidget.Cast( layoutRoot.FindAnyWidget("wgt_btn_mission_close") );

		foreach (string path:m_MissionData.MissionPaths)
		{
			m_WgtLstMsnList.AddItem(path, NULL, 0);
		}
		
		return layoutRoot;
	}

	override bool OnClick(Widget w, int x, int y, int button)
	{
		super.OnClick(w, x, y, button);
		
		if ( w == m_WgtBtnMsnClose )
		{
			Close();
			
			return true;
		}
		else if ( w == m_WgtBtnMsnPlay )
		{
			int rowIndex = m_WgtLstMsnList.GetSelectedRow();
			string missionPath = m_MissionData.MissionPaths.Get(rowIndex);
			GetGame().PlayMission(missionPath);
			return true;
		}
		return false;
	}
	
	
	override bool OnDoubleClick(Widget w, int x, int y, int button)
	{
		super.OnClick(w, x, y, button);
		
		if (w == m_WgtLstMsnList)
		{
			int rowIndex = m_WgtLstMsnList.GetSelectedRow();
			string missionPath = m_MissionData.MissionPaths.Get(rowIndex);
			GetGame().PlayMission(missionPath);
		}
		return false;
	}
	
	override bool OnKeyDown(Widget w, int x, int y, int key)
	{
		super.OnKeyDown(w,x,y,key);
		switch (key)
		{
			case KeyCode.KC_ESCAPE:
			{
				Close();
				return true;
			}
		}
		return false;
	}

}