Modal Dialogs / Support for 9.70

OTC now supports showing and answering modal dialogs.

addDialog(modaldialog, dialogId, cid, callback)

TODO:
-find out what the "popup" value does.. (Maybe someone knows)
This commit is contained in:
Samuel
2012-11-27 14:48:48 +01:00
parent bce8e90ede
commit eb979ef7cd
11 changed files with 217 additions and 11 deletions

View File

@@ -408,6 +408,11 @@ void Game::processQuestLine(int questId, const std::vector<std::tuple<std::strin
g_lua.callGlobalField("g_game", "onQuestLine", questId, questMissions);
}
void Game::processModalDialog(uint32 id, std::string title, std::string message, int enterId, std::string enterText, int escapeId, std::string escapeText, std::vector<std::tuple<int, std::string> > choiceList)
{
g_lua.callGlobalField("g_game", "onModalDialog", id, title, message, enterId, enterText, escapeId, escapeText, choiceList);
}
void Game::processAttackCancel(uint seq)
{
if(isAttacking() && (seq == 0 || m_seq == seq))
@@ -1125,6 +1130,14 @@ void Game::requestItemInfo(const ItemPtr& item, int index)
m_protocolGame->sendRequestItemInfo(item->getId(), item->getSubType(), index);
}
void Game::answerModalDialog(int dialog, int button, int choice)
{
if(!canPerformGameAction())
return;
m_protocolGame->sendAnswerModalDialog(dialog, button, choice);
}
void Game::ping()
{
if(!m_protocolGame || !m_protocolGame->isConnected())
@@ -1168,7 +1181,7 @@ void Game::setClientVersion(int version)
if(isOnline())
stdext::throw_exception("Unable to change client version while online");
if(version != 0 && (version < 810 || version > 963))
if(version != 0 && (version < 810 || version > 970))
stdext::throw_exception(stdext::format("Protocol version %d not supported", version));
m_features.reset();

View File

@@ -122,6 +122,9 @@ protected:
void processQuestLog(const std::vector<std::tuple<int, std::string, bool> >& questList);
void processQuestLine(int questId, const std::vector<std::tuple<std::string, std::string> >& questMissions);
// modal dialogs >= 970
void processModalDialog(uint32 id, std::string title, std::string message, int enterId, std::string enterText, int escapeId, std::string escapeText, std::vector<std::tuple<int, std::string> > choiceList);
friend class ProtocolGame;
friend class Map;
@@ -232,6 +235,10 @@ public:
// 910 only
void requestItemInfo(const ItemPtr& item, int index);
// >= 970 modal dialog
void answerModalDialog(int dialog, int button, int choice);
//void reportRuleViolation2();
void ping();

View File

@@ -228,6 +228,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindSingletonFunction("g_game", "getFeature", &Game::getFeature, &g_game);
g_lua.bindSingletonFunction("g_game", "setFeature", &Game::setFeature, &g_game);
g_lua.bindSingletonFunction("g_game", "enableFeature", &Game::enableFeature, &g_game);
g_lua.bindSingletonFunction("g_game", "answerModalDialog", &Game::answerModalDialog, &g_game);
g_lua.registerSingletonClass("g_shaders");
g_lua.bindSingletonFunction("g_shaders", "createShader", &ShaderManager::createShader, &g_shaders);

View File

@@ -105,6 +105,7 @@ public:
void sendRequestQuestLine(int questId);
void sendNewNewRuleViolation(int reason, int action, const std::string& characterName, const std::string& comment, const std::string& translation);
void sendRequestItemInfo(int itemId, int subType, int index);
void sendAnswerModalDialog(int dialog, int button, int choice);
protected:
void onConnect();

View File

@@ -308,6 +308,10 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg)
case Proto::GameServerExtendedOpcode:
parseExtendedOpcode(msg);
break;
// PROTOCOL>=970
case Proto::GameServerShowModalDialog:
parseShowModalDialog(msg);
break;
default:
stdext::throw_exception(stdext::format("unhandled opcode %d", (int)opcode));
break;
@@ -1358,16 +1362,45 @@ void ProtocolGame::parsePlayerInventory(const InputMessagePtr& msg)
void ProtocolGame::parseShowModalDialog(const InputMessagePtr& msg)
{
msg->getU32(); // id
msg->getString(); // title
msg->getString(); // message
int size = msg->getU8();
for(int i=0;i<size;++i) {
msg->getString(); // button name
msg->getU8(); // button value
uint32 id = msg->getU32();
std::string title = msg->getString();
std::string message = msg->getString();
int sizeButtons = msg->getU8();
std::map<int, std::string > buttonList;
for(int i = 0; i < sizeButtons; ++i) {
std::string name = msg->getString();
int value = msg->getU8();
buttonList[value] = name;
}
msg->getU8(); // default escape button
msg->getU8(); // default enter button
int sizeChoices = msg->getU8();
std::vector<std::tuple<int, std::string> > choiceList;
for(int i = 0; i < sizeChoices; ++i) {
std::string name = msg->getString();
int value = msg->getU8();
choiceList.push_back(std::make_tuple(value, name));
}
int enterButton = msg->getU8();
int escapeButton = msg->getU8();
msg->getU8(); // popup value (no clue what it is for)
std::map<int, std::string >::iterator itEnter = buttonList.find(enterButton);
if(itEnter == buttonList.end())
{
g_logger.info(stdext::format("Enter button does not exist for dialog id: %d", id));
return;
}
std::map<int, std::string >::iterator itEscape = buttonList.find(escapeButton);
if(itEscape == buttonList.end())
{
g_logger.info(stdext::format("Escape button does not exist for dialog id: %d", id));
return;
}
g_game.processModalDialog(id, title, message, itEnter->first, itEnter->second, itEscape->first, itEscape->second, choiceList);
}
void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg)

View File

@@ -751,6 +751,16 @@ void ProtocolGame::sendRequestItemInfo(int itemId, int subType, int index)
send(msg);
}
void ProtocolGame::sendAnswerModalDialog(int dialog, int button, int choice)
{
OutputMessagePtr msg(new OutputMessage);
msg->addU8(Proto::ClientAnswerModalDialog);
msg->addU32(dialog);
msg->addU8(button);
msg->addU8(choice);
send(msg);
}
void ProtocolGame::addPosition(const OutputMessagePtr& msg, const Position& position)
{
msg->addU16(position.x);