Пример #1
0
void ChooseServerForm::Refresh(bool show_errors) {
    bool success = RequestInfos();

    ListControl *plstc = (ListControl *)GetControlPtr(kidcServerList);
    plstc->Clear();

    if (infos_.size() == 0) {
        if (success) {
            errorstr_ = "The multiplayer service is down for maintenance. Try again later.";
        }
        if (show_errors) {
            HtMessageBox(kfMbWhiteBorder, "Service Message",
                errorstr_.c_str());
        } else {
            errors_ = true;
        }
    } else {
        for (int i = 0; i < infos_.size(); i++) {
            const ServerInfo& info = infos_[i];
            const char *s = base::Format::ToString("%s\t%s\t%s\t%d",
                info.name.c_str(), info.location.c_str(), info.status.c_str(),
                info.player_count);
            plstc->Add(s);
        }
        plstc->Select(0, true);
    }
    ShowHide();
}
Пример #2
0
void LobbyForm::OnCreateRoom() {
    char roomname[kcbRoomname];
    char password[kcbPassword];
    if (!CreateRoomForm::DoForm(roomname, sizeof(roomname), password,
            sizeof(password))) {
        return;
    }

    if (gptra == NULL) {
        return;
    }

    dword roomid;
    dword result = gptra->CreateRoom(roomname, password, &roomid);
    switch (result) {
    case knLobbyCreateRoomResultSuccess:
        {
            // Update the list and select the created room, in case
            // the join fails.
            Refresh(-1);
            ListControl *plstc = (ListControl *)GetControlPtr(kidcRoomList);
            refresh_ = false;
            plstc->Select(FindIndex(roomid), true, true);
            refresh_ = true;

            // OnAddRoom has been called already. Shove the password
            // into the info and join the room.
            RoomMap::iterator it = map_.find(roomid);
            if (it != map_.end()) {
                it->second.password = password;
                InitiateJoinRoom(it->second);
            }
        }
        break;

    case knLobbyCreateRoomResultFail:
        HtMessageBox(kfMbWhiteBorder, "Create Room",
                "Error creating this room.");
        break;

    case knLobbyCreateRoomResultFull:
        HtMessageBox(kfMbWhiteBorder, "Create Room", "Too many rooms. Join an existing room");
        break;

    case knLobbyCreateRoomResultExists:
        HtMessageBox(kfMbWhiteBorder, "Create Room",
                "A room with this name already exists.");
        break;

    }
}
Пример #3
0
void LobbyForm::OnTimeout(int id) {
    refresh_ = false;
    ListControl *plstc = (ListControl *)GetControlPtr(kidcRoomList);
    dword roomid = (dword)(pword)plstc->GetSelectedItemData();
    if (!selected_main_) {
        roomid = kroomidMain;
    }
    plstc->Clear();
    RoomMap::iterator it = map_.begin();
    for (; it != map_.end(); it++) {
        RoomInfo& info = it->second;
        const char *s;
        if (info.priv) {
            s = base::Format::ToString("\t%s (%d %s, %d %s)\tPRIVATE",
                    info.name.c_str(), info.cPlayers,
                    info.cPlayers == 1 ? "player" : "players",
                    info.cGames,
                    info.cGames == 1 ? "game" : "games");
        } else {
            s = base::Format::ToString("\t%s (%d %s, %d %s)",
                    info.name.c_str(), info.cPlayers,
                    info.cPlayers == 1 ? "player" : "players",
                    info.cGames,
                    info.cGames == 1 ? "game" : "games");
        }
        plstc->Add(s, (void *)(uintptr_t)info.roomid);
    }
    int selected = FindIndex(roomid);
    if (selected < 0 && map_.size() != 0) {
        plstc->Select(0, true, true);
    } else {
        plstc->Select(selected, true);
        selected_main_ = true;
    }
    Control *pctl = GetControlPtr(kidcJoinRoom);
    refresh_ = true;
    pctl->Show(plstc->GetSelectedItemIndex() >= 0);
}
Пример #4
0
void LoadGameForm::SelectLast(bool fLast)
{
	ListControl *plstc = (ListControl *)GetControlPtr(kidcGameList);
	int nGameSelect;
	if (fLast) {
		nGameSelect = m_nGameLast;
		if (nGameSelect == -1)
			nGameSelect = 0;
	} else {
		nGameSelect = m_nGameLast + 1;
		if (nGameSelect == plstc->GetCount())
			nGameSelect = 0;
	}
	plstc->Select(nGameSelect);
}
Пример #5
0
void DownloadMissionPackForm::ShowIndex(const PackId *ppackidSelect) {
    // Add entries to the list

    ListControl *plstc = (ListControl *)GetControlPtr(kidcMissionPackList);
    plstc->SetTabStops(x0_, x1_, x2_, x3_);
    plstc->SetTabFlags(kfLstTabCenter, kfLstTabEllipsis, kfLstTabCenterOn,
            kfLstTabCenterOn);
    plstc->Clear();
    int iSelect = 0;
    int cAdded = 0;
    int c = idxl_.GetCount();
    for (int i = 0; i < c; i++) {
        const IndexEntry *pentry = idxl_.GetEntry(i);

        // Show either single player packs, or multiplayer packs.
        // If a pack has both single and multiplayer missions, show
        // these in both cases.

        if (pentry->packid.id != PACKID_CUSTOMURL) {
            if (fMultiplayer_) {
                if (pentry->cPlayersMax == 1) {
                    continue;
                }
            } else {
                if (pentry->cPlayersMin != 1) {
                    continue;
                }
            }
        }

        // Remember which entry to select

        if (iSelect == 0 && ppackidSelect != NULL) {
            if (memcmp(ppackidSelect, &pentry->packid,
                    sizeof(*ppackidSelect)) == 0) {
                iSelect = cAdded;
            }
        }

        plstc->Add(GetItemString(pentry), (void *)pentry);
        cAdded++;
    }

    if (cAdded > 0) {
        plstc->Select(iSelect, true, true);
    }
}
Пример #6
0
MissionType CreateGameForm::InitLists(int iMissionSelect) {
    // Fill in the lists, and along the way keep track of useful selection
    // indexes.
    
    int ailiFirstIncomplete[kmtUnknown + 1];
    memset(ailiFirstIncomplete, 0xff, sizeof(ailiFirstIncomplete));
    int iliSelectSpecial = -1;
    MissionType mtSelectSpecial = kmtUnknown;
    
    int cMissions = m_pml->GetCount();
    for (int i = 0; i < cMissions; i++) {
        MissionDescription md;
        if (!m_pml->GetMissionDescription(i, &md)) {
            continue;
        }
        if (md.mt != kmtMultiplayerChallenge && 
            md.mt != kmtMultiplayerAddOn) {
            continue;
        }
        
        // Add the item.
        
        const char *pszT;
        if (md.cPlayersMin == md.cPlayersMax) {
            pszT = base::Format::ToString("%s (%d players)",
                                          md.szLvlTitle, md.cPlayersMin);
        } else {
            pszT = base::Format::ToString("%s (%d-%d players)",
                                          md.szLvlTitle, md.cPlayersMin, md.cPlayersMax);
        }
        ListControl *plstc = m_aplstc[IndexFromMissionType(md.mt)];
        plstc->Add(pszT, (void *)i);
        
        // Track the first incomplete, for later selection
        
        if (ailiFirstIncomplete[md.mt] == -1) {
            MissionIdentifier miid;
            m_pml->GetMissionIdentifier(i, &miid);
            if (!gpcptm->IsComplete(&miid)) {
                ailiFirstIncomplete[md.mt] = plstc->GetCount() - 1;
            }
        }
        
        // This is passed in when the form needs to select a certain
        // mission when it first shows.
        
        if (i == iMissionSelect) {
            iliSelectSpecial = plstc->GetCount() - 1;
            mtSelectSpecial = md.mt;
        }
    }
    
    // The initially selected missions are the first incomplete missions
    // for each mission type.
    
    MissionType mtSelect = kmtMultiplayerChallenge;
    for (int i = 0; i < ARRAYSIZE(m_aplstc); i++) {
        ListControl *plstc = m_aplstc[i];
        
        // Is this the list that is awarded the special selection?
        
        if (i == IndexFromMissionType(mtSelectSpecial)) {
            plstc->Select(iliSelectSpecial, true, true);
            mtSelect = mtSelectSpecial;
            continue;
        }
        
        int iliSelect = ailiFirstIncomplete[MissionTypeFromIndex(i)];
        if (iliSelect < 0) {
            iliSelect = 0;
        }
        plstc->Select(iliSelect, true, true);
    }
    return mtSelect;
}