Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interface_v3 / bot_chat_manager.cpp
blobd25763bffe3ef115af02a64aa45d5bea1364184f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "stdpch.h"
23 #include "bot_chat_manager.h"
24 #include "bot_chat_page.h"
25 #include "../net_manager.h"
26 #include "nel/gui/action_handler.h"
27 #include "../user_entity.h"
28 #include "interface_manager.h"
29 #include "nel/gui/view_text_id.h"
30 #include "nel/gui/interface_group.h"
31 #include "game_share/prerequisit_infos.h"
33 using namespace std;
34 using namespace NLMISC;
35 using namespace NLNET;
37 CBotChatManager *CBotChatManager::_Instance = NULL;
40 // ********************************************************************************************
41 CBotChatManager::CBotChatManager()
43 _CurrPage = NULL;
44 _SessionID = 0;
45 //_ChosenMissionFlags = 0;
48 // ********************************************************************************************
49 CBotChatManager::~CBotChatManager()
51 // Destruct
52 nlassert(_CurrPage == NULL); // should have called setCurrPage(NULL) before quitting (and before releasing the interface) !
55 // ********************************************************************************************
56 CBotChatManager *CBotChatManager::getInstance()
58 if (!_Instance) _Instance = new CBotChatManager;
59 return _Instance;
62 // ********************************************************************************************
63 void CBotChatManager::releaseInstance()
65 if( _Instance )
67 delete _Instance;
68 _Instance = NULL;
72 // ********************************************************************************************
73 void CBotChatManager::setCurrPage(CBotChatPage *page)
75 if (_CurrPage)
77 _CurrPage->end();
79 if (page)
81 page->begin();
83 else
85 if (UserEntity)
86 UserEntity->trader(CLFECOMMON::INVALID_SLOT);
88 _CurrPage = page;
91 // ********************************************************************************************
92 void CBotChatManager::update()
94 if (_CurrPage) _CurrPage->update();
97 // ********************************************************************************************
98 void CBotChatManager::endDialog()
100 NLMISC::CBitMemStream out;
101 if(GenericMsgHeaderMngr.pushNameToStream("BOTCHAT:END", out))
103 // must increment action counter
104 CInterfaceManager *pIM = CInterfaceManager::getInstance();
105 pIM->incLocalSyncActionCounter();
107 // send the msg
108 NetMngr.push(out);
109 //nldebug("impulseCallBack : BOTCHAT:END sent");
111 else
112 nlwarning("impulseCallBack : unknown message name : 'BOTCHAT:END'.");
113 setCurrPage(NULL);
116 // ***************************************************************************
117 void CBotChatManager::addMissionInfoWaiter(IMissionPrereqInfosWaiter *waiter)
119 if(!waiter)
120 return;
122 // first remove the waiter if already here
123 removeMissionInfoWaiter(waiter);
125 // **** send a message to server to ask for prerequisite infos
126 // Send a msg to server
127 if(!ClientCfg.Local)
129 CBitMemStream out;
130 if (GenericMsgHeaderMngr.pushNameToStream("MISSION_PREREQ:GET", out))
132 uint8 slotId = (uint8) waiter->MissionSlotId;
133 out.serial( slotId );
134 NetMngr.push(out);
135 //nlinfo("impulseCallBack : MISSION_PREREQ:GET %d sent", slotId);
137 // Then push_front (stack)
138 _MissionInfoWaiters.push_front(waiter);
140 else
142 nlwarning(" unknown message name 'MISSION_PREREQ:GET'");
145 // Debug Local
146 else
148 _MissionInfoWaiters.push_front(waiter);
152 // ***************************************************************************
153 void CBotChatManager::removeMissionInfoWaiter(IMissionPrereqInfosWaiter *waiter)
155 TMissionPrereqInfosWaiter::iterator it;
156 for(it= _MissionInfoWaiters.begin();it!=_MissionInfoWaiters.end();it++)
158 if(waiter==*it)
160 _MissionInfoWaiters.erase(it);
161 return;
166 // ***************************************************************************
167 void CBotChatManager::onReceiveMissionInfo(uint16 missionSlotId, const CPrerequisitInfos &infos)
169 TMissionPrereqInfosWaiter::iterator it,itDel;
170 for( it = _MissionInfoWaiters.begin() ; it != _MissionInfoWaiters.end() ; )
172 IMissionPrereqInfosWaiter *waiter=*it;
174 if(waiter->MissionSlotId == missionSlotId)
176 waiter->missionInfoReceived(infos);
178 // remove waiter as infos received
179 itDel = it;
180 ++it;
181 _MissionInfoWaiters.erase(itDel);
183 else
185 ++it;
190 // ***************************************************************************
191 void CBotChatManager::debugLocalReceiveMissionInfo()
193 #if FINAL_VERSION
194 return;
195 #endif
196 TMissionPrereqInfosWaiter::iterator it,itNext;
197 for( it = _MissionInfoWaiters.begin() ; it != _MissionInfoWaiters.end() ;)
199 IMissionPrereqInfosWaiter *waiter=*it;
200 TMissionPrereqInfosWaiter::iterator itNext= it;
201 itNext++;
203 // it will be deleted
204 CPrerequisitInfos infos;
205 infos.Prerequisits.push_back(CPrerequisitDesc(1,false, true));
206 infos.Prerequisits.push_back(CPrerequisitDesc(2,true, false));
207 infos.Prerequisits.push_back(CPrerequisitDesc(3,false, false));
208 infos.Prerequisits.push_back(CPrerequisitDesc(4,false, true));
209 onReceiveMissionInfo(waiter->MissionSlotId, infos);
211 // next
212 it= itNext;
218 // ********************************************************************************************
219 /*void CBotChatManager::processMissionHelpInfos(uint8 index, CPrerequisitInfos &infos)
221 std::map<uint8,CInterfaceGroup*>::iterator it = _MissionHelpWindowsWaiting.find(index);
222 if (it == _MissionHelpWindowsWaiting.end())
224 nlwarning("Error, mission help window for mission index %u not found", index);
225 return;
228 CInterfaceGroup *help = (*it).second;
229 nlassert(help != NULL);
231 if (infos.Prerequisits.size() > 15)
233 // blabla
236 for (uint i = 0 ; i < infos.Prerequisits.size() ; ++i)
238 const std::string textId = NLMISC::toString("text_id_prereq_%u",i+1);
240 CViewTextID *viewTextID = dynamic_cast<CViewTextID *>(help->getView(textId));
241 if(viewTextID)
243 viewTextID->setTextId(infos.Prerequisits[i].Description);
245 #if 0
246 if (!help->ScrollTextGroup.empty())
248 CInterfaceGroup *viewTextGroup = help->HelpWindow->getGroup(help->ScrollTextGroup);
249 if (viewTextGroup)
250 viewTextGroup->setActive(false);
252 CInterfaceGroup *viewTextGroup = help->HelpWindow->getGroup(help->ScrollTextIdGroup);
253 if (viewTextGroup)
254 viewTextGroup->setActive(true);
255 #endif
258 _MissionHelpWindowsWaiting.erase(index);
262 /////////////////////
263 // ACTION HANDLERS //
264 /////////////////////
266 /** The user has closed a botchat program
268 class CHandlerCloseBotChatProgram : public IActionHandler
270 public:
271 virtual void execute(CCtrlBase * /* pCaller */, const std::string &/* params */)
273 CBotChatManager::getInstance()->endDialog();
276 REGISTER_ACTION_HANDLER( CHandlerCloseBotChatProgram, "close_bot_chat_program");