bool iwPostWindow::ValidateMessages()
{
    if(lastMsgCt == postBox.GetNumMsgs() && GetMsg(curMsgId) == curMsg)
        return true;
    // Messages have changed -> Update filter
    FilterMessages();
    if(!curMsg)
    {
        // No last message? Display oldest
        curMsgId = 0;
        DisplayPostMessage();
        return false;
    } else
    {
        // Message was either deleted or others were added and message was shifted
        // So first search it, if not found we will display the next (newer) message
        for(unsigned i = curMsgId; i > 0; i--)
        {
            if(postBox.GetMsg(i - 1) == curMsg)
            {
                curMsgId = i - 1;
                DisplayPostMessage();
                return true;
            }
        }
        // Display next valid one
        DisplayPostMessage();
        return false;
    }
}
Beispiel #2
0
wxInt32 CViewMessages::GetDocCount() {
    if (m_enableMsgFilter) {
        FilterMessages();
        return m_filteredIndexes.size();
    } else {
        return wxGetApp().GetDocument()->GetMessageCount();
    }
}
void iwPostWindow::SwitchCategory(PostCategory cat)
{
    showAll = false;
    curCategory = cat;
    FilterMessages();
    curMsgId = curMsgIdxs.size();
    DisplayPostMessage();
}
iwPostWindow::iwPostWindow(GameWorldView& gwv, PostBox& postBox)
    : IngameWindow(CGI_POSTOFFICE, IngameWindow::posLastOrCenter, Extent(254, 295), _("Post office"), LOADER.GetImageN("resource", 41)),
      gwv(gwv), postBox(postBox), showAll(true), curCategory(PostCategory::General), curMsg(nullptr), lastHasMissionGoal(true)
{
    AddImageButton(ID_SHOW_ALL, DrawPoint(18, 25), Extent(35, 35), TC_GREY, LOADER.GetImageN("io", 190));  // Viewer: 191 - Papier
    AddImageButton(ID_SHOW_MIL, DrawPoint(56, 25), Extent(35, 35), TC_GREY, LOADER.GetImageN("io", 30));   // Viewer:  31 - Soldat
    AddImageButton(ID_SHOW_GEO, DrawPoint(91, 25), Extent(35, 35), TC_GREY, LOADER.GetImageN("io", 20));   // Viewer:  21 - Geologe
    AddImageButton(ID_SHOW_ECO, DrawPoint(126, 25), Extent(35, 35), TC_GREY, LOADER.GetImageN("io", 28));  // Viewer:  29 - Wage
    AddImageButton(ID_SHOW_GEN, DrawPoint(161, 25), Extent(35, 35), TC_GREY, LOADER.GetImageN("io", 189)); // Viewer: 190 - Neue Nachricht
    AddImageButton(ID_SHOW_GOAL, DrawPoint(199, 25), Extent(35, 35), TC_GREY, LOADER.GetImageN("io", 79)); // Viewer:  80 - Notiz
    AddImage(0, DrawPoint(126, 151), LOADER.GetImageN("io", 228));
    AddImageButton(ID_HELP, DrawPoint(18, 242), Extent(30, 35), TC_GREY, LOADER.GetImageN("io", 225));     // Viewer: 226 - Hilfe
    AddImageButton(ID_GO_START, DrawPoint(51, 246), Extent(30, 26), TC_GREY, LOADER.GetImageN("io", 102)); // Viewer: 103 - Schnell zurück
    AddImageButton(ID_GO_BACK, DrawPoint(81, 246), Extent(30, 26), TC_GREY, LOADER.GetImageN("io", 103));  // Viewer: 104 - Zurück
    AddImageButton(ID_GO_FWD, DrawPoint(111, 246), Extent(30, 26), TC_GREY, LOADER.GetImageN("io", 104));  // Viewer: 105 - Vor
    AddImageButton(ID_GO_END, DrawPoint(141, 246), Extent(30, 26), TC_GREY, LOADER.GetImageN("io", 105));  // Viewer: 106 - Schnell vor

    // Goto, nur sichtbar wenn Nachricht mit Koordinaten da
    AddImageButton(ID_GOTO, DrawPoint(181, 246), Extent(30, 26), TC_GREY, LOADER.GetImageN("io", 107))->SetVisible(false);
    // Mülleimer, nur sichtbar, wenn Nachricht da
    AddImageButton(ID_DELETE, DrawPoint(211, 246), Extent(30, 26), TC_GREY, LOADER.GetImageN("io", 106))->SetVisible(false);

    AddText(ID_INFO, DrawPoint(127, 228), "", MakeColor(255, 188, 100, 88), FontStyle::CENTER | FontStyle::BOTTOM, SmallFont)
      ->SetVisible(false);

    AddImage(ID_IMG, DrawPoint(127, 155), LOADER.GetImageN("io", 225));

    // Multiline-Teil mit drei leeren Zeilen erzeugen
    ctrlMultiline* text = AddMultiline(ID_TEXT, DrawPoint(126, 141), Extent(200, 0), TC_INVISIBLE, NormalFont,
                                       FontStyle::CENTER | FontStyle::BOTTOM | FontStyle::NO_OUTLINE);
    text->SetNumVisibleLines(4);
    text->ShowBackground(false);

    // Button with OK and deny sign (tick and cross) for contracts
    AddImageButton(ID_ACCEPT, DrawPoint(87, 185), Extent(30, 26), TC_GREEN1, LOADER.GetImageN("io", 32))->SetVisible(false);
    AddImageButton(ID_DENY, DrawPoint(137, 185), Extent(30, 26), TC_RED1, LOADER.GetImageN("io", 40))->SetVisible(false);

    FilterMessages();
    curMsgId = curMsgIdxs.size();
    DisplayPostMessage();
}
void iwPostWindow::Msg_ButtonClick(const unsigned ctrl_id)
{
    switch(ctrl_id)
    {
        case ID_HELP:
            WINDOWMANAGER.Show(
              std::make_unique<iwHelp>(GUI_ID(CGI_HELP), _("All important messages are collected in this window and "
                                                           "sorted into groups. If this window is not open, the dove "
                                                           "symbol at the bottom of the screen indicates the arrival of a new message.")));
            break;
        case ID_SHOW_ALL:
            showAll = true;
            FilterMessages();
            curMsgId = curMsgIdxs.size();
            DisplayPostMessage();
            break;
        case ID_SHOW_GOAL:
            if(!postBox.GetCurrentMissionGoal().empty())
                WINDOWMANAGER.Show(
                  std::make_unique<iwMissionStatement>(_("Diary"), postBox.GetCurrentMissionGoal(), false, iwMissionStatement::IM_AVATAR9));
            break;
        case ID_SHOW_MIL: SwitchCategory(PostCategory::Military); break;
        case ID_SHOW_GEO: SwitchCategory(PostCategory::Geologist); break;
        case ID_SHOW_ECO: SwitchCategory(PostCategory::Economy); break;
        case ID_SHOW_GEN: SwitchCategory(PostCategory::General); break;
        case ID_GO_START:
            // To oldest
            curMsgId = 0;
            DisplayPostMessage();
            break;
        case ID_GO_BACK:
            // Back
            curMsgId = (curMsgId > 0) ? curMsgId - 1 : 0;
            DisplayPostMessage();
            break;
        case ID_GO_FWD:
            // Forward
            ++curMsgId;
            DisplayPostMessage();
            break;
        case ID_GO_END:
            // To newest
            curMsgId = postBox.GetNumMsgs();
            DisplayPostMessage();
            break;
        case ID_GOTO:
        {
            // Goto
            if(!ValidateMessages())
                return;
            if(curMsg && curMsg->GetPos().isValid())
                gwv.MoveToMapPt(curMsg->GetPos());
        }
        break;

        case ID_DELETE: // Delete
        case ID_DENY:   // Cross (Deny)
        {
            if(!ValidateMessages() || !curMsg)
                return;
            const auto* dcurMsg = dynamic_cast<const DiplomacyPostQuestion*>(curMsg);
            if(dcurMsg)
            {
                // If it is a question about a new contract, tell the other player we denied it
                if(dcurMsg->IsAccept())
                    GAMECLIENT.CancelPact(dcurMsg->GetPactType(), dcurMsg->GetPlayerId());
            }
            postBox.DeleteMsg(curMsg);
        }
        break;

        // Haken-Button ("Ja")
        case ID_ACCEPT:
        {
            if(!ValidateMessages())
                return;
            const auto* dcurMsg = dynamic_cast<const DiplomacyPostQuestion*>(GetMsg(curMsgId));
            if(dcurMsg)
            {
                // New contract?
                if(dcurMsg->IsAccept())
                    GAMECLIENT.AcceptPact(dcurMsg->GetPactId(), dcurMsg->GetPactType(), dcurMsg->GetPlayerId());
                else
                    GAMECLIENT.CancelPact(dcurMsg->GetPactType(), dcurMsg->GetPlayerId());
                postBox.DeleteMsg(dcurMsg);
            }
        }
        break;
    }
}