1#textdomain wesnoth-lib
2###
3### The in game portrait dialogs.
4### Due to the excessive amount of dialogs it's not possible to split off the
5### window definitions. So this unit is a bit larger as wanted.
6###
7
8# The maximum width of the text
9#define MAX_TEXT_WIDTH
10675
11#enddef
12
13#define ___GUI_IMAGE_WIDTH
14(
15	max(250, min(500, best_size))
16where
17	best_size = (
18		if((best_width * aspect_ratio) > max_height,
19			floor(max_height / aspect_ratio),
20			best_width
21		)
22	where
23		best_width = (
24			if(gamemap_width > text_width_saturation,
25				gamemap_width - {MAX_TEXT_WIDTH},
26				gamemap_width / size_factor
27			)
28		where
29			# gamemap_width width needed to reach the MAX_TEXT_WIDTH #
30			text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
31			size_factor = 3
32		),
33		aspect_ratio = (
34			if(image_original_width > 0,
35				as_decimal(image_original_height) / image_original_width,
36				0
37			)
38		),
39		#
40		  TODO: this is rather hacky. The old value was gamemap_height - 4 but that caused
41		  crashes with the 727 px high Rithrandil portrait in TRoW. This value seems to work,
42		  but the fact that it crashed at all points to some deeper logic flaw in the size
43		  calculation formulas here. Need to revisit at some point...
44
45		  -- vultraz, 2018-05-24
46		#
47		max_height = (gamemap_height - 30)
48	)
49)#enddef
50
51# This is the version with debug info
52#define __GUI_IMAGE_WIDTH
53([[
54	debug_print('screen_width ', screen_width),
55	debug_print('screen_height ', screen_height),
56	debug_print('gamemap_width ', gamemap_width),
57	debug_print('gamemap_height ', gamemap_height),
58	debug_print('image_original_width ', image_original_width),
59	debug_print('image_original_height ', image_original_height),
60],
61	{___GUI_IMAGE_WIDTH}
62][1]
63)
64#enddef
65
66#undef __GUI_IMAGE_WIDTH
67# This is the version without debug info
68#define __GUI_IMAGE_WIDTH
69({___GUI_IMAGE_WIDTH})#enddef
70
71
72# This is the macro for the image width which is can be used as string
73# parameter.
74#define _GUI_IMAGE_WIDTH
75"{__GUI_IMAGE_WIDTH}"#enddef
76
77# the value the image needs to be scaled by, this version can be used as string
78# parameter.
79#define _GUI_IMAGE_SCALE_FACTOR
80(
81	{__GUI_IMAGE_WIDTH} / 500
82)#enddef
83
84
85# The formula to set the widthe of the real image width depending on the
86# image real size
87#define __GUI_IMAGE_DISPLAYED_WIDTH
88(
89	if((image_original_width < 300) and (image_original_height < 300),
90		image_original_width,
91		((image_original_width * calculated_width) / 500)
92	)
93where calculated_width = {__GUI_IMAGE_WIDTH}
94)#enddef
95
96# The formula to set the heighte of the real image height depending on the
97# image real size
98#define __GUI_IMAGE_DISPLAYED_HEIGHT
99(
100	if((image_original_width < 300) and (image_original_height < 300),
101		image_original_height,
102		((image_original_height * calculated_width) / 500)
103	)
104where calculated_width = {__GUI_IMAGE_WIDTH}
105)#enddef
106
107# The X location of the image to display, only tested on the left side.
108#define __GUI_IMAGE_DISPLAYED_X
109(
110	if(image_original_width > 100,
111		0,
112		(calculated_width - image_width) / 2
113	)
114where calculated_width = {__GUI_IMAGE_WIDTH}
115)#enddef
116
117# The Y location of the image to display, only tested on the left side.
118# Note since we don't know the exact height of the text we can't centre
119# the image. Instead we use the centre of the reserved image space.
120#
121# TODO the Y can't be determined properly since we don't know the height
122# of the panel. Disabled the centring for now.
123#
124#define __GUI_IMAGE_DISPLAYED_Y
125(
126	if(image_original_height > 0,
127		(height - image_height),
128		height - ((calculated_width - image_height) / 2)
129	)
130where calculated_width = {__GUI_IMAGE_WIDTH}
131)#enddef
132
133[window_definition]
134	id = "wml_message_left"
135	description = "bar"
136
137	[resolution]
138
139		[background]
140
141			[draw]
142
143			[/draw]
144
145		[/background]
146
147		[foreground]
148
149			[draw]
150
151				[image]
152					x = "{__GUI_IMAGE_DISPLAYED_X}"
153					y = "{__GUI_IMAGE_DISPLAYED_Y}"
154					w = "{__GUI_IMAGE_DISPLAYED_WIDTH}"
155					h = "{__GUI_IMAGE_DISPLAYED_HEIGHT}"
156					name = "(portrait_image)"
157					vertical_mirror = "(portrait_mirror)"
158				[/image]
159
160			[/draw]
161
162		[/foreground]
163
164	[/resolution]
165
166[/window_definition]
167
168[window_definition]
169	id = "wml_message_right"
170	description = "bar"
171
172	[resolution]
173
174		[background]
175
176			[draw]
177
178			[/draw]
179
180		[/background]
181
182		[foreground]
183
184			[draw]
185
186				[image]
187					x = "(width - {__GUI_IMAGE_DISPLAYED_WIDTH})"
188					y = "(height - image_height)"
189					w = "{__GUI_IMAGE_DISPLAYED_WIDTH}"
190					h = "{__GUI_IMAGE_DISPLAYED_HEIGHT}"
191					name = "(portrait_image)"
192					vertical_mirror = "(portrait_mirror)"
193				[/image]
194
195			[/draw]
196
197		[/foreground]
198
199	[/resolution]
200
201[/window_definition]
202
203[window_definition]
204	id = "wml_message_double"
205	description = "bar"
206
207	[resolution]
208
209		[background]
210
211			[draw]
212
213			[/draw]
214
215		[/background]
216
217		[foreground]
218
219			[draw]
220
221				[image]
222					x = "{__GUI_IMAGE_DISPLAYED_X}"
223					y = "{__GUI_IMAGE_DISPLAYED_Y}"
224					w = "{__GUI_IMAGE_DISPLAYED_WIDTH}"
225					h = "{__GUI_IMAGE_DISPLAYED_HEIGHT}"
226					name = "(portrait_image)"
227					vertical_mirror = "(portrait_mirror)"
228				[/image]
229
230				[image]
231					x = "(width - {__GUI_IMAGE_DISPLAYED_WIDTH})"
232					y = "(height - image_height)"
233					w = "{__GUI_IMAGE_DISPLAYED_WIDTH}"
234					h = "{__GUI_IMAGE_DISPLAYED_HEIGHT}"
235					name = "(second_portrait_image)"
236					vertical_mirror = "(second_portrait_mirror)"
237				[/image]
238
239			[/draw]
240
241		[/foreground]
242
243	[/resolution]
244
245[/window_definition]
246
247#define _GUI_INPUT_LIST
248[listbox]
249	id = "input_list"
250	definition = "wml_message"
251	[list_definition]
252
253		[row]
254
255			 [column]
256				grow_factor = 1
257				horizontal_grow = true
258
259				[toggle_panel]
260					definition = "wml_message"
261
262					return_value_id = "ok"
263					[grid]
264
265						[row]
266
267							[column]
268								grow_factor = 0
269								horizontal_alignment = "left"
270
271								border = "all"
272								border_size = 5
273
274								[image]
275									id = "icon"
276									definition = "default"
277									linked_group = "icon"
278								[/image]
279
280							[/column]
281
282							[column]
283								grow_factor = 0
284								horizontal_alignment = "left"
285
286								border = "all"
287								border_size = 5
288
289								[label]
290									id = "label"
291									definition = "default"
292									linked_group = "label"
293								[/label]
294
295							[/column]
296
297							[column]
298								grow_factor = 1
299								horizontal_grow = true
300
301								border = "all"
302								border_size = 5
303
304								[label]
305									id = "description"
306									definition = "default"
307									linked_group = "description"
308								[/label]
309
310							[/column]
311
312						[/row]
313
314					[/grid]
315
316				[/toggle_panel]
317
318			[/column]
319
320		[/row]
321
322	[/list_definition]
323
324[/listbox]
325#enddef
326
327#define _GUI_WML_MESSAGE_CONTENT
328[column]
329	grow_factor = 1
330	horizontal_grow = true
331	vertical_grow = true
332
333	[grid]
334
335		[row]
336			grow_factor = 0
337
338			[column]
339				border = "all"
340				border_size = 5
341				horizontal_alignment = "left"
342
343				[label]
344					id = "title"
345					definition = "title"
346				[/label]
347
348			[/column]
349
350		[/row]
351
352		[row]
353			grow_factor = 1
354
355			[column]
356				grow_factor = 1
357				horizontal_grow = true
358
359				border = "all"
360				border_size = 5
361
362				[scroll_label]
363					id = "message"
364					definition = "wml_message"
365				[/scroll_label]
366
367			[/column]
368
369		[/row]
370
371		[row]
372			grow_factor = 0
373
374			[column]
375				grow_factor = 1
376				horizontal_grow = true
377
378				[grid]
379
380					[row]
381
382						[column]
383							border = "all"
384							border_size = 5
385
386							[label]
387								id = "input_caption"
388								definition = "default"
389							[/label]
390
391						[/column]
392
393						[column]
394							grow_factor = 1
395							horizontal_grow = true
396
397							border = "all"
398							border_size = 5
399
400							[text_box]
401								id = "input"
402								definition = "transparent"
403							[/text_box]
404
405						[/column]
406
407					[/row]
408
409				[/grid]
410
411			[/column]
412
413		[/row]
414
415		[row]
416			grow_factor = 0
417
418			[column]
419				border = "all"
420				border_size = 5
421				horizontal_grow = true
422
423				{_GUI_INPUT_LIST}
424
425			[/column]
426
427		[/row]
428
429		[row]
430			grow_factor = 0
431
432			[column]
433				border = "all"
434				border_size = 5
435				horizontal_alignment = "center"
436
437				[button]
438					# This button will be shown or hidden depending on the
439					# whether or not a scrollbar is needed to show the
440					# text.
441					id = "ok"
442					definition = "transparent"
443
444					label = _ "OK"
445				[/button]
446
447			[/column]
448
449		[/row]
450
451	[/grid]
452
453[/column]
454#enddef
455
456[window]
457	id = "wml_message_left"
458	description = "Dialog showing a unit portrait on the left side"
459
460	[resolution]
461		window_width = 0
462		window_height = 0
463
464		definition = "wml_message_left"
465
466		automatic_placement = false
467
468		x = "(gamemap_x_offset)"
469		y = 30
470		width = "(gamemap_width)"
471		height = "(screen_height - 30)"
472
473		click_dismiss = true
474
475		[linked_group]
476			id = "icon"
477			fixed_width = true
478		[/linked_group]
479
480		[linked_group]
481			id = "label"
482			fixed_width = true
483		[/linked_group]
484
485		[linked_group]
486			id = "description"
487			fixed_width = true
488		[/linked_group]
489
490		[tooltip]
491			id = "tooltip"
492		[/tooltip]
493
494		[helptip]
495			id = "tooltip"
496		[/helptip]
497
498		[grid]
499
500			[row]
501
502				[column]
503					vertical_alignment = "bottom"
504					horizontal_grow = true
505
506					[panel]
507						definition = "wml_message"
508
509						[grid]
510
511							[row]
512
513								[column]
514									horizontal_grow = true
515
516									[grid]
517
518										[row]
519
520											[column]
521
522												[spacer]
523													# reserve place for the image and set a minimum height for the text
524													id = "image_place_holder"
525
526													width = {_GUI_IMAGE_WIDTH}
527													height = 75
528												[/spacer]
529
530											[/column]
531
532											{_GUI_WML_MESSAGE_CONTENT}
533
534											[column]
535
536												[spacer]
537													width = "(
538if(gamemap_width - ({__GUI_IMAGE_WIDTH}) > {MAX_TEXT_WIDTH}
539, gamemap_width - (({__GUI_IMAGE_WIDTH}) + {MAX_TEXT_WIDTH})
540, 0
541))"
542													height = 75
543												[/spacer]
544
545											[/column]
546
547										[/row]
548
549									[/grid]
550
551								[/column]
552
553							[/row]
554
555						[/grid]
556
557					[/panel]
558
559				[/column]
560
561			[/row]
562
563		[/grid]
564
565	[/resolution]
566
567[/window]
568
569[window]
570	id = "wml_message_right"
571	description = "Dialog showing a unit portrait on the right side"
572
573	[resolution]
574		window_width = 0
575		window_height = 0
576
577		definition = "wml_message_right"
578
579		automatic_placement = false
580
581		x = "(gamemap_x_offset)"
582		y = 30
583		width = "(gamemap_width)"
584		height = "(screen_height - 30)"
585
586		click_dismiss = true
587
588		[linked_group]
589			id = "icon"
590			fixed_width = true
591		[/linked_group]
592
593		[linked_group]
594			id = "label"
595			fixed_width = true
596		[/linked_group]
597
598		[linked_group]
599			id = "description"
600			fixed_width = true
601		[/linked_group]
602
603		[tooltip]
604			id = "tooltip"
605		[/tooltip]
606
607		[helptip]
608			id = "tooltip"
609		[/helptip]
610
611		[grid]
612
613			[row]
614
615				[column]
616					vertical_alignment = "bottom"
617					horizontal_grow = true
618
619					[panel]
620						definition = "wml_message"
621
622						[grid]
623
624							[row]
625
626								[column]
627									horizontal_grow = true
628
629									[grid]
630
631										[row]
632
633											[column]
634
635												[spacer]
636													width = "(
637if(gamemap_width - ({__GUI_IMAGE_WIDTH} + ({__GUI_IMAGE_WIDTH})) > {MAX_TEXT_WIDTH} , {__GUI_IMAGE_WIDTH} , 10)
638)"
639													height = 75
640												[/spacer]
641
642											[/column]
643
644											{_GUI_WML_MESSAGE_CONTENT}
645
646											[column]
647
648												[spacer]
649													width = "(
650if(gamemap_width - (left_padding + ({__GUI_IMAGE_WIDTH})) > {MAX_TEXT_WIDTH}
651, gamemap_width - (left_padding + ({__GUI_IMAGE_WIDTH}) + {MAX_TEXT_WIDTH})
652, 0
653)
654where left_padding = if(gamemap_width - ({__GUI_IMAGE_WIDTH} + ({__GUI_IMAGE_WIDTH})) > {MAX_TEXT_WIDTH} , {__GUI_IMAGE_WIDTH} , 10)
655)"
656													height = 75
657												[/spacer]
658
659											[/column]
660
661											[column]
662
663												[spacer]
664													# reserve place for the image and set a minimum height for the text
665													id = "image_place_holder"
666
667													width = {_GUI_IMAGE_WIDTH}
668													height = 75
669												[/spacer]
670
671											[/column]
672
673
674										[/row]
675
676									[/grid]
677
678								[/column]
679
680							[/row]
681
682						[/grid]
683
684					[/panel]
685
686				[/column]
687
688			[/row]
689
690		[/grid]
691
692	[/resolution]
693
694[/window]
695
696[window]
697	id = "wml_message_double"
698	description = "Dialog showing a unit portrait on each side"
699
700	[resolution]
701		window_width = 0
702		window_height = 0
703
704		definition = "wml_message_double"
705
706		automatic_placement = false
707
708		x = "(gamemap_x_offset)"
709		y = 30
710		width = "(gamemap_width)"
711		height = "(screen_height - 30)"
712
713		click_dismiss = true
714
715		[linked_group]
716			id = "icon"
717			fixed_width = true
718		[/linked_group]
719
720		[linked_group]
721			id = "label"
722			fixed_width = true
723		[/linked_group]
724
725		[linked_group]
726			id = "description"
727			fixed_width = true
728		[/linked_group]
729
730		[tooltip]
731			id = "tooltip"
732		[/tooltip]
733
734		[helptip]
735			id = "tooltip"
736		[/helptip]
737
738		[grid]
739
740			[row]
741
742				[column]
743					vertical_alignment = "bottom"
744					horizontal_grow = true
745
746					[panel]
747						definition = "wml_message"
748
749						[grid]
750
751							[row]
752
753								[column]
754									horizontal_grow = true
755
756									[grid]
757
758										[row]
759
760											[column]
761
762												[spacer]
763													# reserve place for the image and set a minimum height for the text
764													id = "image_place_holder"
765
766													width = {_GUI_IMAGE_WIDTH}
767													height = 75
768												[/spacer]
769
770											[/column]
771
772											{_GUI_WML_MESSAGE_CONTENT}
773
774											[column]
775
776												[spacer]
777													width = "(
778if(gamemap_width - ({__GUI_IMAGE_WIDTH} + ({__GUI_IMAGE_WIDTH})) > {MAX_TEXT_WIDTH}
779, gamemap_width - ({__GUI_IMAGE_WIDTH} + ({__GUI_IMAGE_WIDTH}) + {MAX_TEXT_WIDTH})
780, 0
781))"
782													height = 75
783												[/spacer]
784
785											[/column]
786
787											[column]
788
789												[spacer]
790													# reserve place for the image and set a minimum height for the text
791													id = "image_place_holder"
792
793													width = {_GUI_IMAGE_WIDTH}
794													height = 75
795												[/spacer]
796
797											[/column]
798
799
800										[/row]
801
802									[/grid]
803
804								[/column]
805
806							[/row]
807
808						[/grid]
809
810					[/panel]
811
812				[/column]
813
814			[/row]
815
816		[/grid]
817
818	[/resolution]
819
820[/window]
821
822#undef _GUI_INPUT_LIST
823
824#undef __GUI_IMAGE_DISPLAYED_Y
825#undef __GUI_IMAGE_DISPLAYED_X
826#undef __GUI_IMAGE_DISPLAYED_HEIGHT
827#undef __GUI_IMAGE_DISPLAYED_WIDTH
828#undef _GUI_IMAGE_SCALE_FACTOR
829#undef _GUI_IMAGE_WIDTH
830#undef __GUI_IMAGE_WIDTH
831#undef ___GUI_IMAGE_WIDTH
832#undef MAX_TEXT_WIDTH
833