r3171 - in trunk/data/qcsrc: common menu-div0test/nexuiz
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Fri Jan 18 08:44:31 EST 2008
Author: div0
Date: 2008-01-18 08:44:30 -0500 (Fri, 18 Jan 2008)
New Revision: 3171
Modified:
trunk/data/qcsrc/common/mapinfo.qc
trunk/data/qcsrc/common/mapinfo.qh
trunk/data/qcsrc/common/util.qc
trunk/data/qcsrc/common/util.qh
trunk/data/qcsrc/menu-div0test/nexuiz/maplist.c
Log:
map list can now search a map name while you type it
Modified: trunk/data/qcsrc/common/mapinfo.qc
===================================================================
--- trunk/data/qcsrc/common/mapinfo.qc 2008-01-18 11:54:54 UTC (rev 3170)
+++ trunk/data/qcsrc/common/mapinfo.qc 2008-01-18 13:44:30 UTC (rev 3171)
@@ -500,7 +500,6 @@
return 0;
}
-string _MapInfo_FindName_match;
float MapInfo_FindName(string s)
{
// if there is exactly one map of prefix s, return it
@@ -513,8 +512,8 @@
while(l != r)
{
m = floor((l + r) / 2);
- _MapInfo_FindName_match = _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, m));
- cmp = strcasecmp(_MapInfo_FindName_match, s);
+ MapInfo_FindName_match = _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, m));
+ cmp = strcasecmp(MapInfo_FindName_match, s);
if(cmp == 0)
return m; // found and good
if(cmp < 0)
@@ -522,26 +521,29 @@
else
r = m; // behind s
}
- _MapInfo_FindName_match = _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, l));
+ MapInfo_FindName_match = _MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, l));
+ MapInfo_FindName_firstResult = l;
// r == l, so: l is behind s, l-1 is before
// SO: if there is any, l is the one with the right prefix
// and l+1 may be one too
if(l == MapInfo_count)
{
- _MapInfo_FindName_match = string_null;
- return -1; // no _MapInfo_FindName_match, behind last item
+ MapInfo_FindName_match = string_null;
+ MapInfo_FindName_firstResult = -1;
+ return -1; // no MapInfo_FindName_match, behind last item
}
- if(!startsWith(_MapInfo_FindName_match, s))
+ if(!startsWith(MapInfo_FindName_match, s))
{
- _MapInfo_FindName_match = string_null;
+ MapInfo_FindName_match = string_null;
+ MapInfo_FindName_firstResult = -1;
return -1; // wrong prefix
}
if(l == MapInfo_count - 1)
return l; // last one, nothing can follow => unique
if(startsWith(_MapInfo_GlobItem(HugeSetOfIntegers_get(_MapInfo_filtered, l + 1)), s))
{
- _MapInfo_FindName_match = string_null;
- return -1; // ambigous _MapInfo_FindName_match
+ MapInfo_FindName_match = string_null;
+ return -1; // ambigous MapInfo_FindName_match
}
return l;
}
@@ -549,7 +551,7 @@
string MapInfo_FixName(string s)
{
MapInfo_FindName(s);
- return _MapInfo_FindName_match;
+ return MapInfo_FindName_match;
}
float MapInfo_CurrentFeatures()
Modified: trunk/data/qcsrc/common/mapinfo.qh
===================================================================
--- trunk/data/qcsrc/common/mapinfo.qh 2008-01-18 11:54:54 UTC (rev 3170)
+++ trunk/data/qcsrc/common/mapinfo.qh 2008-01-18 13:44:30 UTC (rev 3171)
@@ -41,6 +41,8 @@
float MapInfo_Get_ByName(string s, float allowGenerate, float gametypeToSet); // 1 on success, 0 on failure, 2 if it autogenerated a mapinfo file
// look for a map by a prefix, returns the actual map name on success, string_null on failure or ambigous match
+string MapInfo_FindName_match; // the name of the map that was found
+float MapInfo_FindName_firstResult; // -1 if none were found, index of first one if not unique but found (FindName then returns -1)
float MapInfo_FindName(string s);
string MapInfo_FixName(string s);
Modified: trunk/data/qcsrc/common/util.qc
===================================================================
--- trunk/data/qcsrc/common/util.qc 2008-01-18 11:54:54 UTC (rev 3170)
+++ trunk/data/qcsrc/common/util.qc 2008-01-18 13:44:30 UTC (rev 3171)
@@ -222,3 +222,14 @@
default: return '0.000 0.000 0.000';
}
}
+
+// unzone the string, and return it as tempstring. Safe to be called on string_null
+string fstrunzone(string s)
+{
+ string sc;
+ if not(s)
+ return s;
+ sc = strcat(s, "");
+ strunzone(s);
+ return sc;
+}
Modified: trunk/data/qcsrc/common/util.qh
===================================================================
--- trunk/data/qcsrc/common/util.qh 2008-01-18 11:54:54 UTC (rev 3170)
+++ trunk/data/qcsrc/common/util.qh 2008-01-18 13:44:30 UTC (rev 3171)
@@ -32,3 +32,6 @@
string ftos_decimals(float number, float decimals);
vector colormapPaletteColor(float c, float isPants);
+
+// unzone the string, and return it as tempstring. Safe to be called on string_null
+string fstrunzone(string s);
Modified: trunk/data/qcsrc/menu-div0test/nexuiz/maplist.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/nexuiz/maplist.c 2008-01-18 11:54:54 UTC (rev 3170)
+++ trunk/data/qcsrc/menu-div0test/nexuiz/maplist.c 2008-01-18 13:44:30 UTC (rev 3171)
@@ -36,6 +36,9 @@
ATTRIB(NexuizMapList, cvarName, string, "dummy")
METHOD(NexuizMapList, loadCvars, void(entity))
+
+ ATTRIB(NexuizMapList, typeToSearchString, string, string_null)
+ ATTRIB(NexuizMapList, typeToSearchTime, float, 0)
ENDCLASS(NexuizMapList)
entity makeNexuizMapList();
void MapList_All(entity btn, entity me);
@@ -254,6 +257,7 @@
float keyDownNexuizMapList(entity me, float scan, float ascii, float shift)
{
+ string ch, save;
if(scan == K_ENTER)
{
// pop up map info screen
@@ -274,6 +278,38 @@
if(me.g_maplistCacheQuery(me, me.selectedItem))
me.g_maplistCacheToggle(me, me.selectedItem);
}
+ else if(scan == K_BACKSPACE)
+ {
+ if(time < me.typeToSearchTime)
+ {
+ save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1);
+ if(me.typeToSearchString)
+ strunzone(me.typeToSearchString);
+ me.typeToSearchString = strzone(save);
+ me.typeToSearchTime = time + 0.5;
+ if(strlen(me.typeToSearchString))
+ {
+ MapInfo_FindName(me.typeToSearchString);
+ if(MapInfo_FindName_firstResult >= 0)
+ me.setSelected(me, MapInfo_FindName_firstResult);
+ }
+ }
+ }
+ else if(ascii >= 32 && ascii != 127)
+ {
+ ch = chr(ascii);
+ if(time > me.typeToSearchTime)
+ save = ch;
+ else
+ save = strcat(me.typeToSearchString, ch);
+ if(me.typeToSearchString)
+ strunzone(me.typeToSearchString);
+ me.typeToSearchString = strzone(save);
+ me.typeToSearchTime = time + 0.5;
+ MapInfo_FindName(me.typeToSearchString);
+ if(MapInfo_FindName_firstResult >= 0)
+ me.setSelected(me, MapInfo_FindName_firstResult);
+ }
else
return keyDownListBox(me, scan, ascii, shift);
return 1;
More information about the nexuiz-commits
mailing list