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
);
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();
109 //nldebug("impulseCallBack : BOTCHAT:END sent");
112 nlwarning("impulseCallBack : unknown message name : 'BOTCHAT:END'.");
116 // ***************************************************************************
117 void CBotChatManager::addMissionInfoWaiter(IMissionPrereqInfosWaiter
*waiter
)
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
130 if (GenericMsgHeaderMngr
.pushNameToStream("MISSION_PREREQ:GET", out
))
132 uint8 slotId
= (uint8
) waiter
->MissionSlotId
;
133 out
.serial( slotId
);
135 //nlinfo("impulseCallBack : MISSION_PREREQ:GET %d sent", slotId);
137 // Then push_front (stack)
138 _MissionInfoWaiters
.push_front(waiter
);
142 nlwarning(" unknown message name 'MISSION_PREREQ:GET'");
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
++)
160 _MissionInfoWaiters
.erase(it
);
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
181 _MissionInfoWaiters
.erase(itDel
);
190 // ***************************************************************************
191 void CBotChatManager::debugLocalReceiveMissionInfo()
196 TMissionPrereqInfosWaiter::iterator it
,itNext
;
197 for( it
= _MissionInfoWaiters
.begin() ; it
!= _MissionInfoWaiters
.end() ;)
199 IMissionPrereqInfosWaiter
*waiter
=*it
;
200 TMissionPrereqInfosWaiter::iterator itNext
= it
;
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
);
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);
228 CInterfaceGroup *help = (*it).second;
229 nlassert(help != NULL);
231 if (infos.Prerequisits.size() > 15)
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));
243 viewTextID->setTextId(infos.Prerequisits[i].Description);
246 if (!help->ScrollTextGroup.empty())
248 CInterfaceGroup *viewTextGroup = help->HelpWindow->getGroup(help->ScrollTextGroup);
250 viewTextGroup->setActive(false);
252 CInterfaceGroup *viewTextGroup = help->HelpWindow->getGroup(help->ScrollTextIdGroup);
254 viewTextGroup->setActive(true);
258 _MissionHelpWindowsWaiting.erase(index);
262 /////////////////////
263 // ACTION HANDLERS //
264 /////////////////////
266 /** The user has closed a botchat program
268 class CHandlerCloseBotChatProgram
: public IActionHandler
271 virtual void execute(CCtrlBase
* /* pCaller */, const std::string
&/* params */)
273 CBotChatManager::getInstance()->endDialog();
276 REGISTER_ACTION_HANDLER( CHandlerCloseBotChatProgram
, "close_bot_chat_program");