Move players.display_list to damage_meter_UI

This commit is contained in:
GreenComfyTea
2023-08-16 11:41:20 +03:00
parent 5ff6af9108
commit f2675e6d23
6 changed files with 186 additions and 148 deletions

View File

@@ -279,6 +279,13 @@ local function update_modules(module_visibility_config, flow_state_name)
end
end
if config.current_config.damage_meter_UI.enabled and module_visibility_config.damage_meter_UI then
local success = pcall(damage_meter_UI.update);
if not success then
error_handler.report("MHR_Overlay.update_modules", string.format("[%s] Damage Meter UI Update Function threw an Exception", flow_state_name));
end
end
if config.current_config.endemic_life_UI.enabled and module_visibility_config.endemic_life_UI then
local success = pcall(env_creature_UI.update);
if not success then
@@ -368,6 +375,13 @@ local function update_UI()
end
end
if config.current_config.damage_meter_UI.enabled and module_visibility_config.damage_meter_UI then
local success = pcall(damage_meter_UI.update);
if not success then
error_handler.report("MHR_Overlay.update_modules", "[In Training Area] Damage Meter UI Update Function threw an Exception");
end
end
if config.current_config.endemic_life_UI.enabled and module_visibility_config.endemic_life_UI then
local success = pcall(env_creature_UI.update);
if not success then

View File

@@ -185,10 +185,6 @@ function this.update_servant_list()
this.servant_list[id] = this.new(id, name, 0, players.types.servant);
end
if not cached_config.settings.hide_servants then
table.insert(players.display_list, this.servant_list[id]);
end
::continue::
end
end
@@ -230,12 +226,10 @@ function this.update_my_otomos()
local level = otomo_create_data_level_field:get_data(first_otomo) or 0;
local myself_id = players.myself.id;
if this.otomo_list[myself_id] == nil then
this.otomo_list[myself_id] = this.new(0, name, level, players.types.my_otomo);
end
if cached_config.settings.show_my_otomos_separately then
table.insert(players.display_list, this.otomo_list[myself_id]);
local otomo = this.otomo_list[myself_id]
if otomo == nil then
otomo = this.new(0, name, level, players.types.my_otomo);
this.otomo_list[myself_id] = otomo;
end
end
end
@@ -253,12 +247,11 @@ function this.update_my_otomos()
local level = otomo_create_data_level_field:get_data(second_otomo) or 0;
-- the secondary otomo is actually the 4th one!
if this.otomo_list[this.my_second_otomo_id] == nil then
this.otomo_list[this.my_second_otomo_id] = this.new(this.my_second_otomo_id, name, level, players.types.my_otomo);
end
local otomo = this.otomo_list[this.my_second_otomo_id];
if cached_config.settings.show_my_otomos_separately then
table.insert(players.display_list, this.otomo_list[this.my_second_otomo_id]);
if otomo == nil then
otomo = this.new(this.my_second_otomo_id, name, level, players.types.my_otomo);
this.otomo_list[this.my_second_otomo_id] = otomo;
end
end
end
@@ -297,12 +290,11 @@ function this.update_servant_otomos()
goto continue;
end
if this.otomo_list[member_id] == nil then
this.otomo_list[member_id] = this.new(member_id, name, level, players.types.servant_otomo);
end
local otomo = this.otomo_list[member_id];
if cached_config.settings.show_servant_otomos_separately then
table.insert(players.display_list, this.otomo_list[member_id]);
if otomo == nil then
otomo = this.new(member_id, name, level, players.types.servant_otomo);
this.otomo_list[member_id] = otomo;
end
end
@@ -367,20 +359,6 @@ function this.update_otomos(otomo_info_field_)
end
end
if id == players.myself.id then
if cached_config.settings.show_my_otomos_separately then
table.insert(players.display_list, otomo);
end
elseif id >= 4 then
if cached_config.settings.show_servant_otomos_separately then
table.insert(players.display_list, otomo);
end
else
if cached_config.settings.show_other_player_otomos_separately then
table.insert(players.display_list, otomo);
end
end
::continue::
end
end

View File

