GUI: Simplify WML message dialog formulas
Now with 99% less WML macros inserted into the formula. This makes it easier to read and possibly even more efficient.
This commit is contained in:
parent
3133ba325f
commit
268620e2ca
1 changed files with 43 additions and 71 deletions
|
@ -5,66 +5,40 @@
|
|||
### window definitions. So this unit is a bit larger as wanted.
|
||||
###
|
||||
|
||||
# These might become global have to evaluate later.
|
||||
#define _GUI_HEIGHT_OFFSET
|
||||
25#enddef
|
||||
|
||||
# helper convert the scale factor, since we use it in two places define it as
|
||||
# helper value. (Two the not working and working version, but want to avoid
|
||||
# surprises when the not working version is fixed).
|
||||
#define __GUI_SIZE_FACTOR
|
||||
3#enddef
|
||||
|
||||
### The formula language doesn't support variables so macros are used to
|
||||
### emulate them. This makes the code what harder to read, so the algorithm for
|
||||
### __GUI_IMAGE_WIDTH is described here:
|
||||
###
|
||||
### if gamemap_width <= TEXT_WIDTH_SATURATION
|
||||
### __GUI_IMAGE_WIDTH = gamemap_width / 3
|
||||
### else
|
||||
### # Text reached it maximum width, take all space.
|
||||
### __GUI_IMAGE_WIDTH = gamemap_width - MAX_TEXT_WIDTH
|
||||
### fi
|
||||
###
|
||||
### if __GUI_IMAGE_WIDTH < 250
|
||||
### __GUI_IMAGE_WIDTH = 250
|
||||
### fi
|
||||
###
|
||||
### if __GUI_IMAGE_WIDTH > 500
|
||||
### __GUI_IMAGE_WIDTH = 500
|
||||
### fi
|
||||
|
||||
#define __GUI_MAX_HEIGHT
|
||||
(gamemap_height - 4)
|
||||
#enddef
|
||||
|
||||
# The maximum width of the text
|
||||
#define MAX_TEXT_WIDTH
|
||||
675
|
||||
#enddef
|
||||
|
||||
# gamemap_width width needed to reach the MAX_TEXT_WIDTH
|
||||
#define TEXT_WIDTH_SATURATION
|
||||
((3 * {_GUI_HEIGHT_OFFSET}) / 2)
|
||||
#enddef
|
||||
|
||||
#define BEST_WIDTH
|
||||
(if(gamemap_width > {TEXT_WIDTH_SATURATION}, gamemap_width - {MAX_TEXT_WIDTH}, (gamemap_width / {__GUI_SIZE_FACTOR})))
|
||||
#enddef
|
||||
|
||||
#define ASPECT_RATIO
|
||||
(if(image_original_width > 0, (as_decimal(image_original_height) / image_original_width), 0))
|
||||
#enddef
|
||||
|
||||
#define __GUI_BEST_SIZE
|
||||
(if(({BEST_WIDTH} * {ASPECT_RATIO}) > {__GUI_MAX_HEIGHT}, floor({__GUI_MAX_HEIGHT} / {ASPECT_RATIO}), {BEST_WIDTH}))
|
||||
#enddef
|
||||
|
||||
#define ___GUI_IMAGE_WIDTH
|
||||
if({__GUI_BEST_SIZE} < 250, 250,
|
||||
if({__GUI_BEST_SIZE} > 500, 500, {__GUI_BEST_SIZE})
|
||||
(
|
||||
max(250, min(500, best_size))
|
||||
where
|
||||
best_size = (
|
||||
if((best_width * aspect_ratio) > max_height,
|
||||
floor(max_height / aspect_ratio),
|
||||
best_width
|
||||
)
|
||||
where
|
||||
best_width = (
|
||||
if(gamemap_width > text_width_saturation,
|
||||
gamemap_width - {MAX_TEXT_WIDTH},
|
||||
gamemap_width / size_factor
|
||||
)
|
||||
where
|
||||
# gamemap_width width needed to reach the MAX_TEXT_WIDTH #
|
||||
text_width_saturation = 3 * height_offset / 2 where height_offset = 25,
|
||||
size_factor = 3
|
||||
),
|
||||
aspect_ratio = (
|
||||
if(image_original_width > 0,
|
||||
as_decimal(image_original_height) / image_original_width,
|
||||
0
|
||||
)
|
||||
),
|
||||
max_height = (gamemap_height - 4)
|
||||
)
|
||||
#enddef
|
||||
)#enddef
|
||||
|
||||
# This is the version with debug info
|
||||
#define __GUI_IMAGE_WIDTH
|
||||
|
@ -75,10 +49,6 @@
|
|||
debug_print('gamemap_height ', gamemap_height),
|
||||
debug_print('image_original_width ', image_original_width),
|
||||
debug_print('image_original_height ', image_original_height),
|
||||
debug_print('ASPECT_RATIO ', {ASPECT_RATIO}),
|
||||
debug_print('__GUI_MAX_HEIGHT ', {__GUI_MAX_HEIGHT}),
|
||||
debug_print('BEST_WIDTH ', {BEST_WIDTH}),
|
||||
debug_print('__GUI_BEST_SIZE ', {__GUI_BEST_SIZE})
|
||||
],
|
||||
{___GUI_IMAGE_WIDTH}
|
||||
][1]
|
||||
|
@ -110,7 +80,9 @@
|
|||
(
|
||||
if((image_original_width < 300) and (image_original_height < 300),
|
||||
image_original_width,
|
||||
((image_original_width * {__GUI_IMAGE_WIDTH}) / 500))
|
||||
((image_original_width * calculated_width) / 500)
|
||||
)
|
||||
where calculated_width = {__GUI_IMAGE_WIDTH}
|
||||
)#enddef
|
||||
|
||||
# The formula to set the heighte of the real image height depending on the
|
||||
|
@ -119,16 +91,19 @@
|
|||
(
|
||||
if((image_original_width < 300) and (image_original_height < 300),
|
||||
image_original_height,
|
||||
((image_original_height * {__GUI_IMAGE_WIDTH}) / 500))
|
||||
((image_original_height * calculated_width) / 500)
|
||||
)
|
||||
where calculated_width = {__GUI_IMAGE_WIDTH}
|
||||
)#enddef
|
||||
|
||||
# The X location of the image to display, only tested on the left side.
|
||||
#define __GUI_IMAGE_DISPLAYED_X X
|
||||
#define __GUI_IMAGE_DISPLAYED_X
|
||||
(
|
||||
if(image_original_width > 100,
|
||||
{X},
|
||||
({__GUI_IMAGE_WIDTH} - image_width) / 2)
|
||||
|
||||
0,
|
||||
(calculated_width - image_width) / 2
|
||||
)
|
||||
where calculated_width = {__GUI_IMAGE_WIDTH}
|
||||
)#enddef
|
||||
|
||||
# The Y location of the image to display, only tested on the left side.
|
||||
|
@ -142,8 +117,9 @@
|
|||
(
|
||||
if(image_original_height > 0,
|
||||
(height - image_height),
|
||||
height - (({__GUI_IMAGE_WIDTH} - image_height) / 2))
|
||||
|
||||
height - ((calculated_width - image_height) / 2)
|
||||
)
|
||||
where calculated_width = {__GUI_IMAGE_WIDTH}
|
||||
)#enddef
|
||||
|
||||
[window_definition]
|
||||
|
@ -165,7 +141,7 @@
|
|||
[draw]
|
||||
|
||||
[image]
|
||||
x = "{__GUI_IMAGE_DISPLAYED_X X}"
|
||||
x = "{__GUI_IMAGE_DISPLAYED_X}"
|
||||
y = "{__GUI_IMAGE_DISPLAYED_Y}"
|
||||
w = "{__GUI_IMAGE_DISPLAYED_WIDTH}"
|
||||
h = "{__GUI_IMAGE_DISPLAYED_HEIGHT}"
|
||||
|
@ -780,8 +756,4 @@ if(gamemap_width - (10 + ({__GUI_IMAGE_WIDTH})) > {MAX_TEXT_WIDTH}
|
|||
#undef _GUI_IMAGE_WIDTH
|
||||
#undef __GUI_IMAGE_WIDTH
|
||||
#undef ___GUI_IMAGE_WIDTH
|
||||
#undef __GUI_BEST_SIZE
|
||||
#undef __GUI_MAX_HEIGHT
|
||||
#undef __GUI_SIZE_FACTOR
|
||||
#undef _GUI_HEIGHT_OFFSET
|
||||
|
||||
#undef MAX_TEXT_WIDTH
|
||||
|
|
Loading…
Add table
Reference in a new issue