Changed: Improve inventory search UI

--HG--
branch : develop
This commit is contained in:
Nimetu 2019-01-03 20:05:00 +02:00
parent 0099eb3ba4
commit c7d65c7063
2 changed files with 167 additions and 55 deletions

View file

@ -2625,6 +2625,7 @@
<!-- * EDIT BOX WIDGET * --> <!-- * EDIT BOX WIDGET * -->
<!-- ********************* --> <!-- ********************* -->
<template name="edit_box_widget" <template name="edit_box_widget"
active="true"
posref="TL TL" posref="TL TL"
text_x="0" text_x="0"
text_y="0" text_y="0"
@ -2669,8 +2670,10 @@
max_float_prec="5" max_float_prec="5"
tooltip="" tooltip=""
tooltip_parent="" tooltip_parent=""
negative_filter=""> negative_filter=""
render_layer="0">
<group id="#id" <group id="#id"
active="#active"
posref="#posref" posref="#posref"
x="#x" x="#x"
y="#y" y="#y"
@ -2679,7 +2682,8 @@
child_resize_hmargin="#child_resize_hmargin" child_resize_hmargin="#child_resize_hmargin"
sizeref="#sizeref" sizeref="#sizeref"
w="#w" w="#w"
h="#h"> h="#h"
render_layer="#render_layer">
<group type="edit_box" <group type="edit_box"
sizeref="w" sizeref="w"
w="-8" w="-8"
@ -2708,7 +2712,8 @@
max_float_prec="#max_float_prec" max_float_prec="#max_float_prec"
tooltip="#tooltip" tooltip="#tooltip"
tooltip_parent="#tooltip_parent" tooltip_parent="#tooltip_parent"
negative_filter="#negative_filter"> negative_filter="#negative_filter"
render_layer="#render_layer">
<view type="bitmap" <view type="bitmap"
id="bg" id="bg"
scale="true" scale="true"
@ -2716,7 +2721,8 @@
h="0" h="0"
w="0" w="0"
texture="#bg_texture" texture="#bg_texture"
inherit_gc_alpha="true" /> inherit_gc_alpha="true"
render_layer="#render_layer" />
<view id="edit_text" <view id="edit_text"
type="text" type="text"
continuous_update="#continuous_text_update" continuous_update="#continuous_text_update"
@ -2733,7 +2739,8 @@
shadow_color="#shadow_color" shadow_color="#shadow_color"
shadow_outline="#shadow_outline" shadow_outline="#shadow_outline"
hardtext="" hardtext=""
global_color="false" /> global_color="false"
render_layer="#render_layer" />
</group> </group>
<!-- border around the list --> <!-- border around the list -->
<view type="bitmap" <view type="bitmap"
@ -2741,25 +2748,29 @@
texture="W_box_top_left.tga" texture="W_box_top_left.tga"
posparent="eb" posparent="eb"
posref="TL BR" posref="TL BR"
inherit_gc_alpha="true" /> inherit_gc_alpha="true"
render_layer="#render_layer" />
<view type="bitmap" <view type="bitmap"
id="trb" id="trb"
texture="W_box_top_right.tga" texture="W_box_top_right.tga"
posparent="eb" posparent="eb"
posref="TR BL" posref="TR BL"
inherit_gc_alpha="true" /> inherit_gc_alpha="true"
render_layer="#render_layer" />
<view type="bitmap" <view type="bitmap"
id="brb" id="brb"
texture="W_box_bot_right.tga" texture="W_box_bot_right.tga"
posparent="eb" posparent="eb"
posref="BR TL" posref="BR TL"
inherit_gc_alpha="true" /> inherit_gc_alpha="true"
render_layer="#render_layer" />
<view type="bitmap" <view type="bitmap"
id="blb" id="blb"
texture="W_box_bot_left.tga" texture="W_box_bot_left.tga"
posparent="eb" posparent="eb"
posref="BL TR" posref="BL TR"
inherit_gc_alpha="true" /> inherit_gc_alpha="true"
render_layer="#render_layer" />
<view type="bitmap" <view type="bitmap"
id="tb" id="tb"
texture="W_box_top.tga" texture="W_box_top.tga"
@ -2769,7 +2780,8 @@
sizeref="w" sizeref="w"
w="0" w="0"
h="4" h="4"
inherit_gc_alpha="true" /> inherit_gc_alpha="true"
render_layer="#render_layer" />
<view type="bitmap" <view type="bitmap"
id="bb" id="bb"
texture="W_box_bot.tga" texture="W_box_bot.tga"
@ -2779,7 +2791,8 @@
sizeref="w" sizeref="w"
w="0" w="0"
h="4" h="4"
inherit_gc_alpha="true" /> inherit_gc_alpha="true"
render_layer="#render_layer" />
<view type="bitmap" <view type="bitmap"
id="lb" id="lb"
texture="W_box_left.tga" texture="W_box_left.tga"
@ -2789,7 +2802,8 @@
sizeref="h" sizeref="h"
h="0" h="0"
w="4" w="4"
inherit_gc_alpha="true" /> inherit_gc_alpha="true"
render_layer="#render_layer" />
<view type="bitmap" <view type="bitmap"
id="rb" id="rb"
texture="W_box_right.tga" texture="W_box_right.tga"
@ -2799,7 +2813,8 @@
sizeref="h" sizeref="h"
h="0" h="0"
w="4" w="4"
inherit_gc_alpha="true" /> inherit_gc_alpha="true"
render_layer="#render_layer" />
</group> </group>
</template> </template>
<!-- ******************************* --> <!-- ******************************* -->
@ -6337,6 +6352,7 @@
x="0" x="0"
y="0" y="0"
posref="BL BL" posref="BL BL"
posparent=""
dblink="" dblink=""
texture="" texture=""
tooltip="" tooltip=""
@ -6345,6 +6361,7 @@
id="but_#id" id="but_#id"
button_type="toggle_button" button_type="toggle_button"
posref="#posref" posref="#posref"
posparent="but_#posparent"
x="#x" x="#x"
y="#y" y="#y"
tx_normal="w_button_filter_off.tga" tx_normal="w_button_filter_off.tga"
@ -6371,6 +6388,7 @@
x="0" x="0"
y="0" y="0"
posref="BL BL" posref="BL BL"
posparent=""
dblink="" dblink=""
texture="" texture=""
tooltip="" tooltip=""
@ -6379,6 +6397,7 @@
id="but_#id" id="but_#id"
button_type="toggle_button" button_type="toggle_button"
posref="#posref" posref="#posref"
posparent="but_#posparent"
x="#x" x="#x"
y="#y" y="#y"
tx_normal="w_button_filter_off.tga" tx_normal="w_button_filter_off.tga"
@ -6553,83 +6572,109 @@
texture="W_line_hor.tga" /> texture="W_line_hor.tga" />
<link expr="eq(@UI:SAVE:#inv_type:ICON_LIST, 0)" <link expr="eq(@UI:SAVE:#inv_type:ICON_LIST, 0)"
target="bag_list:active,sep2:active" /> target="bag_list:active,sep2:active" />
<!-- details -->
<instance template="tinv_item_list_icon_swap"
id="detail"
x="-2"
y="10"
posref="BR MR"
dblink="UI:SAVE:#inv_type:ICON_LIST"
texture="details_on.tga"
tooltip="uittDetail" />
<link expr="ifthenelse(@UI:SAVE:#inv_type:ICON_LIST, 'details_off.tga', 'details_on.tga')"
target="bit_detail:texture" />
<!-- filter -->
<instance template="tinv_item_list_filter" <instance template="tinv_item_list_filter"
id="filter_tp" id="filter_tp"
x="-35" x="-8"
y="1" posref="ML MR"
posref="BR BR" posparent="detail"
inv_type="#inv_type" inv_type="#inv_type"
dblink="UI:SAVE:#inv_type:FILTER_TP" dblink="UI:SAVE:#inv_type:FILTER_TP"
texture="filter_tp.tga" texture="filter_tp.tga"
tooltip="uittFilterTP" /> tooltip="uittFilterTP" />
<instance template="tinv_item_list_filter" <instance template="tinv_item_list_filter"
id="filter_missmp" id="filter_missmp"
x="-60" x="-2"
y="1" posref="ML MR"
posref="BR BR" posparent="filter_tp"
inv_type="#inv_type" inv_type="#inv_type"
dblink="UI:SAVE:#inv_type:FILTER_MISSMP" dblink="UI:SAVE:#inv_type:FILTER_MISSMP"
texture="filter_mission.tga" texture="filter_mission.tga"
tooltip="uittFilterMissMP" /> tooltip="uittFilterMissMP" />
<instance template="tinv_item_list_filter" <instance template="tinv_item_list_filter"
id="filter_mp" id="filter_mp"
x="-85" x="-2"
y="1" posref="ML MR"
posref="BR BR" posparent="filter_missmp"
inv_type="#inv_type" inv_type="#inv_type"
dblink="UI:SAVE:#inv_type:FILTER_MP" dblink="UI:SAVE:#inv_type:FILTER_MP"
texture="filter_mps.tga" texture="filter_mps.tga"
tooltip="uittFilterMP" /> tooltip="uittFilterMP" />
<instance template="tinv_item_list_filter" <instance template="tinv_item_list_filter"
id="filter_tool" id="filter_tool"
x="-110" x="-2"
y="1" posref="ML MR"
posref="BR BR" posparent="filter_mp"
inv_type="#inv_type" inv_type="#inv_type"
dblink="UI:SAVE:#inv_type:FILTER_TOOL" dblink="UI:SAVE:#inv_type:FILTER_TOOL"
texture="filter_tools.tga" texture="filter_tools.tga"
tooltip="uittFilterTool" /> tooltip="uittFilterTool" />
<instance template="tinv_item_list_filter" <instance template="tinv_item_list_filter"
id="filter_weapon" id="filter_weapon"
x="-135" x="-2"
y="1" posref="ML MR"
posref="BR BR" posparent="filter_tool"
inv_type="#inv_type" inv_type="#inv_type"
dblink="UI:SAVE:#inv_type:FILTER_WEAPON" dblink="UI:SAVE:#inv_type:FILTER_WEAPON"
texture="filter_weapon.tga" texture="filter_weapon.tga"
tooltip="uittFilterWeapon" /> tooltip="uittFilterWeapon" />
<instance template="tinv_item_list_filter" <instance template="tinv_item_list_filter"
id="filter_armor" id="filter_armor"
x="-160" x="-2"
y="1" posref="ML MR"
posref="BR BR" posparent="filter_weapon"
inv_type="#inv_type" inv_type="#inv_type"
dblink="UI:SAVE:#inv_type:FILTER_ARMOR" dblink="UI:SAVE:#inv_type:FILTER_ARMOR"
texture="filter_armor.tga" texture="filter_armor.tga"
tooltip="uittFilterArmor" /> tooltip="uittFilterArmor" />
<!-- search -->
<ctrl type="button"
id="but_inv_search"
button_type="toggle_button"
x="-2"
posref="ML MR"
posparent="but_filter_armor"
tx_normal="w_button_filter_off.tga"
tx_pushed="w_button_filter_on.tga"
tx_over=""
tooltip="uittInventorySearch"
onclick_l="inv_search_button"
params_l="inv_query_eb" />
<view type="bitmap"
id="bit_inv_search"
posref="MM MM"
posparent="but_inv_search"
texture="w_help_1.tga"
global_color="false"
color="255 255 255 150" />
<instance template="edit_box_widget" <instance template="edit_box_widget"
id="inv_query_eb" id="inv_query_eb"
posref="BR BR" active="false"
x="-190" posref="TR BR"
y="1" posparent="but_detail"
x="0"
y="8"
w="100" w="100"
render_layer="9"
clear_on_escape="true" clear_on_escape="true"
enter_recover_focus="false" enter_recover_focus="false"
max_num_chars="20" max_num_chars="20"
max_historic="0" max_historic="0"
onenter="inv_set_search" onenter="inv_set_search"
onchange="inv_set_search" onchange_params="#inv_type" /> onchange="inv_set_search"
<!-- details --> on_focus_lost="inv_search_unfocus"
<instance template="tinv_item_list_icon_swap" on_focus_lost_params="but_inv_search" />
id="detail"
x="-4"
y="1"
posref="BR BR"
dblink="UI:SAVE:#inv_type:ICON_LIST"
texture="details_on.tga"
tooltip="uittDetail" />
<link expr="ifthenelse(@UI:SAVE:#inv_type:ICON_LIST, 'details_off.tga', 'details_on.tga')"
target="bit_detail:texture" />
</group> </group>
</template> </template>
<!-- Link to trig brick action message. don't play when 0 (avoid flying text at startup) --> <!-- Link to trig brick action message. don't play when 0 (avoid flying text at startup) -->

