void ChatWindow::manageDiceRoll(QString str,QString& messageTitle,QString& message) { updateListAlias(); QString localPersonIdentifier = m_selectPersonComboBox->itemData(m_selectPersonComboBox->currentIndex(), PlayersList::IdentifierRole).toString(); Person * localPerson = PlayersList::instance()->getPerson(localPersonIdentifier); QColor color; if(m_diceParser->parseLine(str)) { m_diceParser->Start(); if(m_diceParser->getErrorMap().isEmpty()) { messageTitle = tr("You"); QString value; QString cmdLine; QString list; bool onlyValue = getMessageResult(value, cmdLine,list); color = localPerson->color(); if(!onlyValue) { QString diceOutput = tr("got <span class=\"dice\">%1</span> at your dice roll [%2 (%3)]", "You got").arg(value).arg(cmdLine).arg(list); showMessage(messageTitle, color, diceOutput,NetMsg::DiceMessageAction); QString diceOutput2 = tr("got <span class=\"dice\">%1</span> [%2 (%3)]","He got").arg(value).arg(cmdLine).arg(list); message = diceOutput2; } else { messageTitle=""; showMessage(messageTitle, color,value,NetMsg::DiceMessageAction); message = value; } } else { QString messageCorps = m_diceParser->humanReadableError(); messageTitle = tr("Syntax"); color = Qt::red; showMessage(messageTitle, color, messageCorps); } } else { QString messageCorps = m_diceParser->humanReadableError(); messageTitle = tr("Syntax"); color = Qt::red; showMessage(messageTitle, color, messageCorps); } }
QVariant PlayersList::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.column() != 0) return QVariant(); Person * person; int row = index.row(); if (row < 0) return QVariant(); quint32 parentRow = (quint32)(index.internalId() & NoParent); if (parentRow == NoParent) { if (row >= m_playersList.size()) return QVariant(); Player * player = m_playersList.at(row); person = player; if (role == Qt::BackgroundRole && player->isGM()) { QPalette pal = qApp->palette(); return QVariant(pal.color(QPalette::Active,QPalette::Button)); } } else { if (parentRow >= (quint32)m_playersList.size()) return QVariant(); Player * player = m_playersList.at(parentRow); if (row >= player->getCharactersCount()) return QVariant(); person = player->getCharacterByIndex(row); } switch (role) { case Qt::DisplayRole: case Qt::EditRole: return QVariant(person->name()); case Qt::DecorationRole: return QVariant(person->color()); case IdentifierRole: return QVariant(person->uuid()); } return QVariant(); }
// not (const QString & message), because we change it ! void ChatWindow::emettreTexte(bool hasHtml,QString message) { //NetMsg::ChatMessageAction, NetMsg::DiceMessageAction, NetMsg::EmoteMessageAction NetMsg::Action action = NetMsg::DiceMessageAction; bool ok=true; m_editionZone->clear(); QString localPersonIdentifier = m_selectPersonComboBox->itemData(m_selectPersonComboBox->currentIndex(), PlayersList::IdentifierRole).toString(); Person* localPerson = PlayersList::instance()->getPerson(localPersonIdentifier); QString tmpmessage=message.simplified(); QString messageCorps=""; QString messageTitle=""; QColor color; if(m_operatorMap->contains(tmpmessage.left(1))) { CHAT_OPERATOR chatOperator = m_operatorMap->value(tmpmessage.left(1)); tmpmessage=tmpmessage.remove(0,1); switch(chatOperator) { case DICEROLL: manageDiceRoll(tmpmessage,messageTitle,message); break; case SECRET_DICEROLL: manageDiceRoll(tmpmessage,messageTitle,message); return; break; case COMMAND: { int pos = tmpmessage.indexOf(' '); QString cmd = tmpmessage.left(pos); if(m_keyWordList.contains(cmd)) { tmpmessage=tmpmessage.remove(0,pos); message = tmpmessage; if (!m_warnedEmoteUnavailable && !m_chat->everyPlayerHasFeature(QString("Emote"))) { messageTitle = tr("Warning"); messageCorps = tr("Some users won't be enable to see your emotes."); color = Qt::red; showMessage(messageTitle, color, messageCorps); m_warnedEmoteUnavailable = true; } if(NULL!=localPerson) { showMessage(localPerson->name(), localPerson->color(), tmpmessage,NetMsg::EmoteMessageAction); action = NetMsg::EmoteMessageAction; } break; } } } } else {//sending info to others. messageTitle = localPerson->name(); if(!hasHtml) { message = message.toHtmlEscaped(); } message = message.replace('\n',"<br/>"); showMessage(messageTitle, localPerson->color(), message); action = NetMsg::ChatMessageAction; } if(!ok) return; // Emission du message NetworkMessageWriter data(NetMsg::ChatCategory, action); data.string8(localPersonIdentifier); data.string8(m_chat->identifier()); data.string32(message); m_chat->sendThem(data); }