Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / interface_v3 / bot_chat_manager.cpp
blob839381b91e109f282df1d143f56aca5a0a4f8887
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;
90 if (page == NULL && !_AHAfterEnd.empty())
92 CAHManager::getInstance()->runActionHandler(_AHAfterEnd, NULL, "");
93 _AHAfterEnd = "";
97 // ********************************************************************************************
98 void CBotChatManager::update()
100 if (_CurrPage) _CurrPage->update();
103 // ********************************************************************************************
104 void CBotChatManager::endDialog()
106 NLMISC::CBitMemStream out;
107 if(GenericMsgHeaderMngr.pushNameToStream("BOTCHAT:END", out))
109 // must increment action counter
110 CInterfaceManager *pIM = CInterfaceManager::getInstance();
111 pIM->incLocalSyncActionCounter();
113 // send the msg
114 NetMngr.push(out);
115 //nldebug("impulseCallBack : BOTCHAT:END sent");
117 else
118 nlwarning("impulseCallBack : unknown message name : 'BOTCHAT:END'.");
119 setCurrPage(NULL);
122 // ***************************************************************************
123 void CBotChatManager::addMissionInfoWaiter(IMissionPrereqInfosWaiter *waiter)
125 if(!waiter)
126 return;
128 // first remove the waiter if already here
129 removeMissionInfoWaiter(waiter);
131 // **** send a message to server to ask for prerequisite infos
132 // Send a msg to server
133 if(!ClientCfg.Local)
135 CBitMemStream out;
136 if (GenericMsgHeaderMngr.pushNameToStream("MISSION_PREREQ:GET", out))
138 uint8 slotId = (uint8) waiter->MissionSlotId;
139 out.serial( slotId );
140 NetMngr.push(out);
141 //nlinfo("impulseCallBack : MISSION_PREREQ:GET %d sent", slotId);
143 // Then push_front (stack)
144 _MissionInfoWaiters.push_front(waiter);
146 else
148 nlwarning(" unknown message name 'MISSION_PREREQ:GET'");
151 // Debug Local
152 else
154 _MissionInfoWaiters.push_front(waiter);
158 // ***************************************************************************
159 void CBotChatManager::removeMissionInfoWaiter(IMissionPrereqInfosWaiter *waiter)
161 TMissionPrereqInfosWaiter::iterator it;
162 for(it= _MissionInfoWaiters.begin();it!=_MissionInfoWaiters.end();it++)
164 if(waiter==*it)
166 _MissionInfoWaiters.erase(it);
167 return;
172 // ***************************************************************************
173 void CBotChatManager::onReceiveMissionInfo(uint16 missionSlotId, const CPrerequisitInfos &infos)
175 TMissionPrereqInfosWaiter::iterator it,itDel;
176 for( it = _MissionInfoWaiters.begin() ; it != _MissionInfoWaiters.end() ; )
178 IMissionPrereqInfosWaiter *waiter=*it;
180 if(waiter->MissionSlotId == missionSlotId)
182 waiter->missionInfoReceived(infos);
184 // remove waiter as infos received
185 itDel = it;
186 ++it;
187 _MissionInfoWaiters.erase(itDel);
189 else
191 ++it;
196 // ***************************************************************************
197 void CBotChatManager::debugLocalReceiveMissionInfo()
199 #if FINAL_VERSION
200 return;
201 #endif
202 TMissionPrereqInfosWaiter::iterator it,itNext;
203 for( it = _MissionInfoWaiters.begin() ; it != _MissionInfoWaiters.end() ;)
205 IMissionPrereqInfosWaiter *waiter=*it;
206 TMissionPrereqInfosWaiter::iterator itNext= it;
207 itNext++;
209 // it will be deleted
210 CPrerequisitInfos infos;
211 infos.Prerequisits.push_back(CPrerequisitDesc(1,false, true));
212 infos.Prerequisits.push_back(CPrerequisitDesc(2,true, false));
213 infos.Prerequisits.push_back(CPrerequisitDesc(3,false, false));
214 infos.Prerequisits.push_back(CPrerequisitDesc(4,false, true));
215 onReceiveMissionInfo(waiter->MissionSlotId, infos);
217 // next
218 it= itNext;
224 // ********************************************************************************************
225 /*void CBotChatManager::processMissionHelpInfos(uint8 index, CPrerequisitInfos &infos)
227 std::map<uint8,CInterfaceGroup*>::iterator it = _MissionHelpWindowsWaiting.find(index);
228 if (it == _MissionHelpWindowsWaiting.end())
230 nlwarning("Error, mission help window for mission index %u not found", index);
231 return;
234 CInterfaceGroup *help = (*it).second;
235 nlassert(help != NULL);
237 if (infos.Prerequisits.size() > 15)
239 // blabla
242 for (uint i = 0 ; i < infos.Prerequisits.size() ; ++i)
244 const std::string textId = NLMISC::toString("text_id_prereq_%u",i+1);
246 CViewTextID *viewTextID = dynamic_cast<CViewTextID *>(help->getView(textId));
247 if(viewTextID)
249 viewTextID->setTextId(infos.Prerequisits[i].Description);
251 #if 0
252 if (!help->ScrollTextGroup.empty())
254 CInterfaceGroup *viewTextGroup = help->HelpWindow->getGroup(help->ScrollTextGroup);
255 if (viewTextGroup)
256 viewTextGroup->setActive(false);
258 CInterfaceGroup *viewTextGroup = help->HelpWindow->getGroup(help->ScrollTextIdGroup);
259 if (viewTextGroup)
260 viewTextGroup->setActive(true);
261 #endif
264 _MissionHelpWindowsWaiting.erase(index);
268 /////////////////////
269 // ACTION HANDLERS //
270 /////////////////////
272 /** The user has closed a botchat program
274 class CHandlerCloseBotChatProgram : public IActionHandler
276 public:
277 virtual void execute(CCtrlBase * /* pCaller */, const std::string &/* params */)
279 CBotChatManager::getInstance()->endDialog();
282 REGISTER_ACTION_HANDLER( CHandlerCloseBotChatProgram, "close_bot_chat_program");