FreeOrion

Forums for the FreeOrion project
It is currently Thu Jun 20, 2013 1:25 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: [PATCH] Auto complete
PostPosted: Tue Jan 10, 2012 1:22 am 
Offline
Space Floater

Joined: Thu Oct 20, 2011 10:14 pm
Posts: 27
Here is what I have for the ChatWnd autocomplete. I have a few questions though, for now I have it ignore trying to auto complete words unless they are at least 2 characters...does that sound about right? I also added the ability to save user typed words for auto complete but I made it only if they are at least 5 characters long. Dunno if you think that will be useful or if its not necessary just let me know. Also I am not well versed on all the different objects in the game does it look like I covered all of the important game words? Game words are stored with an upper case first letter I made it find it whether the first letter is upper or lower. However should I make it so the first letter is always capitalized of game words when auto completed? Or maybe game words should be in all caps or another color? And if there is anything that you think I should change stylistically or whatever just let me know.




I release my submissions under the GPL 2.0 license.


Attachments:
autocompletepatch.patch [10.65 KiB]
Downloaded 8 times
Top
 Profile  
 
 Post subject: Re: [PATCH] Auto complete
PostPosted: Tue Jan 10, 2012 5:46 am 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 8062
Location: Vancouver, BC
Off the top of my head, the only additional content things you might add are ship hulls and parts.

I have a few issues with the use-typed autocomplete stuff:
* Rather than strtok, having to deal with passing strings by value or copy them, and dealing with casting, you might use boost tokenizer.
* Avoid c-style (casts) and use static_cast or dynamic_cast as appropriate.
* Avoid referencing NULL; I think there are some issues with it, though don't know / remember the details. This shouldn't be an issue if the previous points are followed. For checking if pointers are null, use if (pointer) or if (!pointer), or use if (container.empty()) or similar.
* I'm a bit worried about using std::toupper if non-latin characters get mixed into text; I'm not sure how that will work. Is converting to uppercase really necessary anyway?
* That said, I don't think there's really much need for user-typed words autocomplete anyway...


Top
 Profile  
 
 Post subject: Re: [PATCH] Auto complete
PostPosted: Tue Jan 10, 2012 1:01 pm 
Offline
Space Floater

Joined: Thu Oct 20, 2011 10:14 pm
Posts: 27
Geoff the Medio wrote:
Off the top of my head, the only additional content things you might add are ship hulls and parts.

I have a few issues with the use-typed autocomplete stuff:
* Rather than strtok, having to deal with passing strings by value or copy them, and dealing with casting, you might use boost tokenizer.
* Avoid c-style (casts) and use static_cast or dynamic_cast as appropriate.
* Avoid referencing NULL; I think there are some issues with it, though don't know / remember the details. This shouldn't be an issue if the previous points are followed. For checking if pointers are null, use if (pointer) or if (!pointer), or use if (container.empty()) or similar.
* I'm a bit worried about using std::toupper if non-latin characters get mixed into text; I'm not sure how that will work. Is converting to uppercase really necessary anyway?
* That said, I don't think there's really much need for user-typed words autocomplete anyway...


Okay thanks. I'll add ship hull and parts once I get the chance. I figured there was probably a better way to do it thanks, in the future i'll use boost tokenizer. I will get rid of user typed words than, that should simplify my changes.

the reason I use toupper is because all game words are stored with the first letter in upper case. And the set comparison/matching does not recognize something if you don't match the case. So with my code if you type g or G you'd get grotto or Grotto. Are you saying you want me to find some boost equivalent? Or are you saying to just get rid of it totally? That way game words will only be completed if the user types the first letter in upper case? meaing they would have to type G to get grotto if they typed g nothing would be found?


Top
 Profile  
 
 Post subject: Re: [PATCH] Auto complete
