Added hotkeys, separated player initialization and drawing.

This commit is contained in:
GreenComfyTea
2022-02-20 19:23:36 +02:00
parent 39e324e0a5
commit c6669e5df0
25 changed files with 1458 additions and 361 deletions

View File

@@ -0,0 +1,449 @@
local config = require "MHR_Overlay.Misc.config"
local keyboard = {};
local singletons;
local customization_menu;
local player;
local small_monster;
local large_monster;
local damage_meter_UI;
local time;
local game_keyboard_type_def = sdk.find_type_definition("snow.GameKeyboard");
local hard_keyboard_field = game_keyboard_type_def:get_field("hardKeyboard");
local hard_keyboard_field_type_def = hard_keyboard_field:get_type();
local get_down_method = hard_keyboard_field_type_def:get_method("getDown");
local get_trigger_method = hard_keyboard_field_type_def:get_method("getTrg");
local get_release_method = hard_keyboard_field_type_def:get_method("getRelease");
keyboard.keys = {
[0] = "None",
[1] = "Left Mouse Button",
[2] = "Right Mouse Button",
[3] = "Control-Break",
[4] = "Middle Mouse Button",
[5] = "X1 Mouse Button",
[6] = "X2 Mouse Button",
--[7] = "Undefined 7",
[8] = "Backspace",
[9] = "Tab",
--[10] = "Reserved 10",
--[11] = "Reserved 11",
[12] = "Clear",
[13] = "Enter",
--[14] = "Undefined 14",
--[15] = "Undefined 15",
[16] = "Shift",
[17] = "Ctrl",
[18] = "Alt",
[19] = "Pause Break",
[20] = "Caps Lock",
[21] = "IME Kana/Hanguel/Hangul Mode",
[22] = "IME On",
[23] = "IME Junja Mode",
[24] = "IME Final Mode",
[25] = "IME Hanja/Kanji Mode",
[26] = "IME On",
[27] = "Esc",
[28] = "IME Convert",
[29] = "IME NonConvert",
[30] = "IME Accept",
[31] = "IME Mode Change Request",
[32] = "Spacebar",
[33] = "Page Up",
[34] = "Page Down",
[35] = "End",
[36] = "Home",
[37] = "Left Arrow",
[38] = "Up Arrow",
[39] = "Right Arrow",
[40] = "Down Arrow",
[41] = "Select",
[42] = "Print Screen", -- Print
[43] = "Execute",
[44] = "Print Screen",
[45] = "Ins",
[46] = "Del",
[47] = "Help",
[48] = "0",
[49] = "1",
[50] = "2",
[51] = "3",
[52] = "4",
[53] = "5",
[54] = "6",
[55] = "7",
[56] = "8",
[57] = "9",
--[58] = "Undefined 58",
--[59] = "Undefined 59",
--[60] = "Undefined 60",
--[61] = "Undefined 60"", -- =+
--[62] = "Undefined 62",
--[63] = "Undefined 63",
--[64] = "Undefined 64",
[65] = "A",
[66] = "B",
[67] = "C",
[68] = "D",
[69] = "E",
[70] = "F",
[71] = "G",
[72] = "H",
[73] = "I",
[74] = "J",
[75] = "K",
[76] = "L",
[77] = "M",
[78] = "N",
[79] = "O",
[80] = "P",
[81] = "Q",
[82] = "R",
[83] = "S",
[84] = "T",
[85] = "U",
[86] = "V",
[87] = "W",
[88] = "X",
[89] = "Y",
[90] = "Z",
[91] = "Left Win",
[92] = "Right Win",
[93] = "Applications",
--[94] = "Reserved 94",
[95] = "Sleep",
[96] = "Numpad 0",
[97] = "Numpad 1",
[98] = "Numpad 2",
[99] = "Numpad 3",
[100] = "Numpad 4",
[101] = "Numpad 5",
[102] = "Numpad 6",
[103] = "Numpad 7",
[104] = "Numpad 8",
[105] = "Numpad 9",
[106] = "Numpad *",
[107] = "Numpad +",
[108] = "Numpad Separator",
[109] = "Numpad -",
[110] = "Numpad .",
[111] = "Numpad /",
[112] = "F1",
[113] = "F2",
[114] = "F3",
[115] = "F4",
[116] = "F5",
[117] = "F6",
[118] = "F7",
[119] = "F8",
[120] = "F9",
[121] = "F10",
[122] = "F11",
[123] = "F12",
[124] = "F13",
[125] = "F14",
[126] = "F15",
[127] = "F16",
[128] = "F17",
[129] = "F18",
[130] = "F19",
[131] = "F20",
[132] = "F21",
[133] = "F22",
[134] = "F23",
[135] = "F24",
--[136] = "Unassigned 136",
--[137] = "Unassigned 137",
--[138] = "Unassigned 138",
--[139] = "Unassigned 139",
--[140] = "Unassigned 140",
--[141] = "Unassigned 141",
--[142] = "Unassigned 142",
--[143] = "Unassigned 143",
[144] = "Num Lock",
[145] = "Scroll Lock",
[146] = "Numpad Enter", -- OEM Specific 146
[147] = "OEM Specific 147",
[148] = "OEM Specific 148",
[149] = "OEM Specific 149",
[150] = "OEM Specific 150",
[151] = "OEM Specific 151",
[152] = "OEM Specific 152",
[153] = "OEM Specific 153",
[154] = "OEM Specific 154",
[155] = "OEM Specific 155",
[156] = "OEM Specific 156",
[157] = "OEM Specific 157",
[158] = "OEM Specific 158",
[159] = "OEM Specific 159",
[160] = "Left Shift",
[161] = "Right Shift",
[162] = "Left Ctrl",
[163] = "Right Ctrl",
[164] = "Left Alt",
[165] = "Right Alt",
[166] = "Browser Back",
[167] = "Browser Forward",
[168] = "Browser Refresh",
[169] = "Browser Stop",
[170] = "Browser Search",
[171] = "Browser Favourites",
[172] = "Browser Start and Home",
[173] = "Volume Mute",
[174] = "Volume Down",
[175] = "Volume Up",
[176] = "Next Track",
[177] = "Previous Track",
[178] = "Stop Media",
[179] = "Play/Pause Media",
[180] = "Start Mail",
[181] = "Select Media",
[182] = "Start Application 1",
[183] = "Start Application 2",
--[184] = "Reserved!",
--[185] = "Reserved!",
[186] = ";:",
[187] = ";:", -- +
[188] = ",<",
[189] = "-",
[190] = ".>",
[191] = "/?",
[192] = "`~",
--[193] = "Reserved!",
--[194] = "Reserved!",
--[195] = "Reserved!",
--[196] = "Reserved!",
--[197] = "Reserved!",
--[198] = "Reserved!",
--[199] = "Reserved!",
--[200] = "Reserved!",
--[201] = "Reserved!",
--[202] = "Reserved!",
--[203] = "Reserved!",
--[204] = "Reserved!",
--[205] = "Reserved!",
--[206] = "Reserved!",
--[207] = "Reserved!",
--[208] = "Reserved!",
--[209] = "Reserved!",
--[210] = "Reserved!",
--[211] = "Reserved!",
--[212] = "Reserved!",
--[213] = "Reserved!",
--[214] = "Reserved!",
--[215] = "Reserved!",
--[216] = "Unassigned 216",
--[217] = "Unassigned 217",
--[218] = "Unassigned 218",
[219] = "[{",
[220] = "\\|",
[221] = "]}",
[222] = "\' \"",
[223] = "OEM_8",
--[224] = "Reserved",
[225] = "OEM Specific 225",
[226] = "<>",
[227] = "OEM Specific 227",
[228] = "OEM Specific 228",
[229] = "IME Process",
[230] = "OEM Specific 230",
[231] = "!!!!!!!!!!!!!!!!!!!!!!!",
--[232] = "Unassigned 232",
[233] = "OEM Specific 233",
[234] = "OEM Specific 234",
[235] = "OEM Specific 235",
[236] = "OEM Specific 236",
[237] = "OEM Specific 237",
[238] = "OEM Specific 238",
[239] = "OEM Specific 239",
[240] = "OEM Specific 240",
[241] = "OEM Specific 241",
[242] = "OEM Specific 242",
[243] = "OEM Specific 243",
[244] = "OEM Specific 244",
[245] = "OEM Specific 245",
[246] = "Attn",
[247] = "CrSel",
[248] = "ExSel",
[249] = "Erase EOF",
[250] = "Play",
[251] = "Zoom",
--[252] = "Reserved 252",
[253] = "PA1",
--[254] = "Clear"
};
function keyboard.update()
if singletons.game_keyboard == nil then
customization_menu.status = "No game keyboard";
return;
end
local hard_keyboard = hard_keyboard_field:get_data(singletons.game_keyboard);
if hard_keyboard == nil then
customization_menu.status = "No hard keyboard";
return;
end
local new_hotkey_registered = keyboard.register_hotkey(hard_keyboard);
if new_hotkey_registered then
config.save();
else
keyboard.check_hotkeys(hard_keyboard);
end
end
function keyboard.register_hotkey(hard_keyboard)
if customization_menu.all_UI_waiting_for_key then
for key, key_name in pairs(keyboard.keys) do
if get_release_method:call(hard_keyboard, key) then
config.current_config.global_settings.hotkeys.all_UI = key;
customization_menu.all_UI_waiting_for_key = false;
return true;
end
end
elseif customization_menu.small_monster_UI_waiting_for_key then
for key, key_name in pairs(keyboard.keys) do
if get_release_method:call(hard_keyboard, key) then
config.current_config.global_settings.hotkeys.small_monster_UI = key;
customization_menu.small_monster_UI_waiting_for_key = false;
return true;
end
end
elseif customization_menu.large_monster_UI_waiting_for_key then
for key, key_name in pairs(keyboard.keys) do
if get_release_method:call(hard_keyboard, key) then
config.current_config.global_settings.hotkeys.large_monster_UI = key;
customization_menu.large_monster_UI_waiting_for_key = false;
return true;
end
end
elseif customization_menu.large_monster_dynamic_UI_waiting_for_key then
for key, key_name in pairs(keyboard.keys) do
if get_release_method:call(hard_keyboard, key) then
config.current_config.global_settings.hotkeys.large_monster_dynamic_UI = key;
customization_menu.large_monster_dynamic_UI_waiting_for_key = false;
return true;
end
end
elseif customization_menu.large_monster_static_UI_waiting_for_key then
for key, key_name in pairs(keyboard.keys) do
if get_release_method:call(hard_keyboard, key) then
config.current_config.global_settings.hotkeys.large_monster_static_UI = key;
customization_menu.large_monster_static_UI_waiting_for_key = false;
return true;
end
end
elseif customization_menu.large_monster_highlighted_UI_waiting_for_key then
for key, key_name in pairs(keyboard.keys) do
if get_release_method:call(hard_keyboard, key) then
config.current_config.global_settings.hotkeys.large_monster_highlighted_UI = key;
customization_menu.large_monster_highlighted_UI_waiting_for_key = false;
return true;
end
end
elseif customization_menu.time_UI_waiting_for_key then
for key, key_name in pairs(keyboard.keys) do
if get_release_method:call(hard_keyboard, key) then
config.current_config.global_settings.hotkeys.time_UI = key;
customization_menu.time_UI_waiting_for_key = false;
return true;
end
end
elseif customization_menu.damage_meter_UI_waiting_for_key then
for key, key_name in pairs(keyboard.keys) do
if get_release_method:call(hard_keyboard, key) then
config.current_config.global_settings.hotkeys.damage_meter_UI = key;
customization_menu.damage_meter_UI_waiting_for_key = false;
return true;
end
end
end
end
function keyboard.check_hotkeys(hard_keyboard)
if get_release_method:call(hard_keyboard, config.current_config.global_settings.hotkeys.all_UI) then
local is_any_enabled = config.current_config.time_UI.enabled
or config.current_config.small_monster_UI.enabled
or config.current_config.large_monster_UI.dynamic.enabled
or config.current_config.large_monster_UI.static.enabled
or config.current_config.large_monster_UI.highlighted.enabled
or config.current_config.damage_meter_UI.enabled;
config.current_config.time_UI.enabled = not is_any_enabled;
config.current_config.small_monster_UI.enabled = not is_any_enabled;
config.current_config.large_monster_UI.dynamic.enabled = not is_any_enabled;
config.current_config.large_monster_UI.static.enabled = not is_any_enabled;
config.current_config.large_monster_UI.highlighted.enabled = not is_any_enabled;
config.current_config.damage_meter_UI.enabled = not is_any_enabled;
end
if get_release_method:call(hard_keyboard, config.current_config.global_settings.hotkeys.small_monster_UI) then
config.current_config.small_monster_UI.enabled = not config.current_config.small_monster_UI.enabled;
end
if get_release_method:call(hard_keyboard, config.current_config.global_settings.hotkeys.large_monster_UI) then
local is_any_enabled = config.current_config.large_monster_UI.dynamic.enabled
or config.current_config.large_monster_UI.static.enabled
or config.current_config.large_monster_UI.highlighted.enabled;
config.current_config.large_monster_UI.dynamic.enabled = not is_any_enabled;
config.current_config.large_monster_UI.static.enabled = not is_any_enabled;
config.current_config.large_monster_UI.highlighted.enabled = not is_any_enabled;
end
if get_release_method:call(hard_keyboard, config.current_config.global_settings.hotkeys.large_monster_dynamic_UI) then
config.current_config.large_monster_UI.dynamic.enabled = not config.current_config.large_monster_UI.dynamic.enabled;
end
if get_release_method:call(hard_keyboard, config.current_config.global_settings.hotkeys.large_monster_static_UI) then
config.current_config.large_monster_UI.static.enabled = not config.current_config.large_monster_UI.static.enabled;
end
if get_release_method:call(hard_keyboard, config.current_config.global_settings.hotkeys.large_monster_highlighted_UI) then
config.current_config.large_monster_UI.highlighted.enabled = not config.current_config.large_monster_UI.highlighted.enabled;
end
if get_release_method:call(hard_keyboard, config.current_config.global_settings.hotkeys.time_UI) then
config.current_config.time_UI.enabled = not config.current_config.time_UI.enabled;
end
if get_release_method:call(hard_keyboard, config.current_config.global_settings.hotkeys.damage_meter_UI) then
config.current_config.damage_meter_UI.enabled = not config.current_config.damage_meter_UI.enabled;
end
end
function keyboard.init_module()
singletons = require("MHR_Overlay.Game_Handler.singletons");
customization_menu = require("MHR_Overlay.UI.customization_menu");
player = require("MHR_Overlay.Damage_Meter.player");
small_monster = require("MHR_Overlay.Monsters.small_monster");
large_monster = require("MHR_Overlay.Monsters.large_monster");
damage_meter_UI = require("MHR_Overlay.UI.Modules.damage_meter_UI");
time = require("MHR_Overlay.Game_Handler.time");
end
return keyboard;

