From 5d54971568d3801e1aa146f02dcb2fe117d3806d Mon Sep 17 00:00:00 2001 From: Henrique Date: Thu, 3 Nov 2011 21:10:12 -0200 Subject: [PATCH] healthmana module --- modules/game/game.otmod~ | 17 ++++++++ modules/game/textmessage.lua~ | 60 ++++++++++++++++++++++++++ modules/health_mana/health.otmod~ | 14 ++++++ modules/health_mana/health_mana.lua | 42 ++++++++++++++++++ modules/health_mana/health_mana.lua~ | 42 ++++++++++++++++++ modules/health_mana/health_mana.otmod | 14 ++++++ modules/health_mana/health_mana.otui | 29 +++++++++++++ modules/health_mana/health_mana.otui~ | 29 +++++++++++++ modules/skills/skills.lua~ | 54 +++++++++++++++++++++++ src/otclient/net/protocolgameparse.cpp | 10 +++++ 10 files changed, 311 insertions(+) create mode 100644 modules/game/game.otmod~ create mode 100644 modules/game/textmessage.lua~ create mode 100644 modules/health_mana/health.otmod~ create mode 100644 modules/health_mana/health_mana.lua create mode 100644 modules/health_mana/health_mana.lua~ create mode 100644 modules/health_mana/health_mana.otmod create mode 100644 modules/health_mana/health_mana.otui create mode 100644 modules/health_mana/health_mana.otui~ create mode 100644 modules/skills/skills.lua~ diff --git a/modules/game/game.otmod~ b/modules/game/game.otmod~ new file mode 100644 index 00000000..b6659016 --- /dev/null +++ b/modules/game/game.otmod~ @@ -0,0 +1,17 @@ +Module + name: game + description: Create the game interface, where the ingame stuff starts + author: OTClient team + website: https://github.com/edubart/otclient + autoLoad: true + dependencies: + - core + - tibiafiles + - topmenu + - entergame + - background + + onLoad: | + require 'game' + require 'textmessage' + return true diff --git a/modules/game/textmessage.lua~ b/modules/game/textmessage.lua~ new file mode 100644 index 00000000..b49855b9 --- /dev/null +++ b/modules/game/textmessage.lua~ @@ -0,0 +1,60 @@ +TextMessage = {} + +-- require styles +importStyles '/game/ui/textmessage.otui' + +-- private variables +local bottomLabelWidget, centerLabelWidget +local messageTypes = { + first = 12, + { type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false }, + { type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false }, + { type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' }, + { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' }, + { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' }, + { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' }, + { type = 'MessageGreen', color = '#3FBE32', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' }, + { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = false, showOnWindow = true, windowLocation = 'BottomLabel' }, + { type = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false }, + { type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false } +} + +-- public functions +function TextMessage.create() + bottomLabelWidget = UILabel.create() + Game.gameMapPanel:addChild(bottomLabelWidget) + + centerLabelWidget = UILabel.create() + Game.gameMapPanel:addChild(centerLabelWidget) +end + +-- hooked events +function Game.onTextMessage(type, message) + local messageType = messageTypes[type - messageTypes.first] + + if messageType.showOnConsole then + -- TODO + end + + if messageType.showOnWindow then + local label + if messageType.windowLocation == 'BottomLabel' then + label = bottomLabelWidget + elseif messageType.windowLocation == 'CenterLabel' then + label = centerLabelWidget + end + + label:setVisible(true) + label:setForegroundColor(messageType.color) + label:setText(message) + + label:setStyle(messageType.windowLocation) + + time = #message * 75 + scheduleEvent(function() + label:setVisible(false) + end, time) + end +end + +connect(Game, { onLogin = TextMessage.create }) diff --git a/modules/health_mana/health.otmod~ b/modules/health_mana/health.otmod~ new file mode 100644 index 00000000..51262d89 --- /dev/null +++ b/modules/health_mana/health.otmod~ @@ -0,0 +1,14 @@ +Module + name: health_mana + description: Displays health and mana points + author: OTClient team + website: https://github.com/edubart/otclient + autoLoad: true + dependencies: + - game + + onLoad: | + require 'viplist' + return true + + diff --git a/modules/health_mana/health_mana.lua b/modules/health_mana/health_mana.lua new file mode 100644 index 00000000..f74eee85 --- /dev/null +++ b/modules/health_mana/health_mana.lua @@ -0,0 +1,42 @@ +HealthMana = {} + +-- private variables +local healthManaPanel = nil + +-- public functions +function HealthMana.create() + healthManaPanel = loadUI("/health_mana/health_mana.otui", Game.gameRightPanel) + + local healthLabel = UILabel.create() + healthManaPanel:addChild(healthLabel) + healthLabel:setId('healthLabel') + healthLabel:setStyle('HealthLabel') + healthLabel:setText('0 / 0') + + local manaLabel = UILabel.create() + healthManaPanel:addChild(manaLabel) + manaLabel:setId('manaLabel') + manaLabel:setStyle('ManaLabel') + manaLabel:setText('0 / 0') + + healthManaPanel:setHeight(healthLabel:getHeight() + manaLabel:getHeight()) +end + +function HealthMana.destroy() + healthManaPanel:destroy() + healthManaPanel = nil +end + +-- hooked events +function Game.onHealthChange(health, maxHealth) + local label = healthManaPanel:getChildById('healthLabel') + label:setText(health .. ' / ' .. maxHealth) +end + +function Game.onManaChange(mana, maxMana) + local label = healthManaPanel:getChildById('manaLabel') + label:setText(mana .. ' / ' .. maxMana) +end + +connect(Game, { onLogin = HealthMana.create, + onLogout = HealthMana.destroy }) diff --git a/modules/health_mana/health_mana.lua~ b/modules/health_mana/health_mana.lua~ new file mode 100644 index 00000000..6ee5f6a4 --- /dev/null +++ b/modules/health_mana/health_mana.lua~ @@ -0,0 +1,42 @@ +HealthMana = {} + +-- private variables +local healthManaPanel = nil + +-- public functions +function HealthMana.create() + healthManaPanel = loadUI("/health_mana/health_mana.otui", Game.gameRightPanel) + + local healthLabel = UILabel.create() + healthManaPanel:addChild(healthLabel) + healthLabel:setId('healthLabel') + healthLabel:setStyle('HealthLabel') + healthLabel:setText('0 / 0') + + local manaLabel = UILabel.create() + healthManaPanel:addChild(manaLabel) + manaLabel:setId('manaLabel') + manaLabel:setStyle('ManaLabel') + manaLabel:setText('1 / 1') + + healthManaPanel:setHeight(healthLabel:getHeight() + manaLabel:getHeight()) +end + +function HealthMana.destroy() + healthManaPanel:destroy() + healthManaPanel = nil +end + +-- hooked events +function Game.onHealthChange(health, maxHealth) + local label = healthManaPanel:getChildById('healthLabel') + label:setText(health .. ' / ' .. maxHealth) +end + +function Game.onManaChange(mana, maxMana) + local label = healthManaPanel:getChildById('manaLabel') + label:setText(mana .. ' / ' .. maxMana) +end + +connect(Game, { onLogin = HealthMana.create, + onLogout = HealthMana.destroy }) diff --git a/modules/health_mana/health_mana.otmod b/modules/health_mana/health_mana.otmod new file mode 100644 index 00000000..aa0c828b --- /dev/null +++ b/modules/health_mana/health_mana.otmod @@ -0,0 +1,14 @@ +Module + name: health_mana + description: Displays health and mana points + author: OTClient team + website: https://github.com/edubart/otclient + autoLoad: true + dependencies: + - game + + onLoad: | + require 'health_mana' + return true + + diff --git a/modules/health_mana/health_mana.otui b/modules/health_mana/health_mana.otui new file mode 100644 index 00000000..1c76692c --- /dev/null +++ b/modules/health_mana/health_mana.otui @@ -0,0 +1,29 @@ +HealthLabel < Label + color: white + background-color: red + align: center + font: verdana-11px-monochrome + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + image: /core_styles/images/empty_rect.png + +ManaLabel < Label + color: white + background-color: blue + align: center + font: verdana-11px-monochrome + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + image: /core_styles/images/empty_rect.png + +UIWindow + id: healthManaPanel + width: 192 + margin.top: 6 + margin.left: 6 + margin.right: 6 + move policy: free updated + image: /core_styles/images/empty_rect.png + diff --git a/modules/health_mana/health_mana.otui~ b/modules/health_mana/health_mana.otui~ new file mode 100644 index 00000000..44bd09a7 --- /dev/null +++ b/modules/health_mana/health_mana.otui~ @@ -0,0 +1,29 @@ +HealthLabel < Label + color: red + background-color: green + align: center + font: verdana-11px-monochrome + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + image: /core_styles/images/empty_rect.png + +ManaLabel < Label + color: blue + background-color: red + align: center + font: verdana-11px-monochrome + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + image: /core_styles/images/empty_rect.png + +UIWindow + id: healthManaPanel + width: 192 + margin.top: 6 + margin.left: 6 + margin.right: 6 + move policy: free updated + image: /core_styles/images/empty_rect.png + diff --git a/modules/skills/skills.lua~ b/modules/skills/skills.lua~ new file mode 100644 index 00000000..71fb79b5 --- /dev/null +++ b/modules/skills/skills.lua~ @@ -0,0 +1,54 @@ +Skills = {} + +-- private variables +local skillWindow = nil +local skills = {"Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"} + +-- public functions +function Skills.create() + skillWindow = loadUI("/skills/skills.otui", Game.gameRightPanel) + + local skillPanel = skillWindow:getChildById('skillPanel') + + -- create first widget cause of layout + local widget = UIWidget.create() + skillPanel:addChild(widget) + widget:setStyle('SkillFirstWidget') + + -- create skills + for i=1,#skills,1 do + local nameLabel = UILabel.create() + skillPanel:addChild(nameLabel) + nameLabel:setStyle('SkillNameLabel') + nameLabel:setText(skills[i]) + + local levelLabel = UILabel.create() + skillPanel:addChild(levelLabel) + levelLabel:setStyle('SkillLevelLabel') + levelLabel:setId('skillLevelId' .. i) + levelLabel:setText('0') + + local percentPanel = UIWidget.create() + skillPanel:addChild(percentPanel) + percentPanel:setStyle('SkillPercentPanel') + end +end + +function Skills.destroy() + skillWindow:destroy() + skillWindow = nil +end + +-- hooked events +function Game.setSkill(id, level, percent) + local skillPanel = skillWindow:getChildById('skillPanel') + + local levelLabel = skillPanel:getChildById('skillLevelId' .. id) + levelLabel:setText(level) + + --local percentLabel = skillPanel:getChildById('skillLevelId' .. id) + --levelLabel:setText(percent) +end + +connect(Game, { onLogin = Skills.create, + onLogout = Skills.destroy }) diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index ae2acfe6..a7ac9f53 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -631,12 +631,22 @@ void ProtocolGame::parsePlayerStats(InputMessage& msg) { m_localPlayer->setStatistic(Otc::Health, msg.getU16()); m_localPlayer->setStatistic(Otc::MaxHealth, msg.getU16()); + + g_dispatcher.addEvent([=] { + g_lua.callGlobalField("Game", "onHealthChange", m_localPlayer->getStatistic(Otc::Health), m_localPlayer->getStatistic(Otc::MaxHealth)); + }); + m_localPlayer->setStatistic(Otc::FreeCapacity, msg.getU32()); m_localPlayer->setStatistic(Otc::Experience, msg.getU32()); m_localPlayer->setStatistic(Otc::Level, msg.getU16()); m_localPlayer->setStatistic(Otc::LevelPercent, msg.getU8()); m_localPlayer->setStatistic(Otc::Mana, msg.getU16()); m_localPlayer->setStatistic(Otc::MaxMana, msg.getU16()); + + g_dispatcher.addEvent([=] { + g_lua.callGlobalField("Game", "onManaChange", m_localPlayer->getStatistic(Otc::Mana), m_localPlayer->getStatistic(Otc::MaxMana)); + }); + m_localPlayer->setStatistic(Otc::MagicLevel, msg.getU8()); m_localPlayer->setStatistic(Otc::MagicLevelPercent, msg.getU8()); m_localPlayer->setStatistic(Otc::Soul, msg.getU8());