@@ -49,8 +49,6 @@ this.myself = nil;
this.myself_position = Vector3f.new(0, 0, 0);
this.total = nil;
this.display_list = {};
this.highlighted_damage_UI = nil;
this.damage_types = {
@@ -337,20 +335,6 @@ function this.merge_damage(first, second)
return first;
end
function this.update_display_list()
local is_on_quest = quest_status.flow_state ~= quest_status.flow_states.IN_LOBBY and quest_status.flow_state ~= quest_status.flow_states.IN_TRAINING_AREA;
this.display_list = {};
this.update_player_list(is_on_quest);
non_players.update_servant_list();
non_players.update_otomo_list(is_on_quest, quest_status.is_online);
this.update_dps(false);
this.sort_players();
quest_status.get_cart_count();
end
function this.update_dps(bypass_freeze)
local cached_config = config.current_config.damage_meter_UI.settings;
@@ -396,54 +380,6 @@ function this.update_player_dps(player)
this.total.dps = this.total.dps + player.dps;
end
function this.sort_players()
local cached_config = config.current_config.damage_meter_UI;
if cached_config.settings.my_damage_bar_location == "Normal" then
table.insert(this.display_list, this.myself);
end
-- sort here
if cached_config.sorting.type == "Normal" then
if cached_config.sorting.reversed_order then
table.sort(this.display_list, function(left, right)
return left.id > right.id;
end);
else
table.sort(this.display_list, function(left, right)
return left.id < right.id;
end);
end
elseif cached_config.sorting.type == "DPS" then
if cached_config.sorting.reversed_order then
table.sort(this.display_list, function(left, right)
return left.dps < right.dps;
end);
else
table.sort(this.display_list, function(left, right)
return left.dps > right.dps;
end);
end
else
if cached_config.sorting.reversed_order then
table.sort(this.display_list, function(left, right)
return left.display.total_damage < right.display.total_damage;
end);
else
table.sort(this.display_list, function(left, right)
return left.display.total_damage > right.display.total_damage;
end);
end
end
if cached_config.settings.my_damage_bar_location == "First" then
table.insert(this.display_list, 1, this.myself);
elseif cached_config.settings.my_damage_bar_location == "Last" then
table.insert(this.display_list, this.myself);
end
end
local player_manager_type_def = sdk.find_type_definition("snow.player.PlayerManager");
local find_master_player_method = player_manager_type_def:get_method("findMasterPlayer");
@@ -477,7 +413,6 @@ end
function this.init()
this.list = {};
this.display_list = {};
this.total = this.new(0, "Total", 0, 0, this.types.total);
this.myself = this.new(-1, "DummyMHROverlay", -1, -1, this.types.myself);
end
@@ -509,6 +444,18 @@ local get_master_rank_method = progress_manager_type_def:get_method("get_MasterR
local get_master_player_id_method = player_manager_type_def:get_method("getMasterPlayerID");
function this.update_players()
local is_on_quest = quest_status.flow_state ~= quest_status.flow_states.IN_LOBBY and quest_status.flow_state ~= quest_status.flow_states.IN_TRAINING_AREA;
this.update_player_list(is_on_quest);
non_players.update_servant_list();
non_players.update_otomo_list(is_on_quest, quest_status.is_online);
this.update_dps(false);
quest_status.get_cart_count();
end
function this.update_player_list(is_on_quest)
if is_on_quest then
this.update_player_list_(quest_hunter_info_field);
@@ -618,10 +565,6 @@ function this.update_player_list_(hunter_info_field_)
end
end
if player ~= this.myself then
table.insert(this.display_list, player);
end
::continue::
end
end

View File

@@ -79,7 +79,7 @@ function this.init_global_timers()
this.new_timer(screen.update_window_size, 1);
this.new_timer(quest_status.update_is_online, 1);
this.new_timer(this.update_quest_time, 1 / 60);
this.new_timer(players.update_display_list, 0.5);
this.new_timer(players.update_players, 0.5);
this.new_timer(players.update_myself_position, 1);
this.new_timer(buffs.update, 1/60);
this.new_timer(player_info.update, 0.5);

View File

@@ -44,30 +44,107 @@ local os = os;
local ValueType = ValueType;
local package = package;
local top_damage = 0;
local top_dps = 0;
this.displayed_players = {};
this.last_displayed_players = {};
this.freeze_displayed_players = false;
function this.draw()
function this.update()
local is_on_quest = quest_status.flow_state ~= quest_status.flow_states.IN_LOBBY and quest_status.flow_state ~= quest_status.flow_states.IN_TRAINING_AREA;
local cached_config = config.current_config.damage_meter_UI;
local global_scale_modifier = config.current_config.global_settings.modifiers.global_scale_modifier;
if this.freeze_displayed_players and not utils.table.is_empty(this.last_displayed_players) then
this.displayed_players = this.last_displayed_players;
return;
end;
if players.total.display.total_damage == 0 and cached_config.settings.hide_module_if_total_damage_is_zero then
return;
end
local quest_players = {};
this.displayed_players = {};
if this.freeze_displayed_players and not utils.table.is_empty(this.last_displayed_players) then
quest_players = this.last_displayed_players;
else
quest_players = players.display_list;
for id, player in pairs(players.list) do
if player ~= players.myself then
this.add_to_displayed_players_list(player, cached_config);
end
end
this.last_displayed_players = quest_players;
if not cached_config.settings.hide_servants then
for id, servant in pairs(non_players.servant_list) do
this.add_to_displayed_players_list(servant, cached_config);
end
end
local top_damage = 0;
local top_dps = 0;
for _, player in ipairs(quest_players) do
for id, otomo in pairs(non_players.otomo_list) do
if id == players.myself.id or id == non_players.my_second_otomo_id then
if cached_config.settings.show_my_otomos_separately then
this.add_to_displayed_players_list(otomo, cached_config);
end
elseif id >= 4 then
if cached_config.settings.show_servant_otomos_separately then
this.add_to_displayed_players_list(otomo, cached_config);
end
else
if cached_config.settings.show_other_player_otomos_separately then
this.add_to_displayed_players_list(otomo, cached_config);
end
end
end
this.calculate_top_damage_and_dps();
this.sort();
this.last_displayed_players = this.displayed_players;
end
function this.add_to_displayed_players_list(player, cached_config, position)
cached_config = cached_config.settings;
position = position or #(this.displayed_players) + 1;
if player.display.total_damage == 0 and cached_config.hide_player_if_player_damage_is_zero then
return;
end
if player.type == players.types.myself then
if cached_config.hide_myself then
return;
end
elseif player.type == players.types.servant then
if cached_config.hide_servants then
return;
end
elseif player.type == players.types.other_player then
if cached_config.hide_other_players then
return;
end
elseif player.type == players.types.my_otomo then
if not cached_config.show_my_otomos_separately then
return;
end
elseif player.type == players.types.other_player_otomo then
if not cached_config.show_other_player_otomos_separately then
return;
end
elseif player.type == players.types.servant_otomo then
if not cached_config.show_servant_otomos_separately then
return;
end
end
--if position == nil then
-- table.insert(this.displayed_players, player);
--else
table.insert(this.displayed_players, position, player);
--end
end
function this.calculate_top_damage_and_dps()
top_damage = 0;
top_dps = 0;
for _, player in ipairs(this.displayed_players) do
if player.display.total_damage > top_damage then
top_damage = player.display.total_damage;
end
@@ -76,6 +153,63 @@ function this.draw()
top_dps = player.dps;
end
end
end
function this.sort()
local cached_config = config.current_config.damage_meter_UI;
if cached_config.settings.my_damage_bar_location == "Normal" then
table.insert(this.displayed_players, this.myself);
end
-- sort here
if cached_config.sorting.type == "Normal" then
if cached_config.sorting.reversed_order then
table.sort(this.displayed_players, function(left, right)
return left.id > right.id;
end);
else
table.sort(this.displayed_players, function(left, right)
return left.id < right.id;
end);
end
elseif cached_config.sorting.type == "DPS" then
if cached_config.sorting.reversed_order then
table.sort(this.displayed_players, function(left, right)
return left.dps < right.dps;
end);
else
table.sort(this.displayed_players, function(left, right)
return left.dps > right.dps;
end);
end
else
if cached_config.sorting.reversed_order then
table.sort(this.displayed_players, function(left, right)
return left.display.total_damage < right.display.total_damage;
end);
else
table.sort(this.displayed_players, function(left, right)
return left.display.total_damage > right.display.total_damage;
end);
end
end
if cached_config.settings.my_damage_bar_location == "First" then
this.add_to_displayed_players_list(players.myself, cached_config, 1);
elseif cached_config.settings.my_damage_bar_location == "Last" then
this.add_to_displayed_players_list(players.myself, cached_config);
end
end
function this.draw()
local cached_config = config.current_config.damage_meter_UI;
local global_scale_modifier = config.current_config.global_settings.modifiers.global_scale_modifier;
if players.total.display.total_damage == 0 and cached_config.settings.hide_module_if_total_damage_is_zero then
return;
end
local position_on_screen = screen.calculate_absolute_coordinates(cached_config.position);
@@ -103,37 +237,7 @@ function this.draw()
position_on_screen = screen.calculate_absolute_coordinates(cached_config.position);
end
for _, player in ipairs(quest_players) do
if player.display.total_damage == 0 and cached_config.settings.hide_player_if_player_damage_is_zero then
goto continue;
end
if player.type == players.types.myself then
if cached_config.settings.hide_myself then
goto continue;
end
elseif player.type == players.types.servant then
if cached_config.settings.hide_servants then
goto continue;
end
elseif player.type == players.types.other_player then
if cached_config.settings.hide_other_players then
goto continue;
end
elseif player.type == players.types.my_otomo then
if not cached_config.settings.show_my_otomos_separately then
goto continue;
end
elseif player.type == players.types.other_player_otomo then
if not cached_config.settings.show_other_player_otomos_separately then
goto continue;
end
elseif player.type == players.types.servant_otomo then
if not cached_config.settings.show_servant_otomos_separately then
goto continue;
end
end
for _, player in ipairs(this.displayed_players) do
players.draw(player, position_on_screen, 1, top_damage, top_dps);

View File

@@ -2101,7 +2101,6 @@ function this.draw_damage_meter_UI()
if config_changed then
local is_on_quest = quest_status.flow_state ~= quest_status.flow_states.IN_LOBBY and quest_status.flow_state ~= quest_status.flow_states.IN_TRAINING_AREA;
players.display_list = {};
players.update_player_list(is_on_quest);
non_players.update_servant_list();
non_players.update_otomo_list(is_on_quest, quest_status.is_online);