Beispiel #1
0
bool LobbyForm::DoModal(int *presult, Sfx sfxShow,  Sfx sfxHide) {
    char name[kcbPlayerName*2];
    handler_.GetPlayerName(name, sizeof(name));
    LabelControl *plbl = (LabelControl *)GetControlPtr(kidcPlayerName);
    plbl->Show(false);
    plbl = (LabelControl *)GetControlPtr(kidcPlayerNameLabel);
    const char *s = base::Format::ToString("%s / %s", name,
        server_name_.c_str());
    plbl->SetText(s);

    ListControl *plstc = (ListControl *)GetControlPtr(kidcRoomList);
    Rect rcList;
    plstc->GetRect(&rcList);
    Font *pfnt = plstc->GetFont();
    int cxPrivate = pfnt->GetTextExtent("PRIVATE");
    int cxStart = rcList.Width() / 20; // 10;
    plstc->SetTabStops(0, cxStart, rcList.Width() - cxStart - cxPrivate);
    plstc->SetTabFlags(0, kfLstTabEllipsis, 0);
    GetControlPtr(kidcJoinRoom)->Show(false);

    Show(true);
    gptra->SetCallback(this);
    dword result = gptra->JoinLobby(this);
    if (result != knLobbyJoinResultSuccess) {
        gptra->SetCallback(NULL);
        ShowJoinMessage(result);
        *presult = 0;
        return false;
    }
    bool success = ShellForm::DoModal(presult, sfxShow, sfxHide);
    gptra->LeaveLobby();
    gptra->SetCallback(NULL);

    return success;
}
bool DownloadMissionPackForm::ShowInfo(bool fRequest) {
    ListControl *plstc = (ListControl *)GetControlPtr(kidcMissionPackList);
    IndexEntry *entry = (IndexEntry *)plstc->GetSelectedItemData();
    if (entry == NULL) {
        GetControlPtr(kidcDiscuss)->Show(false);
        return false;
    }
    const json::JsonMap *map = gppim->GetInfoMap(&entry->packid);
    if (map == NULL) {
        if (fRequest) {
            if (entry->packid.id == PACKID_CUSTOMURL) {
               ShowStatus(CTX_INFO, "Press Download to download from a custom URL");
            } else {
                gppim->Start(&entry->packid, CTX_INFO, this);
                ShowStatus(CTX_INFO, "Loading Mission Pack info...");
            }
        }
        GetControlPtr(kidcDiscuss)->Show(false);
        return false;
    }

    const char *author = GetString(map, "a", "unknown");
    const char *desc = GetString(map, "d", "no description");
    const char *s = base::Format::ToString("By %s: %s", author, desc);
    delete map;

    LabelControl *plbl = (LabelControl *)GetControlPtr(kidcMissionPackInfo);
    plbl->SetText((char *)s);
    GetControlPtr(kidcDiscuss)->Show(true);
    return true;
}
Beispiel #3
0
void LobbyForm::OnLurkerCount(dword count) {
    lurkers_ = count;
    if (zipdone_) {
        LabelControl *plbl = (LabelControl *)GetControlPtr(kidcLurkerCount);
        plbl->SetText(base::Format::ToString("Lurkers: %d", count));
    }
}
void DownloadMissionPackForm::ShowStatus(void *ctx, const char *psz) {
    if (ctx == CTX_INDEX) {
        ListControl *plstc = (ListControl *)GetControlPtr(kidcMissionPackList);
        plstc->Clear();
        plstc->SetTabStops(0);
        plstc->SetTabFlags(0);
        plstc->Add(psz, NULL);
    }

    if (ctx == CTX_INFO) {
        LabelControl *plbl =
                (LabelControl *)GetControlPtr(kidcMissionPackInfo);
        plbl->SetText((char *)psz);
    }

    // Force the frame draw, since this gets called while the main loop
    // is "asleep".
    gpmfrmm->DrawFrame(false);
}
void DownloadMissionPackForm::HideShow() {
    ListControl *plstc = (ListControl *)GetControlPtr(kidcMissionPackList);
    LabelControl *plbl = (LabelControl *)GetControlPtr(kidcMissionPackInfo);
    ButtonControl *pbtn = (ButtonControl *)GetControlPtr(kidcOk);
    int selected = plstc->GetSelectedItemIndex();
    if (selected < 0) {
        gppim->Reset();
        plbl->SetText("");
        pbtn->Show(false);
        GetControlPtr(kidcDiscuss)->Show(false);
        return;
    }

    // Get the pack info for this pack
       
    IndexEntry *entry = (IndexEntry *)plstc->GetSelectedItemData();
    if (entry == NULL) {
        return;
    }
        
    char *psz = NULL;
    switch (gppackm->IsInstalled(&entry->packid)) {
    case 0:
        psz = "DOWNLOAD";
        break;

    case 1:
        psz = "REMOVE";
        break;

    case 2:
        psz = "UPGRADE";
        break;
    }
    if (psz != NULL) {
        pbtn->SetText(psz);
    }

    pbtn->Show(true);
    ShowInfo(true);
}
void CreateGameForm::UpdateLabels() {
    // Update Game Speed label
    
    char szT[80];
    GetSpeedMultiplierString(szT, m_tGameSpeed);
    LabelControl *plbl = (LabelControl *)GetControlPtr(kidcGameSpeedLabel);
    plbl->SetText(szT);
    
    // Update Mission Pack Info label
    
    plbl = (LabelControl *)GetControlPtr(kidcMissionPackInfo);
    ListControl *plstc = m_aplstc[IndexFromMissionType(m_mt)];
    if (plstc->GetSelectedItemIndex() == -1) {
        plbl->SetText("");
        return;
    }
    int i = (int)plstc->GetSelectedItemData();
    MissionIdentifier miid;
    if (!m_pml->GetMissionIdentifier(i, &miid)) {
        plbl->SetText("");
        return;
    }
    json::JsonMap *map = gppim->GetInfoMap(&miid.packid);
    if (map == NULL) {
        MissionDescription md;
        if (!m_pml->GetMissionDescription(i, &md)) {
            plbl->SetText("");
            return;
        }
        const char *s;
        if (miid.packid.id == PACKID_MAIN) {
            s = base::Format::ToString("%s by Spiffcode, Inc.",
                                       md.szPackName);
        } else {
            s = md.szPackName;
        }
        plbl->SetText((char *)s);
        return;
    }
    const char *szAuthor = GetString(map, "a");
    const char *szTitle = GetString(map, "t");
    const char *s = base::Format::ToString("%s by %s", szTitle, szAuthor);
    plbl->SetText((char *)s);
    delete map;
}
void DownloadMissionPackForm::Sort(word id) {
    word aidColumns[] = {
        kidcStatus, kidcTitle, kidcNumPlayers, kidcNumMissions
    };

    int iCol;
    for (iCol = 0; iCol < ARRAYSIZE(aidColumns); iCol++) {
        if (id == aidColumns[iCol]) {
            break;
        }
    }
    if (iCol >= ARRAYSIZE(aidColumns)) {
        return;
    }

    HttpIndexLoader::SortType asortFlip[] = {
        HttpIndexLoader::SORT_UNSORTED,
        HttpIndexLoader::SORT_INSTALLEDDESCENDING,
        HttpIndexLoader::SORT_INSTALLEDASCENDING,
        HttpIndexLoader::SORT_TITLEDESCENDING,
        HttpIndexLoader::SORT_TITLEASCENDING,
        HttpIndexLoader::SORT_PLAYERSDESCENDING,
        HttpIndexLoader::SORT_PLAYERSASCENDING,
        HttpIndexLoader::SORT_MISSIONSDESCENDING,
        HttpIndexLoader::SORT_MISSIONSASCENDING
    };

    // If this is already the sort column, flip the sort
    if (id == idSortIndicator_) {
        sort_ = asortFlip[sort_];
        idxl_.Sort(sort_);
        ShowIndex();
        return;
    }

    // Take sort indicator off
    char szT[32];
    if (idSortIndicator_ != 0) {
        LabelControl *plbl = (LabelControl *)GetControlPtr(idSortIndicator_);
        strncpyz(szT, plbl->GetText(), sizeof(szT));
        int cch = (int)strlen(szT);
        if (szT[cch - 1] == '*') {
            szT[cch - 1] = 0;
            plbl->SetText(szT);
        }
        UpdateLabelRects(plbl);
    }

    // Put on new column
    idSortIndicator_ = id;
    LabelControl *plbl = (LabelControl *)GetControlPtr(idSortIndicator_);
    strncpyz(szT, plbl->GetText(), sizeof(szT));
    int cch = (int)strlen(szT);
    if (szT[cch - 1] != '*') {
        szT[cch] = '*';
        szT[cch + 1] = 0;
        plbl->SetText(szT);
        UpdateLabelRects(plbl);
    }

    // Force this before the sort occurs, for immediate visual feedback

    gpmfrmm->DrawFrame(false);

    // Perform default sort for this column
    HttpIndexLoader::SortType asortDefault[] = {
        HttpIndexLoader::SORT_INSTALLEDDESCENDING,
        HttpIndexLoader::SORT_TITLEASCENDING,
        HttpIndexLoader::SORT_PLAYERSASCENDING,
        HttpIndexLoader::SORT_MISSIONSDESCENDING
    };

    sort_ = asortDefault[iCol];
    idxl_.Sort(sort_);
    ShowIndex();
}
void DownloadMissionPackForm::PositionColumns() {
    // Calc tab stops in the list
    // S  Title # Players Downloads
    // S is + for installed, or ! for upgrade
    // Title is the title. Make this as wide as possible
    // # Players is as close to Downloads as is reasonable
    // # Missions is right aligned

    ListControl *plstc = (ListControl *)GetControlPtr(kidcMissionPackList);
    Font *pfnt = plstc->GetFont();
    LabelControl *plbl = (LabelControl *)GetControlPtr(kidcStatus);
#if 1
    plbl->SetText("");
    int cxPlus = pfnt->GetTextExtent("+");
#else
    int cxPlus = pfnt->GetTextExtent(plbl->GetText());
#endif
    plbl = (LabelControl *)GetControlPtr(kidcTitle);
    int cxTitle = pfnt->GetTextExtent(plbl->GetText());
    plbl = (LabelControl *)GetControlPtr(kidcNumPlayers);
    int cxNumPlayers = pfnt->GetTextExtent(plbl->GetText());
    int cxAsterisk = pfnt->GetTextExtent("*");
    plbl = (LabelControl *)GetControlPtr(kidcNumMissions);
    int cxNumMissions = pfnt->GetTextExtent(plbl->GetText());

    Rect rcList;
    plstc->GetRect(&rcList);

    int xStatus = 2;
    int xTitle = (rcList.Width() / 4 - cxTitle) / 2;
    int xNumMissions = rcList.Width() - cxAsterisk - cxNumMissions;
    int xNumPlayers = xNumMissions - 10 - cxNumPlayers; 
    // Calc the top of the list (past the arrow) for better column
    // label hittesting
    Size sizArrow;
    ListControl::s_ptbmScrollUpUp->GetSize(&sizArrow);
    int yListTop = rcList.top + sizArrow.cy;

    // Set the label positions
    // Enable the labels for hittesting

    Rect rc;
    plbl = (LabelControl *)GetControlPtr(kidcStatus);
    plbl->GetRect(&rc);
    rc.left = rcList.left + xStatus;
    rc.right = xTitle;
    rc.bottom += (yListTop - rc.bottom) / 2;
    plbl->SetRect(&rc);
    plbl->SetFlags(plbl->GetFlags() | kfLblHitTest);
    rcStatus_ = rc;

    plbl = (LabelControl *)GetControlPtr(kidcTitle);
    plbl->GetRect(&rc);
    rc.Offset(rcList.left + xTitle - rc.left, 0);
    rc.right += rc.Width();
    rc.bottom += (yListTop - rc.bottom) / 2;
    plbl->SetRect(&rc);
    plbl->SetFlags(plbl->GetFlags() | kfLblHitTest);
    rcTitle_ = rc;
    
    plbl = (LabelControl *)GetControlPtr(kidcNumPlayers);
    plbl->GetRect(&rc);
    rc.Offset(rcList.left + xNumPlayers - rc.left, 0);
    rc.bottom += (yListTop - rc.bottom) / 2;
    plbl->SetRect(&rc);
    plbl->SetFlags(plbl->GetFlags() | kfLblHitTest);
    rcNumPlayers_ = rc;

    plbl = (LabelControl *)GetControlPtr(kidcNumMissions);
    plbl->GetRect(&rc);
    rc.Offset(rcList.left + xNumMissions - rc.left, 0);
    rc.bottom += (yListTop - rc.bottom) / 2;
    plbl->SetRect(&rc);
    plbl->SetFlags(plbl->GetFlags() | kfLblHitTest);
    rcNumMissions_ = rc;

    // Remember the tab settings for later use

    x0_ = 0;
    x1_ = cxPlus + 4;
    x2_ = xNumPlayers + cxNumPlayers / 2;
    x3_ = xNumMissions + cxNumMissions / 2;
}