Add Bar Fill Direction

This commit is contained in:
GreenComfyTea
2023-05-26 13:18:46 +03:00
parent e2354eedcc
commit 7ad40bbb89
10 changed files with 300 additions and 33 deletions

View File

@@ -128,7 +128,6 @@ small_monster.init_module();
ailment_hook.init_module();
ailment_buildup.init_module();
customization_menu.init_module();
label_customization.init_module();
bar_customization.init_module();
line_customization.init_module();
@@ -143,6 +142,7 @@ body_parts_customization.init_module();
ailments_customization.init_module();
ailment_buildups_customization.init_module();
module_visibility_customization.init_module();
customization_menu.init_module();
drawing.init_module();

View File

@@ -405,6 +405,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 0
@@ -597,6 +602,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 14
@@ -783,6 +793,11 @@ function this.init_default()
buildup_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -809,6 +824,11 @@ function this.init_default()
highlighted_buildup_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -962,6 +982,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 0
@@ -1104,6 +1129,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -1224,6 +1254,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -1385,6 +1420,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 6
@@ -1486,6 +1526,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 7
@@ -1586,6 +1631,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 7
@@ -1782,6 +1832,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 14
@@ -1965,6 +2020,11 @@ function this.init_default()
buildup_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -1991,6 +2051,11 @@ function this.init_default()
highlighted_buildup_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -2148,6 +2213,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 0
@@ -2289,6 +2359,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 0
@@ -2409,6 +2484,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 0
@@ -2570,6 +2650,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 6
@@ -2671,6 +2756,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 7
@@ -2771,6 +2861,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 7
@@ -2968,6 +3063,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 14
@@ -3151,6 +3251,11 @@ function this.init_default()
buildup_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -3177,6 +3282,11 @@ function this.init_default()
highlighted_buildup_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -3320,6 +3430,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 0
@@ -3461,6 +3576,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 10 - 10,
y = 17
@@ -3581,6 +3701,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -3742,6 +3867,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 6
@@ -3843,6 +3973,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 7
@@ -3943,6 +4078,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 7
@@ -3967,7 +4107,6 @@ function this.init_default()
}
}
}
},
ailments = {
@@ -4139,6 +4278,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 14
@@ -4322,6 +4466,11 @@ function this.init_default()
buildup_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -4348,6 +4497,11 @@ function this.init_default()
highlighted_buildup_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -4607,6 +4761,11 @@ function this.init_default()
damage_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -4767,6 +4926,11 @@ function this.init_default()
damage_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -4879,6 +5043,11 @@ function this.init_default()
damage_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -5012,6 +5181,11 @@ function this.init_default()
damage_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -5145,6 +5319,11 @@ function this.init_default()
damage_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -5278,6 +5457,11 @@ function this.init_default()
damage_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -5505,6 +5689,11 @@ function this.init_default()
damage_bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17
@@ -5639,6 +5828,11 @@ function this.init_default()
bar = {
visibility = true,
settings = {
fill_direction = "Left to Right"
},
offset = {
x = 0,
y = 17

View File

@@ -541,7 +541,13 @@ this.default_language = {
filter_mode = "Filter Mode",
current_state = "Current State",
default_state = "Default State"
default_state = "Default State",
fill_direction = "Fill Direction",
left_to_right = "Left to Right",
right_to_left = "Right to Left",
top_to_bottom = "Top to Bottom",
bottom_to_top = "Bottom to Top",
}
};

View File

@@ -167,7 +167,6 @@ function this.draw_label(label, position, opacity_scale, ...)
end
function this.draw_bar(bar, position, opacity_scale, percentage)
if bar == nil or not bar.visibility then
return;
end
@@ -182,6 +181,7 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
local outline_visibility = bar.outline.visibility;
local style = bar.outline.style; -- Inside/Center/Outside
local fill_direction = bar.settings.fill_direction; -- Left to Right/Right to Left/Top to Bottom/Bottom to Top
local outline_thickness = bar.outline.thickness;
if not outline_visibility then
@@ -206,10 +206,21 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
local position_x = 0;
local position_y = 0;
local foreground_width = 0;
local background_width = 0;
local width = 0;
local height = 0;
local foreground_width = 0;
local foreground_height = 0;
local background_width = 0;
local background_height = 0;
local foreground_shift_x = 0;
local foreground_shift_y = 0;
local background_shift_x = 0;
local background_shift_y = 0;
if style == "Inside" then
outline_position_x = position.x + bar.offset.x + half_outline_thickness;
outline_position_y = position.y + bar.offset.y + half_outline_thickness;
@@ -220,10 +231,7 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
position_x = outline_position_x + half_outline_thickness + outline_offset;
position_y = outline_position_y + half_outline_thickness + outline_offset;
local width = outline_width - outline_thickness - outline_offset - outline_offset;
foreground_width = width * percentage;
background_width = width - foreground_width;
width = outline_width - outline_thickness - outline_offset - outline_offset;
height = outline_height - outline_thickness - outline_offset - outline_offset;
elseif style == "Center" then
@@ -236,22 +244,16 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
position_x = outline_position_x + half_outline_thickness + outline_offset;
position_y = outline_position_y + half_outline_thickness + outline_offset;
local width = outline_width - outline_thickness - outline_offset - outline_offset;
foreground_width = width * percentage;
background_width = width - foreground_width;
width = outline_width - outline_thickness - outline_offset - outline_offset;
height = outline_height - outline_thickness - outline_offset - outline_offset;
else
else -- Outside
position_x = position.x + bar.offset.x;
position_y = position.y + bar.offset.y;
local width = bar.size.width;
width = bar.size.width;
height = bar.size.height;
foreground_width = width * percentage;
background_width = width - foreground_width;
outline_position_x = position_x - half_outline_thickness - outline_offset;
outline_position_y = position_y - half_outline_thickness - outline_offset;
@@ -259,6 +261,43 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
outline_height = height + outline_thickness + outline_offset + outline_offset;
end
if fill_direction == "Right to Left" then
foreground_width = width * percentage;
foreground_height = height;
background_width = width - foreground_width;
background_height = height;
foreground_shift_x = background_width;
elseif fill_direction == "Top to Bottom" then
foreground_width = width;
foreground_height = height * percentage;
background_width = width;
background_height = height - foreground_height;
background_shift_y = foreground_height;
elseif fill_direction == "Bottom to Top" then
foreground_width = width;
foreground_height = height * percentage;
background_width = width;
background_height = height - foreground_height;
foreground_shift_y = background_height;
else -- Left to Right
foreground_width = width * percentage;
foreground_height = height;
background_width = width - foreground_width;
background_height = height;
background_shift_x = foreground_width;
end
local foreground_color = bar.colors.foreground;
local background_color = bar.colors.background;
local outline_color = bar.colors.outline;
@@ -271,35 +310,33 @@ function this.draw_bar(bar, position, opacity_scale, percentage)
local use_d2d = d2d ~= nil and config.current_config.global_settings.renderer.use_d2d_if_available;
-- outline
if outline_thickness ~= 0 then
-- background
if background_width ~= 0 then
if use_d2d then
d2d.outline_rect(outline_position_x, outline_position_y, outline_width, outline_height, outline_thickness,
outline_color);
d2d.fill_rect(position_x + background_shift_x, position_y + background_shift_y, background_width, background_height, background_color);
else
outline_color = this.argb_color_to_abgr_color(outline_color);
draw.outline_rect(outline_position_x, outline_position_y, outline_width, outline_height, outline_color);
background_color = this.argb_color_to_abgr_color(background_color);
draw.filled_rect(position_x + background_shift_x, position_y + background_shift_y, background_width, background_height, background_color)
end
end
-- foreground
if foreground_width ~= 0 then
if use_d2d then
d2d.fill_rect(position_x, position_y, foreground_width, height, foreground_color);
d2d.fill_rect(position_x + foreground_shift_x, position_y + foreground_shift_y, foreground_width, foreground_height, foreground_color);
else
foreground_color = this.argb_color_to_abgr_color(foreground_color);
draw.filled_rect(position_x, position_y, foreground_width, height, foreground_color)
draw.filled_rect(position_x + foreground_shift_x, position_y + foreground_shift_y, foreground_width, foreground_height, foreground_color)
end
end
-- background
if background_width ~= 0 then
-- outline
if outline_thickness ~= 0 then
if use_d2d then
d2d.fill_rect(position_x + foreground_width, position_y, background_width, height, background_color);
d2d.outline_rect(outline_position_x, outline_position_y, outline_width, outline_height, outline_thickness, outline_color);
else
background_color = this.argb_color_to_abgr_color(background_color);
draw.filled_rect(position_x + foreground_width, position_y, background_width, height, background_color)
outline_color = this.argb_color_to_abgr_color(outline_color);
draw.outline_rect(outline_position_x, outline_position_y, outline_width, outline_height, outline_color);
end
end
end