| 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 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/editor/TextureDialog.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:39 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Texture Dialog keypad |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 26 5/06/99 12:43p Matt |
| 30 | * Fixed a bug when did a texture grab on the terrain with no cells |
| 31 | * selected. |
| 32 | * |
| 33 | * 25 4/19/99 6:45p Jason |
| 34 | * fixed satellite grabbing bug |
| 35 | * |
| 36 | * 24 4/08/99 5:47p Jason |
| 37 | * added face finding function |
| 38 | * |
| 39 | * 23 2/23/99 3:07p Jason |
| 40 | * added grabbing of terrain textures |
| 41 | * |
| 42 | * 22 12/04/98 1:14p Jason |
| 43 | * added "Currently Used" texture flag |
| 44 | * |
| 45 | * 21 8/20/98 4:09p Jason |
| 46 | * added facemap feature |
| 47 | * |
| 48 | * 20 8/05/98 8:44p Jason |
| 49 | * added uniform scaling of textures |
| 50 | * |
| 51 | * 19 8/03/98 2:38p Matt |
| 52 | * Changed the replace texture function to replace all instances of a |
| 53 | * texture in the current room *or* in the whole mine, at the user's |
| 54 | * discretion. |
| 55 | * |
| 56 | * 18 6/23/98 2:43p Matt |
| 57 | * Changed calls to OutrageMessageBox() & Debug_MessageBox() to deal with |
| 58 | * int return value (instead of bool). |
| 59 | * |
| 60 | * 17 6/15/98 4:00p Jason |
| 61 | * replaced monochromatic polymodel lighting with rgb lighting |
| 62 | * |
| 63 | * 16 6/10/98 1:57p Samir |
| 64 | * fixed some listbox problems. |
| 65 | * |
| 66 | * 15 6/10/98 12:21p Matt |
| 67 | * Revamped system that controls what textures are displayed on the |
| 68 | * texture tab. Should work correctly now, and will now save the settings |
| 69 | * to the registry. Also, textures now default to no type set, not all |
| 70 | * types set. |
| 71 | * |
| 72 | * 14 5/20/98 1:08p Jason |
| 73 | * more stuff for adding bumpmaps |
| 74 | * |
| 75 | * 13 3/03/98 5:39p Jason |
| 76 | * added swatch to texture tab |
| 77 | * |
| 78 | * 12 11/14/97 12:41p Jason |
| 79 | * Added ReplaceTexture function |
| 80 | * |
| 81 | * 11 9/18/97 12:32p Samir |
| 82 | * If currently selected texture is not in the list, default to 0 texture. |
| 83 | * |
| 84 | * 10 9/17/97 1:01p Matt |
| 85 | * Ripped out segment code |
| 86 | * |
| 87 | * 9 9/17/97 12:06p Jason |
| 88 | * ripped out segment engine |
| 89 | * |
| 90 | * 8 9/16/97 6:08p Jason |
| 91 | * made texture names appear |
| 92 | * |
| 93 | * 7 9/15/97 1:18p Jason |
| 94 | * got selectable tmap2s working |
| 95 | * |
| 96 | * 6 9/12/97 3:47p Matt |
| 97 | * Fixed grab texture for room engine |
| 98 | * |
| 99 | * 5 8/29/97 1:52p Samir |
| 100 | * Added bitmap buttons for Texture Keypad. |
| 101 | * |
| 102 | * 4 8/25/97 7:39p Samir |
| 103 | * Using new GrListBox from old editorPictListBox |
| 104 | * |
| 105 | * 3 8/13/97 9:53a Matt |
| 106 | * Show selected texture with magenta box around it. |
| 107 | * Use new texture rotate & scale functions |
| 108 | * |
| 109 | * 15 6/03/97 4:55p Mark |
| 110 | * |
| 111 | * 15 6/3/97 4:14p Jeff |
| 112 | * Added Context Sensitive Help |
| 113 | * |
| 114 | * 14 5/28/97 6:15p Samir |
| 115 | * Fixups for missing textures in scrollbox. |
| 116 | * |
| 117 | * 13 5/27/97 5:29p Samir |
| 118 | * Took out mprintf. |
| 119 | * |
| 120 | * 12 5/27/97 3:11p Samir |
| 121 | * Allow 'masking' of textures to be displayed in listbox. |
| 122 | * |
| 123 | * 11 4/11/97 4:53p Samir |
| 124 | * Grab texture button works for tmap 1s |
| 125 | * |
| 126 | * 10 3/13/97 1:42p Matt |
| 127 | * Don't show texture 0 (the error texture) in the texture list |
| 128 | * |
| 129 | * 9 2/26/97 4:00p Samir |
| 130 | * Added most keypad functions. |
| 131 | * |
| 132 | * 8 2/21/97 6:25p Samir |
| 133 | * Set properly the max items for the listbox. |
| 134 | * |
| 135 | * 7 2/21/97 5:09p Samir |
| 136 | * Uses new PictListBox class for texture listbox here. |
| 137 | * |
| 138 | * 6 2/20/97 6:05p Samir |
| 139 | * Allow for clean activation and deactivation of surfaces in editor when |
| 140 | * going into fullscreen mode. |
| 141 | * |
| 142 | * 5 2/19/97 7:29p Samir |
| 143 | * Got scrolling texture view to work. |
| 144 | * |
| 145 | * 4 1/27/97 11:38a Samir |
| 146 | * Added horizontal scrolling of keypad modeless dialog. |
| 147 | * |
| 148 | * $NoKeywords: $ |
| 149 | */ |
| 150 | |
| 151 | #include <algorithm> |
| 152 | |
| 153 | #include "stdafx.h" |
| 154 | #include "editor.h" |
| 155 | #include "TextureDialog.h" |
| 156 | |
| 157 | #include "HTexture.h" |
| 158 | #include "gametexture.h" |
| 159 | #include "gr.h" |
| 160 | #include "descent.h" |
| 161 | #include "erooms.h" |
| 162 | #include "room.h" |
| 163 | #include "terrain.h" |
| 164 | |
| 165 | #ifdef _DEBUG |
| 166 | #define new DEBUG_NEW |
| 167 | #undef THIS_FILE |
| 168 | static char THIS_FILE[] = __FILE__; |
| 169 | #endif |
| 170 | |
| 171 | ///////////////////////////////////////////////////////////////////////////// |
| 172 | // CTextureDialog dialog |
| 173 | |
| 174 | // Initialization and Destruction of the Dialog. |
| 175 | |
| 176 | CTextureDialog::CTextureDialog(CWnd *pParent /*=NULL*/) : CKeypadDialog(CTextureDialog::IDD, pParent) { |
| 177 | //{{AFX_DATA_INIT(CTextureDialog) |
| 178 | // NOTE: the ClassWizard will add member initialization here |
| 179 | //}}AFX_DATA_INIT |
| 180 | } |
| 181 | |
| 182 | void CTextureDialog::DoDataExchange(CDataExchange *pDX) { |
| 183 | CDialog::DoDataExchange(pDX); |
| 184 | //{{AFX_DATA_MAP(CTextureDialog) |
| 185 | // NOTE: the ClassWizard will add DDX and DDV calls here |
| 186 | //}}AFX_DATA_MAP |
| 187 | } |
| 188 | |
| 189 | void CTextureDialog::RunKeypadFunction(int code) { |
| 190 | switch (code) { |
| 191 | case VK_NUMPAD0: |
| 192 | OnTexpadRotate90(); |
| 193 | break; |
| 194 | case VK_NUMPAD1: |
| 195 | OnTexpadRotLeft(); |
| 196 | break; |
| 197 | case VK_NUMPAD2: |
| 198 | OnTexpadSlideDown(); |
| 199 | break; |
| 200 | case VK_NUMPAD3: |
| 201 | OnTexpadRotRight(); |
| 202 | break; |
| 203 | case VK_NUMPAD4: |
| 204 | OnTexpadSlideLeft(); |
| 205 | break; |
| 206 | case VK_NUMPAD5: |
| 207 | OnTexpadSetDefault(); |
| 208 | break; |
| 209 | case VK_NUMPAD6: |
| 210 | OnTexpadSlideRight(); |
| 211 | break; |
| 212 | case VK_NUMPAD7: |
| 213 | OnTexpadStretchLess(); |
| 214 | break; |
| 215 | case VK_NUMPAD8: |
| 216 | OnTexpadSlideUp(); |
| 217 | break; |
| 218 | case VK_NUMPAD9: |
| 219 | OnTexpadStretchMore(); |
| 220 | break; |
| 221 | case VK_DELETE: |
| 222 | OnTexpadNextEdge(); |
| 223 | break; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | // selects a texture in the texture dialog |
| 228 | void CTextureDialog::SelectTexture(int texnum) { m_TexLB.SelectItem(texnum); } |
| 229 | |
| 230 | BEGIN_MESSAGE_MAP(CTextureDialog, CDialog) |
| 231 | //{{AFX_MSG_MAP(CTextureDialog) |
| 232 | ON_WM_KEYDOWN() |
| 233 | ON_WM_SIZE() |
| 234 | ON_WM_VSCROLL() |
| 235 | ON_WM_HSCROLL() |
| 236 | ON_WM_LBUTTONDOWN() |
| 237 | ON_WM_PAINT() |
| 238 | ON_BN_CLICKED(IDC_TEXPAD_FLIPX, OnTexpadFlipX) |
| 239 | ON_BN_CLICKED(IDC_TEXPAD_FLIPY, OnTexpadFlipY) |
| 240 | ON_BN_CLICKED(IDC_TEXPAD_SLIDELEFT, OnTexpadSlideLeft) |
| 241 | ON_BN_CLICKED(IDC_TEXPAD_SLIDERIGHT, OnTexpadSlideRight) |
| 242 | ON_BN_CLICKED(IDC_TEXPAD_ROTLEFT, OnTexpadRotLeft) |
| 243 | ON_BN_CLICKED(IDC_TEXPAD_ROTRIGHT, OnTexpadRotRight) |
| 244 | ON_BN_CLICKED(IDC_TEXPAD_ROTATE90, OnTexpadRotate90) |
| 245 | ON_BN_CLICKED(IDC_TEXPAD_STRETCHLESS, OnTexpadStretchLess) |
| 246 | ON_BN_CLICKED(IDC_TEXPAD_STRETCHMORE, OnTexpadStretchMore) |
| 247 | ON_BN_CLICKED(IDC_TEXPAD_SLIDEUP, OnTexpadSlideUp) |
| 248 | ON_BN_CLICKED(IDC_TEXPAD_SLIDEDOWN, OnTexpadSlideDown) |
| 249 | ON_BN_CLICKED(IDC_TEXPAD_SETDEFAULT, OnTexpadSetDefault) |
| 250 | ON_BN_CLICKED(IDC_TEXPAD_NEXTEDGE, OnTexpadNextEdge) |
| 251 | ON_BN_CLICKED(IDC_TEXPAD_GRAB, OnTexpadGrab) |
| 252 | ON_BN_CLICKED(IDC_SHOW_MINE_TEXTURES2, OnShowMineTextures2) |
| 253 | ON_BN_CLICKED(IDC_SHOW_OBJ_TEXTURES, OnShowObjTextures) |
| 254 | ON_BN_CLICKED(IDC_SHOW_LIGHT_TEXTURES, OnShowLightTextures) |
| 255 | ON_BN_CLICKED(IDC_SHOW_TERRAIN_TEXTURES, OnShowTerrainTextures) |
| 256 | ON_WM_HELPINFO() |
| 257 | ON_BN_CLICKED(IDC_RESET_ALL_TEXTURES, OnResetAllTextures) |
| 258 | ON_WM_DESTROY() |
| 259 | ON_BN_CLICKED(IDC_SHOW_TMAP2_TEXTURES, OnShowTmap2Textures) |
| 260 | ON_BN_CLICKED(IDC_REPLACE_TEXTURE, OnReplaceTexture) |
| 261 | ON_EN_KILLFOCUS(IDC_TEXSCALE_EDIT, OnKillfocusTexscaleEdit) |
| 262 | ON_BN_CLICKED(IDC_TEXPAD_EXPAND_U, OnTexpadExpandU) |
| 263 | ON_BN_CLICKED(IDC_TEXPAD_EXPAND_V, OnTexpadExpandV) |
| 264 | ON_BN_CLICKED(IDC_TEXPAD_CONTRACT_U, OnTexpadContractU) |
| 265 | ON_BN_CLICKED(IDC_TEXPAD_CONTRACT_V, OnTexpadContractV) |
| 266 | ON_BN_CLICKED(IDC_FACE_MAP, OnFaceMap) |
| 267 | ON_BN_CLICKED(IDC_CURRENT_USED, OnCurrentUsed) |
| 268 | ON_BN_CLICKED(IDC_FIND_TEXTURE, OnFindTexture) |
| 269 | //}}AFX_MSG_MAP |
| 270 | END_MESSAGE_MAP() |
| 271 | |
| 272 | ///////////////////////////////////////////////////////////////////////////// |
| 273 | // CTextureDialog message handlers |
| 274 | |
| 275 | static CDialog *ParentDialog = NULL; |
| 276 | static CTextureDialog *ParentTextureDialog = NULL; |
| 277 | uint8_t CurrentlyUsedTextures[MAX_TEXTURES]; |
| 278 | bool Show_used = 0; |
| 279 | |
| 280 | BOOL CTextureDialog::OnInitDialog() { |
| 281 | CDialog::OnInitDialog(); |
| 282 | |
| 283 | RECT rect; |
| 284 | CWnd *wnd; |
| 285 | CEdit *ebox; |
| 286 | char str[20]; |
| 287 | |
| 288 | memset(CurrentlyUsedTextures, 0, MAX_TEXTURES); |
| 289 | |
| 290 | ParentDialog = this; |
| 291 | ParentTextureDialog = this; |
| 292 | wnd = GetDlgItem(IDC_TEXTURE_LISTBOX); |
| 293 | wnd->GetClientRect(&rect); |
| 294 | |
| 295 | if (!GameTextures[D3EditState.texdlg_texture].used) |
| 296 | D3EditState.texdlg_texture = 0; |
| 297 | |
| 298 | m_TexLB.Create(wnd, IDC_TEXTURE_LISTBOX, rect, 36); |
| 299 | m_TexLB.SelectItem(D3EditState.texdlg_texture); |
| 300 | |
| 301 | if (D3EditState.texture_display_flags & TF_TERRAIN) |
| 302 | ((CButton *)GetDlgItem(IDC_SHOW_TERRAIN_TEXTURES))->SetCheck(1); |
| 303 | if (D3EditState.texture_display_flags & TF_MINE) |
| 304 | ((CButton *)GetDlgItem(IDC_SHOW_MINE_TEXTURES2))->SetCheck(1); |
| 305 | if (D3EditState.texture_display_flags & TF_OBJECT) |
| 306 | ((CButton *)GetDlgItem(IDC_SHOW_OBJ_TEXTURES))->SetCheck(1); |
| 307 | if (D3EditState.texture_display_flags & TF_TMAP2) |
| 308 | ((CButton *)GetDlgItem(IDC_SHOW_TMAP2_TEXTURES))->SetCheck(1); |
| 309 | if (D3EditState.texture_display_flags & TF_LIGHT) |
| 310 | ((CButton *)GetDlgItem(IDC_SHOW_LIGHT_TEXTURES))->SetCheck(1); |
| 311 | |
| 312 | // Do bitmap buttons |
| 313 | m_bmUp.LoadBitmap(IDB_NORTH); |
| 314 | m_bmDown.LoadBitmap(IDB_SOUTH); |
| 315 | m_bmLeft.LoadBitmap(IDB_WEST); |
| 316 | m_bmRight.LoadBitmap(IDB_EAST); |
| 317 | m_bmRotLeft.LoadBitmap(IDB_ROTATELEFT); |
| 318 | m_bmRotRight.LoadBitmap(IDB_ROTATERIGHT); |
| 319 | m_bmStretchLess.LoadBitmap(IDB_INARROW); |
| 320 | m_bmStretchMore.LoadBitmap(IDB_OUTARROW); |
| 321 | |
| 322 | // Set bitmap buttons |
| 323 | CButton *btn; |
| 324 | btn = (CButton *)GetDlgItem(IDC_TEXPAD_SLIDEUP); |
| 325 | btn->SetBitmap((HBITMAP)m_bmUp); |
| 326 | btn = (CButton *)GetDlgItem(IDC_TEXPAD_SLIDEDOWN); |
| 327 | btn->SetBitmap((HBITMAP)m_bmDown); |
| 328 | btn = (CButton *)GetDlgItem(IDC_TEXPAD_SLIDELEFT); |
| 329 | btn->SetBitmap((HBITMAP)m_bmLeft); |
| 330 | btn = (CButton *)GetDlgItem(IDC_TEXPAD_SLIDERIGHT); |
| 331 | btn->SetBitmap((HBITMAP)m_bmRight); |
| 332 | btn = (CButton *)GetDlgItem(IDC_TEXPAD_ROTLEFT); |
| 333 | btn->SetBitmap((HBITMAP)m_bmRotLeft); |
| 334 | btn = (CButton *)GetDlgItem(IDC_TEXPAD_ROTRIGHT); |
| 335 | btn->SetBitmap((HBITMAP)m_bmRotRight); |
| 336 | btn = (CButton *)GetDlgItem(IDC_TEXPAD_STRETCHLESS); |
| 337 | btn->SetBitmap((HBITMAP)m_bmStretchLess); |
| 338 | btn = (CButton *)GetDlgItem(IDC_TEXPAD_STRETCHMORE); |
| 339 | btn->SetBitmap((HBITMAP)m_bmStretchMore); |
| 340 | |
| 341 | ebox = (CEdit *)GetDlgItem(IDC_TEXSCALE_EDIT); |
| 342 | sprintf(str, "%f", D3EditState.texscale); |
| 343 | ebox->SetWindowText(str); |
| 344 | |
| 345 | return TRUE; // return TRUE unless you set the focus to a control |
| 346 | // EXCEPTION: OCX Property Pages should return FALSE |
| 347 | } |
| 348 | |
| 349 | void CTextureDialog::OnDestroy() { |
| 350 | CDialog::OnDestroy(); |
| 351 | |
| 352 | // kill all bitmaps |
| 353 | m_bmUp.DeleteObject(); |
| 354 | m_bmDown.DeleteObject(); |
| 355 | m_bmLeft.DeleteObject(); |
| 356 | m_bmRight.DeleteObject(); |
| 357 | m_bmRotLeft.DeleteObject(); |
| 358 | m_bmRotRight.DeleteObject(); |
| 359 | m_bmStretchLess.DeleteObject(); |
| 360 | m_bmStretchMore.DeleteObject(); |
| 361 | } |
| 362 | |
| 363 | void CTextureDialog::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { |
| 364 | // TODO: Add your message handler code here and/or call default |
| 365 | |
| 366 | CDialog::OnKeyDown(nChar, nRepCnt, nFlags); |
| 367 | } |
| 368 | |
| 369 | void CTextureDialog::OnSize(UINT nType, int cx, int cy) { CKeypadDialog::OnSize(nType, cx, cy); } |
| 370 | |
| 371 | void CTextureDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { |
| 372 | CKeypadDialog::OnVScroll(nSBCode, nPos, pScrollBar); |
| 373 | } |
| 374 | |
| 375 | void CTextureDialog::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { |
| 376 | // TODO: Add your message handler code here and/or call default |
| 377 | |
| 378 | CKeypadDialog::OnHScroll(nSBCode, nPos, pScrollBar); |
| 379 | } |
| 380 | |
| 381 | void CTextureDialog::OnLButtonDown(UINT nFlags, CPoint point) { CDialog::OnLButtonDown(nFlags, point); } |
| 382 | |
| 383 | void CTextureDialog::OnPaint() { |
| 384 | CPaintDC dc(this); // device context for painting |
| 385 | |
| 386 | if (!m_Active) |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | // Keypad Functions!! |
| 391 | |
| 392 | void CTextureDialog::OnTexpadFlipX() { HTextureFlipX(); } |
| 393 | |
| 394 | void CTextureDialog::OnTexpadFlipY() { HTextureFlipY(); } |
| 395 | |
| 396 | void CTextureDialog::OnTexpadSlideLeft() { HTextureSlide(Curroomp, Curface, (float)-1.0 * D3EditState.texscale, 0.0f); } |
| 397 | |
| 398 | void CTextureDialog::OnTexpadSlideRight() { HTextureSlide(Curroomp, Curface, (float)1.0 * D3EditState.texscale, 0.0f); } |
| 399 | |
| 400 | void CTextureDialog::OnTexpadSlideUp() { HTextureSlide(Curroomp, Curface, 0.0f, (float)1.0 * D3EditState.texscale); } |
| 401 | |
| 402 | void CTextureDialog::OnTexpadSlideDown() { HTextureSlide(Curroomp, Curface, 0.0f, (float)-1.0 * D3EditState.texscale); } |
| 403 | |
| 404 | void CTextureDialog::OnTexpadRotLeft() { HTextureRotate(Curroomp, Curface, (-512 * D3EditState.texscale)); } |
| 405 | |
| 406 | void CTextureDialog::OnTexpadRotRight() { HTextureRotate(Curroomp, Curface, (512 * D3EditState.texscale)); } |
| 407 | |
| 408 | void CTextureDialog::OnTexpadRotate90() { HTextureRotate(Curroomp, Curface, 0x4000); } |
| 409 | |
| 410 | void CTextureDialog::OnTexpadStretchLess() { HTextureStretchLess(Curroomp, Curface, Curedge); } |
| 411 | |
| 412 | void CTextureDialog::OnTexpadStretchMore() { HTextureStretchMore(Curroomp, Curface, Curedge); } |
| 413 | |
| 414 | void CTextureDialog::OnTexpadSetDefault() { HTextureSetDefault(Curroomp); } |
| 415 | |
| 416 | void CTextureDialog::OnTexpadNextEdge() { HTextureNextEdge(); } |
| 417 | |
| 418 | void CTextureDialog::OnTexpadGrab() { |
| 419 | int texnum = -1; |
| 420 | |
| 421 | if (Editor_view_mode == VM_TERRAIN) { |
| 422 | for (int i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 423 | if (TerrainSelected[i]) { |
| 424 | if (texnum != -1) { |
| 425 | OutrageMessageBox("Cannot grab texture: More than one terrain cell selected."); |
| 426 | return; |
| 427 | } |
| 428 | texnum = Terrain_tex_seg[Terrain_seg[i].texseg_index].tex_index; |
| 429 | } |
| 430 | } |
| 431 | if (texnum == -1) { |
| 432 | OutrageMessageBox("Cannot grab texture: No terrain cell selected."); |
| 433 | return; |
| 434 | } |
| 435 | } else { |
| 436 | if (!Curroomp || Curroomp->used == 0 || Curface >= Curroomp->num_faces) |
| 437 | return; |
| 438 | |
| 439 | texnum = Curroomp->faces[Curface].tmap; |
| 440 | } |
| 441 | |
| 442 | CTextureDialog::SelectTexture(texnum); |
| 443 | EditorStatus("Texture %d, \"%s\", selected.", texnum, GameTextures[texnum].name); |
| 444 | } |
| 445 | |
| 446 | void CTextureDialog::OnShowMineTextures2() { |
| 447 | D3EditState.texture_display_flags ^= TF_MINE; |
| 448 | Invalidate(); |
| 449 | } |
| 450 | |
| 451 | void CTextureDialog::OnShowObjTextures() { |
| 452 | D3EditState.texture_display_flags ^= TF_OBJECT; |
| 453 | Invalidate(); |
| 454 | } |
| 455 | |
| 456 | void CTextureDialog::OnShowLightTextures() { |
| 457 | D3EditState.texture_display_flags ^= TF_LIGHT; |
| 458 | Invalidate(); |
| 459 | } |
| 460 | |
| 461 | void CTextureDialog::OnShowTerrainTextures() { |
| 462 | D3EditState.texture_display_flags ^= TF_TERRAIN; |
| 463 | Invalidate(); |
| 464 | } |
| 465 | |
| 466 | BOOL CTextureDialog::OnHelpInfo(HELPINFO *pHelpInfo) { |
| 467 | // TODO: Add your message handler code here and/or call default |
| 468 | WinHelp(HID_TEXTURETAB, HELP_CONTEXT); |
| 469 | return TRUE; |
| 470 | // return CDialog::OnHelpInfo(pHelpInfo); |
| 471 | } |
| 472 | |
| 473 | extern void AssignDefaultUVsToRoom(room *rp); |
| 474 | void CTextureDialog::OnResetAllTextures() { |
| 475 | int answer = OutrageMessageBox( |
| 476 | MBOX_YESNO, "Are you sure you wish to reset all textures for this room? This change cannot be undone!"); |
| 477 | if (answer != IDYES) |
| 478 | return; |
| 479 | |
| 480 | AssignDefaultUVsToRoom(Curroomp); |
| 481 | |
| 482 | World_changed = 1; |
| 483 | } |
| 484 | |
| 485 | ///////////////////////////////////////////////////////////////////// |
| 486 | // CGrTextureListBox implementation |
| 487 | |
| 488 | // enumerates items maximum in the list box. this is here to insure that any changes in |
| 489 | // the user-managed list. |
| 490 | int CGrTextureListBox::ListEnumerate() { |
| 491 | int count = 0, i; |
| 492 | |
| 493 | for (i = 0; i < MAX_TEXTURES; i++) { |
| 494 | bool countit = true; |
| 495 | ; |
| 496 | if (!GameTextures[i].used) |
| 497 | countit = false; |
| 498 | if (!(GameTextures[i].flags & D3EditState.texture_display_flags)) |
| 499 | countit = false; |
| 500 | if (Show_used && !CurrentlyUsedTextures[i]) |
| 501 | countit = false; |
| 502 | |
| 503 | if (countit) |
| 504 | count++; |
| 505 | } |
| 506 | |
| 507 | return count; |
| 508 | } |
| 509 | |
| 510 | // Specify the first item to be drawn in the box by DrawItem. returns the item # |
| 511 | // return -1 if there is no first item (list is empty, maybe) |
| 512 | int CGrTextureListBox::ListFirstItem(int firsttex) { |
| 513 | // skip the error texture |
| 514 | if (firsttex < 0) |
| 515 | firsttex = 0; |
| 516 | if (firsttex == 0) |
| 517 | firsttex++; |
| 518 | |
| 519 | // find first texture that is used if the texture passed became invalid. |
| 520 | if (!GameTextures[firsttex].used || !(GameTextures[firsttex].flags & D3EditState.texture_display_flags) || |
| 521 | (Show_used && !CurrentlyUsedTextures[firsttex])) { |
| 522 | int new_first = ListNextItem(firsttex); |
| 523 | if (new_first == firsttex) |
| 524 | return -1; |
| 525 | else |
| 526 | return new_first; |
| 527 | } else |
| 528 | return firsttex; |
| 529 | } |
| 530 | |
| 531 | // Specify the next/prev item to be drawn in the box by DrawItem. |
| 532 | // Returns the item # following or preceding the passed the item # |
| 533 | int CGrTextureListBox::ListNextItem(int curtex) { |
| 534 | int next_texture = -1; |
| 535 | |
| 536 | if (curtex >= 0) |
| 537 | next_texture = GetNextTexture(curtex); |
| 538 | if (next_texture <= curtex) |
| 539 | return curtex; |
| 540 | |
| 541 | while ((Show_used && !CurrentlyUsedTextures[next_texture]) || |
| 542 | !(GameTextures[next_texture].flags & D3EditState.texture_display_flags)) { |
| 543 | next_texture = GetNextTexture(next_texture); |
| 544 | // mprintf(0, "next_tex = %d\n", next_texture); |
| 545 | if (next_texture == curtex) { |
| 546 | break; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | return next_texture; |
| 551 | } |
| 552 | |
| 553 | int CGrTextureListBox::ListPrevItem(int curtex) { |
| 554 | int prev_texture = -1; |
| 555 | |
| 556 | if (curtex >= 0) |
| 557 | prev_texture = GetPreviousTexture(curtex); |
| 558 | if (prev_texture >= curtex) |
| 559 | return curtex; |
| 560 | |
| 561 | while ((Show_used && !CurrentlyUsedTextures[prev_texture]) || |
| 562 | !(GameTextures[prev_texture].flags & D3EditState.texture_display_flags)) { |
| 563 | prev_texture = GetPreviousTexture(prev_texture); |
| 564 | // mprintf(0, "prev_tex = %d\n", prev_texture); |
| 565 | if (prev_texture == curtex) { |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | return prev_texture; |
| 571 | } |
| 572 | |
| 573 | // draw the item |
| 574 | void CGrTextureListBox::DrawItem(int x, int y, grHardwareSurface *itemsurf, int item) { |
| 575 | int bm_handle; |
| 576 | |
| 577 | bm_handle = GetTextureBitmap(item, 0); |
| 578 | |
| 579 | itemsurf->load(bm_handle); |
| 580 | Desktop_surf->blt(x, y, itemsurf); |
| 581 | } |
| 582 | |
| 583 | // if item was selected from the list box, this function is invoked. |
| 584 | void CGrTextureListBox::OnItemSelected(int tex) { |
| 585 | D3EditState.texdlg_texture = tex; |
| 586 | |
| 587 | if (ParentDialog != NULL) { |
| 588 | PrintToDlgItem(ParentDialog, IDC_CURRENT_TEXTURE_NAME, "Texture: %s", GameTextures[tex].name); |
| 589 | ParentTextureDialog->DrawSwatch(IDC_TEXTURE_SWATCH, GameTextures[tex].r, GameTextures[tex].g, GameTextures[tex].b); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | void CTextureDialog::OnShowTmap2Textures() { |
| 594 | // TODO: Add your control notification handler code here |
| 595 | D3EditState.texture_display_flags ^= TF_TMAP2; |
| 596 | Invalidate(); |
| 597 | } |
| 598 | |
| 599 | // Returns the number of changes |
| 600 | int ReplaceTextureInRoom(room *rp, int old_tmap, int new_tmap) { |
| 601 | int n_changes = 0; |
| 602 | |
| 603 | for (int i = 0; i < rp->num_faces; i++) { |
| 604 | |
| 605 | if (rp->faces[i].tmap == old_tmap) { |
| 606 | |
| 607 | rp->faces[i].tmap = new_tmap; |
| 608 | n_changes++; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | return n_changes; |
| 613 | } |
| 614 | |
| 615 | void CTextureDialog::OnReplaceTexture() { |
| 616 | ASSERT(Curroomp != NULL); |
| 617 | int n_changes; |
| 618 | |
| 619 | int answer = OutrageMessageBox( |
| 620 | MBOX_YESNOCANCEL, |
| 621 | "Do you wish to change this texture for the whole mine?\n\n(Answer NO to change only the current room.)"); |
| 622 | |
| 623 | if (answer == IDCANCEL) |
| 624 | return; |
| 625 | |
| 626 | int selected_texture = Curroomp->faces[Curface].tmap; |
| 627 | |
| 628 | if (answer == IDYES) { |
| 629 | |
| 630 | n_changes = 0; |
| 631 | |
| 632 | for (int r = 0; r <= Highest_room_index; r++) |
| 633 | if (Rooms[r].used) |
| 634 | n_changes += ReplaceTextureInRoom(&Rooms[r], selected_texture, D3EditState.texdlg_texture); |
| 635 | } else { |
| 636 | |
| 637 | n_changes = ReplaceTextureInRoom(Curroomp, selected_texture, D3EditState.texdlg_texture); |
| 638 | } |
| 639 | |
| 640 | EditorStatus("Texture %d replaced with texture %d on %d faces.", selected_texture, D3EditState.texdlg_texture, |
| 641 | n_changes); |
| 642 | |
| 643 | World_changed = 1; |
| 644 | } |
| 645 | |
| 646 | void CTextureDialog::DrawSwatch(int handle, float r, float g, float b) { |
| 647 | CWnd *texwnd; |
| 648 | RECT rect; |
| 649 | int w, h; |
| 650 | float rmax = std::max(r, g); |
| 651 | rmax = std::max(rmax, b); |
| 652 | |
| 653 | if (rmax >= .001) { |
| 654 | r /= rmax; |
| 655 | g /= rmax; |
| 656 | b /= rmax; |
| 657 | } |
| 658 | |
| 659 | texwnd = GetDlgItem(handle); |
| 660 | texwnd->GetWindowRect(&rect); |
| 661 | ScreenToClient(&rect); |
| 662 | |
| 663 | Desktop_surf->attach_to_window((unsigned)m_hWnd); |
| 664 | |
| 665 | w = rect.right - rect.left; |
| 666 | h = rect.bottom - rect.top; |
| 667 | |
| 668 | ddgr_color color = GR_RGB(r * 255, g * 255, b * 255); |
| 669 | |
| 670 | Desktop_surf->clear(rect.left, rect.top, w, h, color); |
| 671 | |
| 672 | Desktop_surf->attach_to_window(NULL); |
| 673 | } |
| 674 | |
| 675 | void CTextureDialog::OnKillfocusTexscaleEdit() { |
| 676 | CEdit *ebox; |
| 677 | char str[20]; |
| 678 | float val; |
| 679 | |
| 680 | ebox = (CEdit *)GetDlgItem(IDC_TEXSCALE_EDIT); |
| 681 | ebox->GetWindowText(str, 20); |
| 682 | |
| 683 | val = atof(str); |
| 684 | if (val < 0) |
| 685 | val = 0; |
| 686 | if (val > 64) |
| 687 | val = 64; |
| 688 | |
| 689 | D3EditState.texscale = val; |
| 690 | |
| 691 | ebox = (CEdit *)GetDlgItem(IDC_TEXSCALE_EDIT); |
| 692 | sprintf(str, "%f", D3EditState.texscale); |
| 693 | ebox->SetWindowText(str); |
| 694 | } |
| 695 | |
| 696 | void CTextureDialog::OnTexpadExpandU() { |
| 697 | if (Curroomp == NULL) |
| 698 | return; |
| 699 | |
| 700 | face *fp = &Curroomp->faces[Curface]; |
| 701 | |
| 702 | int i; |
| 703 | float mid = 0; |
| 704 | |
| 705 | for (i = 0; i < fp->num_verts; i++) |
| 706 | mid += fp->face_uvls[i].u; |
| 707 | |
| 708 | mid /= fp->num_verts; |
| 709 | |
| 710 | for (i = 0; i < fp->num_verts; i++) { |
| 711 | float diff = fp->face_uvls[i].u - mid; |
| 712 | |
| 713 | diff *= 1.0 / D3EditState.texscale; |
| 714 | |
| 715 | fp->face_uvls[i].u = mid + diff; |
| 716 | } |
| 717 | |
| 718 | World_changed = 1; |
| 719 | } |
| 720 | |
| 721 | void CTextureDialog::OnTexpadExpandV() { |
| 722 | if (Curroomp == NULL) |
| 723 | return; |
| 724 | |
| 725 | face *fp = &Curroomp->faces[Curface]; |
| 726 | |
| 727 | int i; |
| 728 | float mid = 0; |
| 729 | |
| 730 | for (i = 0; i < fp->num_verts; i++) |
| 731 | mid += fp->face_uvls[i].v; |
| 732 | |
| 733 | mid /= fp->num_verts; |
| 734 | |
| 735 | for (i = 0; i < fp->num_verts; i++) { |
| 736 | float diff = fp->face_uvls[i].v - mid; |
| 737 | |
| 738 | diff *= 1.0 / D3EditState.texscale; |
| 739 | |
| 740 | fp->face_uvls[i].v = mid + diff; |
| 741 | } |
| 742 | |
| 743 | World_changed = 1; |
| 744 | } |
| 745 | |
| 746 | void CTextureDialog::OnTexpadContractU() { |
| 747 | if (Curroomp == NULL) |
| 748 | return; |
| 749 | |
| 750 | face *fp = &Curroomp->faces[Curface]; |
| 751 | |
| 752 | int i; |
| 753 | float mid = 0; |
| 754 | |
| 755 | for (i = 0; i < fp->num_verts; i++) |
| 756 | mid += fp->face_uvls[i].u; |
| 757 | |
| 758 | mid /= fp->num_verts; |
| 759 | |
| 760 | for (i = 0; i < fp->num_verts; i++) { |
| 761 | float diff = fp->face_uvls[i].u - mid; |
| 762 | |
| 763 | diff *= D3EditState.texscale; |
| 764 | |
| 765 | fp->face_uvls[i].u = mid + diff; |
| 766 | } |
| 767 | |
| 768 | World_changed = 1; |
| 769 | } |
| 770 | |
| 771 | void CTextureDialog::OnTexpadContractV() { |
| 772 | if (Curroomp == NULL) |
| 773 | return; |
| 774 | |
| 775 | face *fp = &Curroomp->faces[Curface]; |
| 776 | |
| 777 | int i; |
| 778 | float mid = 0; |
| 779 | |
| 780 | for (i = 0; i < fp->num_verts; i++) |
| 781 | mid += fp->face_uvls[i].v; |
| 782 | |
| 783 | mid /= fp->num_verts; |
| 784 | |
| 785 | for (i = 0; i < fp->num_verts; i++) { |
| 786 | float diff = fp->face_uvls[i].v - mid; |
| 787 | |
| 788 | diff *= D3EditState.texscale; |
| 789 | |
| 790 | fp->face_uvls[i].v = mid + diff; |
| 791 | } |
| 792 | |
| 793 | World_changed = 1; |
| 794 | } |
| 795 | |
| 796 | void CTextureDialog::OnFaceMap() { |
| 797 | if (Curroomp == NULL) |
| 798 | return; |
| 799 | |
| 800 | face *fp = &Curroomp->faces[Curface]; |
| 801 | |
| 802 | if (fp->num_verts != 4) { |
| 803 | OutrageMessageBox("Face must have four vertices to use face mapping."); |
| 804 | return; |
| 805 | } |
| 806 | |
| 807 | // Simply square off this face |
| 808 | |
| 809 | fp->face_uvls[0].u = 0.0; |
| 810 | fp->face_uvls[0].v = 0.0; |
| 811 | |
| 812 | fp->face_uvls[1].u = 1.0; |
| 813 | fp->face_uvls[1].v = 0.0; |
| 814 | |
| 815 | fp->face_uvls[2].u = 1.0; |
| 816 | fp->face_uvls[2].v = 1.0; |
| 817 | |
| 818 | fp->face_uvls[3].u = 0.0; |
| 819 | fp->face_uvls[3].v = 1.0; |
| 820 | |
| 821 | World_changed = 1; |
| 822 | } |
| 823 | |
| 824 | void CTextureDialog::OnCurrentUsed() { |
| 825 | // TODO: Add your control notification handler code here |
| 826 | int c = IsDlgButtonChecked(IDC_CURRENT_USED); |
| 827 | |
| 828 | // If we just turned this on, build a list of textures used |
| 829 | if (c) { |
| 830 | Show_used = 1; |
| 831 | memset(CurrentlyUsedTextures, 0, MAX_TEXTURES); |
| 832 | for (int i = 0; i <= Highest_room_index; i++) { |
| 833 | room *rp = &Rooms[i]; |
| 834 | if (!rp->used) |
| 835 | continue; |
| 836 | for (int t = 0; t < rp->num_faces; t++) { |
| 837 | CurrentlyUsedTextures[rp->faces[t].tmap] = 1; |
| 838 | } |
| 839 | } |
| 840 | } else |
| 841 | Show_used = 0; |
| 842 | |
| 843 | Invalidate(); |
| 844 | } |
| 845 | |
| 846 | void CTextureDialog::OnFindTexture() { |
| 847 | int i, t; |
| 848 | |
| 849 | mprintf(0, "Searching...please wait...\n"); |
| 850 | int found = 0, found_room, found_face; |
| 851 | |
| 852 | for (i = 0; i <= Highest_room_index && !found; i++) { |
| 853 | room *rp = &Rooms[i]; |
| 854 | if (rp->used == 0) |
| 855 | continue; |
| 856 | |
| 857 | for (t = 0; t < rp->num_faces && !found; t++) { |
| 858 | if (rp->faces[t].tmap == D3EditState.texdlg_texture) { |
| 859 | if (rp != Curroomp || t != Curface) { |
| 860 | found_room = i; |
| 861 | found_face = t; |
| 862 | found = 1; |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | mprintf(0, "Done searching!\n"); |
| 869 | |
| 870 | if (found == 0) { |
| 871 | mprintf(0, "Couldn't find another face with that texture!\n"); |
| 872 | } else { |
| 873 | Curroomp = &Rooms[found_room]; |
| 874 | Curface = found_face; |
| 875 | mprintf(0, "Found that texture in room %d face %d.\n", found_room, found_face); |
| 876 | mprintf(0, "Press C to center on that face\n"); |
| 877 | } |
| 878 | } |