1// ==================
2// MARKET MENU
3// ==================
4
5component cmpMarketItem extends panel {
6	{
7		size "425 25"
8		onClick {
9			cmd "ui_market_select <node:this.id@string>;"
10		}
11	}
12
13	data id {
14	}
15
16	checkbox_blue autosell {
17		current		0
18		pos			"0 0"
19		size		"22 18"
20
21		onChange {
22			cmd "ui_market_setautosell \"<node:parent.id@string>\" <node:this@current>;"
23			cmd "ui_market_fill <cvar:ui_market_category>;"
24			cmd "ui_market_select <node:parent.id@string>;"
25		}
26	}
27
28	string name {
29		color		"0 .78 0 1"
30		pos			"25 0"
31		size		"250 25"
32		ghost		true
33	}
34	string storage {
35		color		"0 .78 0 1"
36		contentalign	ALIGN_CR
37		pos			"280 0"
38		size		"60 25"
39		ghost		true
40	}
41	string market {
42		color		"0 .78 0 1"
43		contentalign	ALIGN_CR
44		pos			"370 0"
45		size		"46 25"
46		ghost true
47	}
48	string price {
49		color		"0 .78 0 1"
50		contentalign	ALIGN_CR
51		pos			"432 0"
52		size		"60 25"
53		ghost		true
54	}
55
56	spinner_blue buysell {
57		tooltip		"_Buy and sell item"
58		pos			"346 0"
59		shiftincreasefactor	10.0
60		onChange {
61			if ( ( ( <node:parent.storage@string> + <node:parent.market@string> ) + <lastdiff> ) < 1 ) {
62				*node:root.selected@string = ""
63			}
64			cmd "ui_market_buy \"<node:parent.id@string>\" <lastdiff>;"
65			cmd "ui_market_fill <cvar:ui_market_category>;"
66			if ( *node:root.selected@string ne "" ) {
67				cmd "ui_market_select \"<node:parent.id@string>\";"
68			}
69		}
70	}
71}
72
73window market extends objectinfo {
74	{
75		background	"background/base_bg"
76	}
77
78	cmpBaseHeader baseHeader {
79	}
80
81	// ==================
82	// tab
83	// ==================
84
85	data selected {
86		string	""
87	}
88
89	panel tab_background {
90		pos		"24 96"
91		size	"986 56"
92		background	"ui/panel_tab"
93	}
94
95	tab market_navigation {
96		{
97			pos		"47 106"
98			size	"938 39"
99			cvar	*cvar:ui_market_category
100
101			onChange {
102				*node:root.selected@string = ""
103				cmd "ui_market_fill <cvar:ui_market_category>;"
104			}
105		}
106
107		option primary {
108			label	"_Primary"
109			value	"primary"
110		}
111		option secondary {
112			label	"_Secondary"
113			value	"secondary"
114		}
115		option heavy {
116			label	"_Heavy"
117			value	"heavy"
118		}
119		option misc {
120			label	"_Misc"
121			value	"misc"
122		}
123		option armour {
124			label	"_Armour"
125			value	"armour"
126		}
127		option craftitem {
128			label	"_Craft items"
129			value	"craftitem"
130		}
131		option aircraft {
132			label	"_Aircraft"
133			value	"aircraft"
134		}
135		option dummy {
136			label	"_Other"
137			value	"dummy"
138		}
139	}
140
141	// ==================
142	// lists
143	// ==================
144
145	rows lines {
146		pos			"28 175"
147		size		"530 568"
148		color1		"0 0.08 0 1"
149		color2		"0 0.16 0 1"
150		lineheight	25
151	}
152
153	panel verticalline {
154		pos		"451 175"
155		size	"4 565"
156		bgcolor	"0.03 0.42 0.03 1"
157	}
158
159	panel itemlist_back {
160		pos		"12 160"
161		size	"553 597"
162		background	"ui/panel_grey_green_large2"
163	}
164	string name_label {
165		string		"_Name"
166		pos			"55 180"
167		size		"250 25"
168		color		"0 .78 0 1"
169	}
170	string storage_label {
171		string		"_Store"
172		tooltip		"_Number of such items in base"
173		pos			"325 180"
174		size		"60 25"
175		color		"0 .78 0 1"
176		contentalign	ALIGN_CR
177	}
178	string market_label {
179		string		"_Market"
180		tooltip		"_Number of such items on the market"
181		pos			"390 180"
182		size		"60 25"
183		color		"0 .78 0 1"
184		contentalign	ALIGN_CR
185	}
186	string price {
187		string		"_Price"
188		pos			"462 180"
189		size		"60 25"
190		color		"0 .78 0 1"
191		contentalign	ALIGN_CR
192	}
193
194	panel itemlist {
195		pos		"30 205"
196		size	"500 535"
197		layout	LAYOUT_TOP_DOWN_FLOW
198		wheelscrollable	true
199		onViewChange {
200			*node:parent.itemlist_scroll@fullsize = <fullsize>
201			*node:parent.itemlist_scroll@current = <viewpos>
202			*node:parent.itemlist_scroll@viewsize = <viewsize>
203		}
204	}
205	vscrollbar itemlist_scroll {
206		image		"ui/scrollbar_v_green"
207		pos			"530 205"
208		height		"535"
209		current		0
210		viewsize	21
211		fullsize	21
212		hidewhenunused true
213		onChange {
214			*node:parent.itemlist@viewpos = <current>
215		}
216	}
217
218	/*
219	 * @brief Select an entry from thelist
220	 * <1> item id
221	 */
222	confunc ui_market_select {
223		if ( *node:root.selected@string ne "" ) {
224			*node:root.itemlist.item_<node:root.selected@string>.name@color = "0 .78 0 1"
225			*node:root.itemlist.item_<node:root.selected@string>.storage@color = "0 .78 0 1"
226			*node:root.itemlist.item_<node:root.selected@string>.market@color = "0 .78 0 1"
227			*node:root.itemlist.item_<node:root.selected@string>.price@color = "0 .78 0 1"
228		}
229		*node:root.selected@string = <1>
230		if ( *node:root.selected@string ne "" ) {
231			*node:root.itemlist.item_<node:root.selected@string>.name@color = "1 1 1 1"
232			*node:root.itemlist.item_<node:root.selected@string>.storage@color = "1 1 1 1"
233			*node:root.itemlist.item_<node:root.selected@string>.market@color = "1 1 1 1"
234			*node:root.itemlist.item_<node:root.selected@string>.price@color = "1 1 1 1"
235			cmd "ui_market_showinfo <1>;"
236		}
237	}
238	/*
239	 * @brief Confunc to clear the itemlist
240	 */
241	confunc ui_market_clear {
242		call *node:root.itemlist@removeAllchild
243	}
244	/*
245	 * @brief Confunc to add the item to market's itemlist
246	 * <1> reference id
247	 * <2> name
248	 * <3> count at base
249	 * <4> count on market
250	 * <5> buy price
251	 * <6> sell price
252	 * <7> autosell (0: off, 1: on, -: not available"
253	 * <8> tooltip for disabled entries, "-" otherwise
254     */
255	confunc ui_market_add {
256		call *node:root.itemlist@createChild("item_<1>", "cmpMarketItem")
257
258		// autosell
259		*node:root.itemlist.item_<1>.id@string = <7>
260		if ( *node:root.itemlist.item_<1>.id@string eq "-" ) {
261			*node:root.itemlist.item_<1>.autosell@invis = true
262		} else {
263			*node:root.itemlist.item_<1>.autosell@current = <7>
264			if ( *node:root.itemlist.item_<1>.autosell@current != 0 ) {
265				*node:root.itemlist.item_<1>.autosell@tooltip = "_Item autosell enabled"
266			} else {
267				*node:root.itemlist.item_<1>.autosell@tooltip = "_Item autosell disabled"
268			}
269		}
270		*node:root.itemlist.item_<1>.id@string = <8>
271		if ( *node:root.itemlist.item_<1>.id@string ne "-" ) {
272			*node:root.itemlist.item_<1>.autosell@tooltip = <8>
273			*node:root.itemlist.item_<1>.autosell@disabled = true
274			*node:root.itemlist.item_<1>.buysell@disabled = true
275			*node:root.itemlist.item_<1>.buysell@tooltip = <8>
276		}
277
278		*node:root.itemlist.item_<1>.id@string = <1>
279		*node:root.itemlist.item_<1>.name@string = <2>
280		*node:root.itemlist.item_<1>.storage@string = <3>
281		*node:root.itemlist.item_<1>.market@string = <4>
282		*node:root.itemlist.item_<1>.price@string = <5>
283		if ( *node:root.itemlist.item_<1>.price@string eq "0" ) {
284			*node:root.itemlist.item_<1>.price@string = <6>
285		}
286		*node:root.itemlist.item_<1>.buysell@min = 0
287		*node:root.itemlist.item_<1>.buysell@current = <3>
288		*node:root.itemlist.item_<1>.buysell@max = ( <3> + <4> )
289
290		if ( *node:root.selected@string eq "" ) {
291			call *node:root.ui_market_select ( "<1>" )
292		}
293	}
294
295	panel basedescription {
296		{
297			pos		"588 167"
298			size	"410 115"
299			background	"ui/panel_grey_green"
300		}
301
302		string header_capacity {
303			string 		"_Capacity"
304			pos			"15 20"
305			size		"230 20"
306			font		"f_small_bold"
307			contentalign	ALIGN_CL
308		}
309		string header_free {
310			string 		"_free"
311			pos			"245 20"
312			size		"75 20"
313			font		"f_small_bold"
314			contentalign	ALIGN_CR
315		}
316		string header_all {
317			string 		"_all"
318			pos			"320 20"
319			size		"75 20"
320			font		"f_small_bold"
321			contentalign	ALIGN_CR
322		}
323
324		string storage_caption {
325			string 		"_Storage"
326			pos			"15 40"
327			size		"230 20"
328			font		"f_small"
329		}
330		string storage_free {
331			pos			"245 40"
332			size		"75 20"
333			font		"f_small"
334			contentalign	ALIGN_CR
335		}
336		string storage_all {
337			pos			"320 40"
338			size		"75 20"
339			font		"f_small"
340			contentalign	ALIGN_CR
341		}
342		string interceptor_caption {
343			string 		"_Interceptor Hangar"
344			pos			"15 60"
345			size		"230 20"
346			font		"f_small"
347		}
348		string interceptor_free {
349			pos			"245 60"
350			size		"75 20"
351			font		"f_small"
352			contentalign	ALIGN_CR
353		}
354		string interceptor_all {
355			pos			"320 60"
356			size		"75 20"
357			font		"f_small"
358			contentalign	ALIGN_CR
359		}
360		string dropship_caption {
361			string 		"_Dropship Hangar"
362			pos			"15 80"
363			size		"230 20"
364			font		"f_small"
365		}
366		string dropship_free {
367			pos			"245 80"
368			size		"75 20"
369			font		"f_small"
370			contentalign	ALIGN_CR
371		}
372		string dropship_all {
373			pos			"320 80"
374			size		"75 20"
375			font		"f_small"
376			contentalign	ALIGN_CR
377		}
378
379		confunc ui_market_update_caps {
380			*node:parent.storage_free@string = "<1>"
381			*node:parent.storage_all@string = "<2>"
382			*node:parent.interceptor_free@string = "<3>"
383			*node:parent.interceptor_all@string = "<4>"
384			*node:parent.dropship_free@string = "<5>"
385			*node:parent.dropship_all@string = "<6>"
386		}
387
388	}
389
390	confunc listen_openpedia {
391		cmd "ui_market_select \"<node:root.selected@string>\";"
392		cmd "ui_removelistener ufopedia@onWindowClosed <path:this>;"
393	}
394
395	panel itemdescription {
396		{
397			pos		"588 303"
398			size	"410 455"
399			background	"ui/panel_grey_green"
400		}
401
402		// ==================
403		// item description
404		// ==================
405
406		string itemname
407		{
408			visiblewhen "*cvar:ui_market_category ne \"aircraft\""	// for everything except aircraft
409			string		*cvar:mn_itemname
410			pos			"22 25"
411			size		"365 20"
412			contentalign	ALIGN_UC
413		}
414		string aircraftname
415		{
416			visiblewhen "*cvar:ui_market_category eq \"aircraft\""	// Only for aircraft.
417			string		*cvar:mn_aircraftname
418			pos			"22 25"
419			size		"365 20"
420			contentalign	ALIGN_UC
421		}
422
423		button ufopedia_link
424		{
425			icon		"icons/bordered_magnifying_glass"
426			tooltip		"_UFOpaedia"
427			pos			"370 27"
428			size		"16 16"
429			onClick		{
430				cmd "ui_addlistener ufopedia@onWindowClosed <path:root>.listen_openpedia;"
431				cmd "market_openpedia;"
432			}
433		}
434
435		item itemmodel
436		{
437			src			*cvar:mn_item
438			pos			"13 55"
439			size		"384 200"
440			angles		"0 180 90"
441			omega		"0 10 0"
442			autoscale	true
443		}
444
445		text description
446		{
447			dataid		TEXT_ITEMDESCRIPTION
448			pos			"32 257"
449			size		"336 120"
450			rows		"8"
451			lineheight	15
452			tabwidth	168
453			font		"f_verysmall"
454			onViewChange {
455				*node:root.itemdescription.description_scroll@fullsize = <fullsize>
456				*node:root.itemdescription.description_scroll@current = <viewpos>
457			}
458			onWheel {
459				*node:root.itemdescription.description_scroll@current = <viewpos>
460			}
461		}
462		vscrollbar description_scroll {
463			image		"ui/scrollbar_v_green"
464			pos			"370 257"
465			height		"120"
466			current		0
467			viewsize	8
468			fullsize	8
469			hidewhenunused true
470			onChange {
471				*node:root.itemdescription.description@viewpos = <current>
472			}
473		}
474
475		// ======================
476		// useable weapon or ammo
477		// ======================
478
479		string header_item
480		{
481			string	"_With:"
482			pos		"32 390"
483			size	"100 16"
484			font	"f_small"
485		}
486
487		button action_dec
488		{
489			pos		"142 390"
490			icon	"icons/prev"
491			size	"16 16"
492			onClick	{ cmd "mn_decreaseitem;" }
493		}
494
495		string item_name
496		{
497			string	*cvar:mn_linkname
498			pos		"162 390"
499			size	"190 16"
500			contentalign	ALIGN_CC
501			font	"f_small"
502		}
503
504		button action_inc
505		{
506			pos		"356 390"
507			icon	"icons/next"
508			size	"16 16"
509			onClick	{ cmd "mn_increaseitem;" }
510		}
511
512		// ==================
513		// firemode
514		// ==================
515
516		string header_firemode
517		{
518			string	"_Firemode:"
519			pos		"32 414"
520			size	"100 16"
521			font	"f_small"
522		}
523
524		button firemode_dec
525		{
526			tooltip "_Previous firemode"
527			pos		"142 414"
528			icon	"icons/prev"
529			size	"16 16"
530			onClick	{ cmd "mn_decreasefiremode;" }
531		}
532
533		string firemode_name
534		{
535			string	*cvar:mn_firemodename
536			pos		"162 414"
537			size	"190 16"
538			contentalign	ALIGN_CC
539			font	"f_small"
540		}
541
542		button firemode_inc
543		{
544			tooltip "_Next firemode"
545			pos		"356 414"
546			icon	"icons/next"
547			size	"16 16"
548			onClick	{ cmd "mn_increasefiremode;" }
549		}
550
551	}
552
553	// ==================
554	// init
555	// ==================
556
557	func onWindowOpened {
558		*node:root.selected@string = ""
559		cmd "ui_market_fill \"<cvar:ui_market_category>\";"
560		*cvar:mn_lastsubmenu = "market"
561	}
562
563	func onWindowClosed {
564		call *node:root.ui_market_clear
565		// Call base_init so that storage data can be updated
566		cmd "base_init;"
567	}
568}
569