Stats UI: Add Health and Max Health

This commit is contained in:
GreenComfyTea
2023-08-20 10:48:25 +03:00
parent 67e0e6db6b
commit 13e68d67a9
12 changed files with 212 additions and 67 deletions

View File

@@ -105,7 +105,6 @@ function this.init_global_timers()
this.new_timer(players.update_myself_position, 1); this.new_timer(players.update_myself_position, 1);
this.new_timer(buffs.update, 1/60); this.new_timer(buffs.update, 1/60);
this.new_timer(player_info.update, 0.5); this.new_timer(player_info.update, 0.5);
end end
function this.update_timers() function this.update_timers()

View File

@@ -7603,6 +7603,74 @@ function this.init_default()
anchor = "Bottom-Right" 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 = { attack_label = {
visibility = true, 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 = { element_label = {
visibility = false, visibility = false,

View File

@@ -677,6 +677,8 @@ this.default_language = {
value = "Value", value = "Value",
stats_UI = "Stats UI", stats_UI = "Stats UI",
health_label = "Health Label",
stamina_label = "Stamina Label",
attack_label = "Attack Label", attack_label = "Attack Label",
defense_label = "Defense Label", defense_label = "Defense Label",
affinity_label = "Affinity Label", affinity_label = "Affinity Label",
@@ -685,7 +687,6 @@ this.default_language = {
thunder_resistance_label = "Thunder Resistance Label", thunder_resistance_label = "Thunder Resistance Label",
ice_resistance_label = "Ice Resistance Label", ice_resistance_label = "Ice Resistance Label",
dragon_resistance_label = "Dragon Resistance Label", dragon_resistance_label = "Dragon Resistance Label",
stamina_label = "Stamina Label",
element_label = "Element Label", element_label = "Element Label",
element_2_label = "Element 2 Label" element_2_label = "Element 2 Label"
}, },

View File

@@ -42,6 +42,9 @@ local ValueType = ValueType;
local package = package; local package = package;
this.list = { this.list = {
health = 0;
max_health = 0;
attack = 0; attack = 0;
defense = 0; defense = 0;
affinity = 0; affinity = 0;
@@ -62,6 +65,8 @@ this.list = {
dragon_resistance = 0; dragon_resistance = 0;
}; };
local should_health_update = true;
local player_manager_type_def = sdk.find_type_definition("snow.player.PlayerManager"); local player_manager_type_def = sdk.find_type_definition("snow.player.PlayerManager");
local get_player_method = player_manager_type_def:get_method("getPlayer"); local get_player_method = player_manager_type_def:get_method("getPlayer");
local find_master_player_method = player_manager_type_def:get_method("findMasterPlayer"); 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 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 attack_field = player_data_type_def:get_field("_Attack");
local defence_field = player_data_type_def:get_field("_Defence"); local defence_field = player_data_type_def:get_field("_Defence");
local critical_rate_field = player_data_type_def:get_field("_CriticalRate"); 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_field = player_data_type_def:get_field("_stamina");
local stamina_max_field = player_data_type_def:get_field("_staminaMax"); 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_length_method = system_array_type_def:get_method("get_Length");
local get_value_method = system_array_type_def:get_method("GetValue(System.Int32)"); 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() function this.update()
if quest_status.flow_state == quest_status.flow_states.NONE then if quest_status.flow_state == quest_status.flow_states.NONE then
return; return;
@@ -119,6 +133,12 @@ function this.update()
error_handler.report("player_info.update", "Failed to access Data: master_player_data"); error_handler.report("player_info.update", "Failed to access Data: master_player_data");
end 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.update_generic("stamina", master_player_data, stamina_field);
this.list.stamina = math.floor(this.list.stamina / 30); this.list.stamina = math.floor(this.list.stamina / 30);
@@ -235,6 +255,26 @@ function this.update_resistances(player_data)
end end
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() function this.init_dependencies()
singletons = require("MHR_Overlay.Game_Handler.singletons"); singletons = require("MHR_Overlay.Game_Handler.singletons");
customization_menu = require("MHR_Overlay.UI.customization_menu"); customization_menu = require("MHR_Overlay.UI.customization_menu");
@@ -252,6 +292,12 @@ function this.init_dependencies()
end end
function this.init_module() 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 end
return this; return this;

View File

@@ -60,6 +60,7 @@ this.label_list = {
}; };
this.affinity_label = nil; this.affinity_label = nil;
this.health_label = nil;
this.stamina_label = nil; this.stamina_label = nil;
this.element_label = nil; this.element_label = nil;
this.element_2_label = nil; this.element_2_label = nil;
@@ -81,7 +82,11 @@ function this.draw()
for label_key, label in pairs(this.label_list) do for label_key, label in pairs(this.label_list) do
local name_text = ""; local name_text = "";
if label.include.name then if label.include.name then
if label.include.value then
name_text = string.format("%s: ", cached_names[label_key]); name_text = string.format("%s: ", cached_names[label_key]);
else
name_text = string.format("%s", cached_names[label_key]);
end
end end
if label.include.value then if label.include.value then
@@ -93,22 +98,38 @@ function this.draw()
::continue:: ::continue::
end end
-- Affinity Label -- Health Label
local affinity_name_text = ""; local health_name_text = "";
if this.affinity_label.include.name then if this.health_label.include.name then
affinity_name_text = string.format("%s: ", cached_names.affinity); 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 end
if this.affinity_label.include.value then if this.health_label.include.value and not this.health_label.include.max_value then
affinity_name_text = string.format("%s%s%%", affinity_name_text, tostring(player_info.list.affinity)); 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 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 -- Stamina Label
local stamina_name_text = ""; local stamina_name_text = "";
if this.stamina_label.include.name then if this.stamina_label.include.name then
if this.stamina_label.include.value or this.stamina_label.include.max_value then
stamina_name_text = string.format("%s: ", cached_names.stamina); stamina_name_text = string.format("%s: ", cached_names.stamina);
else
stamina_name_text = string.format("%s", cached_names.stamina);
end
end end
if this.stamina_label.include.value and not this.stamina_label.include.max_value then 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); 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 -- Element Label
if player_info.list.element_type ~= 0 then if player_info.list.element_type ~= 0 then
@@ -131,26 +168,33 @@ function this.draw()
local ailment_names = language.current_language.ailments; local ailment_names = language.current_language.ailments;
local ailment_name = "";
if player_info.list.element_type == 1 then 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 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 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 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 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 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 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 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 elseif player_info.list.element_type == 9 then
element_name_text = string.format("%s: ", ailment_names.blast); ailment_name = ailment_names.blast;
end 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 end
if this.element_label.include.value then if this.element_label.include.value then
@@ -169,24 +213,32 @@ function this.draw()
local ailment_names = language.current_language.ailments; local ailment_names = language.current_language.ailments;
local ailment_name = "";
if player_info.list.element_type_2 == 1 then 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 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 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 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 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 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 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 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 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
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.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.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.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_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); 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.x = this.affinity_label.offset.x * global_scale_modifier;
this.affinity_label.offset.y = this.affinity_label.offset.y * 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.x = this.stamina_label.offset.x * global_scale_modifier;
this.stamina_label.offset.y = this.stamina_label.offset.y * global_scale_modifier; this.stamina_label.offset.y = this.stamina_label.offset.y * global_scale_modifier;

View File

@@ -2355,6 +2355,12 @@ function this.draw_stats_UI()
imgui.tree_pop(); imgui.tree_pop();
end 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); changed = label_customization.draw(language.current_language.customization_menu.attack_label, cached_config.attack_label);
config_changed = config_changed or changed; 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); changed = label_customization.draw(language.current_language.customization_menu.dragon_resistance_label, cached_config.dragon_resistance_label);
config_changed = config_changed or changed; 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); changed = label_customization.draw(language.current_language.customization_menu.element_label, cached_config.element_label);
config_changed = config_changed or changed; config_changed = config_changed or changed;

