void ChooseServerForm::OnControlSelected(word idc) {
    switch (idc) {
    case kidcOk:
        {
            ListControl *plstc = (ListControl *)GetControlPtr(kidcServerList);
            int index = plstc->GetSelectedItemIndex();
            if (index >= 0 && index < infos_.size()) {
                dword result = Connect(infos_[index]);
                if (result == knTransportOpenResultSuccess) {
                    EndForm(kidcOk);
                    break;
                }
                ShowTransportError(result);
            }
        }
        break;

    case kidcRefresh:
        Refresh();
        break;

    case kidcCancel:
        EndForm(kidcCancel);
        break;
    }
}
bool DownloadMissionPackForm::OnFilterEvent(Event *pevt) {
    if (pevt->eType != askStringEvent) {
        return false;
    }

    // Get the URL and Save preferences so this url is remembered
    HostGetAskString(gszAskURL, sizeof(gszAskURL));
    ggame.SavePreferences();

    // Download this custom pack
    PackId packid;
    bool play = false;
    if (!DownloadMissionPackFromURL(gszAskURL, &packid, &play)) {
        // Some kind of error occured
        return true;
    }

    // User wants to play now?
    if (play) {
        // The user wants to play the mission
        fWantsPlay_ = true;
        packidPlay_ = packid;
        EndForm(kidcOk);
        return true;
    }

    // Add this mission pack to the index, and re-fill the list control,
    // and select it.
    idxl_.AddIndexEntry(&packid);
    idxl_.Sort(sort_);
    ShowIndex(&packid);
    return true;
}
示例#3
0
bool LobbyForm::OnFilterEvent(Event *pevt) {
    if (pevt->eType == askStringEvent) {
        if (gptra == NULL) {
            return true;
        }

        char s[512];
        HostGetAskString(s, sizeof(s));

        ListControl *plstc = (ListControl *)GetControlPtr(kidcRoomList);
        dword roomid = (dword)(pword)plstc->GetSelectedItemData();
        RoomMap::iterator it = map_.find(roomid);
        if (it != map_.end()) {
            it->second.password = s;
            InitiateJoinRoom(it->second);
        }
        return true;
    }

    if (pevt->eType == connectionCloseEvent) {
        HtMessageBox(kfMbWhiteBorder, "Comm Problem", "The server has closed your connection.");
        EndForm(kidcCancel);
        return true;
    }

    if (pevt->eType == showMessageEvent) {
        HtMessageBox(kfMbWhiteBorder, "Server Message", message_.c_str());
        message_ = "";
        return true;
    }
    return false;
}
示例#4
0
void LoadGameForm::OnControlSelected(word idc)
{
	switch (idc) {
	case kidcOk:
		{
			ListControl *plstc = (ListControl *)GetControlPtr(kidcGameList);
			int nGame = ((int)plstc->GetSelectedItemData()) - 1;
			EndForm(nGame);
		}
		return;

	case kidcCancel:
		ShellForm::OnControlSelected(idc);
		break;
	}
}
示例#5
0
bool CreateGameForm::OnFilterEvent(Event *pevt) {
    if (pevt->eType == connectionCloseEvent) {
        chatter_.HideChat();
        HtMessageBox(kfMbWhiteBorder, "Comm Problem", "The server has closed your connection.");
        EndForm(kidcCancel);
        return true;
    }

    if (pevt->eType == showMessageEvent) {
        chatter_.HideChat();
        HtMessageBox(kfMbWhiteBorder, "Server Message", message_.c_str());
        message_ = "";
        return true;
    }
    return false;
}
示例#6
0
void LobbyForm::OnControlSelected(word idc) {
    switch (idc) {
    case kidcNewRoom:
        OnCreateRoom();
        break;

    case kidcJoinRoom:
        OnJoinRoom();
        break;

    case kidcCancel:
    case kidcSignOut:
        EndForm(idc);
        break;
    }
}
示例#7
0
void LobbyForm::InitiateJoinRoom(const RoomInfo& info) {
    if (gptra == NULL) {
        return;
    }

    // Before joining, check to see if this room is joinable.
    // Actually joining also checks, but this is a way to provide the user
    // with feedback before exiting this form (actual joining happens
    // in RoomForm).
    dword result = gptra->CanJoinRoom(info.roomid, info.password.c_str());
    RoomForm::ShowJoinMessage(result);
    switch (result) {
    case knRoomJoinResultWrongPassword:
        OnJoinRoom();
        break;

    case knRoomJoinResultSuccess:
        joininfo_ = info;
        EndForm(kidcJoinRoom);
        break;
    }
}
void DownloadMissionPackForm::OnControlSelected(word idc) {
    if (idc == kidcCancel) {
        EndForm(idc);
        return;
    }

    ListControl *plstc = (ListControl *)GetControlPtr(kidcMissionPackList);
    IndexEntry *entry = (IndexEntry *)plstc->GetSelectedItemData();
    if (entry == NULL) {
        return;
    }

    switch (idc) {
    case kidcOk:
        switch (gppackm->IsInstalled(&entry->packid)) {
        case 0:
            // If this is a custom URL entry handle specially
            if (entry->packid.id == PACKID_CUSTOMURL) {
                HandleCustomURL();
                break;
            }
            // fall through

        case 2:
            // Pack not install or needs upgrade. In either case, download
            if (DownloadMissionPack(&entry->packid, NULL, true)) {
                fWantsPlay_ = true;
                packidPlay_ = entry->packid;
                EndForm(kidcOk);
            }
            plstc->SetSelectedItemText(GetItemString(entry));
            HideShow();
            break;

        case 1:
            // Pack is installed, so this action means remove
            if (HtMessageBox(kidfMessageBoxQuery,
                    kfMbWhiteBorder | kfMbKeepTimersEnabled,
                    "Remove Mission Pack", "Are you sure?")) {
                gppackm->Remove(&entry->packid);
                if (idxl_.OnRemoved(&entry->packid)) {
                    ShowIndex();
                } else {
                    plstc->SetSelectedItemText(GetItemString(entry));
                }
                HideShow();
            }
            break;
        }
        break;

    case kidcDiscuss:
        {
            json::JsonMap *map = gppim->GetInfoMap(&entry->packid);
            if (map != NULL) {
                const json::JsonObject *obj = map->GetObject("di");
                if (obj != NULL && obj->type() == json::JSONTYPE_STRING) {
                    HostOpenUrl(((const json::JsonString *)obj)->GetString());
                }
                delete map;
            }
        }
        break;
    }
}
示例#9
0
void CreateGameForm::OnControlSelected(word idc) {
    switch (idc) {
    case kidcPasswordPanel:
        DoInputPanelForm(this, kidcPasswordLabel, kidcPassword);
        break;
        
    case kidcGameSpeed:
        {
            SliderControl *psldr = (SliderControl *)GetControlPtr(
                    kidcGameSpeed);
            m_tGameSpeed = gatGameSpeeds[psldr->GetValue()];
            UpdateLabels();
        }
        break;
       
    case kidcChat:
        chatter_.ShowChat();
        break;
 
    case kidcCancel:
        EndForm(idc);
        break;
        
    case kidcOk:
        // Fill in GameParams
        
        ListControl *plstc = m_aplstc[IndexFromMissionType(m_mt)];
        int nLevel = (int)plstc->GetSelectedItemData();
        
        MissionIdentifier miid;
        if (!m_pml->GetMissionIdentifier(nLevel, &miid)) {
            HtMessageBox(kfMbWhiteBorder, "Error!",
                         "First you must select a map to play on.");
            return;
        }
        
        // Mount the pdb
        if (!gppackm->Mount(gpakr, &miid.packid)) {
            HtMessageBox(kfMbWhiteBorder, "Error!",
                         "Cannot load mission pack.");
            return;
        }
        
        // Remember for later selecting from the list
        
        m_miidFind = miid;
        
        // Read the level info
        
        Level *plvl = new Level();
        if (plvl != NULL) {
            if (plvl->LoadLevelInfo(miid.szLvlFilename)) {
                m_prams->packid = miid.packid;
                m_prams->dwVersionSimulation = knVersionSimulation;
                m_prams->tGameSpeed = m_tGameSpeed;
                strncpyz(m_prams->szLvlFilename, miid.szLvlFilename,
                         sizeof(m_prams->szLvlFilename));
            }
            delete plvl;
        } else {
            HtMessageBox(kfMbWhiteBorder, "Error", "Out of memory!");
            idc = kidcCancel;
        }
        
        gppackm->Unmount(gpakr, &miid.packid);
        
        // Keep this game speed around for next time
        
        gtGameSpeed = m_tGameSpeed;
        ggame.SavePreferences();
        
        EndForm(idc);
        break;
    }
}