| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | // RoomListCombo.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | |
| 24 | #ifndef NEWEDITOR |
| 25 | #include "editor.h" |
| 26 | #else |
| 27 | #include "neweditor.h" |
| 28 | #endif |
| 29 | |
| 30 | #include "RoomListCombo.h" |
| 31 | #include "room.h" |
| 32 | |
| 33 | #ifdef _DEBUG |
| 34 | #define new DEBUG_NEW |
| 35 | #undef THIS_FILE |
| 36 | static char THIS_FILE[] = __FILE__; |
| 37 | #endif |
| 38 | |
| 39 | ///////////////////////////////////////////////////////////////////////////// |
| 40 | // CRoomListCombo |
| 41 | |
| 42 | CRoomListCombo::CRoomListCombo() {} |
| 43 | |
| 44 | CRoomListCombo::~CRoomListCombo() {} |
| 45 | |
| 46 | BEGIN_MESSAGE_MAP(CRoomListCombo, CComboBox) |
| 47 | //{{AFX_MSG_MAP(CRoomListCombo) |
| 48 | ON_CONTROL_REFLECT(CBN_SETFOCUS, OnSetfocus) |
| 49 | //}}AFX_MSG_MAP |
| 50 | END_MESSAGE_MAP() |
| 51 | |
| 52 | ///////////////////////////////////////////////////////////////////////////// |
| 53 | // CRoomListCombo message handlers |
| 54 | |
| 55 | void CRoomListCombo::Init(int selected) { |
| 56 | // Clear the combo box |
| 57 | ResetContent(); |
| 58 | |
| 59 | // Add the "none" sound |
| 60 | AddString("<none>"); |
| 61 | SetItemData(0, -1); |
| 62 | SetCurSel(0); // default |
| 63 | |
| 64 | // Now add all the sounsd |
| 65 | for (int i = 0; i <= Highest_room_index; i++) { |
| 66 | if (Rooms[i].used && Rooms[i].name) { |
| 67 | int index = AddString(Rooms[i].name); |
| 68 | SetItemData(index, i); |
| 69 | if (selected == i) |
| 70 | SetCurSel(index); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void CRoomListCombo::SetSelected(int selected) { |
| 76 | // Now add all the sounsd |
| 77 | int count = GetCount(); |
| 78 | for (int i = 0; i < count; i++) { |
| 79 | if (selected == (int)GetItemData(i)) |
| 80 | SetCurSel(i); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | int CRoomListCombo::GetSelected() { return (int)GetItemData(GetCurSel()); } |
| 85 | |
| 86 | void CRoomListCombo::OnSetfocus() { |
| 87 | // Update list in case the items have changed |
| 88 | Init(GetSelected()); |
| 89 | } |