View File

@@ -5,10 +5,12 @@ local player;
local small_monster;
local large_monster;
local damage_meter_UI;
local time;
quest_status.index = 0;
quest_status.is_online = false;
quest_status.is_training_area = false;
quest_status.update_is_result_screen = false;
local quest_manager_type_definition = sdk.find_type_definition("snow.QuestManager");
local on_changed_game_status = quest_manager_type_definition:get_method("onChangedGameStatus");
@@ -25,14 +27,15 @@ end);
function quest_status.update(args)
local new_quest_status = sdk.to_int64(args[3]);
if new_quest_status ~= nil then
if (quest_status.index < 2 and new_quest_status == 2) or
new_quest_status < 2 then
if (quest_status.index < 2 and new_quest_status == 2)
or new_quest_status < 2 then
player.list = {};
player.total = player.new(0, "Total", 0);
player.init();
small_monster.list = {};
large_monster.list = {};
damage_meter_UI.freeze_displayed_players = false;
damage_meter_UI.last_displayed_players = {};
time.last_whole_seconds = 0;
end
quest_status.index = new_quest_status;
@@ -53,6 +56,7 @@ function quest_status.init()
quest_status.index = new_quest_status;
quest_status.update_is_online();
quest_status.update_is_training_area();
quest_status.update_is_result_screen();
end
function quest_status.update_is_online()
@@ -86,6 +90,20 @@ function quest_status.update_is_training_area()
quest_status.is_training_area = _is_training_area;
end
function quest_status.update_is_result_screen()
if singletons.quest_manager == nil then
customization_menu.status = "No quest manager";
return;
end
local is_result_demo_play_start = singletons.quest_manager:call("isResultDemoPlayStart");
if is_result_demo_play_start == nil then
return;
end
quest_status.is_result_screen = is_result_demo_play_start;
end
function quest_status.init_module()
singletons = require("MHR_Overlay.Game_Handler.singletons");
customization_menu = require("MHR_Overlay.UI.customization_menu");
@@ -93,7 +111,8 @@ function quest_status.init_module()
small_monster = require("MHR_Overlay.Monsters.small_monster");
large_monster = require("MHR_Overlay.Monsters.large_monster");
damage_meter_UI = require("MHR_Overlay.UI.Modules.damage_meter_UI");
time = require("MHR_Overlay.Game_Handler.time");
quest_status.init();
end

