Added: Map search filter

--HG--
branch : develop
This commit is contained in:
Nimetu 2017-03-01 20:04:54 +02:00
parent b48b1dc0cc
commit 23d95705fd
5 changed files with 196 additions and 7 deletions

View file

@ -1005,7 +1005,6 @@ namespace NLGUI
{
case KeyESCAPE:
_CurrentHistoricIndex= -1;
CWidgetManager::getInstance()->setCaptureKeyboard(NULL);
// stop selection
_CurrSelection = NULL;
_CursorAtPreviousLineEnd = false;
@ -1014,6 +1013,7 @@ namespace NLGUI
setInputString(ucstring(""));
triggerOnChangeAH();
}
CWidgetManager::getInstance()->setCaptureKeyboard(NULL);
break;
case KeyTAB:
makeTopWindow();

View file

@ -122,6 +122,9 @@
<command name="loot" action="inv_temp_all" params="" />
<command name="mapsearch" action="proc" params="map_search_show_set|+" />
<command name="mapsearch" action="proc" params="map_search_show" />
<!-- WebIG -->
<command name="go" action="browse" params="name=ui:interface:webig:content:html|url=home"/>
<command name="webdev" action="browse" params="name=ui:interface:webig:content:html|url=http://localhost/index.html"/>

View file

