mirror of
https://github.com/GreenComfyTea/MHR-Overlay.git
synced 2026-01-24 04:18:11 -08:00
Stats UI: Add Health and Max Health
This commit is contained in:
@@ -105,7 +105,6 @@ function this.init_global_timers()
|
||||
this.new_timer(players.update_myself_position, 1);
|
||||
this.new_timer(buffs.update, 1/60);
|
||||
this.new_timer(player_info.update, 0.5);
|
||||
|
||||
end
|
||||
|
||||
function this.update_timers()
|
||||
|
||||
@@ -7603,6 +7603,74 @@ function this.init_default()
|
||||
anchor = "Bottom-Right"
|
||||
},
|
||||
|
||||
health_label = {
|
||||
visibility = false,
|
||||
|
||||
settings = {
|
||||
right_alignment_shift = 16
|
||||
},
|
||||
|
||||
text_formatting = "%s",
|
||||
|
||||
include = {
|
||||
name = true,
|
||||
value = true,
|
||||
max_value = true
|
||||
},
|
||||
|
||||
offset = {
|
||||
x = -514,
|
||||
y = -35
|
||||
},
|
||||
|
||||
color = 0xFFFEFF88,
|
||||
|
||||
shadow = {
|
||||
visibility = true,
|
||||
|
||||
offset = {
|
||||
x = 1,
|
||||
y = 1
|
||||
},
|
||||
|
||||
color = 0xFF000000
|
||||
}
|
||||
},
|
||||
|
||||
stamina_label = {
|
||||
visibility = false,
|
||||
|
||||
settings = {
|
||||
right_alignment_shift = 16
|
||||
},
|
||||
|
||||
text_formatting = "%s",
|
||||
|
||||
include = {
|
||||
name = true,
|
||||
value = true,
|
||||
max_value = true
|
||||
},
|
||||
|
||||
offset = {
|
||||
x = -382,
|
||||
y = -35
|
||||
},
|
||||
|
||||
color = 0xFFFEFF88,
|
||||
|
||||
shadow = {
|
||||
visibility = true,
|
||||
|
||||
offset = {
|
||||
x = 1,
|
||||
y = 1
|
||||
},
|
||||
|
||||
color = 0xFF000000
|
||||
}
|
||||
},
|
||||
|
||||
attack_label = {
|
||||
visibility = true,
|
||||
|
||||
@@ -7867,40 +7935,6 @@ function this.init_default()
|
||||
}
|
||||
},
|
||||
|
||||
stamina_label = {
|
||||
visibility = false,
|
||||
|
||||
settings = {
|
||||
right_alignment_shift = 16
|
||||
},
|
||||
|
||||
text_formatting = "%s",
|
||||
|
||||
include = {
|
||||
name = true,
|
||||
value = true,
|
||||
max_value = true
|
||||
},
|
||||
|
||||
offset = {
|
||||
x = -382,
|
||||
y = -35
|
||||
},
|
||||
|
||||
color = 0xFFFEFF88,
|
||||
|
||||
shadow = {
|
||||
visibility = true,
|
||||
|
||||
offset = {
|
||||
x = 1,
|
||||
y = 1
|
||||
},
|
||||
|
||||
color = 0xFF000000
|
||||
}
|
||||
},
|
||||
|
||||
element_label = {
|
||||
visibility = false,
|
||||
|
||||
|
||||
@@ -677,6 +677,8 @@ this.default_language = {
|
||||
value = "Value",
|
||||
|
||||
stats_UI = "Stats UI",
|
||||
health_label = "Health Label",
|
||||
stamina_label = "Stamina Label",
|
||||
attack_label = "Attack Label",
|
||||
defense_label = "Defense Label",
|
||||
affinity_label = "Affinity Label",
|
||||
@@ -685,7 +687,6 @@ this.default_language = {
|
||||
thunder_resistance_label = "Thunder Resistance Label",
|
||||
ice_resistance_label = "Ice Resistance Label",
|
||||
dragon_resistance_label = "Dragon Resistance Label",
|
||||
stamina_label = "Stamina Label",
|
||||
element_label = "Element Label",
|
||||
element_2_label = "Element 2 Label"
|
||||
},
|
||||
|
||||
@@ -42,6 +42,9 @@ local ValueType = ValueType;
|
||||
local package = package;
|
||||
|
||||
this.list = {
|
||||
health = 0;
|
||||
max_health = 0;
|
||||
|
||||
attack = 0;
|
||||
defense = 0;
|
||||
affinity = 0;
|
||||
@@ -62,6 +65,8 @@ this.list = {
|
||||
dragon_resistance = 0;
|
||||
};
|
||||
|
||||
local should_health_update = true;
|
||||
|
||||
local player_manager_type_def = sdk.find_type_definition("snow.player.PlayerManager");
|
||||
local get_player_method = player_manager_type_def:get_method("getPlayer");
|
||||
local find_master_player_method = player_manager_type_def:get_method("findMasterPlayer");
|
||||
@@ -71,10 +76,12 @@ local get_player_data_method = player_base_type_def:get_method("get_PlayerData")
|
||||
|
||||
local player_data_type_def = get_player_data_method:get_return_type();
|
||||
|
||||
local get_vital_method = player_data_type_def:get_method("get_vital");
|
||||
local attack_field = player_data_type_def:get_field("_Attack");
|
||||
local defence_field = player_data_type_def:get_field("_Defence");
|
||||
local critical_rate_field = player_data_type_def:get_field("_CriticalRate");
|
||||
|
||||
local vital_max_field = player_data_type_def:get_field("_vitalMax");
|
||||
|
||||
local stamina_field = player_data_type_def:get_field("_stamina");
|
||||
local stamina_max_field = player_data_type_def:get_field("_staminaMax");
|
||||
@@ -91,6 +98,13 @@ local system_array_type_def = sdk.find_type_definition("System.Array");
|
||||
local get_length_method = system_array_type_def:get_method("get_Length");
|
||||
local get_value_method = system_array_type_def:get_method("GetValue(System.Int32)");
|
||||
|
||||
local player_quest_base_type_def = sdk.find_type_definition("snow.player.PlayerQuestBase");
|
||||
local player_quest_base_update_method = player_quest_base_type_def:get_method("update");
|
||||
local is_master_player_method = player_quest_base_type_def:get_method("isMasterPlayer");
|
||||
|
||||
local master_player_ref = nil;
|
||||
local master_player_data_ref = nil;
|
||||
|
||||
function this.update()
|
||||
if quest_status.flow_state == quest_status.flow_states.NONE then
|
||||
return;
|
||||
@@ -118,6 +132,12 @@ function this.update()
|
||||
if master_player_data == nil then
|
||||
error_handler.report("player_info.update", "Failed to access Data: master_player_data");
|
||||
end
|
||||
|
||||
master_player_ref = master_player;
|
||||
master_player_data_ref = master_player_data;
|
||||
should_health_update = true;
|
||||
|
||||
this.update_generic("max_health", master_player_data, vital_max_field);
|
||||
|
||||
this.update_generic("stamina", master_player_data, stamina_field);
|
||||
this.list.stamina = math.floor(this.list.stamina / 30);
|
||||
@@ -138,7 +158,7 @@ function this.update()
|
||||
|
||||
this.update_generic("element_type_2", master_player_data, element_type_2nd_field);
|
||||
this.update_generic("element_attack_2", master_player_data, element_attack_2nd_field);
|
||||
|
||||
|
||||
this.update_resistances(master_player_data);
|
||||
end
|
||||
|
||||
@@ -235,6 +255,26 @@ function this.update_resistances(player_data)
|
||||
end
|
||||
end
|
||||
|
||||
function this.update_health(quest_player_base)
|
||||
if quest_player_base ~= master_player_ref then
|
||||
return;
|
||||
end
|
||||
|
||||
if not should_health_update then
|
||||
return;
|
||||
end
|
||||
|
||||
should_health_update = false;
|
||||
|
||||
local vital = get_vital_method:call(master_player_data_ref);
|
||||
if vital == nil then
|
||||
error_handler.report("player_info.update_health", "Failed to access Data: vital");
|
||||
return;
|
||||
end
|
||||
|
||||
this.list.health = vital;
|
||||
end
|
||||
|
||||
function this.init_dependencies()
|
||||
singletons = require("MHR_Overlay.Game_Handler.singletons");
|
||||
customization_menu = require("MHR_Overlay.UI.customization_menu");
|
||||
@@ -252,6 +292,12 @@ function this.init_dependencies()
|
||||
end
|
||||
|
||||
function this.init_module()
|
||||
sdk.hook(player_quest_base_update_method, function(args)
|
||||
local quest_player_base = sdk.to_managed_object(args[2]);
|
||||
this.update_health(quest_player_base);
|
||||
end, function(retval)
|
||||
return retval;
|
||||
end);
|
||||
end
|
||||
|
||||
return this;
|
||||
|
||||
@@ -60,6 +60,7 @@ this.label_list = {
|
||||
};
|
||||
|
||||
this.affinity_label = nil;
|
||||
this.health_label = nil;
|
||||
this.stamina_label = nil;
|
||||
this.element_label = nil;
|
||||
this.element_2_label = nil;
|
||||
@@ -81,7 +82,11 @@ function this.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]);
|
||||
if label.include.value then
|
||||
name_text = string.format("%s: ", cached_names[label_key]);
|
||||
else
|
||||
name_text = string.format("%s", cached_names[label_key]);
|
||||
end
|
||||
end
|
||||
|
||||
if label.include.value then
|
||||
@@ -93,22 +98,38 @@ function this.draw()
|
||||
::continue::
|
||||
end
|
||||
|
||||
-- Affinity Label
|
||||
local affinity_name_text = "";
|
||||
if this.affinity_label.include.name then
|
||||
affinity_name_text = string.format("%s: ", cached_names.affinity);
|
||||
-- Health Label
|
||||
local health_name_text = "";
|
||||
if this.health_label.include.name then
|
||||
health_name_text = string.format("%s: ", language.current_language.customization_menu.health);
|
||||
|
||||
if this.health_label.include.value or this.health_label.include.max_value then
|
||||
health_name_text = string.format("%s: ", language.current_language.customization_menu.health);
|
||||
else
|
||||
health_name_text = string.format("%s", language.current_language.customization_menu.health);
|
||||
end
|
||||
end
|
||||
|
||||
if this.affinity_label.include.value then
|
||||
affinity_name_text = string.format("%s%s%%", affinity_name_text, tostring(player_info.list.affinity));
|
||||
if this.health_label.include.value and not this.health_label.include.max_value then
|
||||
health_name_text = string.format("%s%s", health_name_text, tostring(player_info.list.health));
|
||||
|
||||
elseif not this.health_label.include.value and this.health_label.include.max_value then
|
||||
health_name_text = string.format("%s%s", health_name_text, tostring(player_info.list.max_health));
|
||||
|
||||
elseif this.health_label.include.value and this.health_label.include.max_value then
|
||||
health_name_text = string.format("%s%s/%s", health_name_text, tostring(player_info.list.health), tostring(player_info.list.max_health));
|
||||
end
|
||||
|
||||
drawing.draw_label(this.affinity_label, position_on_screen, 1, affinity_name_text);
|
||||
drawing.draw_label(this.health_label, position_on_screen, 1, health_name_text);
|
||||
|
||||
-- Stamina Label
|
||||
local stamina_name_text = "";
|
||||
if this.stamina_label.include.name then
|
||||
stamina_name_text = string.format("%s: ", cached_names.stamina);
|
||||
if this.stamina_label.include.value or this.stamina_label.include.max_value then
|
||||
stamina_name_text = string.format("%s: ", cached_names.stamina);
|
||||
else
|
||||
stamina_name_text = string.format("%s", cached_names.stamina);
|
||||
end
|
||||
end
|
||||
|
||||
if this.stamina_label.include.value and not this.stamina_label.include.max_value then
|
||||
@@ -123,6 +144,22 @@ function this.draw()
|
||||
|
||||
drawing.draw_label(this.stamina_label, position_on_screen, 1, stamina_name_text);
|
||||
|
||||
-- Affinity Label
|
||||
local affinity_name_text = "";
|
||||
if this.affinity_label.include.name then
|
||||
if this.affinity_label.include.value then
|
||||
affinity_name_text = string.format("%s: ", cached_names.affinity);
|
||||
else
|
||||
affinity_name_text = string.format("%s", cached_names.affinity);
|
||||
end
|
||||
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);
|
||||
|
||||
-- Element Label
|
||||
if player_info.list.element_type ~= 0 then
|
||||
|
||||
@@ -131,26 +168,33 @@ function this.draw()
|
||||
|
||||
local ailment_names = language.current_language.ailments;
|
||||
|
||||
local ailment_name = "";
|
||||
|
||||
if player_info.list.element_type == 1 then
|
||||
element_name_text = string.format("%s: ", cached_names.fire);
|
||||
ailment_name = cached_names.fire;
|
||||
elseif player_info.list.element_type == 2 then
|
||||
element_name_text = string.format("%s: ", cached_names.water);
|
||||
ailment_name = cached_names.water;
|
||||
elseif player_info.list.element_type == 3 then
|
||||
element_name_text = string.format("%s: ", cached_names.thunder);
|
||||
ailment_name = cached_names.thunder;
|
||||
elseif player_info.list.element_type == 4 then
|
||||
element_name_text = string.format("%s: ", cached_names.ice);
|
||||
ailment_name = cached_names.ice;
|
||||
elseif player_info.list.element_type == 5 then
|
||||
element_name_text = string.format("%s: ", cached_names.dragon);
|
||||
ailment_name = cached_names.dragon;
|
||||
elseif player_info.list.element_type == 6 then
|
||||
element_name_text = string.format("%s: ", ailment_names.poison);
|
||||
ailment_name = ailment_names.poison;
|
||||
elseif player_info.list.element_type == 7 then
|
||||
element_name_text = string.format("%s: ", ailment_names.sleep);
|
||||
ailment_name = ailment_names.sleep;
|
||||
elseif player_info.list.element_type == 8 then
|
||||
element_name_text = string.format("%s: ", ailment_names.paralysis);
|
||||
ailment_name = ailment_names.paralysis;
|
||||
elseif player_info.list.element_type == 9 then
|
||||
element_name_text = string.format("%s: ", ailment_names.blast);
|
||||
ailment_name = ailment_names.blast;
|
||||
end
|
||||
|
||||
if this.element_label.include.value then
|
||||
element_name_text = string.format("%s: ", ailment_name);
|
||||
else
|
||||
element_name_text = string.format("%s", ailment_name);
|
||||
end
|
||||
end
|
||||
|
||||
if this.element_label.include.value then
|
||||
@@ -169,24 +213,32 @@ function this.draw()
|
||||
|
||||
local ailment_names = language.current_language.ailments;
|
||||
|
||||
local ailment_name = "";
|
||||
|
||||
if player_info.list.element_type_2 == 1 then
|
||||
element_2_name_text = string.format("%s: ", cached_names.fire);
|
||||
ailment_name = cached_names.fire;
|
||||
elseif player_info.list.element_type_2 == 2 then
|
||||
element_2_name_text = string.format("%s: ", cached_names.water);
|
||||
ailment_name = cached_names.water;
|
||||
elseif player_info.list.element_type_2 == 3 then
|
||||
element_2_name_text = string.format("%s: ", cached_names.thunder);
|
||||
ailment_name = cached_names.thunder;
|
||||
elseif player_info.list.element_type_2 == 4 then
|
||||
element_2_name_text = string.format("%s: ", cached_names.ice);
|
||||
ailment_name = cached_names.ice;
|
||||
elseif player_info.list.element_type_2 == 5 then
|
||||
element_2_name_text = string.format("%s: ", cached_names.dragon);
|
||||
ailment_name = cached_names.dragon;
|
||||
elseif player_info.list.element_type_2 == 6 then
|
||||
element_2_name_text = string.format("%s: ", ailment_names.poison);
|
||||
ailment_name = ailment_names.poison;
|
||||
elseif player_info.list.element_type_2 == 7 then
|
||||
element_2_name_text = string.format("%s: ", ailment_names.sleep);
|
||||
ailment_name = ailment_names.sleep;
|
||||
elseif player_info.list.element_type_2 == 8 then
|
||||
element_2_name_text = string.format("%s: ", ailment_names.paralysis);
|
||||
ailment_name = ailment_names.paralysis;
|
||||
elseif player_info.list.element_type_2 == 9 then
|
||||
element_2_name_text = string.format("%s: ", ailment_names.blast);
|
||||
ailment_name = ailment_names.blast;
|
||||
end
|
||||
|
||||
if this.element_2_label.include.value then
|
||||
element_2_name_text = string.format("%s: ", ailment_name);
|
||||
else
|
||||
element_2_name_text = string.format("%s", ailment_name);
|
||||
end
|
||||
|
||||
end
|
||||
@@ -210,6 +262,7 @@ function this.init_UI()
|
||||
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.health_label = utils.table.deep_copy(config.current_config.stats_UI.health_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);
|
||||
@@ -224,6 +277,9 @@ function this.init_UI()
|
||||
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.health_label.offset.x = this.health_label.offset.x * global_scale_modifier;
|
||||
this.health_label.offset.y = this.health_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;
|
||||
|
||||
|
||||
@@ -2355,6 +2355,12 @@ function this.draw_stats_UI()
|
||||
imgui.tree_pop();
|
||||
end
|
||||
|
||||
changed = label_customization.draw(language.current_language.customization_menu.health_label, cached_config.health_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.attack_label, cached_config.attack_label);
|
||||
config_changed = config_changed or changed;
|
||||
|
||||
@@ -2379,9 +2385,6 @@ function this.draw_stats_UI()
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user