View File

@@ -179,6 +179,7 @@
"health_break_sever_anomaly_filter": "Health + Break + Sever + Anomaly Core", "health_break_sever_anomaly_filter": "Health + Break + Sever + Anomaly Core",
"health_break_sever_filter": "Health + Break + Sever", "health_break_sever_filter": "Health + Break + Sever",
"health_filter": "Health", "health_filter": "Health",
"health_label": "Health Label",
"health_percentage": "Health Percentage", "health_percentage": "Health Percentage",
"health_sever_anomaly_filter": "Health + Sever + Anomaly Core", "health_sever_anomaly_filter": "Health + Sever + Anomaly Core",
"health_sever_filter": "Health + Sever", "health_sever_filter": "Health + Sever",

View File

@@ -180,6 +180,7 @@
"health_break_sever_anomaly_filter": "Health + Break + Sever + Anomaly Core", "health_break_sever_anomaly_filter": "Health + Break + Sever + Anomaly Core",
"health_break_sever_filter": "Health + Break + Sever", "health_break_sever_filter": "Health + Break + Sever",
"health_filter": "Health", "health_filter": "Health",
"health_label": "Health Label",
"health_percentage": "ダメージ割合()", "health_percentage": "ダメージ割合()",
"health_sever_anomaly_filter": "Health + Sever + Anomaly Core", "health_sever_anomaly_filter": "Health + Sever + Anomaly Core",
"health_sever_filter": "Health + Sever", "health_sever_filter": "Health + Sever",

