| 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 | // BriefBitmapEdit.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "editor.h" |
| 24 | #include "BriefBitmapEdit.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 | // CBriefBitmapEdit dialog |
| 36 | |
| 37 | CBriefBitmapEdit::CBriefBitmapEdit(int curr_screen, TCBMPDESC *d, CWnd *pParent /*=NULL*/) |
| 38 | : CDialog(CBriefBitmapEdit::IDD, pParent) { |
| 39 | //{{AFX_DATA_INIT(CBriefBitmapEdit) |
| 40 | m_sFilename = _T(""); |
| 41 | m_fSpeed = 0.0f; |
| 42 | m_fStartTime = 0.0f; |
| 43 | m_iX = 0; |
| 44 | m_iY = 0; |
| 45 | m_iEffectType = -1; |
| 46 | m_sDesc = _T(""); |
| 47 | m_NoRenderUntilStart = FALSE; |
| 48 | //}}AFX_DATA_INIT |
| 49 | |
| 50 | // set to default values |
| 51 | memset(&desc, 0, sizeof(TCBMPDESC)); |
| 52 | desc.type = TC_BMP_STATIC; |
| 53 | m_Screen = curr_screen; |
| 54 | desc.mission_mask_set = 0; |
| 55 | desc.mission_mask_unset = 0; |
| 56 | |
| 57 | if (d) { |
| 58 | // set to values passed in |
| 59 | desc.caps = d->caps; |
| 60 | if (d->caps & TCBD_XY) { |
| 61 | desc.x = d->x; |
| 62 | desc.y = d->y; |
| 63 | } |
| 64 | if (d->caps & TCBD_LOOPING) { |
| 65 | desc.looping = d->looping; |
| 66 | } |
| 67 | if (d->caps & TCBD_WAITTIME) { |
| 68 | desc.waittime = d->waittime; |
| 69 | } |
| 70 | if (d->caps & TCBD_SPEED) { |
| 71 | desc.speed = d->speed; |
| 72 | } |
| 73 | if (d->flags & TC_NOEARLYRENDER) { |
| 74 | m_NoRenderUntilStart = true; |
| 75 | } |
| 76 | |
| 77 | desc.type = d->type; |
| 78 | desc.flags = d->flags; |
| 79 | strcpy(desc.filename, d->filename); |
| 80 | desc.mission_mask_set = d->mission_mask_set; |
| 81 | desc.mission_mask_unset = d->mission_mask_unset; |
| 82 | } |
| 83 | |
| 84 | switch (desc.type) { |
| 85 | case TC_BMP_STATIC: |
| 86 | m_iEffectType = 0; |
| 87 | break; |
| 88 | case TC_BMP_BLUR: |
| 89 | if (desc.flags == TC_BMPF_IN) |
| 90 | m_iEffectType = 1; |
| 91 | else |
| 92 | m_iEffectType = 2; |
| 93 | break; |
| 94 | case TC_BMP_SCANLINE: |
| 95 | if (desc.flags == TC_BMPF_IN) |
| 96 | m_iEffectType = 3; |
| 97 | else |
| 98 | m_iEffectType = 4; |
| 99 | break; |
| 100 | case TC_BMP_INVERT: |
| 101 | if (desc.flags == TC_BMPF_IN) |
| 102 | m_iEffectType = 5; |
| 103 | else |
| 104 | m_iEffectType = 6; |
| 105 | break; |
| 106 | case TC_BMP_STRETCH: |
| 107 | if (desc.flags == TC_BMPF_IN) |
| 108 | m_iEffectType = 7; |
| 109 | else |
| 110 | m_iEffectType = 8; |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | m_sFilename = desc.filename; |
| 115 | m_fSpeed = desc.speed; |
| 116 | m_fStartTime = desc.waittime; |
| 117 | m_iX = desc.x; |
| 118 | m_iY = desc.y; |
| 119 | } |
| 120 | |
| 121 | void CBriefBitmapEdit::DoDataExchange(CDataExchange *pDX) { |
| 122 | CDialog::DoDataExchange(pDX); |
| 123 | //{{AFX_DATA_MAP(CBriefBitmapEdit) |
| 124 | DDX_Text(pDX, IDC_BRIEF_B_FILENAME, m_sFilename); |
| 125 | DDX_Text(pDX, IDC_BRIEF_B_SPEED, m_fSpeed); |
| 126 | DDV_MinMaxFloat(pDX, m_fSpeed, 0.f, 99999.f); |
| 127 | DDX_Text(pDX, IDC_BRIEF_B_STARTTIME, m_fStartTime); |
| 128 | DDV_MinMaxFloat(pDX, m_fStartTime, 0.f, 99999.f); |
| 129 | DDX_Text(pDX, IDC_BRIEF_B_X, m_iX); |
| 130 | DDV_MinMaxInt(pDX, m_iX, 0, 639); |
| 131 | DDX_Text(pDX, IDC_BRIEF_B_Y, m_iY); |
| 132 | DDV_MinMaxInt(pDX, m_iY, 0, 479); |
| 133 | DDX_Radio(pDX, IDC_BRIEF_B_STATIC, m_iEffectType); |
| 134 | DDX_Text(pDX, IDC_BRIEF_B_DESC, m_sDesc); |
| 135 | DDX_Check(pDX, IDC_BRIEF_B_NORENDER, m_NoRenderUntilStart); |
| 136 | //}}AFX_DATA_MAP |
| 137 | } |
| 138 | |
| 139 | BEGIN_MESSAGE_MAP(CBriefBitmapEdit, CDialog) |
| 140 | //{{AFX_MSG_MAP(CBriefBitmapEdit) |
| 141 | ON_BN_CLICKED(IDC_BRIEF_B_CHOOSE, OnBriefBChoose) |
| 142 | ON_CBN_SELCHANGE(IDC_BRIEF_B_PREDEF, OnSelchangeBriefBPredef) |
| 143 | ON_BN_CLICKED(IDC_MISSIONFLAGS, OnMissionflags) |
| 144 | ON_BN_CLICKED(IDC_BRIEF_B_NORENDER, OnBriefBNorender) |
| 145 | //}}AFX_MSG_MAP |
| 146 | END_MESSAGE_MAP() |
| 147 | |
| 148 | ///////////////////////////////////////////////////////////////////////////// |
| 149 | // CBriefBitmapEdit message handlers |
| 150 | |
| 151 | void CBriefBitmapEdit::OnOK() { |
| 152 | UpdateData(true); |
| 153 | |
| 154 | if (!cfexist(m_sFilename.GetBuffer(0))) { |
| 155 | MessageBox("Not A Valid Filename", "Error"); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | desc.caps = TCBD_XY | TCBD_LOOPING | TCBD_WAITTIME | TCBD_SPEED; |
| 160 | strcpy(desc.filename, m_sFilename); |
| 161 | desc.speed = m_fSpeed; |
| 162 | desc.waittime = m_fStartTime; |
| 163 | desc.x = m_iX; |
| 164 | desc.y = m_iY; |
| 165 | |
| 166 | switch (m_iEffectType) { |
| 167 | case 0: |
| 168 | desc.type = TC_BMP_STATIC; |
| 169 | desc.flags = TC_BMPF_IN; |
| 170 | break; |
| 171 | case 1: |
| 172 | desc.type = TC_BMP_BLUR; |
| 173 | desc.flags = TC_BMPF_IN; |
| 174 | break; |
| 175 | case 2: |
| 176 | desc.type = TC_BMP_BLUR; |
| 177 | desc.flags = TC_BMPF_OUT; |
| 178 | break; |
| 179 | case 3: |
| 180 | desc.type = TC_BMP_SCANLINE; |
| 181 | desc.flags = TC_BMPF_IN; |
| 182 | break; |
| 183 | case 4: |
| 184 | desc.type = TC_BMP_SCANLINE; |
| 185 | desc.flags = TC_BMPF_OUT; |
| 186 | break; |
| 187 | case 5: |
| 188 | desc.type = TC_BMP_INVERT; |
| 189 | desc.flags = TC_BMPF_IN; |
| 190 | break; |
| 191 | case 6: |
| 192 | desc.type = TC_BMP_INVERT; |
| 193 | desc.flags = TC_BMPF_OUT; |
| 194 | break; |
| 195 | case 7: |
| 196 | desc.type = TC_BMP_STRETCH; |
| 197 | desc.flags = TC_BMPF_IN; |
| 198 | break; |
| 199 | case 8: |
| 200 | desc.type = TC_BMP_STRETCH; |
| 201 | desc.flags = TC_BMPF_OUT; |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | if (m_NoRenderUntilStart) |
| 206 | desc.flags |= TC_NOEARLYRENDER; |
| 207 | else |
| 208 | desc.flags &= ~TC_NOEARLYRENDER; |
| 209 | |
| 210 | CDialog::OnOK(); |
| 211 | } |
| 212 | |
| 213 | void CBriefBitmapEdit::OnBriefBChoose() { |
| 214 | UpdateData(true); |
| 215 | char szFilter[] = "Outrage Graphic Files (*.ogf)|*.ogf|32bit Uncompressed Targa (*.tga)|*.tga|PCX (*.pcx)|*.pcx|All " |
| 216 | "Files (*.*)|*.*||"; |
| 217 | CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, szFilter); |
| 218 | |
| 219 | if (dlg.DoModal() == IDOK) { |
| 220 | // handle |
| 221 | m_sFilename = dlg.GetFileName(); |
| 222 | UpdateData(false); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | BOOL CBriefBitmapEdit::OnInitDialog() { |
| 227 | CDialog::OnInitDialog(); |
| 228 | |
| 229 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_B_PREDEF); |
| 230 | combo->AddString("<Raw>"); |
| 231 | combo->SetCurSel(0); |
| 232 | |
| 233 | int layout = -1; |
| 234 | |
| 235 | for (int i = 0; i < (*PBnum_layouts); i++) { |
| 236 | if (!stricmp(Briefing_screens[m_Screen].layout, PBlayouts[i].filename)) |
| 237 | layout = i; |
| 238 | } |
| 239 | |
| 240 | if (layout != -1) { |
| 241 | int count = PBlayouts[layout].num_bmps; |
| 242 | for (int j = 0; j < count; j++) { |
| 243 | char buffer[100]; |
| 244 | sprintf(buffer, "(%d,%d)", PBlayouts[layout].bmps[j].x, PBlayouts[layout].bmps[j].y); |
| 245 | combo->AddString(buffer); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | UpdateData(false); |
| 250 | |
| 251 | return TRUE; |
| 252 | } |
| 253 | |
| 254 | void CBriefBitmapEdit::OnSelchangeBriefBPredef() { |
| 255 | CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_B_PREDEF); |
| 256 | int item = combo->GetCurSel(); |
| 257 | |
| 258 | if (item <= 0) |
| 259 | return; |
| 260 | |
| 261 | UpdateData(true); |
| 262 | |
| 263 | int layout = -1; |
| 264 | |
| 265 | for (int i = 0; i < (*PBnum_layouts); i++) { |
| 266 | if (!stricmp(Briefing_screens[m_Screen].layout, PBlayouts[i].filename)) |
| 267 | layout = i; |
| 268 | } |
| 269 | |
| 270 | if (layout != -1) { |
| 271 | m_iX = PBlayouts[layout].bmps[item - 1].x; |
| 272 | m_iY = PBlayouts[layout].bmps[item - 1].y; |
| 273 | UpdateData(false); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | void CBriefBitmapEdit::OnMissionflags() { |
| 278 | CBriefMissionFlagsDlg dlg(desc.mission_mask_set, desc.mission_mask_unset); |
| 279 | |
| 280 | if (dlg.DoModal()) { |
| 281 | desc.mission_mask_set = dlg.m_Set; |
| 282 | desc.mission_mask_unset = dlg.m_UnSet; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void CBriefBitmapEdit::OnBriefBNorender() {} |