Add Stats UI

This commit is contained in:
GreenComfyTea
2023-08-15 16:02:01 +03:00
parent 9d16048c8d
commit 758a02bce8
13 changed files with 1272 additions and 14 deletions

View File

@@ -97,6 +97,10 @@ function this.draw(cached_config)
language.current_language.customization_menu.buff_UI,
cached_config.buff_UI);
changed, cached_config.stats_UI = imgui.checkbox(
language.current_language.customization_menu.stats_UI,
cached_config.stats_UI);
config_changed = config_changed or changed;
return config_changed;

View File

@@ -0,0 +1,266 @@
local this = {};
local buff_UI_entity;
local config;
local buffs;
local consumables;
local melody_effects;
local endemic_life_buff;
local screen;
local utils;
local error_handler;
local skills;
local dangos;
local abnormal_statuses;
local drawing;
local player_info;
local language;
local sdk = sdk;
local tostring = tostring;
local pairs = pairs;
local ipairs = ipairs;
local tonumber = tonumber;
local require = require;
local pcall = pcall;
local table = table;
local string = string;
local Vector3f = Vector3f;
local d2d = d2d;
local math = math;
local json = json;
local log = log;
local fs = fs;
local next = next;
local type = type;
local setmetatable = setmetatable;
local getmetatable = getmetatable;
local assert = assert;
local select = select;
local coroutine = coroutine;
local utf8 = utf8;
local re = re;
local imgui = imgui;
local draw = draw;
local Vector2f = Vector2f;
local reframework = reframework;
local os = os;
local ValueType = ValueType;
local package = package;
this.label_list = {
attack = nil,
defense = nil,
fire_resistance = nil,
water_resistance = nil,
thunder_resistance = nil,
ice_resistance = nil,
dragon_resistance = nil
};
this.affinity_label = nil;
this.stamina_label = nil;
this.element_label = nil;
this.element_2_label = nil;
function this.draw()
local cached_config = config.current_config.stats_UI;
if not cached_config.enabled then
return;
end
local cached_names = language.current_language.stats;
local global_scale_modifier = config.current_config.global_settings.modifiers.global_scale_modifier;
local position_on_screen = screen.calculate_absolute_coordinates(cached_config.position);
-- draw
for label_key, label in pairs(this.label_list) do
local name_text = "";
if label.include.name then
name_text = string.format("%s: ", cached_names[label_key]);
end
if label.include.value then
name_text = string.format("%s%s", name_text, tostring(player_info.list[label_key]));
end
drawing.draw_label(label, position_on_screen, 1, name_text);
::continue::
end
-- Affinity Label
local affinity_name_text = "";
if this.affinity_label.include.name then
affinity_name_text = string.format("%s: ", cached_names.affinity);
end
if this.affinity_label.include.value then
affinity_name_text = string.format("%s%s%%", affinity_name_text, tostring(player_info.list.affinity));
end
drawing.draw_label(this.affinity_label, position_on_screen, 1, affinity_name_text);
-- Stamina Label
local stamina_name_text = "";
if this.stamina_label.include.name then
stamina_name_text = string.format("%s: ", cached_names.stamina);
end
if this.stamina_label.include.value and not this.stamina_label.include.max_value then
stamina_name_text = string.format("%s%s", stamina_name_text, tostring(player_info.list.stamina));
elseif not this.stamina_label.include.value and this.stamina_label.include.max_value then
stamina_name_text = string.format("%s%s", stamina_name_text, tostring(player_info.list.max_stamina));
elseif this.stamina_label.include.value and this.stamina_label.include.max_value then
stamina_name_text = string.format("%s%s/%s", stamina_name_text, tostring(player_info.list.stamina), tostring(player_info.list.max_stamina));
end
drawing.draw_label(this.stamina_label, position_on_screen, 1, stamina_name_text);
-- Element Label
if player_info.list.element_type ~= 0 then
local element_name_text = "";
if this.element_label.include.name then
local ailment_names = language.current_language.ailments;
if player_info.list.element_type == 1 then
element_name_text = string.format("%s: ", cached_names.fire);
elseif player_info.list.element_type == 2 then
element_name_text = string.format("%s: ", cached_names.water);
elseif player_info.list.element_type == 3 then
element_name_text = string.format("%s: ", cached_names.thunder);
elseif player_info.list.element_type == 4 then
element_name_text = string.format("%s: ", cached_names.ice);
elseif player_info.list.element_type == 5 then
element_name_text = string.format("%s: ", cached_names.dragon);
elseif player_info.list.element_type == 6 then
element_name_text = string.format("%s: ", ailment_names.poison);
elseif player_info.list.element_type == 7 then
element_name_text = string.format("%s: ", ailment_names.sleep);
elseif player_info.list.element_type == 8 then
element_name_text = string.format("%s: ", ailment_names.paralysis);
elseif player_info.list.element_type == 9 then
element_name_text = string.format("%s: ", ailment_names.blast);
end
end
if this.element_label.include.value then
element_name_text = string.format("%s%s", element_name_text, tostring(player_info.list.element_attack));
end
drawing.draw_label(this.element_label, position_on_screen, 1, element_name_text);
end
-- Element 2 Label
if player_info.list.element_type_2 ~= 0 then
local element_2_name_text = "";
if this.element_2_label.include.name then
local ailment_names = language.current_language.ailments;
if player_info.list.element_type_2 == 1 then
element_2_name_text = string.format("%s: ", cached_names.fire);
elseif player_info.list.element_type_2 == 2 then
element_2_name_text = string.format("%s: ", cached_names.water);
elseif player_info.list.element_type_2 == 3 then
element_2_name_text = string.format("%s: ", cached_names.thunder);
elseif player_info.list.element_type_2 == 4 then
element_2_name_text = string.format("%s: ", cached_names.ice);
elseif player_info.list.element_type_2 == 5 then
element_2_name_text = string.format("%s: ", cached_names.dragon);
elseif player_info.list.element_type_2 == 6 then
element_2_name_text = string.format("%s: ", ailment_names.poison);
elseif player_info.list.element_type_2 == 7 then
element_2_name_text = string.format("%s: ", ailment_names.sleep);
elseif player_info.list.element_type_2 == 8 then
element_2_name_text = string.format("%s: ", ailment_names.paralysis);
elseif player_info.list.element_type_2 == 9 then
element_2_name_text = string.format("%s: ", ailment_names.blast);
end
end
if this.element_2_label.include.value then
element_2_name_text = string.format("%s%s", element_2_name_text, tostring(player_info.list.element_attack_2));
end
drawing.draw_label(this.element_2_label, position_on_screen, 1, element_2_name_text);
end
end
function this.init_UI()
this.label_list.attack = utils.table.deep_copy(config.current_config.stats_UI.attack_label);
this.label_list.defense = utils.table.deep_copy(config.current_config.stats_UI.defense_label);
this.label_list.fire_resistance = utils.table.deep_copy(config.current_config.stats_UI.fire_resistance_label);
this.label_list.water_resistance = utils.table.deep_copy(config.current_config.stats_UI.water_resistance_label);
this.label_list.thunder_resistance = utils.table.deep_copy(config.current_config.stats_UI.thunder_resistance_label);
this.label_list.ice_resistance = utils.table.deep_copy(config.current_config.stats_UI.ice_resistance_label);
this.label_list.dragon_resistance = utils.table.deep_copy(config.current_config.stats_UI.dragon_resistance_label);
this.affinity_label = utils.table.deep_copy(config.current_config.stats_UI.affinity_label);
this.stamina_label = utils.table.deep_copy(config.current_config.stats_UI.stamina_label);
this.element_label = utils.table.deep_copy(config.current_config.stats_UI.element_label);
this.element_2_label = utils.table.deep_copy(config.current_config.stats_UI.element_2_label);
local global_scale_modifier = config.current_config.global_settings.modifiers.global_scale_modifier;
for label_key, label in pairs(this.label_list) do
label.offset.x = label.offset.x * global_scale_modifier;
label.offset.y = label.offset.y * global_scale_modifier;
end
this.affinity_label.offset.x = this.affinity_label.offset.x * global_scale_modifier;
this.affinity_label.offset.y = this.affinity_label.offset.y * global_scale_modifier;
this.stamina_label.offset.x = this.stamina_label.offset.x * global_scale_modifier;
this.stamina_label.offset.y = this.stamina_label.offset.y * global_scale_modifier;
this.element_label.offset.x = this.element_label.offset.x * global_scale_modifier;
this.element_label.offset.y = this.element_label.offset.y * global_scale_modifier;
this.element_2_label.offset.x = this.element_2_label.offset.x * global_scale_modifier;
this.element_2_label.offset.y = this.element_2_label.offset.y * global_scale_modifier;
end
function this.init_dependencies()
config = require("MHR_Overlay.Misc.config");
buff_UI_entity = require("MHR_Overlay.UI.UI_Entities.buff_UI_entity");
consumables = require("MHR_Overlay.Buffs.consumables");
melody_effects = require("MHR_Overlay.Buffs.melody_effects");
buffs = require("MHR_Overlay.Buffs.buffs");
--singletons = require("MHR_Overlay.Game_Handler.singletons");
config = require("MHR_Overlay.Misc.config");
--customization_menu = require("MHR_Overlay.UI.customization_menu");
--players = require("MHR_Overlay.Damage_Meter.players");
--non_players = require("MHR_Overlay.Damage_Meter.non_players");
--quest_status = require("MHR_Overlay.Game_Handler.quest_status");
screen = require("MHR_Overlay.Game_Handler.screen");
--drawing = require("MHR_Overlay.UI.drawing");
utils = require("MHR_Overlay.Misc.utils");
error_handler = require("MHR_Overlay.Misc.error_handler");
endemic_life_buff = require("MHR_Overlay.Buffs.endemic_life_buffs");
skills = require("MHR_Overlay.Buffs.skills");
dangos = require("MHR_Overlay.Buffs.dangos");
abnormal_statuses = require("MHR_Overlay.Buffs.abnormal_statuses");
drawing = require("MHR_Overlay.UI.drawing");
player_info = require("MHR_Overlay.Misc.player_info");
language = require("MHR_Overlay.Misc.language");
end
function this.init_module()
this.init_UI();
end
return this;

