progress bar and skills improve

master
Henrique 13 years ago
parent f46e5aae43
commit f3b3ecada1

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

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

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

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

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

@ -108,6 +108,12 @@ void LuaInterface::registerFunctions()
g_lua.bindClassMemberFunction<UILabel>("setText", &UILabel::setText);
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
g_lua.registerClass<UIButton, UIWidget>();
g_lua.bindClassStaticFunction<UIButton>("create", &UIWidget::create<UIButton>);

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

@ -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;
}

@ -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
Loading…
Cancel
Save