From 3f689e0edf0db0074d09fa25a5daf52f047a13f0 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 30 Apr 2012 03:34:29 -0300 Subject: [PATCH] optimize UIWidget for largers NPC trades --- modules/game_npctrade/npctrade.lua | 2 +- modules/game_npctrade/npctrade.otui | 2 +- src/framework/ui/uiwidget.cpp | 20 +++++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/modules/game_npctrade/npctrade.lua b/modules/game_npctrade/npctrade.lua index 959e8bbf..64cb3fc0 100644 --- a/modules/game_npctrade/npctrade.lua +++ b/modules/game_npctrade/npctrade.lua @@ -148,7 +148,7 @@ local function refreshTradeItems() for key,item in pairs(currentTradeItems) do local itemBox = createWidget('NPCItemBox', itemsPanel) itemBox.item = item - + local name = item.name local weight = string.format('%.2f', item.weight) .. ' ' .. WEIGHT_UNIT local price = item.price .. ' ' .. CURRENCY diff --git a/modules/game_npctrade/npctrade.otui b/modules/game_npctrade/npctrade.otui index bfe4b647..1c8ae6d6 100644 --- a/modules/game_npctrade/npctrade.otui +++ b/modules/game_npctrade/npctrade.otui @@ -19,7 +19,7 @@ NPCItemBox < UICheckBox anchors.horizontalCenter: parent.horizontalCenter margin-top: 5 - $checked: + $checked: border-color: #ffffff $hover !checked: diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index effdb586..e99f1693 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -133,6 +133,8 @@ void UIWidget::addChild(const UIWidgetPtr& child) return; } + UIWidgetPtr oldLastChild = getLastChild(); + m_children.push_back(child); child->setParent(asUIWidget()); @@ -145,7 +147,12 @@ void UIWidget::addChild(const UIWidgetPtr& child) // update new child states child->updateStates(); - updateChildrenIndexStates(); + + // update old child index states + if(oldLastChild) { + oldLastChild->updateState(Fw::MiddleState); + oldLastChild->updateState(Fw::LastState); + } g_ui.onWidgetAppear(child); } @@ -714,8 +721,15 @@ void UIWidget::destroyChildren() if(layout) layout->disableUpdates(); - while(!m_children.empty()) - m_children[0]->destroy(); + m_focusedChild = nullptr; + m_lockedChildren.clear(); + while(!m_children.empty()) { + UIWidgetPtr child = m_children.front(); + m_children.pop_front(); + child->setParent(nullptr); + m_layout->removeWidget(child); + child->destroy(); + } layout->enableUpdates(); }