Skip to content

Commit

Permalink
Added in_combat option which is off by default and means Balloon won'…
Browse files Browse the repository at this point in the history
…t open in combat
  • Loading branch information
onimitch committed Feb 28, 2024
1 parent 32a5b5d commit 754eef0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Balloon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ balloon.process_incoming_message = function(e)
end

balloon.process_balloon = function(message, mode)
-- Do we need to check if the player is in combat?
-- We only check if the player is engaged (has weapon out) but this should be enough for our use case.
if not balloon.settings.in_combat then
local entity = AshitaCore:GetMemoryManager():GetEntity()
local party = AshitaCore:GetMemoryManager():GetParty()
local player_index = party:GetMemberTargetIndex(0)
if entity:GetStatus(player_index) == 1 then
return
end
end

balloon.last_text = message
balloon.last_mode = mode

Expand All @@ -234,12 +245,6 @@ balloon.process_balloon = function(message, mode)
end
local timed = (not balloon.in_menu and not ends_with_prompt)

-- local timed = true
-- if (S{chat_modes.message, chat_modes.system}[mode] and message:endswith(defines.PROMPT_CHARS[1]))
-- or balloon.in_menu then -- or balloon.in_mog_menu
-- timed = false
-- end

-- Extract speaker name
local npc_prefix_start, npc_prefix_end = message:find('.- : ')
local npc_prefix = ''
Expand Down Expand Up @@ -280,7 +285,6 @@ balloon.process_balloon = function(message, mode)
-- strip the NPC name from the start of the message
if npc_prefix ~= '' then
message = message:sub(npc_prefix_end)
-- message = message:gsub(npc_prefix:gsub('-', '--'), '')
end

-- log debug info
Expand All @@ -305,12 +309,6 @@ balloon.process_balloon = function(message, mode)
-- Strip out prompt characters
message = message:gsub(defines.auto_prompt_chars_pattern, '')
message = message:gsub(defines.prompt_chars_pattern, '')
-- for _, prompt_chars in ipairs(defines.PROMPT_CHARS) do
-- local prompt_pos, _ = message:find(prompt_chars, -4, true)
-- if prompt_pos ~= nil then
-- message = message:sub(1, prompt_pos - 1)
-- end
-- end

message = message:gsub(chat_color_codes.standard, '[BL_c1]') --color code 1 (black/reset)
message = message:gsub(chat_color_codes.item, '[BL_c2]') --color code 2 (green/regular items)
Expand Down Expand Up @@ -432,6 +430,7 @@ local function print_help(isError)
{ '/balloon portrait', 'Toggle the display of character portraits, if the theme has settings for them.' },
{ '/balloon move_closes', 'Toggle balloon auto-close on player movement.' },
{ '/balloon always_on_top', 'Toggle always on top (IMGUI mode).' },
{ '/balloon in_combat', 'Toggle displaying balloon during combat.' },
{ '/balloon test <name> <lang> <mode>', 'Display a test bubble. Lang: - (auto), en or ja. Mode: 1 (dialogue), 2 (system). "/balloon test" to see the list of available tests.' },
}

Expand Down Expand Up @@ -553,7 +552,7 @@ ashita.events.register('command', 'balloon_command_cb', function(e)
-- Handle toggle options
-- Handle: /balloon portrait
-- Handle: /balloon move_closes
if (#args == 2 and args[2]:any('portrait', 'portraits', 'move_closes', 'move_close', 'always_on_top')) then
if (#args == 2 and args[2]:any('portrait', 'portraits', 'move_closes', 'move_close', 'always_on_top', 'in_combat')) then
local setting_key_alias = {
portrait = 'portraits',
move_closes = 'move_close',
Expand All @@ -562,6 +561,7 @@ ashita.events.register('command', 'balloon_command_cb', function(e)
portraits = 'Display portraits',
move_close = 'Close balloons on player movement',
always_on_top = 'Always on top (IMGUI mode)',
in_combat = 'Display in combat',
}
local setting_key = setting_key_alias[args[2]] or args[2]
local setting_name = setting_names[setting_key] or args[2]
Expand Down
1 change: 1 addition & 0 deletions defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defaults.theme = 'default'
defaults.scale = 1
defaults.portraits = true
defaults.always_on_top = true
defaults.in_combat = false

defaults.additional_chat_modes = {
144
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ You can use `/balloon` or `/bl`

`/balloon always_on_top` - Toggle always on top (IMGUI mode). This mode renders the final elements using IMGUI to ensure Balloon always appears in front of any other custom UI. If for some reason you have issues with this mode, you can use this command to disable it.

`/balloon in_combat` - Toggle displaying balloon during combat (off by default).

`/balloon test <name> <lang> <mode>` - Display a test bubble. Lang: "-" (auto), "en" or "ja". Mode: 1 (dialogue), 2 (system).

`/balloon test` - List all available tests.
Expand Down

0 comments on commit 754eef0

Please sign in to comment.