@ -25,6 +25,8 @@
<action id="teleport" name="uiTeleport" handler="map_teleport" params=""/>
<action id="create_at_user_pos" name="uiCreateUserLMAtUserPos" handler="create_user_landmark_at_user_pos" params=""/>
<separator/>
<action id="search" name="uiMapSearch" handler="proc" params="map_search_show"/>
<separator/>
<action id="center" name="uiMenuCenter" handler="map_center" params="map=ui:interface:map:content:map_content:actual_map"/>
</group>
@ -144,6 +146,7 @@
<!-- * USER MAP * -->
<!-- ******************************************************************** -->
<variable entry="UI:VARIABLES:ISACTIVE:MAP_SEARCH" type="sint32" value="0" />
<proc id="map_proc_active">
<action handler="set" params="dblink=UI:VARIABLES:ISACTIVE:MAP|value=1" />
@ -155,7 +158,49 @@
<action handler="lua" params="if (r2 and r2.Mode == 'Edit') then r2.ToolUI:updateToggleWindowButtons() end" />
</proc>
<proc id="map_search_toggle">
<action handler="set" params="dblink=UI:VARIABLES:ISACTIVE:MAP_SEARCH|value=not(@UI:VARIABLES:ISACTIVE:MAP_SEARCH)"/>
<action handler="proc" params="map_search_focus" cond="@UI:VARIABLES:ISACTIVE:MAP_SEARCH"/>
<action handler="proc" params="map_search_reset" cond="not(@UI:VARIABLES:ISACTIVE:MAP_SEARCH)"/>
</proc>
<proc id="map_search_focus">
<action handler="set_keyboard_focus" params="target=ui:interface:map:content:map_content:lm_search:search:eb|select_all=true" />
</proc>
<proc id="map_search_reset">
<action handler="proc" params="map_search_setfilter" />
</proc>
<proc id="map_search_show">
<action handler="set" params="dblink=UI:VARIABLES:ISACTIVE:MAP_SEARCH|value=1" />
<action handler="proc" params="map_search_focus" />
</proc>
<proc id="map_search_hide">
<action handler="set" params="dblink=UI:VARIABLES:ISACTIVE:MAP_SEARCH|value=0" />
</proc>
<proc id="map_search_setfilter">
<action handler="set" params="target_property=ui:interface:map:content:map_content:lm_search:search:eb:input_string|value='@0'" />
<action handler="land_mark_filter" params="map=ui:interface:map:content:map_content:actual_map|text=@0" />
</proc>
<!-- set search string from /mapsearch command -->
<proc id="map_search_show_set">
<action handler="set" params="dblink=UI:VARIABLES:ISACTIVE:MAP_SEARCH|value=1" />
<action handler="proc" params="map_search_setfilter|@0" />
</proc>
<!-- hide search if focus was lost and input is empty (esc key) -->
<proc id="map_search_focuslost">
<action handler="proc" params="map_search_hide"
cond="eq(getprop('ui:interface:map:content:map_content:lm_search:search:eb:input_string'),'')" />
</proc>
<proc id="map_search_onchange">
<action handler="land_mark_filter" params="map=ui:interface:map:content:map_content:actual_map|group=@0" />
</proc>
<define id="map_min_size" value="256" />
@ -191,8 +236,10 @@
<!-- center on player -->
<ctrl type="button" id="center" button_type="push_button" posparent="zoom_out" posref="TR TL" y="0" x="4" tx_normal="w_center_map.tga" tx_pushed="W_button_16_over.tga" tx_over="W_button_16_over.tga"
onclick_l="map_center" params_l="map=ui:interface:map:content:map_content:actual_map" tooltip="uittCenter" />
<ctrl type="button" id="lm_search_btn" button_type="push_button" posparent="center" posref="TR TL" y="0" x="4" tx_normal="w_help_1.tga" tx_pushed="W_button_16_over.tga" tx_over="W_button_16_over.tga"
onclick_l="proc" params_l="map_search_toggle" tooltip="uittMapSearch" />
<view type="text" id="time" x="12" y="0" posparent="center" posref="MR ML" color="255 255 255 255" fontsize="12" shadow="true" hardtext="" />
<view type="text" id="time" x="12" y="0" posparent="lm_search_btn" posref="MR ML" color="255 255 255 255" fontsize="12" shadow="true" hardtext="" />
<view type="text" id="weather" x="8" y="-16" posref="TL TL" color="255 255 255 255" fontsize="12" shadow="true" hardtext="" />
<ctrl type="tooltip" id="weather_tt" posparent="weather" sizeref="wh" w="0" h="0" tooltip="" tooltip_parent="ctrl" tooltip_posref="BL TL" />
@ -317,8 +364,39 @@
compass="ui:interface:compass"
/>
<!-- border around the map -->
<!-- border around the map -->
<group id="lm_search"
posparent="back"
posref="TR TR"
x="-2"
y="-2"
child_resize_w="true"
child_resize_h="true">
<instance template="edit_box_widget"
id="search"
posref="TR TR"
w="150"
clear_on_escape="true"
enter_recover_focus="false"
on_focus_lost="proc" on_focus_lost_params="map_search_focuslost"
onenter=""
onchange="proc" onchange_params="map_search_onchange|ui:interface:map:content:map_content:lm_search:search:eb" />
<ctrl type="button"
id="reset"
button_type="push_button"
posparent="search"
posref="ML MR"
x="-2"
tx_normal="w_close_0.tga"
tx_pushed="w_close_0.tga"
tx_over="W_button_16_over"
onclick_l="proc" params_l="map_search_toggle"
tooltip="" />
<view type="text" id="lm_count" posparent="search" posref="BR TR" x="-2" color="200 200 200 255" fontsize="10" shadow="true" hardtext="0" />
</group>
<link expr="@UI:VARIABLES:ISACTIVE:MAP_SEARCH" target="lm_search:active" />
</group>
</group>
</group>

View file