View File

@@ -181,6 +181,7 @@
"health_break_sever_anomaly_filter": "체력 + 파괴 + 절단 + 괴이핵", "health_break_sever_anomaly_filter": "체력 + 파괴 + 절단 + 괴이핵",
"health_break_sever_filter": "체력 + 파괴 + 절단", "health_break_sever_filter": "체력 + 파괴 + 절단",
"health_filter": "체력", "health_filter": "체력",
"health_label": "Health Label",
"health_percentage": "체력 비율", "health_percentage": "체력 비율",
"health_sever_anomaly_filter": "체력 + 절단 + 괴이핵", "health_sever_anomaly_filter": "체력 + 절단 + 괴이핵",
"health_sever_filter": "체력 + 절단", "health_sever_filter": "체력 + 절단",

View File

@@ -181,6 +181,7 @@
"health_break_sever_anomaly_filter": "Здоровье + Повреждение + Отсечение + Ядро аномалии", "health_break_sever_anomaly_filter": "Здоровье + Повреждение + Отсечение + Ядро аномалии",
"health_break_sever_filter": "Здоровье + Повреждение + Отсечение", "health_break_sever_filter": "Здоровье + Повреждение + Отсечение",
"health_filter": "Здоровье", "health_filter": "Здоровье",
"health_label": "Health Label",
"health_percentage": "Здоровье в процентах", "health_percentage": "Здоровье в процентах",
"health_sever_anomaly_filter": "Здоровье + Отсечение + Ядро аномалии", "health_sever_anomaly_filter": "Здоровье + Отсечение + Ядро аномалии",
"health_sever_filter": "Здоровье + Отсечение", "health_sever_filter": "Здоровье + Отсечение",

View File

@@ -181,6 +181,7 @@
"health_break_sever_anomaly_filter": "生命+破坏+切断+怪异核", "health_break_sever_anomaly_filter": "生命+破坏+切断+怪异核",
"health_break_sever_filter": "生命+破坏+切断", "health_break_sever_filter": "生命+破坏+切断",
"health_filter": "生命", "health_filter": "生命",
"health_label": "Health Label",
"health_percentage": "生命百分比", "health_percentage": "生命百分比",
"health_sever_anomaly_filter": "生命+切断+怪异核", "health_sever_anomaly_filter": "生命+切断+怪异核",
"health_sever_filter": "生命+切断", "health_sever_filter": "生命+切断",

View File

@@ -181,6 +181,7 @@
"health_break_sever_anomaly_filter": "Health + Break + Sever + Anomaly Core", "health_break_sever_anomaly_filter": "Health + Break + Sever + Anomaly Core",
"health_break_sever_filter": "Health + Break + Sever", "health_break_sever_filter": "Health + Break + Sever",
"health_filter": "Health", "health_filter": "Health",
"health_label": "Health Label",
"health_percentage": "血量百分比", "health_percentage": "血量百分比",
"health_sever_anomaly_filter": "Health + Sever + Anomaly Core", "health_sever_anomaly_filter": "Health + Sever + Anomaly Core",
"health_sever_filter": "Health + Sever", "health_sever_filter": "Health + Sever",