Exemplo n.º 1
0
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;
    }
}
Exemplo n.º 2
0
    void Create(const DialogLook &look, PixelSize size) {
        SingleWindow::Create(_T("RunRenderOZ"), size);

        const PixelRect rc = GetClientRect();

        WindowStyle with_border;
        with_border.Border();

        PixelRect oz_rc = rc;
        oz_rc.left = oz_rc.right / 2;
        oz.Create(*this, oz_rc, with_border);

        const PixelRect list_rc(0, 0, rc.right / 2, rc.bottom - 30);

        type_list = new ListControl(*this, look, list_rc,
                                    with_border, 25);

        type_list->SetItemRenderer(this);
        type_list->SetCursorHandler(this);
        type_list->SetLength(NUM_OZ_TYPES);

        PixelRect button_rc = rc;
        button_rc.right = (rc.left + rc.right) / 2;
        button_rc.top = button_rc.bottom - 30;
        close_button.Create(*this, _T("Close"), ID_CLOSE, button_rc);

        oz.set_shape(ObservationZone::Shape::LINE);

        type_list->SetFocus();
    }
Exemplo n.º 3
0
void ChooseServerForm::PositionColumns() {
    ListControl *plstc = (ListControl *)GetControlPtr(kidcServerList);
    Rect rcList;
    plstc->GetRect(&rcList);
    Font *pfnt = plstc->GetFont();

    LabelControl *plblPlayers = (LabelControl *)GetControlPtr(kidcNumPlayers);
    int cxNumPlayers = pfnt->GetTextExtent(plblPlayers->GetText());
    int xNumPlayers = rcList.right - cxNumPlayers;
    LabelControl *plblStatus = (LabelControl *)GetControlPtr(kidcServerStatus);
    int cxStatus = pfnt->GetTextExtent(plblStatus->GetText());
    int xStatus = xNumPlayers - 40 - cxStatus;
    int xLocation = rcList.left + (xStatus - rcList.left) / 2;
    int xName = rcList.left;
    
    plstc->SetTabStops(xName - rcList.left, xLocation - rcList.left,
            xStatus + cxStatus / 2 - rcList.left,
            xNumPlayers + cxNumPlayers / 2 - rcList.left);
    plstc->SetTabFlags(0, 0, kfLstTabCenterOn, kfLstTabCenterOn);

    word ids[] = { kidcServerName, kidcServerLocation, kidcServerStatus,
            kidcNumPlayers };
    int ax[] = { xName, xLocation, xStatus, xNumPlayers };

    for (int i = 0; i < ARRAYSIZE(ids); i++) {
        LabelControl *plbl = (LabelControl *)GetControlPtr(ids[i]);
        Rect rcCtl;
        plbl->GetRect(&rcCtl);
        plbl->SetPosition(ax[i], rcCtl.top);
    }
}
Exemplo n.º 4
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();
}
Exemplo n.º 5
0
  void Create(const DialogLook &look, PixelSize size) {
    SingleWindow::Create(_T("RunChartRenderer"), size);

    const PixelRect rc = GetClientRect();

    WindowStyle with_border;
    with_border.Border();

    const PixelRect list_rc(0, 0, 250, rc.bottom - 30);

    type_list = new ListControl(*this, look, list_rc,
                                with_border, 25);

    type_list->SetItemRenderer(this);
    type_list->SetCursorHandler(this);
    type_list->SetLength(ARRAY_SIZE(chart_names));

    PixelRect chart_rc = rc;
    chart_rc.left = list_rc.right;
    chart.Create(*this, chart_rc, with_border);

    PixelRect button_rc = rc;
    button_rc.right = list_rc.right;
    button_rc.top = button_rc.bottom - 30;
    close_button.Create(*this, *button_look, _T("Close"), button_rc,
                        WindowStyle(),
                        *this, CLOSE);

    type_list->SetFocus();
  }