@ -426,6 +426,8 @@ CGroupMap::CGroupMap(const TCtorParam &param)
//
_TargetLM = NULL;
_HomeLM = NULL;
_LandmarkFilter.clear();
_MatchedLandmarkCount = 0;
//
_ScaleMax = 8.f;
_ScaleMaxR2 = 8.f;
@ -902,9 +904,19 @@ void CGroupMap::updateCoords()
// bool newLandMarkShown = false;
uint i;
for (i = 0; i < _ContinentLM.size(); ++i)
setupFromZoom(_ContinentLM[i], _ContinentLM[i]->Type, _MeterPerPixel);
{
if (_ContinentLM[i]->SearchMatch)
_ContinentLM[i]->setActive(true);
else
setupFromZoom(_ContinentLM[i], _ContinentLM[i]->Type, _MeterPerPixel);
}
for (i = 0; i < _ContinentText.size(); ++i)
setupFromZoom(_ContinentText[i], _ContinentText[i]->Type, _MeterPerPixel);
{
if (_ContinentText[i]->SearchMatch)
_ContinentText[i]->setActive(true);
else
setupFromZoom(_ContinentText[i], _ContinentText[i]->Type, _MeterPerPixel);
}
//
updateLandMarkList(_ContinentLM);
updateLandMarkTextList(_ContinentText);
@ -2316,6 +2328,12 @@ void CGroupMap::createLMWidgets(const std::vector<CContLandMark> &lms)
worldToMap(mapPos, rCLM.Pos);
const ucstring ucsTmp(CStringManagerClient::getPlaceLocalizedName(rCLM.TitleTextID));
const ucstring lcTitle = toLower(ucsTmp);
bool searchMatch = _LandmarkFilter.size() > 0 && filterLandmark(lcTitle);
if (searchMatch)
_MatchedLandmarkCount++;
// Add button if not a region nor a place
if ((rCLM.Type != CContLandMark::Region) && (rCLM.Type != CContLandMark::Place) &&
(rCLM.Type != CContLandMark::Street))
@ -2325,6 +2343,7 @@ void CGroupMap::createLMWidgets(const std::vector<CContLandMark> &lms)
else
addLandMark(_ContinentLM, mapPos, CI18N::get("uiStable"), _ContinentLMOptions);
_ContinentLM.back()->Type = rCLM.Type;
_ContinentLM.back()->SearchMatch = searchMatch;
}
else // just add a text
{
@ -2343,6 +2362,7 @@ void CGroupMap::createLMWidgets(const std::vector<CContLandMark> &lms)
pNewText->setShadowColor(CRGBA(0,0,0,255));
pNewText->setModulateGlobalColor(false);
pNewText->Type = rCLM.Type;
pNewText->SearchMatch = searchMatch;
_ContinentText.push_back(pNewText);
addView(pNewText);
}
@ -2372,6 +2392,8 @@ void CGroupMap::createContinentLandMarks()
{
uint32 k;
_MatchedLandmarkCount = 0;
if (_MapMode != MapMode_Normal) return;
if (_CurMap == NULL) return;
@ -2403,8 +2425,24 @@ void CGroupMap::createContinentLandMarks()
NLMISC::CVector2f mapPos;
worldToMap(mapPos, _CurContinent->UserLandMarks[k].Pos);
addLandMark(_UserLM, mapPos, _CurContinent->UserLandMarks[k].Title, getUserLandMarkOptions(k));
if (filterLandmark(_CurContinent->UserLandMarks[k].Title))
{
addLandMark(_UserLM, mapPos, _CurContinent->UserLandMarks[k].Title, getUserLandMarkOptions(k));
_MatchedLandmarkCount++;
}
}
// update visible landmark count
CInterfaceGroup *gc = getParentContainer();
if (gc)
{
CViewText *pVT = dynamic_cast<CViewText *>(gc->getView("lm_count"));
if (pVT)
{
pVT->setText(toString(_MatchedLandmarkCount));
}
}
invalidateCoords();
}
@ -2423,6 +2461,20 @@ static void hideTeleportButtonsInPopupMenuIfNotEnoughPriv()
if(ie) ie->setActive(showTeleport);
}
//============================================================================================================
void CGroupMap::setLandmarkFilter(const std::string &s)
{
_LandmarkFilter.clear();
if (!s.empty()) {
ucstring ucs;
ucs.fromUtf8(s);
splitUCString(toLower(s), ucstring(" "), _LandmarkFilter);
}
// recreate landmarks
createContinentLandMarks();
}
//============================================================================================================
void CGroupMap::updateUserLandMarks()
@ -2484,6 +2536,22 @@ void CGroupMap::updateLandMarkButton(CLandMarkButton *lmb, const CLandMarkOption
lmb->setColorPushed(options.ColorPushed);
}
//============================================================================================================
bool CGroupMap::filterLandmark(const ucstring &title) const
{
if (_LandmarkFilter.size() > 0)
{
ucstring lcTitle = toLower(title);
for(uint i = 0; i< _LandmarkFilter.size(); ++i) {
if (lcTitle.find(_LandmarkFilter[i]) == ucstring::npos) {
return false;
}
}
}
return true;
}
//============================================================================================================
void CGroupMap::addLandMark(TLandMarkButtonVect &destList, const NLMISC::CVector2f &pos, const ucstring &title, const CLandMarkOptions &options)
{
@ -3161,6 +3229,32 @@ SMap *CGroupMap::getParentMap(SMap *map)
// ACTION HANDLERS //
/////////////////////
//=========================================================================================================
// Set landmark filter
class CAHLandMarkFilter : public IActionHandler
{
virtual void execute (CCtrlBase * /* pCaller */, const string &params )
{
string id = getParam(params, "map");
CGroupMap* map = dynamic_cast<CGroupMap*>(CWidgetManager::getInstance()->getElementFromId(id));
if (!map) return;
string text = getParam(params, "text");
if (text.empty() && params.find("text=") == std::string::npos)
{
string group = getParam(params, "group");
CGroupEditBox* eb = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(group));
if (!eb) return;
text = eb->getInputString().toUtf8();
}
map->setLandmarkFilter(text);
}
};
REGISTER_ACTION_HANDLER(CAHLandMarkFilter, "land_mark_filter");
//=========================================================================================================
// A land mark button has been pushed
class CAHLandMarkSelected : public IActionHandler

