focus and active states fixes
This commit is contained in:
parent
fa8291a433
commit
63c018ba4c
|
@ -2,6 +2,9 @@ Label < UILabel
|
||||||
font: verdana-11px-antialised
|
font: verdana-11px-antialised
|
||||||
color: #aaaaaa
|
color: #aaaaaa
|
||||||
|
|
||||||
|
$disabled:
|
||||||
|
color: #aaaaaa88
|
||||||
|
|
||||||
LargerLabel < Label
|
LargerLabel < Label
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,5 +7,8 @@ LineEdit < UILineEdit
|
||||||
source: /core_styles/images/panel_flat.png
|
source: /core_styles/images/panel_flat.png
|
||||||
border: 1
|
border: 1
|
||||||
|
|
||||||
|
$disabled:
|
||||||
|
color: #aaaaaa88
|
||||||
|
|
||||||
PasswordLineEdit < LineEdit
|
PasswordLineEdit < LineEdit
|
||||||
text hidden: true
|
text hidden: true
|
||||||
|
|
|
@ -2,6 +2,7 @@ Window < UIWindow
|
||||||
font: verdana-11px-antialised
|
font: verdana-11px-antialised
|
||||||
size: 200 200
|
size: 200 200
|
||||||
opacity: 255
|
opacity: 255
|
||||||
|
color: white
|
||||||
background-color: white
|
background-color: white
|
||||||
head height: 20
|
head height: 20
|
||||||
head text align: center
|
head text align: center
|
||||||
|
@ -15,6 +16,9 @@ Window < UIWindow
|
||||||
$pressed:
|
$pressed:
|
||||||
opacity: 192
|
opacity: 192
|
||||||
|
|
||||||
|
$disabled:
|
||||||
|
color: #aaaaaa88
|
||||||
|
|
||||||
MiniWindow < UIWindow
|
MiniWindow < UIWindow
|
||||||
font: verdana-11px-antialised
|
font: verdana-11px-antialised
|
||||||
size: 192 200
|
size: 192 200
|
||||||
|
|
|
@ -7,8 +7,17 @@ local motdNumber
|
||||||
local motdMessage
|
local motdMessage
|
||||||
|
|
||||||
-- private functions
|
-- private functions
|
||||||
|
local function clearAccountFields()
|
||||||
|
enterGame:getChildById('accountNameLineEdit'):clearText()
|
||||||
|
enterGame:getChildById('accountPasswordLineEdit'):clearText()
|
||||||
|
enterGame:getChildById('accountNameLineEdit'):focus()
|
||||||
|
Configs.set('account', nil)
|
||||||
|
Configs.set('password', nil)
|
||||||
|
end
|
||||||
|
|
||||||
local function onError(protocol, error)
|
local function onError(protocol, error)
|
||||||
loadBox:destroy()
|
loadBox:destroy()
|
||||||
|
clearAccountFields()
|
||||||
local errorBox = displayErrorBox('Login Error', error)
|
local errorBox = displayErrorBox('Login Error', error)
|
||||||
errorBox.onOk = EnterGame.show
|
errorBox.onOk = EnterGame.show
|
||||||
end
|
end
|
||||||
|
@ -25,10 +34,7 @@ local function onCharacterList(protocol, characters, premDays)
|
||||||
Configs.set('password', EnterGame.password)
|
Configs.set('password', EnterGame.password)
|
||||||
Configs.set('autologin', tostring(enterGame:getChildById('autoLoginBox'):isChecked()))
|
Configs.set('autologin', tostring(enterGame:getChildById('autoLoginBox'):isChecked()))
|
||||||
else
|
else
|
||||||
Configs.set('account', nil)
|
clearAccountFields()
|
||||||
Configs.set('password', nil)
|
|
||||||
enterGame:getChildById('accountNameLineEdit'):clearText()
|
|
||||||
enterGame:getChildById('accountPasswordLineEdit'):clearText()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
loadBox:destroy()
|
loadBox:destroy()
|
||||||
|
@ -59,6 +65,7 @@ function EnterGame.create()
|
||||||
enterGame:getChildById('serverPortLineEdit'):setText(port)
|
enterGame:getChildById('serverPortLineEdit'):setText(port)
|
||||||
enterGame:getChildById('autoLoginBox'):setChecked(autologin)
|
enterGame:getChildById('autoLoginBox'):setChecked(autologin)
|
||||||
enterGame:getChildById('rememberPasswordBox'):setChecked(#account > 0)
|
enterGame:getChildById('rememberPasswordBox'):setChecked(#account > 0)
|
||||||
|
enterGame:getChildById('accountNameLineEdit'):focus()
|
||||||
|
|
||||||
if #account > 0 and autologin then
|
if #account > 0 and autologin then
|
||||||
addEvent(EnterGame.doLogin)
|
addEvent(EnterGame.doLogin)
|
||||||
|
|
|
@ -16,7 +16,7 @@ end
|
||||||
function Game.createInterface()
|
function Game.createInterface()
|
||||||
Background.hide()
|
Background.hide()
|
||||||
CharacterList.destroyLoadBox()
|
CharacterList.destroyLoadBox()
|
||||||
Game.gameUi = loadUI('/game/game.otui', UI.root)
|
Game.gameUi = UI.loadAndDisplay('/game/game.otui')
|
||||||
UI.root:moveChildToIndex(Game.gameUi, 1)
|
UI.root:moveChildToIndex(Game.gameUi, 1)
|
||||||
Game.gameMapPanel = Game.gameUi:getChildById('mapPanel')
|
Game.gameMapPanel = Game.gameUi:getChildById('mapPanel')
|
||||||
Game.gameRightPanel = Game.gameUi:getChildById('rightPanel')
|
Game.gameRightPanel = Game.gameUi:getChildById('rightPanel')
|
||||||
|
|
|
@ -104,7 +104,7 @@ void UIWidget::renderChildren()
|
||||||
{
|
{
|
||||||
// draw children
|
// draw children
|
||||||
for(const UIWidgetPtr& child : m_children) {
|
for(const UIWidgetPtr& child : m_children) {
|
||||||
// render only visible children with a valid rect
|
// render only visible children with a valid rect inside our rect
|
||||||
if(child->isExplicitlyVisible() && child->getRect().isValid() && child->getRect().intersects(m_rect)) {
|
if(child->isExplicitlyVisible() && child->getRect().isValid() && child->getRect().intersects(m_rect)) {
|
||||||
// store current graphics opacity
|
// store current graphics opacity
|
||||||
int oldOpacity = g_graphics.getOpacity();
|
int oldOpacity = g_graphics.getOpacity();
|
||||||
|
@ -125,12 +125,43 @@ void UIWidget::renderChildren()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIWidget::setEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
if(enabled != m_enabled) {
|
||||||
|
m_enabled = enabled;
|
||||||
|
|
||||||
|
updateState(Fw::DisabledState);
|
||||||
|
updateState(Fw::ActiveState);
|
||||||
|
updateState(Fw::HoverState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UIWidget::setVisible(bool visible)
|
void UIWidget::setVisible(bool visible)
|
||||||
{
|
{
|
||||||
m_visible = visible;
|
if(m_visible != visible) {
|
||||||
if(!visible && isFocused()) {
|
m_visible = visible;
|
||||||
if(UIWidgetPtr parent = getParent())
|
|
||||||
parent->focusNextChild(Fw::ActiveFocusReason);
|
// make parent focus another child
|
||||||
|
if(!visible && isFocused()) {
|
||||||
|
if(UIWidgetPtr parent = getParent())
|
||||||
|
parent->focusPreviousChild(Fw::ActiveFocusReason);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateState(Fw::ActiveState);
|
||||||
|
updateState(Fw::HoverState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIWidget::setFocusable(bool focusable)
|
||||||
|
{
|
||||||
|
if(m_focusable != focusable) {
|
||||||
|
m_focusable = focusable;
|
||||||
|
|
||||||
|
// make parent focus another child
|
||||||
|
if(!focusable && isFocused()) {
|
||||||
|
if(UIWidgetPtr parent = getParent())
|
||||||
|
parent->focusPreviousChild(Fw::ActiveFocusReason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +239,8 @@ void UIWidget::unlock()
|
||||||
|
|
||||||
void UIWidget::focus()
|
void UIWidget::focus()
|
||||||
{
|
{
|
||||||
|
if(!m_focusable)
|
||||||
|
return;
|
||||||
if(UIWidgetPtr parent = getParent())
|
if(UIWidgetPtr parent = getParent())
|
||||||
parent->focusChild(asUIWidget(), Fw::ActiveFocusReason);
|
parent->focusChild(asUIWidget(), Fw::ActiveFocusReason);
|
||||||
}
|
}
|
||||||
|
@ -357,14 +390,6 @@ void UIWidget::addChild(const UIWidgetPtr& child)
|
||||||
m_children.push_back(child);
|
m_children.push_back(child);
|
||||||
child->setParent(asUIWidget());
|
child->setParent(asUIWidget());
|
||||||
|
|
||||||
// focus must be set after the style has been loaded
|
|
||||||
auto self = asUIWidget();
|
|
||||||
g_dispatcher.addEvent([self,child]() {
|
|
||||||
// always focus new child
|
|
||||||
if(child->getParent() == self && child->isFocusable() && child->isExplicitlyVisible() && child->isExplicitlyEnabled())
|
|
||||||
self->focusChild(child, Fw::ActiveFocusReason);
|
|
||||||
});
|
|
||||||
|
|
||||||
// create default layout
|
// create default layout
|
||||||
if(!m_layout)
|
if(!m_layout)
|
||||||
m_layout = UILayoutPtr(new UIAnchorLayout(asUIWidget()));
|
m_layout = UILayoutPtr(new UIAnchorLayout(asUIWidget()));
|
||||||
|
@ -670,7 +695,7 @@ void UIWidget::updateState(Fw::WidgetState state)
|
||||||
UIWidgetPtr parent;
|
UIWidgetPtr parent;
|
||||||
do {
|
do {
|
||||||
parent = widget->getParent();
|
parent = widget->getParent();
|
||||||
if(!widget->isExplicitlyEnabled() || !widget->getRect().contains(mousePos) ||
|
if(!widget->isExplicitlyEnabled() || !widget->isExplicitlyVisible() || !widget->getRect().contains(mousePos) ||
|
||||||
(parent && widget != parent->getChildByPos(mousePos))) {
|
(parent && widget != parent->getChildByPos(mousePos))) {
|
||||||
newStatus = false;
|
newStatus = false;
|
||||||
break;
|
break;
|
||||||
|
@ -760,6 +785,8 @@ void UIWidget::updateStyle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: prevent setting already set proprieties
|
||||||
|
|
||||||
applyStyle(newStateStyle);
|
applyStyle(newStateStyle);
|
||||||
m_stateStyle = newStateStyle;
|
m_stateStyle = newStateStyle;
|
||||||
}
|
}
|
||||||
|
@ -904,6 +931,12 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_firstOnStyle) {
|
||||||
|
// always focus new child
|
||||||
|
if(isFocusable() && isExplicitlyVisible() && isExplicitlyEnabled())
|
||||||
|
focus();
|
||||||
|
}
|
||||||
|
|
||||||
m_firstOnStyle = false;
|
m_firstOnStyle = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,10 @@ public:
|
||||||
void renderChildren();
|
void renderChildren();
|
||||||
|
|
||||||
void setVisible(bool visible);
|
void setVisible(bool visible);
|
||||||
void setEnabled(bool enabled) { m_enabled = enabled; updateState(Fw::DisabledState); }
|
void setEnabled(bool enabled);
|
||||||
void setPressed(bool pressed) { m_pressed = pressed; updateState(Fw::PressedState); }
|
void setPressed(bool pressed) { m_pressed = pressed; updateState(Fw::PressedState); }
|
||||||
void setId(const std::string& id) { m_id = id; }
|
void setId(const std::string& id) { m_id = id; }
|
||||||
void setFocusable(bool focusable) { m_focusable = focusable; }
|
void setFocusable(bool focusable);
|
||||||
void setPhantom(bool phantom) { m_phantom = phantom; }
|
void setPhantom(bool phantom) { m_phantom = phantom; }
|
||||||
void setStyle(const std::string& styleName);
|
void setStyle(const std::string& styleName);
|
||||||
void setStyleFromNode(const OTMLNodePtr& styleNode);
|
void setStyleFromNode(const OTMLNodePtr& styleNode);
|
||||||
|
|
Loading…
Reference in New Issue