| 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 | // BriefScreenEdit.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "mfc_compatibility.h" |
| 23 | #include "editor.h" |
| 24 | #include "BriefScreenEdit.h" |
| 25 | #include "BriefEdit.h" |
| 26 | #include "BriefMissionFlagsDlg.h" |
| 27 | |
| 28 | #ifdef _DEBUG |
| 29 | #define new DEBUG_NEW |
| 30 | #undef THIS_FILE |
| 31 | static char THIS_FILE[] = __FILE__; |
| 32 | #endif |
| 33 | |
| 34 | ///////////////////////////////////////////////////////////////////////////// |
| 35 | // CBriefScreenEdit dialog |
| 36 | |
| 37 | CBriefScreenEdit::CBriefScreenEdit(int screen_idx, CWnd *pParent /*=NULL*/) : CDialog(CBriefScreenEdit::IDD, pParent) { |
| 38 | //{{AFX_DATA_INIT(CBriefScreenEdit) |
| 39 | m_sDesc = _T(""); |
| 40 | //}}AFX_DATA_INIT |
| 41 | m_Screen = screen_idx; |
| 42 | bm_handle = -1; |
| 43 | m_Set = m_UnSet = 0; |
| 44 | } |
| 45 | |
| 46 | void CBriefScreenEdit::DoDataExchange(CDataExchange *pDX) { |
| 47 | CDialog::DoDataExchange(pDX); |
| 48 | //{{AFX_DATA_MAP(CBriefScreenEdit) |
| 49 | DDX_Text(pDX, IDC_BRIEF_ADDS_DESC, m_sDesc); |
| 50 | //}}AFX_DATA_MAP |
| 51 | } |
| 52 | |
| 53 | BEGIN_MESSAGE_MAP(CBriefScreenEdit, CDialog) |
| 54 | //{{AFX_MSG_MAP(CBriefScreenEdit) |
| 55 | ON_WM_TIMER() |
| 56 | ON_CBN_SELCHANGE(IDC_BRIEF_ADDS_LAYOUT_LIST, OnSelchangeBriefAddsLayoutList) |
| 57 | ON_BN_CLICKED(IDC_MISSIONFLAGS, OnMissionflags) |
| 58 | //}}AFX_MSG_MAP |
| 59 | END_MESSAGE_MAP() |
| 60 | |
| 61 | ///////////////////////////////////////////////////////////////////////////// |
| 62 | // CBriefScreenEdit message handlers |
| 63 | |
| 64 | void CBriefScreenEdit::OnOK() { |
| 65 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_ADDS_LAYOUT_LIST); |
| 66 | int sel = combo->GetCurSel(); |
| 67 | if (sel > 0) { |
| 68 | combo->GetLBText(sel, layout_str); |
| 69 | } else { |
| 70 | layout_str = ""; |
| 71 | } |
| 72 | |
| 73 | if (bm_handle > BAD_BITMAP_HANDLE) |
| 74 | bm_FreeBitmap(bm_handle); |
| 75 | |
| 76 | CDialog::OnOK(); |
| 77 | } |
| 78 | |
| 79 | BOOL CBriefScreenEdit::OnInitDialog() { |
| 80 | CDialog::OnInitDialog(); |
| 81 | |
| 82 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_ADDS_LAYOUT_LIST); |
| 83 | |
| 84 | // Start the timer |
| 85 | CWnd::SetTimer(1, 50, NULL); |
| 86 | |
| 87 | combo->AddString("<None>"); |
| 88 | int sel = 0; |
| 89 | |
| 90 | for (int i = 0; i < (*PBnum_layouts); i++) { |
| 91 | combo->AddString(PBlayouts[i].filename); |
| 92 | if (m_Screen != -1) { |
| 93 | if (!stricmp(Briefing_screens[m_Screen].layout, PBlayouts[i].filename)) |
| 94 | sel = i + 1; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if (m_Screen != -1) { |
| 99 | m_Set = Briefing_screens[m_Screen].mission_mask_set; |
| 100 | m_UnSet = Briefing_screens[m_Screen].mission_mask_unset; |
| 101 | } |
| 102 | |
| 103 | combo->SetCurSel(sel); |
| 104 | |
| 105 | return TRUE; |
| 106 | } |
| 107 | |
| 108 | void CBriefScreenEdit::UpdateView(void) { |
| 109 | CWnd *objwnd; |
| 110 | RECT rect; |
| 111 | int x, y, w, h; |
| 112 | |
| 113 | objwnd = GetDlgItem(IDC_BRIEF_ADDS_PICTURE); |
| 114 | objwnd->GetWindowRect(&rect); |
| 115 | ScreenToClient(&rect); |
| 116 | |
| 117 | int bmw, bmh; |
| 118 | |
| 119 | Desktop_surf->attach_to_window((unsigned)m_hWnd); |
| 120 | |
| 121 | w = rect.right - rect.left; |
| 122 | h = rect.bottom - rect.top; |
| 123 | |
| 124 | bmw = w; |
| 125 | bmh = h; |
| 126 | |
| 127 | static bool first_call = true; |
| 128 | |
| 129 | if (first_call) |
| 130 | Desktop_surf->clear(rect.left, rect.top, w, h); |
| 131 | |
| 132 | m_ObjectSurf.create(bmw, bmh, BPP_16); |
| 133 | |
| 134 | if (bm_handle > BAD_BITMAP_HANDLE) { |
| 135 | m_ObjectSurf.load(bm_handle); |
| 136 | } else |
| 137 | Desktop_surf->clear(rect.left, rect.top, w, h); |
| 138 | |
| 139 | x = rect.left + (w / 2) - m_ObjectSurf.width() / 2; |
| 140 | y = rect.top + (h / 2) - m_ObjectSurf.height() / 2; |
| 141 | |
| 142 | Desktop_surf->blt(x, y, &m_ObjectSurf); |
| 143 | |
| 144 | m_ObjectSurf.free(); |
| 145 | Desktop_surf->attach_to_window((unsigned)NULL); |
| 146 | |
| 147 | if (first_call) |
| 148 | first_call = false; |
| 149 | } |
| 150 | |
| 151 | void CBriefScreenEdit::OnTimer(UINT nIDEvent) { |
| 152 | UpdateView(); |
| 153 | CDialog::OnTimer(nIDEvent); |
| 154 | } |
| 155 | |
| 156 | void CBriefScreenEdit::OnSelchangeBriefAddsLayoutList() { |
| 157 | if (bm_handle > BAD_BITMAP_HANDLE) { |
| 158 | bm_FreeBitmap(bm_handle); |
| 159 | bm_handle = -1; |
| 160 | } |
| 161 | |
| 162 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_ADDS_LAYOUT_LIST); |
| 163 | int sel = combo->GetCurSel(); |
| 164 | if (sel > 0) { |
| 165 | bm_handle = bm_AllocLoadFileBitmap(PBlayouts[sel - 1].filename, 0); |
| 166 | } |
| 167 | |
| 168 | CWnd *objwnd; |
| 169 | RECT rect; |
| 170 | int w, h; |
| 171 | |
| 172 | objwnd = GetDlgItem(IDC_BRIEF_ADDS_PICTURE); |
| 173 | objwnd->GetWindowRect(&rect); |
| 174 | w = rect.right - rect.left; |
| 175 | h = rect.bottom - rect.top; |
| 176 | |
| 177 | int temp = bm_AllocBitmap(w, h, 0); |
| 178 | if (temp > BAD_BITMAP_HANDLE) { |
| 179 | bm_ClearBitmap(temp); |
| 180 | if (bm_handle > BAD_BITMAP_HANDLE) { |
| 181 | bm_ScaleBitmapToBitmap(temp, bm_handle); |
| 182 | } |
| 183 | bm_FreeBitmap(bm_handle); |
| 184 | bm_handle = temp; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | void CBriefScreenEdit::OnMissionflags() { |
| 189 | CBriefMissionFlagsDlg dlg(m_Set, m_UnSet); |
| 190 | |
| 191 | if (dlg.DoModal()) { |
| 192 | m_Set = dlg.m_Set; |
| 193 | m_UnSet = dlg.m_UnSet; |
| 194 | } |
| 195 | } |