Exemplo n.º 6
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;
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
  void set(const DialogLook &look, PixelRect _rc) {
    SingleWindow::set(_T("RunRenderOZ"), _T("RunRenderOZ"), _rc);

    const PixelRect rc = get_client_rect();

    WindowStyle with_border;
    with_border.Border();

    oz.set(*this, rc.right / 2, 0, rc.right - (rc.right / 2), rc.bottom,
           with_border);
    oz_window = &oz;

    const PixelRect list_rc = {
      0, 0, PixelScalar(rc.right / 2), PixelScalar(rc.bottom - 30),
    };

    type_list = new ListControl(*this, look, list_rc,
                                with_border, 25);
    type_list->SetPaintItemCallback(paint_oz_type_name);
    type_list->SetCursorCallback(oz_type_cursor_callback);
    type_list->SetLength(NUM_OZ_TYPES);

    PixelRect button_rc = rc;
    button_rc.right = (rc.left + rc.right) / 2;
    button_rc.top = button_rc.bottom - 30;
    close_button.set(*this, _T("Close"), ID_CLOSE, button_rc);

    oz.set_shape(ObservationZonePoint::LINE);

    type_list->SetFocus();
  }
Exemplo n.º 10
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;

    }
}
Exemplo n.º 11
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);
}
Exemplo n.º 12
0
void ChooseServerForm::ShowHide() {
    ListControl *plstc = (ListControl *)GetControlPtr(kidcServerList);
    ButtonControl *pbtn = (ButtonControl *)GetControlPtr(kidcOk);
    int index = plstc->GetSelectedItemIndex();
    if (index < 0 || index >= infos_.size()) {
        pbtn->Show(false);
        return;
    }
    ServerInfo& info = infos_[index];
    if (strcmp(info.status.c_str(), "ok") != 0) {
        pbtn->Show(false);
        return;
    }
    pbtn->Show(true);
}
Exemplo n.º 13
0
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);
}
Exemplo n.º 14
0
  void Move(const PixelRect &rc) override {
    const Layout layout(rc, waypoint);

    if (allow_navigation)
      goto_button.Move(layout.goto_button);

    if (!images.empty()) {
      magnify_button.Move(layout.magnify_button);
      shrink_button.Move(layout.shrink_button);
    }

    if (allow_navigation) {
      previous_button.Move(layout.previous_button);
      next_button.Move(layout.next_button);
    }

    close_button.Move(layout.close_button);

    info_dock.Move(layout.main);
    details_panel.Move(layout.main);
    details_text.Move(layout.details_text);
#ifdef HAVE_RUN_FILE
    if (!waypoint.files_external.empty())
      file_list.Move(layout.file_list);
#endif
    commands_dock.Move(layout.main);

    if (!images.empty())
      image_window.Move(layout.main);
  }
Exemplo n.º 15
0
  void Show(const PixelRect &rc) override {
    const Layout layout(rc, *waypoint);

    if (task_manager != nullptr)
      goto_button.MoveAndShow(layout.goto_button);

    if (!images.empty()) {
      magnify_button.MoveAndShow(layout.magnify_button);
      shrink_button.MoveAndShow(layout.shrink_button);
    }

    previous_button.MoveAndShow(layout.previous_button);
    next_button.MoveAndShow(layout.next_button);

    close_button.MoveAndShow(layout.close_button);

    info_dock.Move(layout.main);
    details_panel.Move(layout.main);
    details_text.Move(layout.details_text);
#ifdef HAVE_RUN_FILE
    if (!waypoint->files_external.empty())
      file_list.Move(layout.file_list);
#endif

    commands_dock.Move(layout.main);

    if (!images.empty())
      image_window.Move(layout.main);

    UpdatePage();
  }
