wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src playturn.hpp playturn.cpp


From: Isaac Clerencia
Subject: [Wesnoth-cvs-commits] wesnoth/src playturn.hpp playturn.cpp
Date: Sun, 19 Dec 2004 21:05:56 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Isaac Clerencia <address@hidden>        04/12/20 01:49:19

Modified files:
        src            : playturn.hpp playturn.cpp 

Log message:
        Added in-game chat tab-completion for player names.
        ToDo:
        * Look for memory leaks (can you review it, Dave? :) )
        * Make it work in the lobby
        * Be case insensitive (any easy way?)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.hpp.diff?tr1=1.57&tr2=1.58&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playturn.cpp.diff?tr1=1.310&tr2=1.311&r1=text&r2=text

Patches:
Index: wesnoth/src/playturn.cpp
diff -u wesnoth/src/playturn.cpp:1.310 wesnoth/src/playturn.cpp:1.311
--- wesnoth/src/playturn.cpp:1.310      Sun Dec 12 22:02:01 2004
+++ wesnoth/src/playturn.cpp    Mon Dec 20 01:49:19 2004
@@ -1,4 +1,4 @@
-/* $Id: playturn.cpp,v 1.310 2004/12/12 22:02:01 silene Exp $ */
+/* $Id: playturn.cpp,v 1.311 2004/12/20 01:49:19 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -209,6 +209,8 @@
                        hotkey::key_event(gui_,event.key,this);
                } else if(event.key.keysym.sym == SDLK_ESCAPE) {
                        close_textbox();
+               } else if(event.key.keysym.sym == SDLK_TAB) {
+                       tab_textbox();
                } else if(event.key.keysym.sym == SDLK_RETURN) {
                        enter_textbox();
                }
@@ -2720,6 +2722,72 @@
        close_textbox();
 }
 
+void turn_info::tab_textbox()
+{
+       if(textbox_.active() == false) {
+               return;
+       }
+
+       switch(textbox_.mode) {
+       case floating_textbox::TEXTBOX_MESSAGE:
+       {
+               std::cerr << "Tab pressed in active textbox" << std::endl;
+               std::string text = textbox_.box->text();
+               std::cerr << "Current text: " << text << std::endl;
+               std::string semiword;
+       
+               const size_t last_space = text.rfind(" ");
+
+               //if last character is a space return
+               if(last_space == text.size() -1) {
+                       return;
+               }
+
+               if(last_space == -1) {
+                       semiword = text;        
+               }else{
+                       semiword.assign(text,last_space+1,text.size());
+               }
+
+               std::cerr << "Semiword: " << semiword << std::endl;
+               std::string guess;
+
+               for(size_t n = 0; n != teams_.size(); ++n) {
+                       if(teams_[n].is_empty()) {
+                               continue;
+                       }
+                       const unit_map::const_iterator leader = 
team_leader(n+1,units_);
+                       if(leader != units_.end()) {
+                               const std::string name = 
leader->second.description();
+                               if(name.find(semiword) == 0) {
+                                       if(guess.size() == 0) {
+                                               guess = name;
+                                       }else{
+                                               int i;
+                                               for(i=0; (i < guess.size()) || 
(i < name.size()); i++) {
+                                                       if(guess[i] != name[i]) 
{
+                                                               break;
+                                                       }
+                                               }
+                                               guess.assign(guess,0,i);
+                                       }
+                               }
+                       }
+               }
+
+               std::cerr << "Guess: " << guess << std::endl;
+               if(guess.size() != 0) {
+                       text.replace(last_space+1, semiword.size(), guess);
+                       std::cerr << "Replaced text: " << text << std::endl;
+                       textbox_.box->set_text(text);
+               }
+               break;
+       }
+       default:
+               lg::err(lg::display) << "unknown textbox mode\n";
+       }
+}
+
 const unit_map& turn_info::visible_units() const
 {
        if(viewing_team().uses_shroud() == false && viewing_team().uses_fog() 
== false) {
Index: wesnoth/src/playturn.hpp
diff -u wesnoth/src/playturn.hpp:1.57 wesnoth/src/playturn.hpp:1.58
--- wesnoth/src/playturn.hpp:1.57       Sat Dec  4 23:44:09 2004
+++ wesnoth/src/playturn.hpp    Mon Dec 20 01:49:19 2004
@@ -1,4 +1,4 @@
-/* $Id: playturn.hpp,v 1.57 2004/12/04 23:44:09 isaaccp Exp $ */
+/* $Id: playturn.hpp,v 1.58 2004/12/20 01:49:19 isaaccp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -249,6 +249,7 @@
        void create_textbox(floating_textbox::MODE mode, const std::string& 
label, const std::string& check_label="", bool checked=false);
        void close_textbox();
        void enter_textbox();
+       void tab_textbox();
 
        replay_network_sender& replay_sender_;
 };




reply via email to

[Prev in Thread] Current Thread [Next in Thread]