From 09f5033dec67c5754a3d2bf2579be5f4be6c82d5 Mon Sep 17 00:00:00 2001 From: kokekanon <114332266+kokekanon@users.noreply.github.com> Date: Mon, 19 May 2025 17:35:41 -0400 Subject: [PATCH] fix: #1129 onHungryChange (#1154) * fix:1129 --- modules/game_interface/widgets/statsbar.lua | 29 +++++++++++++++++++++ modules/game_skills/skills.lua | 26 +++++++++++++++--- modules/gamelib/player.lua | 1 + sonar-project.properties | 1 + 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/modules/game_interface/widgets/statsbar.lua b/modules/game_interface/widgets/statsbar.lua index 800348233..032d2f71a 100644 --- a/modules/game_interface/widgets/statsbar.lua +++ b/modules/game_interface/widgets/statsbar.lua @@ -668,3 +668,32 @@ function StatsBar.terminate() StatsBar.destroyAllBars() end + +function StatsBar.onHungryChange(regenerationTime, alert) + local contents = getStatsBarsIconContent() + local info = Icons[PlayerStates.Hungry] + if regenerationTime <= alert then + for _, contentData in ipairs(contents) do + local icon = contentData.content:getChildById(info.id) + if not icon then + icon = g_ui.createWidget('ConditionWidget', contentData.content) + icon:setId(info.id) + icon:setImageSource("/images/game/states/player-state-flags") + icon:setImageClip(((info.clip - 1) * 9) .. ' 0 9 9') + icon:setTooltip(info.tooltip) + icon:setImageSize(tosize("9 9")) + if contentData.loadIconTransparent then + icon:setMarginTop(5) + end + end + end + else + for _, contentData in ipairs(contents) do + local icon = contentData.content:getChildById(info.id) + if icon then + icon:destroy() + icon = nil + end + end + end +end diff --git a/modules/game_skills/skills.lua b/modules/game_skills/skills.lua index 7c9294b38..5921190b1 100644 --- a/modules/game_skills/skills.lua +++ b/modules/game_skills/skills.lua @@ -235,6 +235,9 @@ end function online() skillsWindow:setupOnStart() -- load character window configuration refresh() + if g_game.getFeature(GameEnterGameShowAppearance) then + skillsWindow:recursiveGetChildById('regenerationTime'):getChildByIndex(1):setText('Food') + end end function refresh() @@ -509,14 +512,31 @@ function onRegenerationChange(localPlayer, regenerationTime) if not g_game.getFeature(GamePlayerRegenerationTime) or regenerationTime < 0 then return end + local hours = math.floor(regenerationTime / 3600) local minutes = math.floor(regenerationTime / 60) local seconds = regenerationTime % 60 if seconds < 10 then seconds = '0' .. seconds end - - setSkillValue('regenerationTime', minutes .. ':' .. seconds) - checkAlert('regenerationTime', regenerationTime, false, 300) + if minutes < 10 then + minutes = '0' .. minutes + end + if hours < 10 then + hours = '0' .. hours + end + local fmt = "" + local alert = 300 + if g_game.getFeature(GameEnterGameShowAppearance) then + fmt = string.format("%02d:%02d:%02d", hours, minutes, seconds) + alert = 0 + else + fmt = string.format("%02d:%02d", minutes, seconds) + end + setSkillValue('regenerationTime', fmt) + checkAlert('regenerationTime', regenerationTime, false, alert) + if g_game.getFeature(GameEnterGameShowAppearance) then + modules.game_interface.StatsBar.onHungryChange(regenerationTime, alert) + end end function onSpeedChange(localPlayer, speed) diff --git a/modules/gamelib/player.lua b/modules/gamelib/player.lua index 0365d44f2..66938f5f4 100644 --- a/modules/gamelib/player.lua +++ b/modules/gamelib/player.lua @@ -67,6 +67,7 @@ Icons[PlayerStates.GoshnarTaint5] = { clip = 26, tooltip = tr('You are GoshnarTa Icons[PlayerStates.NewManaShield] = { clip = 27, tooltip = tr('You are NewManaShield'), id = 'condition_NewManaShield' } Icons[PlayerStates.Agony] = { clip = 28, tooltip = tr('You are Agony'), id = 'condition_Agony' } Icons[PlayerStates.Rewards] = { clip = 30, tooltip = tr('Rewards'), id = 'condition_Rewards' } +Icons[PlayerStates.Hungry] = { clip = 32, tooltip = tr('You are hungry'), id = 'condition_hungry' } InventorySlotOther = 0 InventorySlotHead = 1 diff --git a/sonar-project.properties b/sonar-project.properties index 03c900c4b..0dac88b04 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -5,3 +5,4 @@ sonar.projectVersion=1.0 sonar.sources=./src sonar.sourceEncoding=UTF-8 sonar.cfamily.cpp20=true +sonar.exclusions=**/*.html, **/*.css