View File

@@ -16,6 +16,7 @@ local quest_status;
local buffs;
local error_handler;
local time;
local stats_UI;
local label_customization;
local bar_customization;
@@ -365,6 +366,7 @@ function this.draw()
local damage_meter_UI_changed = false;
local endemic_life_UI_changed = false;
local buff_UI_changed = false;
local stats_UI_changed = false;
local debug_changed = false;
local apply_font_requested = false;
@@ -404,6 +406,7 @@ function this.draw()
damage_meter_UI_changed = this.draw_damage_meter_UI();
endemic_life_UI_changed = this.draw_endemic_life_UI()
buff_UI_changed = this.draw_buff_UI();
stats_UI_changed = this.draw_stats_UI()
imgui.new_line();
debug_changed = this.draw_debug();
@@ -471,6 +474,11 @@ function this.draw()
end
end
if stats_UI_changed or modifiers_changed or config_changed then
stats_UI.init_UI();
end
if this.menu_font_changed and (apply_font_requested or config_changed) then
this.menu_font_changed = false;
this.reload_font();
@@ -478,7 +486,7 @@ function this.draw()
if window_changed or modules_changed or global_settings_changed or small_monster_UI_changed or large_monster_dynamic_UI_changed or
large_monster_static_UI_changed or large_monster_highlighted_UI_changed or time_UI_changed or damage_meter_UI_changed or
endemic_life_UI_changed or buff_UI_changed or modifiers_changed or config_changed or debug_changed then
endemic_life_UI_changed or buff_UI_changed or stats_UI_changed or modifiers_changed or config_changed or debug_changed then
config.save_current();
end
@@ -1002,6 +1010,17 @@ function this.draw_global_settings(apply_font_requested, language_changed)
if imgui.tree_node(language.current_language.customization_menu.module_visibility_based_on_game_state) then
if imgui.tree_node(language.current_language.customization_menu.in_lobby) then
changed, cached_config.module_visibility.in_lobby.stats_UI = imgui.checkbox(
language.current_language.customization_menu.stats_UI,
cached_config.module_visibility.in_lobby.stats_UI);
config_changed = config_changed or changed;
imgui.tree_pop();
end
if imgui.tree_node(language.current_language.customization_menu.in_training_area) then
changed, cached_config.module_visibility.in_training_area.large_monster_dynamic_UI = imgui.checkbox(
@@ -1040,6 +1059,12 @@ function this.draw_global_settings(apply_font_requested, language_changed)
config_changed = config_changed or changed;
changed, cached_config.module_visibility.in_training_area.stats_UI = imgui.checkbox(
language.current_language.customization_menu.stats_UI,
cached_config.module_visibility.in_training_area.stats_UI);
config_changed = config_changed or changed;
imgui.tree_pop();
end
@@ -2296,6 +2321,83 @@ function this.draw_buff_UI()
return config_changed;
end
function this.draw_stats_UI()
local changed = false;
local config_changed = false;
local index = 0;
if imgui.tree_node(language.current_language.customization_menu.stats_UI) then
local cached_config = config.current_config.stats_UI;
changed, cached_config.enabled = imgui.checkbox(
language.current_language.customization_menu.enabled, cached_config.enabled);
config_changed = config_changed or changed;
if imgui.tree_node(language.current_language.customization_menu.position) then
changed, cached_config.position.x = imgui.drag_float(
language.current_language.customization_menu.x, cached_config.position.x, 0.1, 0, screen.width, "%.1f");
config_changed = config_changed or changed;
changed, cached_config.position.y = imgui.drag_float(
language.current_language.customization_menu.y, cached_config.position.y, 0.1, 0, screen.height, "%.1f");
config_changed = config_changed or changed;
changed, index = imgui.combo(
language.current_language.customization_menu.anchor,
utils.table.find_index(this.anchor_types, cached_config.position.anchor),
this.displayed_anchor_types);
config_changed = config_changed or changed;
if changed then
cached_config.position.anchor = this.anchor_types[index];
end
imgui.tree_pop();
end
changed = label_customization.draw(language.current_language.customization_menu.attack_label, cached_config.attack_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.affinity_label, cached_config.affinity_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.defense_label, cached_config.defense_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.fire_resistance_label, cached_config.fire_resistance_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.water_resistance_label, cached_config.water_resistance_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.thunder_resistance_label, cached_config.thunder_resistance_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.ice_resistance_label, cached_config.ice_resistance_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.dragon_resistance_label, cached_config.dragon_resistance_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.stamina_label, cached_config.stamina_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.element_label, cached_config.element_label);
config_changed = config_changed or changed;
changed = label_customization.draw(language.current_language.customization_menu.element_2_label, cached_config.element_2_label);
config_changed = config_changed or changed;
imgui.tree_pop();
end
return config_changed;
end
function this.draw_debug()
local cached_config = config.current_config.debug;
@@ -2369,6 +2471,7 @@ function this.init_dependencies()
buffs = require("MHR_Overlay.Buffs.buffs");
error_handler = require("MHR_Overlay.Misc.error_handler");
time = require("MHR_Overlay.Game_Handler.time");
stats_UI = require("MHR_Overlay.UI.Modules.stats_UI");
label_customization = require("MHR_Overlay.UI.Customizations.label_customization");
bar_customization = require("MHR_Overlay.UI.Customizations.bar_customization");