View file

@ -2528,25 +2528,92 @@ class CHandlerInvDrag : public IActionHandler
}; };
REGISTER_ACTION_HANDLER( CHandlerInvDrag, "inv_drag" ); REGISTER_ACTION_HANDLER( CHandlerInvDrag, "inv_drag" );
// ********************************************************************************************************** // ***************************************************************************
class CHandlerInvSetSearch : public IActionHandler // show/hide edit box, set keyboard focus if 'show'
class CHandlerInvSearchButton : public IActionHandler
{ {
void execute (CCtrlBase *pCaller, const std::string &sParams) virtual void execute (CCtrlBase *pCaller, const string &sParams)
{
if (sParams.empty())
{
nlwarning("inv_search_button: missing edit box shortid");
return;
}
CCtrlBaseButton* btn = dynamic_cast<CCtrlBaseButton *>(pCaller);
if (!btn)
{
nlwarning("inv_search_button pCaller == NULL, caller must be CCtrlBaseButton with 'toggle_button' type");
return;
}
ucstring filter;
std::string id = btn->getParent()->getId() + ":" + sParams + ":eb";
CGroupEditBox *eb = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(id));
if (!eb)
{
nlwarning("inv_search_button: editbox (%s) not found\n", id.c_str());
return;
}
eb->getParent()->setActive(btn->getPushed());
if (eb->getParent()->getActive())
{
CWidgetManager::getInstance()->setCaptureKeyboard(eb);
eb->setSelectionAll();
filter = eb->getInputString();
}
CDBGroupListSheetBag *pList = dynamic_cast<CDBGroupListSheetBag*>(CWidgetManager::getInstance()->getElementFromId(btn->getParent()->getId() + ":bag_list"));
if (pList != NULL) pList->setSearchFilter(filter);
CDBGroupIconListBag *pIcons = dynamic_cast<CDBGroupIconListBag*>(CWidgetManager::getInstance()->getElementFromId(btn->getParent()->getId() + ":bag_icons"));
if (pIcons != NULL) pIcons->setSearchFilter(filter);
}
};
REGISTER_ACTION_HANDLER( CHandlerInvSearchButton, "inv_search_button" );
// ***************************************************************************
// if :eb is empty then hide edit box, unpush search button
class CHandlerInvSearchUnfocus : public IActionHandler
{
virtual void execute (CCtrlBase *pCaller, const string &sParams)
{ {
if (!pCaller) return; if (!pCaller) return;
CGroupEditBox *eb = dynamic_cast<CGroupEditBox *>(pCaller); CGroupEditBox *eb = dynamic_cast<CGroupEditBox *>(pCaller);
if (!eb) return; if (!eb || !eb->getInputString().empty()) return;
CInterfaceManager *pIM = CInterfaceManager::getInstance();
// ui:interface:inventory:content:bag:iil:inv_query_eb:eb // ui:interface:inventory:content:bag:iil:inv_query_eb:eb
string invId = pCaller->getParent()->getParent()->getId(); std::string id = pCaller->getParent()->getParent()->getId() + ":" + sParams;
CCtrlBaseButton *btn = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(id));
if (btn) btn->setPushed(false);
CDBGroupListSheetBag *pList = dynamic_cast<CDBGroupListSheetBag*>(CWidgetManager::getInstance()->getElementFromId(invId + ":bag_list")); // hide :inv_query_eb
pCaller->getParent()->setActive(false);
// clear filter
CAHManager::getInstance()->runActionHandler("inv_set_search", pCaller, "");
}
};
REGISTER_ACTION_HANDLER( CHandlerInvSearchUnfocus, "inv_search_unfocus" );
// **********************************************************************************************************
// set inventory search string
class CHandlerInvSetSearch : public IActionHandler
{
void execute (CCtrlBase *pCaller, const std::string &sParams)
{
CGroupEditBox *eb = dynamic_cast<CGroupEditBox *>(pCaller);
if (!eb) return;
// ui:interface:inventory:content:bag:iil:inv_query_eb:eb
std::string id = pCaller->getParent()->getParent()->getId();
CDBGroupListSheetBag *pList = dynamic_cast<CDBGroupListSheetBag*>(CWidgetManager::getInstance()->getElementFromId(id + ":bag_list"));
if (pList != NULL) pList->setSearchFilter(eb->getInputString()); if (pList != NULL) pList->setSearchFilter(eb->getInputString());
CDBGroupIconListBag *pIcons = dynamic_cast<CDBGroupIconListBag*>(CWidgetManager::getInstance()->getElementFromId(invId + ":bag_icons")); CDBGroupIconListBag *pIcons = dynamic_cast<CDBGroupIconListBag*>(CWidgetManager::getInstance()->getElementFromId(id + ":bag_icons"));
if (pIcons != NULL) pIcons->setSearchFilter(eb->getInputString()); if (pIcons != NULL) pIcons->setSearchFilter(eb->getInputString());
} }
}; };