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; }
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; }
void LobbyForm::OnJoinRoom() { ListControl *plstc = (ListControl *)GetControlPtr(kidcRoomList); dword roomid = (dword)(pword)plstc->GetSelectedItemData(); RoomMap::iterator it = map_.find(roomid); if (it == map_.end()) { return; } if (it->second.priv) { HostInitiateAsk("Enter Password:", kcbPassword - 1, it->second.password.c_str(), knKeyboardAskDefault, true); return; } InitiateJoinRoom(it->second); }
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; } }
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::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 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); }
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; } }
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; } }