progress bar and skills improve

This commit is contained in:
Henrique 2011-11-14 00:40:18 -02:00
parent f46e5aae43
commit f3b3ecada1
9 changed files with 132 additions and 22 deletions

View File

@ -140,6 +140,7 @@ SET(SOURCES src/framework/ui/uiframecounter.cpp
src/framework/ui/uianchorlayout.cpp src/framework/ui/uianchorlayout.cpp
src/framework/ui/uiverticallayout.cpp src/framework/ui/uiverticallayout.cpp
src/framework/ui/uilayout.cpp src/framework/ui/uilayout.cpp
src/framework/ui/uiprogressbar.cpp
) )
IF(HANDLE_EXCEPTIONS) IF(HANDLE_EXCEPTIONS)

View File

@ -28,9 +28,10 @@ function Skills.create()
levelLabel:setId('skillLevelId' .. i) levelLabel:setId('skillLevelId' .. i)
levelLabel:setText('0') levelLabel:setText('0')
local percentPanel = UIWidget.create() local percentBar = UIProgressBar.create()
skillPanel:addChild(percentPanel) skillPanel:addChild(percentBar)
percentPanel:setStyle('SkillPercentPanel') percentBar:setStyle('SkillPercentPanel')
percentBar:setId('skillPercentId' .. i)
end end
end end
@ -46,8 +47,9 @@ function Game.onSkillUpdate(id, level, percent)
local levelLabel = skillPanel:getChildById('skillLevelId' .. (id + 1)) local levelLabel = skillPanel:getChildById('skillLevelId' .. (id + 1))
levelLabel:setText(level) levelLabel:setText(level)
--local percentLabel = skillPanel:getChildById('skillLevelId' .. id) local percentBar = skillPanel:getChildById('skillPercentId' .. (id + 1))
--levelLabel:setText(percent) percentBar:setPercent(percent)
percentBar:setTooltip(percent .. "% to go")
end end
connect(Game, { onLogin = Skills.create, connect(Game, { onLogin = Skills.create,

View File

@ -28,9 +28,10 @@ function Skills.create()
levelLabel:setId('skillLevelId' .. i) levelLabel:setId('skillLevelId' .. i)
levelLabel:setText('0') levelLabel:setText('0')
local percentPanel = UIWidget.create() local percentBar = UIProgressBar.create()
skillPanel:addChild(percentPanel) skillPanel:addChild(percentBar)
percentPanel:setStyle('SkillPercentPanel') percentBar:setStyle('SkillPercentPanel')
percentBar:setId('skillPercentId' .. i)
end end
end end
@ -40,14 +41,15 @@ function Skills.destroy()
end end
-- hooked events -- hooked events
function Game.setSkill(id, level, percent) function Game.onSkillUpdate(id, level, percent)
local skillPanel = skillWindow:getChildById('skillPanel') local skillPanel = skillWindow:getChildById('skillPanel')
local levelLabel = skillPanel:getChildById('skillLevelId' .. id) local levelLabel = skillPanel:getChildById('skillLevelId' .. (id + 1))
levelLabel:setText(level) levelLabel:setText(level)
--local percentLabel = skillPanel:getChildById('skillLevelId' .. id) local percentBar = skillPanel:getChildById('skillPercentId' .. (id + 1))
--levelLabel:setText(percent) percentBar:setPercent(percent)
percentBar:setTooltip("lalalalal2")
end end
connect(Game, { onLogin = Skills.create, connect(Game, { onLogin = Skills.create,

View File

@ -1,11 +1,10 @@
SkillFirstWidget < UIWidget SkillFirstWidget < UIWidget
margin.top: 2
anchors.top: parent.top anchors.top: parent.top
SkillNameLabel < Label SkillNameLabel < Label
font: verdana-11px-monochrome font: verdana-11px-monochrome
margin.top: 2 margin.top: 4
margin.left: 10 margin.left: 10
margin.right: 10 margin.right: 10
anchors.top: prev.bottom anchors.top: prev.bottom
@ -15,18 +14,18 @@ SkillNameLabel < Label
SkillLevelLabel < Label SkillLevelLabel < Label
font: verdana-11px-monochrome font: verdana-11px-monochrome
align: right align: right
margin.top: 2
margin.left: 10 margin.left: 10
margin.right: 10 margin.right: 10
anchors.top: prev.top anchors.top: prev.top
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
SkillPercentPanel < UIWidget SkillPercentPanel < UIProgressBar
color: blue color: black
background-color: red background-color: green
height: 4 tooltip: test
margin.top: 2 height: 5
margin.top: 3
margin.left: 10 margin.left: 10
margin.right: 10 margin.right: 10
anchors.top: prev.bottom anchors.top: prev.bottom
@ -36,7 +35,7 @@ SkillPercentPanel < UIWidget
MiniWindow MiniWindow
id: skillWindow id: skillWindow
title: Skills title: Skills
size: 200 185 size: 200 220
Panel Panel
id: skillPanel id: skillPanel
@ -44,4 +43,4 @@ MiniWindow
margin.top: 26 margin.top: 26
margin.bottom: 3 margin.bottom: 3
margin.left: 3 margin.left: 3
margin.right: 3 margin.right: 3

View File

@ -48,5 +48,10 @@ function ToolTip.hide()
end end
end end
function UIWidget:setTooltip(text)
self:applyStyle({ tooltip = text })
end
-- hooks -- hooks
connect(UIButton, { onHoverChange = onButtonHoverChange}) connect(UIButton, { onHoverChange = onButtonHoverChange})
connect(UIProgressBar, { onHoverChange = onButtonHoverChange})

View File

@ -108,6 +108,12 @@ void LuaInterface::registerFunctions()
g_lua.bindClassMemberFunction<UILabel>("setText", &UILabel::setText); g_lua.bindClassMemberFunction<UILabel>("setText", &UILabel::setText);
g_lua.bindClassMemberFunction("resizeToText", &UILabel::resizeToText); g_lua.bindClassMemberFunction("resizeToText", &UILabel::resizeToText);
// UILabel
g_lua.registerClass<UIProgressBar, UIWidget>();
g_lua.bindClassStaticFunction<UIProgressBar>("create", &UIWidget::create<UIProgressBar>);
g_lua.bindClassMemberFunction<UIProgressBar>("getPercent", &UIProgressBar::getPercent);
g_lua.bindClassMemberFunction<UIProgressBar>("setPercent", &UIProgressBar::setPercent);
// UIButton // UIButton
g_lua.registerClass<UIButton, UIWidget>(); g_lua.registerClass<UIButton, UIWidget>();
g_lua.bindClassStaticFunction<UIButton>("create", &UIWidget::create<UIButton>); g_lua.bindClassStaticFunction<UIButton>("create", &UIWidget::create<UIButton>);

View File

@ -30,5 +30,6 @@
#include "uilineedit.h" #include "uilineedit.h"
#include "uiwindow.h" #include "uiwindow.h"
#include "uiframecounter.h" #include "uiframecounter.h"
#include "uiprogressbar.h"
#endif #endif

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "uiprogressbar.h"
#include <framework/graphics/graphics.h>
#include <framework/otml/otmlnode.h>
void UIProgressBar::setup()
{
UIWidget::setup();
setPhantom(true);
setFocusable(false);
m_percent = 0;
}
void UIProgressBar::render()
{
UIWidget::render();
g_graphics.bindColor(m_foregroundColor);
g_graphics.drawBoundingRect(m_rect, 1);
Rect fillRect = m_rect.expanded(-1);
fillRect.setWidth(fillRect.width() * m_percent / 100.0);
g_graphics.bindColor(m_backgroundColor);
g_graphics.drawFilledRect(fillRect);
}
void UIProgressBar::setPercent(double percent)
{
assert(percent >= 0 && percent <= 100);
m_percent = percent;
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef UIPROGRESSBAR_H
#define UIPROGRESSBAR_H
#include "uiwidget.h"
class UIProgressBar : public UIWidget
{
public:
virtual void setup();
virtual void render();
void setPercent(double percent);
double getPercent() { return m_percent; }
private:
double m_percent;
};
#endif