PostPosted: Tue Jan 10, 2012 5:49 pm 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 8062
Location: Vancouver, BC
fixIt wrote:
Are you saying you want me to find some boost equivalent [for toupper]? Or are you saying to just get rid of it totally?
The boost equivalent idea sounds good. I think there are also case-insensitive string matching functions available... The ValueRef code probably uses them, for example, to recognize Target.Owner or TARGET.owner or whatever variation thereof the scripter uses.


Top
 Profile  
 
 Post subject: Re: [PATCH] Auto complete
PostPosted: Wed Jan 11, 2012 1:36 am 
Offline
Space Floater

Joined: Thu Oct 20, 2011 10:14 pm
Posts: 27
Geoff the Medio wrote:
fixIt wrote:
Are you saying you want me to find some boost equivalent [for toupper]? Or are you saying to just get rid of it totally?
The boost equivalent idea sounds good. I think there are also case-insensitive string matching functions available... The ValueRef code probably uses them, for example, to recognize Target.Owner or TARGET.owner or whatever variation thereof the scripter uses.


Thanks, boost surely simplified it a lot. I was using the toupper to get things working case insensitive in hopes of keeping what was already in place.

Anyways now things are case insensitive, I added hulls and parts and got rid of the user typed words.


Attachments:
autocompletepatch.patch [8.31 KiB]
Downloaded 6 times


Last edited by fixIt on Thu Jan 12, 2012 1:23 am, edited 1 time in total.
Top
 Profile  
 
 Post subject: Re: [PATCH] Auto complete
PostPosted: Wed Jan 11, 2012 1:54 am 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 8062
Location: Vancouver, BC
I am slightly concerned that the auto keyword might cause some problems as you're using it... It seems to compile with MSVC 2010, but I can't test the OSX or Linux GCC builds. The internet says GCC 4.4 or later should support auto as well, at least with a compiler switch. I'm not sure if anyone is still trying to build FO on GCC 4.3, though...

"a lot" is two words.

When I type "imp" into the chat box and press tab, the autocomplete gives me BLD_IMPERIAL_PALACE. You probably need to look things up in the stringtable before adding to the autocomplete list (except not ShipDesigns, which look their own names up when predefined, or return their user-entered name if user-created).

When I type "bl" and press tab, I get BLD_ART_BLACK_HOLE. I would expect it to only match the start of a word, not find any partial matches in the middle.

It would also be nice if pressing tab repeatedly would cycle through alternative matches.


Top
 Profile  
 
 Post subject: Re: [PATCH] Auto complete
PostPosted: Wed Jan 11, 2012 2:31 am 
Offline
Space Floater

Joined: Thu Oct 20, 2011 10:14 pm
Posts: 27
Ah okay noted, replaced the autos with iterators. Alright I'll look into the rest.


Attachments:
autocompletepatch.patch [8.51 KiB]
Downloaded 9 times
Top
 Profile  
 
 Post subject: Re: [PATCH] Auto complete
PostPosted: Wed Jan 11, 2012 10:24 pm 
Offline
Programmer and Packager
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 807
Location: Sol III
fixIt wrote:
Ah okay noted, replaced the autos with iterators...

I've been able to build FO successfully with this new version of your patch on OS X.


Top
 Profile  
 
 Post subject: Re: [PATCH] Auto complete
PostPosted: Thu Jan 12, 2012 1:22 am 
Offline
Space Floater

Joined: Thu Oct 20, 2011 10:14 pm
Posts: 27
Vezzra wrote:
fixIt wrote:
Ah okay noted, replaced the autos with iterators...

I've been able to build FO successfully with this new version of your patch on OS X.


Thanks for checking. I'll just write everything out in the future though just to be safe.


Heres my updated patch:

-Looks up game words in string table that needed to be
-Repeated tabs allows you to cycle through alternative matches
-It only matches words from the start of a word


Attachments:
autocompletepatch.patch [11.92 KiB]
Downloaded 7 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: AhrefsBot and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group