| 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 | // ProceduralDialog.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "mfc_compatibility.h" |
| 23 | #include "editor.h" |
| 24 | #include "ProceduralDialog.h" |
| 25 | #include "bitmap.h" |
| 26 | #include "gametexture.h" |
| 27 | #include "manage.h" |
| 28 | #include "texpage.h" |
| 29 | #include "pserror.h" |
| 30 | #include "mono.h" |
| 31 | #include "vclip.h" |
| 32 | #include "Macros.h" |
| 33 | #include "EditLineDialog.h" |
| 34 | #include "ddio.h" |
| 35 | #include "game.h" |
| 36 | |
| 37 | #ifdef _DEBUG |
| 38 | #define new DEBUG_NEW |
| 39 | #undef THIS_FILE |
| 40 | static char THIS_FILE[] = __FILE__; |
| 41 | #endif |
| 42 | |
| 43 | #define MAX_SLIDER_RANGE 255 |
| 44 | |
| 45 | ///////////////////////////////////////////////////////////////////////////// |
| 46 | // CProceduralDialog dialog |
| 47 | |
| 48 | CProceduralDialog::CProceduralDialog(CWnd *pParent /*=NULL*/) : CDialog(CProceduralDialog::IDD, pParent) { |
| 49 | //{{AFX_DATA_INIT(CProceduralDialog) |
| 50 | // NOTE: the ClassWizard will add member initialization here |
| 51 | //}}AFX_DATA_INIT |
| 52 | } |
| 53 | |
| 54 | void CProceduralDialog::DoDataExchange(CDataExchange *pDX) { |
| 55 | CDialog::DoDataExchange(pDX); |
| 56 | //{{AFX_DATA_MAP(CProceduralDialog) |
| 57 | DDX_Control(pDX, IDC_FP_HEAT_SLIDER, m_heat_slider); |
| 58 | DDX_Control(pDX, IDC_FREQ_SLIDER, m_freq_slider); |
| 59 | DDX_Control(pDX, IDC_SIZE_SLIDER, m_size_slider); |
| 60 | DDX_Control(pDX, IDC_SPEED_SLIDER, m_speed_slider); |
| 61 | //}}AFX_DATA_MAP |
| 62 | } |
| 63 | |
| 64 | BEGIN_MESSAGE_MAP(CProceduralDialog, CDialog) |
| 65 | //{{AFX_MSG_MAP(CProceduralDialog) |
| 66 | ON_WM_TIMER() |
| 67 | ON_WM_LBUTTONDOWN() |
| 68 | ON_WM_MOUSEMOVE() |
| 69 | ON_WM_LBUTTONUP() |
| 70 | ON_BN_CLICKED(IDC_CLEAR_PROCEDURALS, OnClearProcedurals) |
| 71 | ON_CBN_SELENDOK(IDC_PROCEDURAL_PULLDOWN, OnSelendokProceduralPulldown) |
| 72 | ON_BN_CLICKED(IDC_PROCEDURAL_UPDATE, OnProceduralUpdate) |
| 73 | ON_BN_CLICKED(IDC_IMPORT_PALETTE, OnImportPalette) |
| 74 | ON_BN_CLICKED(IDC_DEFAULT_PALETTE, OnDefaultPalette) |
| 75 | ON_BN_CLICKED(IDC_COPY_PROCEDURAL, OnCopyProcedural) |
| 76 | //}}AFX_MSG_MAP |
| 77 | END_MESSAGE_MAP() |
| 78 | |
| 79 | ///////////////////////////////////////////////////////////////////////////// |
| 80 | // CProceduralDialog message handlers |
| 81 | |
| 82 | static static_proc_element save_elements[8000]; |
| 83 | BOOL CProceduralDialog::OnInitDialog() { |
| 84 | CDialog::OnInitDialog(); |
| 85 | CWnd::SetTimer(1, 33, NULL); // 30 frames per second |
| 86 | |
| 87 | int save_num = 0; |
| 88 | int n = D3EditState.texdlg_texture; |
| 89 | |
| 90 | // Make a temp buffer for our static elements |
| 91 | if (GameTextures[n].procedural->num_static_elements > 0) { |
| 92 | save_num = GameTextures[n].procedural->num_static_elements; |
| 93 | memcpy(save_elements, GameTextures[n].procedural->static_proc_elements, save_num * sizeof(static_proc_element)); |
| 94 | } |
| 95 | |
| 96 | FreeStaticProceduralsForTexture(n); |
| 97 | Sleep(2000); |
| 98 | |
| 99 | AllocateStaticProceduralsForTexture(n, 8000); |
| 100 | |
| 101 | memcpy(GameTextures[n].procedural->static_proc_elements, save_elements, save_num * sizeof(static_proc_element)); |
| 102 | GameTextures[n].procedural->num_static_elements = save_num; |
| 103 | |
| 104 | m_button_down = 0; |
| 105 | m_proc_type = 0; |
| 106 | m_size = 255; |
| 107 | m_saturate = 0; |
| 108 | m_speed = 0; |
| 109 | m_frequency = 0; |
| 110 | m_cur_color = 255; |
| 111 | |
| 112 | // Allocate bitmap memory |
| 113 | CWnd *texwnd; |
| 114 | RECT rect; |
| 115 | |
| 116 | texwnd = GetDlgItem(IDC_PALETTE_VIEW); |
| 117 | texwnd->GetWindowRect(&rect); |
| 118 | ScreenToClient(&rect); |
| 119 | |
| 120 | int w = rect.right - rect.left; |
| 121 | int h = rect.bottom - rect.top; |
| 122 | |
| 123 | m_palette_bitmap = bm_AllocBitmap(w, h, ((w * h) / 3) * 2); |
| 124 | ASSERT(m_palette_bitmap >= 0); |
| 125 | m_PaletteSurf.create(bm_w(m_palette_bitmap, 0), bm_h(m_palette_bitmap, 0), bm_bpp(m_palette_bitmap)); |
| 126 | |
| 127 | texwnd = GetDlgItem(IDC_PROCEDURAL_VIEW); |
| 128 | texwnd->GetWindowRect(&rect); |
| 129 | ScreenToClient(&rect); |
| 130 | |
| 131 | w = rect.right - rect.left; |
| 132 | h = rect.bottom - rect.top; |
| 133 | |
| 134 | m_window_bitmap = bm_AllocBitmap(w, h, ((w * h) / 3) * 2); |
| 135 | ASSERT(m_window_bitmap >= 0); |
| 136 | m_TextureSurf.create(bm_w(m_window_bitmap, 0), bm_h(m_window_bitmap, 0), bm_bpp(m_window_bitmap)); |
| 137 | |
| 138 | // Set default slider values |
| 139 | m_freq_slider.SetRange(0, MAX_SLIDER_RANGE); |
| 140 | m_freq_slider.SetPos(255 - m_frequency); |
| 141 | |
| 142 | m_speed_slider.SetRange(0, MAX_SLIDER_RANGE); |
| 143 | m_speed_slider.SetPos(m_speed); |
| 144 | |
| 145 | m_size_slider.SetRange(1, MAX_SLIDER_RANGE); |
| 146 | m_size_slider.SetPos(m_size); |
| 147 | |
| 148 | m_heat_slider.SetRange(0, MAX_SLIDER_RANGE); |
| 149 | m_heat_slider.SetPos(GameTextures[n].procedural->heat); |
| 150 | |
| 151 | UpdateDialog(); |
| 152 | |
| 153 | return TRUE; // return TRUE unless you set the focus to a control |
| 154 | // EXCEPTION: OCX Property Pages should return FALSE |
| 155 | } |
| 156 | |
| 157 | void CProceduralDialog::PrintValue(int whichbox, uint8_t val) { |
| 158 | CEdit *ebox; |
| 159 | char str[255]; |
| 160 | |
| 161 | ebox = (CEdit *)GetDlgItem(whichbox); |
| 162 | sprintf(str, "%d", val); |
| 163 | ebox->SetWindowText(str); |
| 164 | } |
| 165 | |
| 166 | void CProceduralDialog::UpdateDialog() { |
| 167 | int n = D3EditState.texdlg_texture; |
| 168 | |
| 169 | // Update procedural box |
| 170 | SendDlgItemMessage(IDC_PROCEDURAL_PULLDOWN, CB_RESETCONTENT, 0, 0); |
| 171 | for (int i = 0; stricmp("End", ProcNames[i]) != 0; i++) { |
| 172 | SendDlgItemMessage(IDC_PROCEDURAL_PULLDOWN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)ProcNames[i]); |
| 173 | } |
| 174 | SendDlgItemMessage(IDC_PROCEDURAL_PULLDOWN, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)ProcNames[m_proc_type]); |
| 175 | |
| 176 | // Update palette box |
| 177 | CWnd *texwnd; |
| 178 | RECT rect; |
| 179 | |
| 180 | texwnd = GetDlgItem(IDC_PALETTE_VIEW); |
| 181 | texwnd->GetWindowRect(&rect); |
| 182 | ScreenToClient(&rect); |
| 183 | |
| 184 | int w = rect.right - rect.left; |
| 185 | int h = rect.bottom - rect.top; |
| 186 | |
| 187 | Desktop_surf->attach_to_window((unsigned)m_hWnd); |
| 188 | |
| 189 | uint16_t *data = bm_data(m_palette_bitmap, 0); |
| 190 | |
| 191 | for (i = 0; i < h; i++) { |
| 192 | float cur_color = 0; |
| 193 | float color_delta = 256.0 / (float)w; |
| 194 | for (int t = 0; t < w; t++, cur_color += color_delta) { |
| 195 | data[i * w + t] = GameTextures[n].procedural->palette[(int)cur_color]; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | m_PaletteSurf.load(m_palette_bitmap); |
| 200 | |
| 201 | int x = rect.left + ((rect.right - rect.left) / 2) - m_PaletteSurf.width() / 2; |
| 202 | int y = rect.top + ((rect.bottom - rect.top) / 2) - m_PaletteSurf.height() / 2; |
| 203 | |
| 204 | Desktop_surf->blt(x, y, &m_PaletteSurf); |
| 205 | |
| 206 | // fill in the combo box for copy procedural data |
| 207 | CComboBox *combo; |
| 208 | combo = (CComboBox *)GetDlgItem(IDC_PROC_COPY_LIST); |
| 209 | combo->ResetContent(); |
| 210 | for (i = 0; i < MAX_TEXTURES; i++) { |
| 211 | if (!GameTextures[i].used) |
| 212 | continue; |
| 213 | if (i == D3EditState.texdlg_texture) |
| 214 | continue; |
| 215 | if (!(GameTextures[i].flags & TF_PROCEDURAL)) |
| 216 | continue; |
| 217 | if ((GameTextures[i].flags & TF_WATER_PROCEDURAL)) |
| 218 | continue; |
| 219 | combo->AddString(GameTextures[i].name); |
| 220 | } |
| 221 | combo->SetCurSel(0); |
| 222 | } |
| 223 | |
| 224 | void CProceduralDialog::UpdateProcView() { |
| 225 | int n = D3EditState.texdlg_texture; |
| 226 | |
| 227 | FrameCount++; |
| 228 | |
| 229 | CWnd *texwnd; |
| 230 | RECT rect; |
| 231 | |
| 232 | texwnd = GetDlgItem(IDC_PROCEDURAL_VIEW); |
| 233 | texwnd->GetWindowRect(&rect); |
| 234 | ScreenToClient(&rect); |
| 235 | |
| 236 | int w = rect.right - rect.left; |
| 237 | int h = rect.bottom - rect.top; |
| 238 | |
| 239 | Desktop_surf->attach_to_window((unsigned)m_hWnd); |
| 240 | |
| 241 | int bm_handle = GetTextureBitmap(n, 0, 1); |
| 242 | |
| 243 | if (GameBitmaps[bm_handle].flags & BF_MIPMAPPED) |
| 244 | GameBitmaps[m_window_bitmap].flags |= BF_MIPMAPPED; |
| 245 | |
| 246 | bm_ScaleBitmapToBitmap(m_window_bitmap, bm_handle); |
| 247 | |
| 248 | m_TextureSurf.load(m_window_bitmap); |
| 249 | |
| 250 | int x = rect.left + ((rect.right - rect.left) / 2) - m_TextureSurf.width() / 2; |
| 251 | int y = rect.top + ((rect.bottom - rect.top) / 2) - m_TextureSurf.height() / 2; |
| 252 | |
| 253 | Desktop_surf->blt(x, y, &m_TextureSurf); |
| 254 | |
| 255 | // Do slider values |
| 256 | m_frequency = 255 - m_freq_slider.GetPos(); |
| 257 | m_speed = m_speed_slider.GetPos(); |
| 258 | m_size = m_size_slider.GetPos(); |
| 259 | |
| 260 | GameTextures[n].procedural->heat = m_heat_slider.GetPos(); |
| 261 | |
| 262 | PrintValue(IDC_SPEED_TEXT, m_speed); |
| 263 | PrintValue(IDC_SIZE_TEXT2, m_size); |
| 264 | PrintValue(IDC_FREQUENCY_TEXT, 255 - m_frequency); |
| 265 | PrintValue(IDC_HEAT_TEXT, GameTextures[n].procedural->heat); |
| 266 | } |
| 267 | |
| 268 | void CProceduralDialog::OnTimer(UINT nIDEvent) { |
| 269 | UpdateProcView(); |
| 270 | CDialog::OnTimer(nIDEvent); |
| 271 | } |
| 272 | |
| 273 | BOOL CProceduralDialog::DestroyWindow() { |
| 274 | CWnd::KillTimer(1); |
| 275 | int n = D3EditState.texdlg_texture; |
| 276 | |
| 277 | int save_num = 0; |
| 278 | |
| 279 | // Restore our static proc elements |
| 280 | save_num = GameTextures[n].procedural->num_static_elements; |
| 281 | |
| 282 | if (save_num > 0) |
| 283 | memcpy(save_elements, GameTextures[n].procedural->static_proc_elements, save_num * sizeof(static_proc_element)); |
| 284 | |
| 285 | FreeStaticProceduralsForTexture(n); |
| 286 | Sleep(2000); |
| 287 | |
| 288 | if (save_num > 0) { |
| 289 | AllocateStaticProceduralsForTexture(n, save_num); |
| 290 | memcpy(GameTextures[n].procedural->static_proc_elements, save_elements, save_num * sizeof(static_proc_element)); |
| 291 | GameTextures[n].procedural->num_static_elements = save_num; |
| 292 | } else |
| 293 | GameTextures[n].flags &= ~(TF_PROCEDURAL | TF_WATER_PROCEDURAL); |
| 294 | |
| 295 | bm_FreeBitmap(m_palette_bitmap); |
| 296 | m_PaletteSurf.free(); |
| 297 | |
| 298 | bm_FreeBitmap(m_window_bitmap); |
| 299 | m_TextureSurf.free(); |
| 300 | |
| 301 | return CDialog::DestroyWindow(); |
| 302 | } |
| 303 | |
| 304 | void CProceduralDialog::OnLButtonDown(UINT nFlags, CPoint point) { |
| 305 | // TODO: Add your message handler code here and/or call default |
| 306 | CPoint tpoint = point; |
| 307 | CWnd *texwnd; |
| 308 | RECT rect; |
| 309 | int n = D3EditState.texdlg_texture; |
| 310 | |
| 311 | texwnd = GetDlgItem(IDC_PROCEDURAL_VIEW); |
| 312 | texwnd->GetWindowRect(&rect); |
| 313 | |
| 314 | int w = rect.right - rect.left; |
| 315 | int h = rect.bottom - rect.top; |
| 316 | |
| 317 | MapWindowPoints(texwnd, &tpoint, 1); |
| 318 | |
| 319 | if (tpoint.x < 0) |
| 320 | return; |
| 321 | if (tpoint.y < 0) |
| 322 | return; |
| 323 | |
| 324 | if (tpoint.x >= w) |
| 325 | return; |
| 326 | if (tpoint.y >= h) |
| 327 | return; |
| 328 | |
| 329 | int bm_handle = GameTextures[n].procedural->procedural_bitmap; |
| 330 | int bw = bm_w(bm_handle, 0); |
| 331 | int bh = bm_h(bm_handle, 0); |
| 332 | |
| 333 | int dest_x = ((float)tpoint.x * (float)((float)bw / (float)w)); |
| 334 | int dest_y = ((float)tpoint.y * (float)((float)bh / (float)h)); |
| 335 | |
| 336 | if (m_proc_type == PROC_LINE_LIGHTNING) { |
| 337 | m_save_x = dest_x; |
| 338 | m_save_y = dest_y; |
| 339 | } else if (m_proc_type != PROC_NONE) { |
| 340 | CreateElement(tpoint.x, tpoint.y); |
| 341 | } |
| 342 | |
| 343 | m_button_down = 1; |
| 344 | |
| 345 | CDialog::OnLButtonDown(nFlags, point); |
| 346 | } |
| 347 | |
| 348 | // Creates a procedural element at x,y |
| 349 | static_proc_element *CProceduralDialog::CreateElement(int x, int y) { |
| 350 | int n = D3EditState.texdlg_texture; |
| 351 | proc_struct *procedural = GameTextures[n].procedural; |
| 352 | |
| 353 | int index; |
| 354 | |
| 355 | if (GameTextures[n].procedural->num_static_elements >= MAX_PROC_ELEMENTS) |
| 356 | return NULL; |
| 357 | else |
| 358 | index = GameTextures[n].procedural->num_static_elements; |
| 359 | |
| 360 | static_proc_element *proc_elem = &procedural->static_proc_elements[index]; |
| 361 | |
| 362 | CWnd *texwnd; |
| 363 | RECT rect; |
| 364 | |
| 365 | texwnd = GetDlgItem(IDC_PROCEDURAL_VIEW); |
| 366 | texwnd->GetWindowRect(&rect); |
| 367 | |
| 368 | int w = rect.right - rect.left; |
| 369 | int h = rect.bottom - rect.top; |
| 370 | |
| 371 | int bm_handle = GameTextures[n].procedural->procedural_bitmap; |
| 372 | int bw = bm_w(bm_handle, 0); |
| 373 | int bh = bm_h(bm_handle, 0); |
| 374 | |
| 375 | int dest_x = ((float)x * (float)((float)bw / (float)w)); |
| 376 | int dest_y = ((float)y * (float)((float)bh / (float)h)); |
| 377 | |
| 378 | proc_elem->type = m_proc_type; |
| 379 | |
| 380 | proc_elem->x1 = dest_x; |
| 381 | proc_elem->y1 = dest_y; |
| 382 | proc_elem->color = m_cur_color; |
| 383 | proc_elem->size = m_size; |
| 384 | proc_elem->speed = m_speed; |
| 385 | proc_elem->frequency = m_frequency; |
| 386 | |
| 387 | procedural->num_static_elements++; |
| 388 | |
| 389 | return &procedural->static_proc_elements[index]; |
| 390 | } |
| 391 | |
| 392 | void CProceduralDialog::OnMouseMove(UINT nFlags, CPoint point) { |
| 393 | // TODO: Add your message handler code here and/or call default |
| 394 | CPoint tpoint = point; |
| 395 | CWnd *texwnd; |
| 396 | RECT rect; |
| 397 | int n = D3EditState.texdlg_texture; |
| 398 | |
| 399 | if (m_button_down == 0) |
| 400 | return; |
| 401 | |
| 402 | texwnd = GetDlgItem(IDC_PROCEDURAL_VIEW); |
| 403 | texwnd->GetWindowRect(&rect); |
| 404 | |
| 405 | int w = rect.right - rect.left; |
| 406 | int h = rect.bottom - rect.top; |
| 407 | |
| 408 | MapWindowPoints(texwnd, &tpoint, 1); |
| 409 | |
| 410 | if (tpoint.x < 0) |
| 411 | return; |
| 412 | if (tpoint.y < 0) |
| 413 | return; |
| 414 | |
| 415 | if (tpoint.x >= w) |
| 416 | return; |
| 417 | if (tpoint.y >= h) |
| 418 | return; |
| 419 | |
| 420 | if (m_proc_type != PROC_NONE && m_proc_type != PROC_LINE_LIGHTNING) { |
| 421 | CreateElement(tpoint.x, tpoint.y); |
| 422 | } |
| 423 | |
| 424 | CDialog::OnMouseMove(nFlags, point); |
| 425 | } |
| 426 | |
| 427 | void CProceduralDialog::OnLButtonUp(UINT nFlags, CPoint point) { |
| 428 | int n = D3EditState.texdlg_texture; |
| 429 | CPoint tpoint = point; |
| 430 | |
| 431 | if (m_button_down == 1 && m_proc_type == PROC_LINE_LIGHTNING) { |
| 432 | CWnd *texwnd; |
| 433 | RECT rect; |
| 434 | |
| 435 | texwnd = GetDlgItem(IDC_PROCEDURAL_VIEW); |
| 436 | texwnd->GetWindowRect(&rect); |
| 437 | |
| 438 | int w = rect.right - rect.left; |
| 439 | int h = rect.bottom - rect.top; |
| 440 | |
| 441 | int bm_handle = GameTextures[n].procedural->procedural_bitmap; |
| 442 | int bw = bm_w(bm_handle, 0); |
| 443 | int bh = bm_h(bm_handle, 0); |
| 444 | |
| 445 | int dest_x = ((float)tpoint.x * (float)((float)bw / (float)w)); |
| 446 | int dest_y = ((float)tpoint.y * (float)((float)bh / (float)h)); |
| 447 | |
| 448 | static_proc_element *proc_elem = CreateElement(0, 0); |
| 449 | |
| 450 | if (proc_elem != NULL) { |
| 451 | proc_elem->x1 = m_save_x; |
| 452 | proc_elem->y1 = m_save_y; |
| 453 | proc_elem->x2 = dest_x; |
| 454 | proc_elem->y2 = dest_y; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | m_button_down = 0; |
| 459 | |
| 460 | CDialog::OnLButtonUp(nFlags, point); |
| 461 | } |
| 462 | |
| 463 | void CProceduralDialog::OnClearProcedurals() { ClearAllProceduralsFromTexture(D3EditState.texdlg_texture); } |
| 464 | |
| 465 | void CProceduralDialog::OnSelendokProceduralPulldown() { |
| 466 | int cur = SendDlgItemMessage(IDC_PROCEDURAL_PULLDOWN, CB_GETCURSEL, 0, 0); |
| 467 | m_proc_type = cur; |
| 468 | UpdateDialog(); |
| 469 | } |
| 470 | |
| 471 | void CProceduralDialog::OnProceduralUpdate() { UpdateDialog(); } |
| 472 | |
| 473 | void CProceduralDialog::HarvestValue(int whichbox, uint8_t *val) { |
| 474 | CEdit *ebox; |
| 475 | char name[20]; |
| 476 | int num = 0; |
| 477 | |
| 478 | ebox = (CEdit *)GetDlgItem(whichbox); |
| 479 | ebox->GetWindowText(name, 20); |
| 480 | |
| 481 | num = atoi(name); |
| 482 | if (num < 0) |
| 483 | num = 0; |
| 484 | if (num > 255) |
| 485 | num = 255; |
| 486 | |
| 487 | *val = num; |
| 488 | |
| 489 | UpdateDialog(); |
| 490 | } |
| 491 | |
| 492 | void CProceduralDialog::OnImportPalette() { |
| 493 | CFILE *infile; |
| 494 | char filename[255]; |
| 495 | uint8_t r[256], g[256], b[256]; |
| 496 | int n = D3EditState.texdlg_texture; |
| 497 | |
| 498 | CString filter = "PCX files (*.pcx)|*.pcx||"; |
| 499 | |
| 500 | if (!OpenFileDialog(this, (LPCSTR)filter, filename, Current_bitmap_dir, sizeof(Current_bitmap_dir))) |
| 501 | return; |
| 502 | |
| 503 | if ((infile = cfopen(filename, "rb")) == NULL) { |
| 504 | OutrageMessageBox("Couldn't open that PCX file!"); |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | cfseek(infile, -768, SEEK_END); |
| 509 | for (int i = 0; i < 256; i++) { |
| 510 | r[i] = cf_ReadByte(infile); |
| 511 | g[i] = cf_ReadByte(infile); |
| 512 | b[i] = cf_ReadByte(infile); |
| 513 | } |
| 514 | |
| 515 | cfclose(infile); |
| 516 | |
| 517 | GeneratePaletteForProcedural(r, g, b, GameTextures[n].procedural->palette); |
| 518 | |
| 519 | UpdateDialog(); |
| 520 | } |
| 521 | |
| 522 | void CProceduralDialog::OnDefaultPalette() { |
| 523 | int n = D3EditState.texdlg_texture; |
| 524 | memcpy(GameTextures[n].procedural->palette, DefaultProcPalette, 256 * 2); |
| 525 | UpdateDialog(); |
| 526 | } |
| 527 | |
| 528 | void CProceduralDialog::OnCopyProcedural() { |
| 529 | // get the name of the texture |
| 530 | CComboBox *combo; |
| 531 | CString str; |
| 532 | int src_id; |
| 533 | |
| 534 | combo = (CComboBox *)GetDlgItem(IDC_PROC_COPY_LIST); |
| 535 | combo->GetLBText(combo->GetCurSel(), str); |
| 536 | src_id = FindTextureName(str.GetBuffer(0)); |
| 537 | ASSERT(src_id != -1); |
| 538 | |
| 539 | bool do_pal = false; |
| 540 | char buffer[512]; |
| 541 | sprintf(buffer, "Are you sure you want to replace the procedural elements of %s with %s?", |
| 542 | GameTextures[D3EditState.texdlg_texture].name, GameTextures[src_id].name); |
| 543 | if (MessageBox(buffer, "Confirm", MB_YESNO) != IDYES) |
| 544 | return; |
| 545 | if (MessageBox("Would you like to replace the palette also?", "Palette", MB_YESNO) == IDYES) |
| 546 | do_pal = true; |
| 547 | |
| 548 | mngs_texture_page src_page, dest_page; |
| 549 | mng_AssignTextureToTexPage(src_id, &src_page); |
| 550 | mng_AssignTextureToTexPage(D3EditState.texdlg_texture, &dest_page); |
| 551 | |
| 552 | ClearAllProceduralsFromTexture(D3EditState.texdlg_texture); |
| 553 | FreeProceduralForTexture(D3EditState.texdlg_texture); |
| 554 | |
| 555 | int i; |
| 556 | if (src_page.tex_struct.flags & TF_WATER_PROCEDURAL) |
| 557 | dest_page.tex_struct.flags |= TF_WATER_PROCEDURAL; |
| 558 | else |
| 559 | dest_page.tex_struct.flags &= ~TF_WATER_PROCEDURAL; |
| 560 | |
| 561 | if (do_pal) { |
| 562 | for (i = 0; i < 255; i++) { |
| 563 | dest_page.proc_palette[i] = src_page.proc_palette[i]; |
| 564 | } |
| 565 | } |
| 566 | dest_page.proc_heat = src_page.proc_heat; |
| 567 | dest_page.proc_light = src_page.proc_light; |
| 568 | dest_page.proc_thickness = src_page.proc_thickness; |
| 569 | dest_page.proc_evaluation_time = src_page.proc_evaluation_time; |
| 570 | dest_page.osc_time = src_page.osc_time; |
| 571 | dest_page.osc_value = src_page.osc_value; |
| 572 | dest_page.num_proc_elements = src_page.num_proc_elements; |
| 573 | |
| 574 | for (i = 0; i < dest_page.num_proc_elements; i++) { |
| 575 | dest_page.proc_type[i] = src_page.proc_type[i]; |
| 576 | dest_page.proc_frequency[i] = src_page.proc_frequency[i]; |
| 577 | dest_page.proc_speed[i] = src_page.proc_speed[i]; |
| 578 | dest_page.proc_size[i] = src_page.proc_size[i]; |
| 579 | dest_page.proc_x1[i] = src_page.proc_x1[i]; |
| 580 | dest_page.proc_y1[i] = src_page.proc_y1[i]; |
| 581 | dest_page.proc_x2[i] = src_page.proc_x2[i]; |
| 582 | dest_page.proc_y2[i] = src_page.proc_y2[i]; |
| 583 | } |
| 584 | |
| 585 | AllocateProceduralForTexture(D3EditState.texdlg_texture); |
| 586 | AllocateStaticProceduralsForTexture(D3EditState.texdlg_texture, dest_page.num_proc_elements); |
| 587 | GameTextures[D3EditState.texdlg_texture].procedural->num_static_elements = dest_page.num_proc_elements; |
| 588 | GameTextures[D3EditState.texdlg_texture].procedural->heat = dest_page.proc_heat; |
| 589 | GameTextures[D3EditState.texdlg_texture].procedural->light = dest_page.proc_light; |
| 590 | GameTextures[D3EditState.texdlg_texture].procedural->thickness = dest_page.proc_thickness; |
| 591 | GameTextures[D3EditState.texdlg_texture].procedural->evaluation_time = dest_page.proc_evaluation_time; |
| 592 | GameTextures[D3EditState.texdlg_texture].procedural->osc_time = dest_page.osc_time; |
| 593 | GameTextures[D3EditState.texdlg_texture].procedural->osc_value = dest_page.osc_value; |
| 594 | |
| 595 | // Last 2 colors are the same |
| 596 | dest_page.proc_palette[255] = dest_page.proc_palette[254]; |
| 597 | memcpy(GameTextures[D3EditState.texdlg_texture].procedural->palette, dest_page.proc_palette, 256 * 2); |
| 598 | |
| 599 | for (i = 0; i < dest_page.num_proc_elements; i++) { |
| 600 | static_proc_element *proc = &GameTextures[D3EditState.texdlg_texture].procedural->static_proc_elements[i]; |
| 601 | proc->type = dest_page.proc_type[i]; |
| 602 | proc->frequency = dest_page.proc_frequency[i]; |
| 603 | proc->speed = dest_page.proc_speed[i]; |
| 604 | proc->size = dest_page.proc_size[i]; |
| 605 | proc->x1 = dest_page.proc_x1[i]; |
| 606 | proc->y1 = dest_page.proc_y1[i]; |
| 607 | proc->x2 = dest_page.proc_x2[i]; |
| 608 | proc->y2 = dest_page.proc_y2[i]; |
| 609 | } |
| 610 | |
| 611 | UpdateDialog(); |
| 612 | } |