Exemplo n.º 16
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;
	}
}
Exemplo n.º 17
0
BOOL VisibleList::Display(ListControl& Control)
{
	m_pUIElement = &Control;
	Control.Disable();
	// should display the entries we have and InsertEntry, etc. only update if we've
	// got a UIElement, but for now we'll insist on a display before InsertEntry, etc.
	return TRUE;
}
Exemplo n.º 18
0
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;
}
Exemplo n.º 19
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void
ListControlDesc::drawRow(size_t aRowIndex, const Core::Rectangle& aRowRectangle) const
{
    ListControl* listControl = dynamic_cast<ListControl*>(listWindow_);

    const ListControl::Row& row = listControl->rowAt(aRowIndex);

    Core::Rectangle textRectangle = aRowRectangle;
    textRectangle.translateBy(Core::Vector2(2.0f, 0.0f));

    bool isNormalText = true;
    Color backgroundColor;
    Color textColor;
    if(static_cast<int>(aRowIndex) == listControl->selectedIndex())
    {
        isNormalText = false;
        backgroundColor = selectionColor_;
        textColor = selectedTextColor_;
    }
    else if(static_cast<int>(aRowIndex) == listControl->highlightedIndex())
    {
        isNormalText = false;
        backgroundColor = highlightColor_;
        textColor = highlightedTextColor_;
    }

    if(!isNormalText)
    {
        Renderer::setCurrentColor(backgroundColor);
        Renderer::drawRectangle(aRowRectangle.topLeft(), aRowRectangle.bottomRight(), true);
        const Color unselectedTextColor = textDesc_->color();
        textDesc_->setColor(textColor);
        for(unsigned j = 0; j < listControl->numberOfColumns(); ++j)
        {
            (*textDesc_)
                .setText(row.stringAt(j))
                .draw(textRectangle)
                ;
            textRectangle.translateBy(Core::Vector2(listControl->columnWidth(j), 0.0f));
        }
        textDesc_->setColor(unselectedTextColor);
    }
    else
    {
        for(unsigned j = 0; j < listControl->numberOfColumns(); ++j)
        {
            (*textDesc_)
                .setText(row.stringAt(j))
                .draw(textRectangle)
                ;
            textRectangle.translateBy(Core::Vector2(listControl->columnWidth(j), 0.0f));
        }
    }
}
Exemplo n.º 20
0
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);
}
Exemplo n.º 21
0
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);
}
Exemplo n.º 22
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void
ListControlDesc::draw(const Core::Rectangle& anArea) const
{
    ListWindowDesc::draw(anArea);

    // ***********************************************************************
    //  draw the column separators
    // ***********************************************************************

    const Core::Vector2 topLeft     = anArea.topLeft();
    const Core::Vector2 bottomLeft  = anArea.bottomLeft();

    ListControl* listControl = dynamic_cast<ListControl*>(listWindow_);
    Renderer::setCurrentColor(separatorColor_);
    Renderer::setLineWidth(separatorWidth_);
    float curX = listControl->columnWidth(0);
    for(size_t sep = 1; sep < listControl->numberOfColumns(); ++sep)
    {
        Core::Vector2 offs(curX, 0);
        Renderer::drawLine(topLeft + offs, bottomLeft + offs);
        curX += listControl->columnWidth(sep);
    }
}
Exemplo n.º 23
0
void CreateGameForm::OnControlNotify(word idc, int nNotify) {
    if (idc == kidcCategories) {
        RadioButtonBarControl *prbbc =
        (RadioButtonBarControl *)GetControlPtr(kidcCategories);
        int iButtonSelected = prbbc->GetSelectionIndex();
        if (iButtonSelected < 0) {
            iButtonSelected = 0;
        }
        MissionType mtNew = MissionTypeFromIndex(iButtonSelected);
        if (mtNew == m_mt) {
            return;
        }
        SwitchToMissionType(mtNew);
        
        // If in Add-On category, and there is nothing there, show this
        // label, otherwise hide it
        
        bool fShowLabel = false;
        ListControl *plstc =
        m_aplstc[IndexFromMissionType(kmtMultiplayerAddOn)];
        if (m_mt == kmtMultiplayerAddOn) {
            if (plstc->GetCount() == 0) {
                fShowLabel = true;
            }
        }
        
        LabelControl *plbl =
        (LabelControl *)GetControlPtr(kidcAddOnMessage);
        if (fShowLabel) {
            plbl->Show(true);
            if (m_mt == kmtMultiplayerAddOn) {
                plstc->Show(false);
            }
        } else {
            plbl->Show(false);
            if (m_mt == kmtMultiplayerAddOn) {
                plstc->Show(true);
            }
        }
    }
    
    if (idc == kidcChallengeList || idc == kidcAddOnList) {
        UpdateLabels();
    }
    
    // Handle button hiding
    
    bool fShow = true;
    ListControl *plstc = m_aplstc[IndexFromMissionType(m_mt)];
    if (plstc->GetSelectedItemIndex() == -1) {
        fShow = false;
    }
    GetControlPtr(kidcOk)->Show(fShow);
}
Exemplo n.º 24
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);
    }
}
Exemplo n.º 25
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);
}
Exemplo n.º 26
0
void
WaypointDetailsWidget::Prepare(ContainerWindow &parent, const PixelRect &rc)
{
  for (const auto &i : waypoint.files_embed) {
    if (images.full())
      break;

    try {
      if (!images.append().LoadFile(LocalPath(i.c_str())))
        images.shrink(images.size() - 1);
    } catch (const std::exception &e) {
      LogFormat("Failed to load %s: %s",
                (const char *)NarrowPathName(Path(i.c_str())),
                e.what());
      images.shrink(images.size() - 1);
    }
  }

  const Layout layout(rc, waypoint);

  WindowStyle dock_style;
  dock_style.Hide();
  dock_style.ControlParent();

  WindowStyle button_style;
  button_style.Hide();
  button_style.TabStop();

  if (allow_navigation)
    goto_button.Create(parent, look.button, _("GoTo"), layout.goto_button,
                       button_style, *this, GOTO);

  if (!images.empty()) {
    magnify_button.Create(parent, layout.magnify_button, button_style,
                          new SymbolButtonRenderer(look.button, _T("+")),
                          *this, MAGNIFY);
    shrink_button.Create(parent, layout.shrink_button, button_style,
                         new SymbolButtonRenderer(look.button, _T("-")),
                         *this, SHRINK);
  }

  if (allow_navigation) {
    previous_button.Create(parent, layout.previous_button, button_style,
                           new SymbolButtonRenderer(look.button, _T("<")),
                           *this, PREVIOUS);
    next_button.Create(parent, layout.next_button, button_style,
                       new SymbolButtonRenderer(look.button, _T(">")),
                       *this, NEXT);
  }

  close_button.Create(parent, look.button, _("Close"), layout.close_button,
                      button_style, dialog, mrOK);

  info_dock.Create(parent, layout.main, dock_style);
  info_dock.SetWidget(&info_widget);

  details_panel.Create(parent, look, layout.main, dock_style);
  details_text.Create(details_panel, layout.details_text);
  details_text.SetFont(look.text_font);
  details_text.SetText(waypoint.details.c_str());

#ifdef HAVE_RUN_FILE
  const unsigned num_files = std::distance(waypoint.files_external.begin(),
                                           waypoint.files_external.end());
  if (num_files > 0) {
    file_list.Create(details_panel, layout.file_list,
                     WindowStyle(), layout.file_list_item_height);
    file_list.SetItemRenderer(&file_list_handler);
    file_list.SetCursorHandler(&file_list_handler);
    file_list.SetLength(num_files);
  }
#endif

  commands_dock.Create(parent, layout.main, dock_style);
  commands_dock.SetWidget(&commands_widget);

  if (!images.empty())
    image_window.Create(parent, layout.main, dock_style,
                        [this](Canvas &canvas, const PixelRect &rc){
                          OnImagePaint(canvas, rc);
                        });

  last_page = 2 + images.size();
}
Exemplo n.º 27
0
void
dlgWaypointDetailsShowModal(SingleWindow &parent, const Waypoint &_waypoint,
                            bool allow_navigation)
{
    waypoint = &_waypoint;

    wf = LoadDialog(CallBackTable, parent,
                    Layout::landscape ? _T("IDR_XML_WAYPOINTDETAILS_L") :
                    _T("IDR_XML_WAYPOINTDETAILS"));
    assert(wf != NULL);

    LastUsedWaypoints::Add(_waypoint);

    UpdateCaption(waypoint->name.c_str(), waypoint->file_num);

    wf->SetKeyDownNotify(FormKeyDown);

    wInfo = (DockWindow *)wf->FindByName(_T("info"));
    assert(wInfo != NULL);
    wInfo->SetWidget(new WaypointInfoWidget(UIGlobals::GetDialogLook(),
                                            _waypoint));

    wCommand = (DockWindow *)wf->FindByName(_T("commands"));
    assert(wCommand != NULL);
    wCommand->SetWidget(new WaypointCommandsWidget(UIGlobals::GetDialogLook(),
                        wf, _waypoint,
                        protected_task_manager));
    wCommand->Hide();

    wDetails = wf->FindByName(_T("frmDetails"));
    assert(wDetails != NULL);

    ListControl *wFilesList = (ListControl *)wf->FindByName(_T("Files"));
    assert(wFilesList != NULL);

    EditWindow *wDetailsText = (EditWindow *)wf->FindByName(_T("Details"));
    assert(wDetailsText != NULL);
    wDetailsText->SetText(waypoint->details.c_str());

#ifdef ANDROID
    int num_files = std::distance(waypoint->files_external.begin(),
                                  waypoint->files_external.end());
    if (num_files > 0) {
        wFilesList->SetPaintItemCallback(OnFileListItemPaint);
        wFilesList->SetCursorCallback(OnFileListEnter);
        wFilesList->SetActivateCallback(OnFileListEnter);

        unsigned list_height = wFilesList->GetItemHeight() * std::min(num_files, 5);
        wFilesList->Resize(wFilesList->GetWidth(), list_height);
        wFilesList->SetLength(num_files);

        PixelRect rc = wDetailsText->GetPosition();
        rc.top += list_height;
        wDetailsText->Move(rc);
    } else
#endif
        wFilesList->Hide();

    wImage = (PaintWindow *)wf->FindByName(_T("frmImage"));
    assert(wImage != NULL);
    wMagnify = (WndButton *)wf->FindByName(_T("cmdMagnify"));
    assert(wMagnify != NULL);
    wShrink = (WndButton *)wf->FindByName(_T("cmdShrink"));
    assert(wShrink != NULL);

    if (!allow_navigation) {
        WndButton* butnav = (WndButton *)wf->FindByName(_T("cmdPrev"));
        assert(butnav != NULL);
        butnav->Hide();

        butnav = (WndButton *)wf->FindByName(_T("cmdNext"));
        assert(butnav != NULL);
        butnav->Hide();

        butnav = (WndButton *)wf->FindByName(_T("cmdGoto"));
        assert(butnav != NULL);
        butnav->Hide();
    }

    for (auto it = waypoint->files_embed.begin(),
            it_end = waypoint->files_embed.end();
            it != it_end && !images.full(); it++) {
        TCHAR path[MAX_PATH];
        LocalPath(path, it->c_str());
        if (!images.append().LoadFile(path))
            images.shrink(images.size() - 1);
    }

    page = 0;

    NextPage(0); // JMW just to turn proper pages on/off

    wf->ShowModal();

    delete wf;

    for (auto image = images.begin(); image < images.end(); image++)
        image->Reset();

    images.clear();
}
Exemplo n.º 28
0
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;
}
Exemplo n.º 29
0
BOOL VisibleList::Interact(ListControl& Control)
{
	BOOL Ok = Display(Control);
	Control.Enable();
	return Ok;
}
Exemplo n.º 30
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;
    }
}