File size: 5,231 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
class ModsMenuDetailedEntry extends ScriptedWidgetEventHandler
{
	protected Widget			m_Root;
	protected Widget			m_Detail;
	
	//Header
	protected ImageWidget		m_IconSmall;
	protected ImageWidget		m_IconCollapse;
	protected TextWidget		m_Name;
	
	//Left Side Panel
	protected ImageWidget		m_IconBig;
	protected MultilineTextWidget		m_Author;
	protected TextWidget		m_Version;
	protected RichTextWidget	m_ActionWebsite;
	protected RichTextWidget	m_ActionPurchase;
	
	//Description Panel
	protected RichTextWidget	m_Description;

	protected ModInfo			m_Data;
	protected ModsMenuDetailed	m_ParentMenu;
	protected bool				m_IsOpen;

	void ModsMenuDetailedEntry(ModInfo data, Widget parent, ModsMenuDetailed parent_menu)
	{
		m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/mods_menu/mods_menu_detailed_entry.layout", parent);
		m_Detail = m_Root.FindAnyWidget("DetailContainer");
		
		m_IconSmall = ImageWidget.Cast(m_Root.FindAnyWidget("IconSmall"));
		m_IconCollapse = ImageWidget.Cast(m_Root.FindAnyWidget("collapse_button"));
		m_IconCollapse.LoadImageFile( 1, "set:dayz_gui image:icon_open" );
		m_Name = TextWidget.Cast(m_Root.FindAnyWidget("Name"));
		
		m_IconBig = ImageWidget.Cast(m_Root.FindAnyWidget("IconBig"));
		m_Author = MultilineTextWidget.Cast(m_Root.FindAnyWidget("Author"));
		m_Author.SetLineBreakingOverride(LinebreakOverrideMode.LINEBREAK_WESTERN);
		
		m_Version = TextWidget.Cast(m_Root.FindAnyWidget("Version"));
		m_ActionWebsite = RichTextWidget.Cast(m_Root.FindAnyWidget("Link"));
		m_ActionPurchase = RichTextWidget.Cast(m_Root.FindAnyWidget("Purchase"));
		
		m_Description = RichTextWidget.Cast(m_Root.FindAnyWidget("Description"));
		
		m_Data = data;
		m_ParentMenu = parent_menu;
		
		m_Root.SetHandler(this);

		LoadData();
	}
	
	void ~ModsMenuDetailedEntry()
	{
		delete m_Root;
	}
	
	Widget GetWidget()
	{
		return m_Root;
	}
	
	void Select()
	{
		m_Root.SetColor( ARGBF( m_Root.GetAlpha(), 0.3, 0, 0 ) );
		
		m_Detail.Show(true);
		m_IconBig.Show( true );
		m_IconSmall.Show( false );
		m_IconCollapse.SetImage( 1 );
		m_Detail.Update();
		m_Root.Update();
		m_IsOpen = true;
	}
	
	void Deselect()
	{
		m_Root.SetColor( ARGBF( m_Root.GetAlpha(), 0.2, 0.2, 0.2 ) );
		
		m_Detail.Show(false);
		m_IconBig.Show( false );
		m_IconSmall.Show( true );
		m_IconCollapse.SetImage( 0 );
		m_Detail.Update();
		m_Root.Update();
		m_IsOpen = false;
	}

	void LoadData()
	{
		string picture = m_Data.GetPicture();
		string logo = m_Data.GetLogoSmall();
		string name = m_Data.GetName();
		string description = m_Data.GetOverview();
		string author = m_Data.GetAuthor();
		string version = m_Data.GetVersion();
		string action = m_Data.GetAction();

		//Load Large Icon
		if (picture != "")
		{
			m_IconBig.LoadImageFile(0, picture);
		}
		else if (logo != "")
		{
			m_IconBig.LoadImageFile(0, logo);
		}
		else
		{
			m_IconBig.LoadImageFile(0, ModInfo.DEFAULT_PICTURE);
		}
		
		//Load Small Icon
		if (logo != "")
		{
			m_IconSmall.LoadImageFile(0, logo);
		}
		else if (picture != "")
		{
			m_IconSmall.LoadImageFile(0, picture);
		}
		else
		{
			m_IconSmall.LoadImageFile(0, ModInfo.DEFAULT_LOGO_SMALL);
		}

		if (name != "")
		{
			m_Name.SetText(name);
		}

		if (description != "")
		{
			m_Description.SetText(description);
		}
		else
		{
			m_Description.SetText(ModInfo.DEFAULT_OVERVIEW);
		}
		m_Description.Update();
		m_Detail.Update();
		
		if (author != "")
		{
			m_Author.Show( true );
			m_Author.SetText(author);
		}
		
		if (version != "")
		{
			m_Version.Show( true );
			m_Version.SetText(version);
		}
		
		#ifdef PLATFORM_WINDOWS
		if (action != "")
		{
			m_ActionWebsite.Show( true );
		}
		#endif
		
		if ( m_Data.GetIsDLC() )
		{
			bool isOwned = m_Data.GetIsOwned();
			m_Root.FindAnyWidget("ModOwnership").Show( true );
			m_Root.FindAnyWidget("Owned").Show( isOwned );
			m_Root.FindAnyWidget("Unowned").Show( !isOwned );
			m_ActionPurchase.Show( true );
			m_Version.Show( false );
		}
	}
	
	override bool OnMouseButtonUp(Widget w, int x, int y, int button)
	{
		if( w == m_IconCollapse )
		{
			m_ParentMenu.Select( m_Data, !m_IsOpen );
			return true;
		}
		else if( w == m_ActionWebsite )
		{
			GetGame().OpenURL( m_Data.GetAction() );
		}
		else if( w == m_ActionPurchase )
		{
			m_Data.GoToStore();
		}
		return false;
	}
	
	override bool OnMouseEnter(Widget w, int x, int y)
	{
		if( w == m_ActionWebsite )
		{
			m_ActionWebsite.SetBold( true );
			m_ActionWebsite.SetText( "#mod_detail_info_website" );
		}
		
		if( w == m_ActionPurchase )
		{
			m_ActionPurchase.SetBold( true );
			m_ActionPurchase.SetText( "#mod_detail_info_store" );
		}
		
		if( w == m_Root )
		{
			if( m_Data.GetTooltip() != "" )
				m_ParentMenu.PrepareTooltip( m_Data );
			return true;
		}
		
		return false;
	}
	
	override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
	{
		if( w == m_ActionWebsite )
		{
			m_ActionWebsite.SetBold( false );
			m_ActionWebsite.SetText( "#mod_detail_info_website" );
		}
		
		if( w == m_ActionPurchase )
		{
			m_ActionPurchase.SetBold( false );
			m_ActionPurchase.SetText( "#mod_detail_info_store" );
		}
		
		if( enterW != m_Root )
		{
			m_ParentMenu.HideTooltip();
			return true;
		}
		
		return false;
	}
}