Planeshift

chatwindow.h

Go to the documentation of this file.
00001 /*
00002  * chatwindow.h - Author: Andrew Craig
00003  *
00004  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 // chatwindow.h: interface for the pawsChatWindow class.
00021 //
00023 
00024 #ifndef PAWS_CHAT_WINDOW
00025 #define PAWS_CHAT_WINDOW
00026 
00027 // CS INCLUDES
00028 #include <csutil/array.h>
00029 #include <csutil/redblacktree.h>
00030 #include <csutil/hashr.h>
00031 
00032 #include "net/cmdbase.h"
00033 #include "util/stringarray.h"
00034 
00035 // Hunspell includes
00036 #ifdef HUNSPELL
00037 #include <hunspell.hxx>
00038 #endif
00039 
00040 // PAWS INCLUDES
00041 #include "paws/pawswidget.h"
00042 #include "paws/pawsmenu.h"
00043 #include "gui/pawsignore.h"
00044 #include "gui/pawscontrolwindow.h"
00045 
00046 #define CONFIG_CHAT_FILE_NAME       "/planeshift/userdata/options/chat.xml"
00047 #define CONFIG_CHAT_FILE_NAME_DEF   "/planeshift/data/options/chat_def.xml"
00048 
00049 enum CHAT_COMBAT_FILTERS {
00050     COMBAT_SUCCEEDED = 1,
00051     COMBAT_BLOCKED   = 2,
00052     COMBAT_DODGED    = 4,
00053     COMBAT_MISSED    = 8,
00054     COMBAT_FAILED    = 16,
00055     COMBAT_STANCE    = 32,
00056     COMBAT_TOTAL_AMOUNT = 6
00057 };
00058 
00059 class pawsMessageTextBox;
00060 //class pawsEditTextBox;
00061 class pawsChatHistory;
00062 class pawsTabWindow;
00063 //struct iSoundManager;
00064 
00066 struct ChatSettings
00067 {
00069     int playerColor;
00070     int chatColor;
00071     int systemColor;
00072     int adminColor;
00073     int npcColor;
00074     int tellColor;
00075     int guildColor;
00076     int allianceColor;
00077     int shoutColor;
00078     int channelColor;
00079     int gmColor;
00080     int yourColor;
00081     int groupColor;
00082     int auctionColor;
00083     int helpColor;
00084     bool joindefaultchannel;
00085     bool defaultlastchat;
00086     bool looseFocusOnSend;
00087     bool mouseFocus;
00088     bool dirtyLogChannelFile[CHAT_END]; 
00089     csString logChannelFile[CHAT_END];  
00090     csString channelBracket[CHAT_END];  
00091     bool enabledLogging[CHAT_END]; 
00092     bool enableBadWordsFilterIncoming;
00093     bool enableBadWordsFilterOutgoing;
00094     bool echoScreenInSystem;
00095     bool mainBrackets; 
00096     bool yourColorMix; 
00097 
00098     csArray<csString> badWords;
00099     csArray<csString> goodWords;
00100     csArray<csString> completionItems; 
00101 
00102     csHash<csString, csString> bindings;
00103     csArray<csString> subNames;
00104     int selectTabStyle;
00105     int vicinityFilters; 
00106     int meFilters; 
00107     unsigned int tabSetting; 
00108     
00114     void SetLogChannelFile(unsigned int type, csString newName)
00115     {
00116         if(type < CHAT_END && newName != logChannelFile[type])
00117         {
00118             dirtyLogChannelFile[type] = true;
00119             logChannelFile[type] = newName;
00120         }
00121     }
00122 };
00123 
00124 
00125 //--------------------------------------------------------------------------
00126 
00127 
00133 class pawsChatWindow  : public pawsControlledWindow, public psCmdBase
00134 {
00135 public:
00136     pawsChatWindow();
00137     virtual ~pawsChatWindow();
00138 
00141     void HandleMessage( MsgEntry* message );
00142 
00145     const char* HandleCommand( const char* cmd );
00146 
00147     bool OnMenuAction(pawsWidget * widget, const pawsMenuAction & action);
00148     bool PostSetup();
00149 
00150     bool OnChildMouseEnter(pawsWidget* widget);
00151     bool OnChildMouseExit(pawsWidget* widget);
00152 
00153     bool OnMouseDown( int button, int modifiers, int x , int y );
00154 
00155     bool OnKeyDown( utf32_char keyCode, utf32_char key, int modifiers );
00156 
00165     bool OnDoubleClick(int button, int modifiers, int x , int y) { return OnMouseDown(button, modifiers, x, y); }
00166 
00170     bool InputActive();
00171 
00172     virtual bool OnButtonPressed( int button, int keyModifier, pawsWidget* widget );
00173     void SwitchChannel(const csString &name, pawsWidget* widget = NULL);
00174 
00175     void PerformAction( const char* action );
00176 
00178     void Clear(int mode = -2); // -2 means "/clear all"
00179 
00180        void SelectChatTab(int tab);
00181 
00182 
00183     void AutoReply(void);
00184 
00186     void SetAway(const char* text);
00187 
00188     virtual void OnLostFocus();
00189     virtual void Show();
00190 
00191     csString GetBracket(int type); 
00192 
00194     void ChatOutput(const char* data, int colour = -1, int type = CHAT_SYSTEM, bool flashEnabled = true, bool hasCharName = false, int hotkeyChannel = 0);
00195 
00196     void AddAutoCompleteName(const char *name);
00197     void RemoveAutoCompleteName(const char *name);
00198 
00199     ChatSettings& GetSettings() {return settings;}
00200 
00201     void SaveChatSettings();
00202     void LoadChatSettings();
00203 
00204     void RefreshCommandList();
00205 
00206     pawsIgnoreWindow*  GetIgnoredList() { return IgnoredList; }
00207 
00209     void BadWordsFilter(csString& s);
00210 
00212     int mixColours(int colour1, int colour2);
00213 
00215     bool LeaveChannel(int hotkeyChannel);
00216 
00218     void JoinChannel(csString name);
00219     
00220     /* returns the input text box widget
00221      */
00222     pawsEditTextBox* getInputTextBox() {return inputText;};
00223     
00224     void writeChatHistory();
00225 
00227     void ReloadChatWindow();
00228 
00232     char const * GetFontName()
00233     {
00234         return fontName.GetData();
00235     }
00236 
00240     bool LoadSetting();
00241 
00245    void  SetChatWindowFont(const char *FontName, int FontSize);
00246 
00247 
00248 protected:
00249 
00250     void HandleSystemMessage( MsgEntry* message );
00251 
00260     void FormatMessage(csString &sText, csString &sPerson, csString prependingText, csString &buff, bool &hasCharName);
00261 
00263     void SendChatLine(csString& inputText);
00264 
00266     void SubscribeCommands();
00267 
00269     void TabCompleteCommand(const char *cmd);
00270     void TabCompleteName(const char *cmd);
00271 
00272     void DetermineChatTabAndSelect(int chattype);        
00273 
00274 
00275     pawsIgnoreWindow*  IgnoredList;
00276     csString           replyList[4];
00277     int replyCount;
00278 
00279     csString awayText;
00280 
00282     csArray<csString> autoCompleteNames;
00284     csArray<csArray<csString> *> autoCompleteLists;
00285 
00287     csRedBlackTree<psString> commandList;
00288     csArray<csString> systemTriggers;
00289     csArray<csString> chatTriggers;
00290 
00292     pawsEditTextBox* inputText;
00293 
00294     pawsTabWindow* tabs;
00295 
00297     bool havePlayerName;
00298 
00300     csString noCasePlayerName;
00301     csString noCasePlayerForename;
00302 
00304     pawsChatHistory* chatHistory;
00305 
00307     csString currLine;
00308 
00310     ChatSettings settings;
00311 
00313     csRef<iFile> logFile[CHAT_END];
00315     csHash<csRef<iFile>, uint> openLogFiles;
00316 
00318     bool isInChannel;
00319 
00326     void LogMessage(const char* message, int type = CHAT_SAY);
00327 
00328     void CreateSettingNode(iDocumentNode* mNode,int color,const char* name);
00329 
00333     void ReplayMessages(unsigned int reqLines);
00334 
00336     csHashReversible<uint32_t, csString> channelIDs;
00338     csArray<uint16_t> channels;        
00339 };
00340 
00341 //--------------------------------------------------------------------------
00342 
00343 CREATE_PAWS_FACTORY( pawsChatWindow );
00344 
00345 
00346 //--------------------------------------------------------------------------
00351 class pawsChatHistory
00352 {
00353 public:
00354     pawsChatHistory();
00355     ~pawsChatHistory();
00356 
00360     void Insert(const char *str);
00361 
00366     csString* GetCommand(int n);
00367 
00369     csString* GetNext();
00370 
00372     csString* GetPrev();
00373 
00374     void SetGetLoc(unsigned int pos) { getLoc = pos; }
00375     unsigned int curLoc() { return getLoc; };
00376 
00377 private:
00379     unsigned int getLoc;
00380 
00382     csPDelArray<csString> buffer;
00383 };
00384 
00385 #endif