View File

@@ -1,4 +1,6 @@
local config = require "MHR_Overlay.Misc.config"
local screen = {};
local config;
screen.width = 1920;
screen.height = 1080;
@@ -16,35 +18,40 @@ function screen.update_window_size()
end
function screen.calculate_absolute_coordinates(position)
local _position = {
x = position.x * config.current_config.global_settings.modifiers.global_position_modifier;
y = position.y * config.current_config.global_settings.modifiers.global_position_modifier;
}
-- top left
if position.anchor == "Top-Left" then
return {x = position.x, y = position.y};
return {x = _position.x, y = _position.y};
end
-- top right
if position.anchor == "Top-Right" then
local screen_x = screen.width - position.x;
return {x = screen_x, y = position.y};
local screen_x = screen.width - _position.x;
return {x = screen_x, y = _position.y};
end
-- bottom left
if position.anchor == "Bottom-Left" then
local screen_y = screen.height - position.y;
return {x = position.x, y = screen_y};
local screen_y = screen.height - _position.y;
return {x = _position.x, y = screen_y};
end
-- bottom right
if position.anchor == "Bottom-Right" then
local screen_x = screen.width - position.x;
local screen_y = screen.height - position.y;
local screen_x = screen.width - _position.x;
local screen_y = screen.height - _position.y;
return {x = screen_x, y = screen_y};
end
return {x = position.x, y = position.y};
return {x = _position.x, y = _position.y};
end
function screen.init_module()
config = require("MHR_Overlay.Misc.config");
end
return screen;