View file

@ -175,6 +175,9 @@ public:
//Remove and re-create UserLandMarks
void updateUserLandMarks();
// set landmarks visibility based text query
void setLandmarkFilter(const std::string &s);
// set the selection axis pos & visibility
void setSelectionAxis(bool active, const NLMISC::CVector2f &worldPos = NLMISC::CVector2f::Null);
@ -262,6 +265,7 @@ private:
NLMISC::CVector2f Pos;
CContLandMark::TContLMType Type;
bool HandleEvents;
bool SearchMatch;
public:
virtual bool handleEvent (const NLGUI::CEventDescriptor& event)
{
@ -279,6 +283,7 @@ private:
Type = CContLandMark::Unknown;
Pos.set(0.f, 0.f);
HandleEvents = true;
SearchMatch = false;
}
};
typedef std::vector<CLandMarkButton*> TLandMarkButtonVect;
@ -289,12 +294,14 @@ private:
public:
NLMISC::CVector2f Pos;
CContLandMark::TContLMType Type;
bool SearchMatch;
CLandMarkText(const TCtorParam &param)
: CViewText(param)
{
Type = CContLandMark::Unknown;
Pos.set(0.f, 0.f);
SearchMatch = false;
}
};
typedef std::vector<CLandMarkText*> TLandMarkTextVect;
@ -448,6 +455,10 @@ private:
typedef std::set<IDeco *> TDecos;
TDecos _Decos;
// filter keywords
std::vector<ucstring> _LandmarkFilter;
uint32 _MatchedLandmarkCount;
//////////////////////
// Respawn handling //
// //////////////// //
@ -501,6 +512,9 @@ private:
// update a landmark button
void updateLandMarkButton(CLandMarkButton *lmb, const CLandMarkOptions &options);
// Test title against landmark filter
bool filterLandmark(const ucstring &title) const;
// update the scale depending on the window size and the user scale
void updateScale();