Exemple #1
0
C4GUI::Edit::InputResult C4ChatInputDialog::OnChatInput(C4GUI::Edit *edt,
                                                        bool fPasting,
                                                        bool fPastingMore) {
  // no double processing
  if (fProcessed) return C4GUI::Edit::IR_CloseDlg;
  // get edit text
  C4GUI::Edit *pEdt = reinterpret_cast<C4GUI::Edit *>(edt);
  char *szInputText = const_cast<char *>(pEdt->GetText());
  // Store to back buffer
  Game.MessageInput.StoreBackBuffer(szInputText);
  // script queried input?
  if (fObjInput) {
    fProcessed = true;
    // check if the target input is still valid
    C4Player *pPlr = Game.Players.Get(iPlr);
    if (!pPlr) return C4GUI::Edit::IR_CloseDlg;
    if (!pPlr->MarkMessageBoardQueryAnswered(pTarget)) {
      // there was no associated query!
      return C4GUI::Edit::IR_CloseDlg;
    }
    // then do a script callback, incorporating the input into the answer
    if (fUppercase) SCapitalize(szInputText);
    StdStrBuf sInput;
    sInput.Copy(szInputText);
    sInput.EscapeString();
    Game.Control.DoInput(
        CID_Script,
        new C4ControlScript(
            FormatString("OnMessageBoardAnswer(Object(%d), %d, \"%s\")",
                         pTarget ? pTarget->Number : 0, iPlr,
                         sInput.getData()).getData()),
        CDT_Decide);
    return C4GUI::Edit::IR_CloseDlg;
  } else
    // reroute to message input class
    Game.MessageInput.ProcessInput(szInputText);
  // safety: message board commands may do strange things
  if (!C4GUI::IsGUIValid() || this != pInstance) return C4GUI::Edit::IR_Abort;
  // select all text to be removed with next keypress
  // just for pasting mode; usually the dlg will be closed now anyway
  pEdt->SelectAll();
  // avoid dlg close, if more content is to be pasted
  if (fPastingMore) return C4GUI::Edit::IR_None;
  fProcessed = true;
  return C4GUI::Edit::IR_CloseDlg;
}
Exemple #2
0
void C4ChatInputDialog::OnChatCancel() {
  // abort chat: Make sure msg board query is aborted
  fProcessed = true;
  if (fObjInput) {
    // check if the target input is still valid
    C4Player *pPlr = Game.Players.Get(iPlr);
    if (!pPlr) return;
    if (pPlr->MarkMessageBoardQueryAnswered(pTarget)) {
      // there was an associated query - it must be removed on all clients
      // synchronized via queue
      // do this by calling OnMessageBoardAnswer without an answer
      Game.Control.DoInput(
          CID_Script,
          new C4ControlScript(
              FormatString("OnMessageBoardAnswer(Object(%d), %d, 0)",
                           pTarget ? pTarget->Number : 0, iPlr).getData()),
          CDT_Decide);
    }
  }
}