View File

@@ -8,6 +8,7 @@ singletons.quest_manager = nil;
singletons.player_manager = nil;
singletons.village_area_manager = nil;
singletons.gui_manager = nil;
singletons.game_keyboard = nil;
function singletons.init()
singletons.init_message_manager();
@@ -18,6 +19,7 @@ function singletons.init()
singletons.init_player_manager();
singletons.init_village_area_manager();
singletons.init_gui_manager();
singletons.init_game_keyboard()
end
function singletons.init_message_manager()
@@ -126,6 +128,18 @@ function singletons.init_gui_manager()
return singletons.gui_manager;
end
function singletons.init_game_keyboard()
if singletons.game_keyboard ~= nil then
return;
end
singletons.game_keyboard = sdk.get_managed_singleton("snow.GameKeyboard");
if singletons.game_keyboard == nil then
--log.error("[MHR Overlay] No game keyboard");
end
return singletons.ggame_keyboard;
end
function singletons.init_module()
singletons.init();

View File

@@ -43,9 +43,12 @@ function time.tick()
end
function time.update_players_dps()
local new_total_dps = 0;
for _, _player in pairs(player.list) do
if _player.join_time == -1 then
_player.join_time = time.total_elapsed_seconds;
end
if config.current_config.damage_meter_UI.settings.dps_mode == "Quest Time" then
if time.total_elapsed_seconds > 0 then
_player.dps = _player.display.total_damage / time.total_elapsed_seconds;