| 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 | // SoundListCombo.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "editor.h" |
| 24 | #include "SoundListCombo.h" |
| 25 | #include "soundload.h" |
| 26 | |
| 27 | #ifdef _DEBUG |
| 28 | #define new DEBUG_NEW |
| 29 | #undef THIS_FILE |
| 30 | static char THIS_FILE[] = __FILE__; |
| 31 | #endif |
| 32 | |
| 33 | ///////////////////////////////////////////////////////////////////////////// |
| 34 | // CSoundListCombo |
| 35 | |
| 36 | CSoundListCombo::CSoundListCombo() {} |
| 37 | |
| 38 | CSoundListCombo::~CSoundListCombo() {} |
| 39 | |
| 40 | BEGIN_MESSAGE_MAP(CSoundListCombo, CComboBox) |
| 41 | //{{AFX_MSG_MAP(CSoundListCombo) |
| 42 | ON_CONTROL_REFLECT(CBN_SETFOCUS, OnSetfocus) |
| 43 | //}}AFX_MSG_MAP |
| 44 | END_MESSAGE_MAP() |
| 45 | |
| 46 | ///////////////////////////////////////////////////////////////////////////// |
| 47 | // CSoundListCombo message handlers |
| 48 | |
| 49 | void CSoundListCombo::Init(int selected) { |
| 50 | // Clear the combo box |
| 51 | ResetContent(); |
| 52 | |
| 53 | // Add the "none" sound |
| 54 | AddString("<none>"); |
| 55 | SetItemData(0, -1); |
| 56 | SetCurSel(0); // default |
| 57 | |
| 58 | // Now add all the sounsd |
| 59 | for (int i = 0; i < MAX_SOUNDS; i++) { |
| 60 | if (Sounds[i].used) { |
| 61 | int index; |
| 62 | |
| 63 | index = AddString(Sounds[i].name); |
| 64 | SetItemData(index, i); |
| 65 | if (selected == i) |
| 66 | SetCurSel(index); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | void CSoundListCombo::SetSelected(int selected) { |
| 72 | // Now add all the sounsd |
| 73 | int count = GetCount(); |
| 74 | for (int i = 0; i < count; i++) { |
| 75 | if (selected == (int)GetItemData(i)) |
| 76 | SetCurSel(i); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | int CSoundListCombo::GetSelected() { return (int)GetItemData(GetCurSel()); } |
| 81 | |
| 82 | #include "mono.h" |
| 83 | |
| 84 | void CSoundListCombo::OnSetfocus() { |
| 85 | // Update list in case the items have changed |
| 86 | Init(GetSelected()); |
| 87 | } |