1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
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/>.
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"
34 using namespace NLMISC
;
35 using namespace NLNET
;
37 CBotChatManager
*CBotChatManager::_Instance
= NULL
;
40 // ********************************************************************************************
41 CBotChatManager::CBotChatManager()
45 //_ChosenMissionFlags = 0;
48 // ********************************************************************************************
49 CBotChatManager::~CBotChatManager()
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
;
62 // ********************************************************************************************
63 void CBotChatManager::releaseInstance()
72 // ********************************************************************************************
73 void CBotChatManager::setCurrPage(CBotChatPage
*page
)
86 UserEntity
->trader(CLFECOMMON::INVALID_SLOT
);
90 if (page
== NULL
&& !_AHAfterEnd
.empty())
92 CAHManager::getInstance()->runActionHandler(_AHAfterEnd
, NULL
, "");
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();
115 //nldebug("impulseCallBack : BOTCHAT:END sent");
118 nlwarning("impulseCallBack : unknown message name : 'BOTCHAT:END'.");
122 // ***************************************************************************
123 void CBotChatManager::addMissionInfoWaiter(IMissionPrereqInfosWaiter
*waiter
)
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
136 if (GenericMsgHeaderMngr
.pushNameToStream("MISSION_PREREQ:GET", out
))
138 uint8 slotId
= (uint8
) waiter
->MissionSlotId
;
139 out
.serial( slotId
);
141 //nlinfo("impulseCallBack : MISSION_PREREQ:GET %d sent", slotId);
143 // Then push_front (stack)
144 _MissionInfoWaiters
.push_front(waiter
);
148 nlwarning(" unknown message name 'MISSION_PREREQ:GET'");
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
++)
166 _MissionInfoWaiters
.erase(it
);
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
187 _MissionInfoWaiters
.erase(itDel
);
196 // ***************************************************************************
197 void CBotChatManager::debugLocalReceiveMissionInfo()
202 TMissionPrereqInfosWaiter::iterator it
,itNext
;
203 for( it
= _MissionInfoWaiters
.begin() ; it
!= _MissionInfoWaiters
.end() ;)
205 IMissionPrereqInfosWaiter
*waiter
=*it
;
206 TMissionPrereqInfosWaiter::iterator itNext
= it
;
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
);
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);
234 CInterfaceGroup *help = (*it).second;
235 nlassert(help != NULL);
237 if (infos.Prerequisits.size() > 15)
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));
249 viewTextID->setTextId(infos.Prerequisits[i].Description);
252 if (!help->ScrollTextGroup.empty())
254 CInterfaceGroup *viewTextGroup = help->HelpWindow->getGroup(help->ScrollTextGroup);
256 viewTextGroup->setActive(false);
258 CInterfaceGroup *viewTextGroup = help->HelpWindow->getGroup(help->ScrollTextIdGroup);
260 viewTextGroup->setActive(true);
264 _MissionHelpWindowsWaiting.erase(index);
268 /////////////////////
269 // ACTION HANDLERS //
270 /////////////////////
272 /** The user has closed a botchat program
274 class CHandlerCloseBotChatProgram
: public IActionHandler
277 virtual void execute(CCtrlBase
* /* pCaller */, const std::string
&/* params */)
279 CBotChatManager::getInstance()->endDialog();
282 REGISTER_ACTION_HANDLER( CHandlerCloseBotChatProgram
, "close_bot_chat_program");