00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "stdafx.h"
00023 #include "qe3.h"
00024 #include "entityw.h"
00025 #include "TexWnd.h"
00026 #include "WaveOpen.h"
00027
00028 int rgIds[EntLast] = {
00029 IDC_E_LIST,
00030 IDC_E_COMMENT,
00031 IDC_CHECK1,
00032 IDC_CHECK2,
00033 IDC_CHECK3,
00034 IDC_CHECK4,
00035 IDC_CHECK5,
00036 IDC_CHECK6,
00037 IDC_CHECK7,
00038 IDC_CHECK8,
00039 IDC_CHECK9,
00040 IDC_CHECK10,
00041 IDC_CHECK11,
00042 IDC_CHECK12,
00043 IDC_E_PROPS,
00044 IDC_E_0,
00045 IDC_E_45,
00046 IDC_E_90,
00047 IDC_E_135,
00048 IDC_E_180,
00049 IDC_E_225,
00050 IDC_E_270,
00051 IDC_E_315,
00052 IDC_E_UP,
00053 IDC_E_DOWN,
00054 IDC_E_DELPROP,
00055
00056 IDC_STATIC_KEY,
00057 IDC_E_KEY_FIELD,
00058 IDC_STATIC_VALUE,
00059 IDC_E_VALUE_FIELD,
00060
00061 IDC_E_COLOR,
00062
00063 IDC_BTN_ASSIGNSOUND,
00064 IDC_BTN_ASSIGNMODEL
00065
00066 };
00067
00068 HWND hwndEnt[EntLast];
00069 CTabCtrl g_wndTabs;
00070
00071 int inspector_mode;
00072
00073 qboolean multiple_entities;
00074
00075 entity_t *edit_entity;
00076
00077
00078 BOOL CALLBACK EntityWndProc(
00079 HWND hwndDlg,
00080 UINT uMsg,
00081 WPARAM wParam,
00082 LPARAM lParam);
00083
00084 void SizeEntityDlg(int iWidth, int iHeight);
00085 void AddProp();
00086 void GetTexMods(void);
00087
00088
00089 LRESULT (CALLBACK* OldFieldWindowProc) (HWND, UINT, WPARAM, LPARAM);
00090 LRESULT (CALLBACK* OldEntityListWindowProc) (HWND, UINT, WPARAM, LPARAM);
00091
00092
00093
00094
00095
00096
00097
00098
00099 BOOL CALLBACK FieldWndProc(
00100 HWND hwnd,
00101 UINT uMsg,
00102 WPARAM wParam,
00103 LPARAM lParam)
00104 {
00105 switch (uMsg)
00106 {
00107 case WM_CHAR:
00108 if (LOWORD(wParam) == VK_TAB)
00109 return FALSE;
00110 if (LOWORD(wParam) == VK_RETURN)
00111 return FALSE;
00112 if (LOWORD(wParam) == VK_ESCAPE)
00113 {
00114 SetFocus (g_qeglobals.d_hwndCamera);
00115 return FALSE;
00116 }
00117 break;
00118
00119 case WM_KEYDOWN:
00120 if (LOWORD(wParam) == VK_TAB)
00121 {
00122 if (hwnd == hwndEnt[EntKeyField])
00123 {
00124 SendMessage (hwndEnt[EntValueField], WM_SETTEXT, 0, (long)"");
00125 SetFocus (hwndEnt[EntValueField]);
00126 }
00127 else
00128 SetFocus (hwndEnt[EntKeyField]);
00129 }
00130 if (LOWORD(wParam) == VK_RETURN)
00131 {
00132 if (hwnd == hwndEnt[EntKeyField])
00133 {
00134 SendMessage (hwndEnt[EntValueField], WM_SETTEXT, 0, (long)"");
00135 SetFocus (hwndEnt[EntValueField]);
00136 }
00137 else
00138 {
00139 AddProp ();
00140 SetFocus (g_qeglobals.d_hwndCamera);
00141 }
00142 }
00143 break;
00144
00145 case WM_LBUTTONDOWN:
00146 SetFocus (hwnd);
00147 break;
00148 }
00149 return CallWindowProc (OldFieldWindowProc, hwnd, uMsg, wParam, lParam);
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 BOOL CALLBACK EntityListWndProc(
00161 HWND hwnd,
00162 UINT uMsg,
00163 WPARAM wParam,
00164 LPARAM lParam)
00165 {
00166 switch (uMsg)
00167 {
00168 case WM_KEYDOWN:
00169 if (LOWORD(wParam) == VK_RETURN)
00170 {
00171 SendMessage ( g_qeglobals.d_hwndEntity,
00172 WM_COMMAND,
00173 (LBN_DBLCLK<<16) + IDC_E_LIST,
00174 0 );
00175 return 0;
00176 }
00177 break;
00178 }
00179 return CallWindowProc (OldEntityListWindowProc, hwnd, uMsg, wParam, lParam);
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 void GetEntityControls(HWND ghwndEntity)
00192 {
00193 int i;
00194
00195 for (i = 0; i < EntLast; i++)
00196 {
00197 if (i == EntList || i == EntProps || i == EntComment)
00198 continue;
00199 if (i == EntKeyField || i == EntValueField)
00200 continue;
00201 hwndEnt[i] = GetDlgItem(ghwndEntity, rgIds[i]);
00202 if (hwndEnt[i])
00203 {
00204 SetParent (hwndEnt[i], g_qeglobals.d_hwndEntity );
00205 SendMessage(hwndEnt[i], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00206 }
00207 }
00208
00209
00210
00211
00212
00213 hwndEnt[EntList] = CreateWindow ("listbox", NULL,
00214 LBS_STANDARD | LBS_NOINTEGRALHEIGHT | LBS_WANTKEYBOARDINPUT
00215 | WS_VSCROLL | WS_CHILD | WS_VISIBLE,
00216 5, 5, 180, 99,
00217 g_qeglobals.d_hwndEntity,
00218 (HMENU)IDC_E_LIST,
00219 g_qeglobals.d_hInstance,
00220 NULL);
00221 if (!hwndEnt[EntList])
00222 Error ("CreateWindow failed");
00223
00224 hwndEnt[EntProps] = CreateWindow ("listbox", NULL,
00225 LBS_STANDARD | LBS_NOINTEGRALHEIGHT | LBS_USETABSTOPS
00226 | WS_VSCROLL | WS_CHILD | WS_VISIBLE,
00227 5, 100, 180, 99,
00228 g_qeglobals.d_hwndEntity,
00229 (HMENU)IDC_E_PROPS,
00230 g_qeglobals.d_hInstance,
00231 NULL);
00232 if (!hwndEnt[EntProps])
00233 Error ("CreateWindow failed");
00234
00235 hwndEnt[EntComment] = CreateWindow ("edit", NULL,
00236 ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER,
00237 5, 100, 180, 99,
00238 g_qeglobals.d_hwndEntity,
00239 (HMENU)IDC_E_COMMENT,
00240 g_qeglobals.d_hInstance,
00241 NULL);
00242 if (!hwndEnt[EntComment])
00243 Error ("CreateWindow failed");
00244
00245 hwndEnt[EntKeyField] = CreateWindow ("edit", NULL,
00246 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
00247 5, 100, 180, 99,
00248 g_qeglobals.d_hwndEntity,
00249 (HMENU)IDC_E_KEY_FIELD,
00250 g_qeglobals.d_hInstance,
00251 NULL);
00252 if (!hwndEnt[EntKeyField])
00253 Error ("CreateWindow failed");
00254
00255 hwndEnt[EntValueField] = CreateWindow ("edit", NULL,
00256 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
00257 5, 100, 180, 99,
00258 g_qeglobals.d_hwndEntity,
00259 (HMENU)IDC_E_VALUE_FIELD,
00260 g_qeglobals.d_hInstance,
00261 NULL);
00262 if (!hwndEnt[EntValueField])
00263 Error ("CreateWindow failed");
00264
00265 g_wndTabs.SubclassDlgItem(IDC_TAB_MODE, CWnd::FromHandle(ghwndEntity));
00266 hwndEnt[EntTab] = g_wndTabs.GetSafeHwnd();
00267 g_wndTabs.InsertItem(0, "Groups");
00268 ::SetParent(g_wndTabs.GetSafeHwnd(), g_qeglobals.d_hwndEntity);
00269
00270 if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
00271 {
00272 g_qeglobals.d_hwndEdit = CreateWindow ("edit", NULL, ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER,
00273 5, 100, 180, 99, g_qeglobals.d_hwndEntity, (HMENU)IDC_E_STATUS,
00274 g_qeglobals.d_hInstance, NULL);
00275 if (!g_qeglobals.d_hwndEdit)
00276 Error ("CreateWindow failed");
00277 g_wndTabs.InsertItem(0, "Console");
00278 g_wndTabs.InsertItem(0, "Textures");
00279 }
00280 g_wndTabs.InsertItem(0, "Entities");
00281 g_wndTabs.ShowWindow(SW_SHOW);
00282
00283 #if 0
00284 for (i=0 ; i<12 ; i++)
00285 {
00286 hwndEnt[EntCheck1 + i] = CreateWindow ("button", NULL,
00287 BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE,
00288 5, 100, 180, 99,
00289 entwindow,
00290 (HMENU)IDC_E_STATUS,
00291 main_instance,
00292 NULL);
00293 if (!hwndEnt[EntCheck1 + i])
00294 Error ("CreateWindow failed");
00295 }
00296 #endif
00297 SendMessage(hwndEnt[EntList], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00298 SendMessage(hwndEnt[EntProps], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00299 SendMessage(hwndEnt[EntComment], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00300 SendMessage(hwndEnt[EntKeyField], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00301 SendMessage(hwndEnt[EntValueField], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00302 SendMessage(hwndEnt[EntTab], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00303
00304 if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
00305 SendMessage(g_qeglobals.d_hwndEdit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 void FillClassList (void)
00320 {
00321 eclass_t *pec;
00322 int iIndex;
00323
00324 SendMessage(hwndEnt[EntList], LB_RESETCONTENT, 0 , 0);
00325
00326 for (pec = eclass ; pec ; pec = pec->next)
00327 {
00328 iIndex = SendMessage(hwndEnt[EntList], LB_ADDSTRING, 0 , (LPARAM)pec->name);
00329 SendMessage(hwndEnt[EntList], LB_SETITEMDATA, iIndex, (LPARAM)pec);
00330 }
00331
00332 }
00333
00334
00335
00336
00337
00338
00339
00340 void WEnt_Create (HINSTANCE hInstance)
00341 {
00342 WNDCLASS wc;
00343
00344
00345 memset (&wc, 0, sizeof(wc));
00346
00347 wc.style = CS_NOCLOSE | CS_OWNDC;
00348 wc.lpfnWndProc = (WNDPROC)EntityWndProc;
00349 wc.cbClsExtra = 0;
00350 wc.cbWndExtra = 0;
00351 wc.hInstance = hInstance;
00352 wc.hIcon = 0;
00353 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
00354 wc.hbrBackground = (HBRUSH)GetStockObject (LTGRAY_BRUSH);
00355 wc.lpszMenuName = NULL;
00356 wc.lpszClassName = ENT_WINDOW_CLASS;
00357
00358 RegisterClass (&wc);
00359
00360 int nStyle = (g_pParentWnd->CurrentStyle() == QR_QE4) ? QE3_STYLE : QE3_STYLE2;
00361 g_qeglobals.d_hwndEntity = CreateWindow (ENT_WINDOW_CLASS ,
00362 "Entity",
00363 nStyle,
00364 20,
00365 20,
00366 100,
00367 480,
00368
00369 g_qeglobals.d_hwndMain,
00370 0,
00371 hInstance,
00372 NULL);
00373
00374 if (!g_qeglobals.d_hwndEntity )
00375 Error ("Couldn't create Entity window");
00376 }
00377
00378
00379
00380
00381
00382
00383 BOOL CreateEntityWindow(HINSTANCE hInstance)
00384 {
00385 HWND hwndEntityPalette;
00386
00387 inspector_mode = W_ENTITY;
00388
00389 WEnt_Create (hInstance);
00390
00391 hwndEntityPalette = CreateDialog(hInstance, (char *)IDD_ENTITY, g_qeglobals.d_hwndMain, (DLGPROC)NULL);
00392 if (!hwndEntityPalette)
00393 Error ("CreateDialog failed");
00394
00395 GetEntityControls (hwndEntityPalette);
00396 DestroyWindow (hwndEntityPalette);
00397
00398 OldFieldWindowProc = (WNDPROC)GetWindowLong (hwndEnt[EntKeyField], GWL_WNDPROC);
00399 SetWindowLong (hwndEnt[EntKeyField], GWL_WNDPROC, (long)FieldWndProc);
00400 SetWindowLong (hwndEnt[EntValueField], GWL_WNDPROC, (long)FieldWndProc);
00401
00402 OldEntityListWindowProc = (WNDPROC)GetWindowLong (hwndEnt[EntList], GWL_WNDPROC);
00403 SetWindowLong (hwndEnt[EntList], GWL_WNDPROC, (long)EntityListWndProc);
00404
00405 FillClassList ();
00406
00407
00408 LoadWindowPlacement(g_qeglobals.d_hwndEntity, "EntityWindowPlace");
00409 ShowWindow (g_qeglobals.d_hwndEntity, SW_HIDE);
00410 SetInspectorMode (W_CONSOLE);
00411
00412 return TRUE;
00413 }
00414
00415
00416
00417
00418
00419
00420 void SetInspectorMode(int iType)
00421 {
00422 RECT rc;
00423 HMENU hMenu = GetMenu( g_qeglobals.d_hwndMain );
00424
00425 if ((g_pParentWnd->CurrentStyle() == QR_SPLIT || g_pParentWnd->CurrentStyle() == QR_SPLITZ) && (iType == W_TEXTURE || iType == W_CONSOLE))
00426 return;
00427
00428
00429
00430
00431 if (iType == -1)
00432 {
00433 if (inspector_mode == W_ENTITY)
00434 iType = W_TEXTURE;
00435 else if (inspector_mode == W_TEXTURE)
00436 iType = W_CONSOLE;
00437 else if (inspector_mode == W_CONSOLE)
00438 iType = W_GROUP;
00439 else
00440 iType = W_ENTITY;
00441 }
00442
00443 inspector_mode = iType;
00444 switch(iType)
00445 {
00446
00447 case W_ENTITY:
00448 SetWindowText(g_qeglobals.d_hwndEntity, "Entity");
00449 EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_ENABLED | MF_BYCOMMAND );
00450
00451 g_wndTabs.SetCurSel(0);
00452 break;
00453
00454 case W_TEXTURE:
00455 SetWindowText(g_qeglobals.d_hwndEntity, "Textures");
00456 g_pParentWnd->GetTexWnd()->FocusEdit();
00457 EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
00458 if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
00459 g_wndTabs.SetCurSel(1);
00460 break;
00461
00462 case W_CONSOLE:
00463 SetWindowText(g_qeglobals.d_hwndEntity, "Console");
00464 EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
00465 if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
00466 g_wndTabs.SetCurSel(2);
00467 break;
00468
00469 case W_GROUP:
00470 SetWindowText(g_qeglobals.d_hwndEntity, "Groups");
00471 EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
00472 if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
00473 g_wndTabs.SetCurSel(3);
00474 else
00475 g_wndTabs.SetCurSel(1);
00476 break;
00477
00478
00479 default:
00480 break;
00481 }
00482
00483 GetWindowRect (g_qeglobals.d_hwndEntity, &rc);
00484 SizeEntityDlg( rc.right - rc.left - 8, rc.bottom - rc.top - 20);
00485
00486
00487
00488
00489
00490
00491 HWND hFlag = (g_pParentWnd->CurrentStyle() == QR_QE4) ? HWND_TOP : HWND_TOPMOST;
00492 SetWindowPos( g_qeglobals.d_hwndEntity, hFlag, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOSIZE | SWP_NOMOVE );
00493 RedrawWindow (g_qeglobals.d_hwndEntity, NULL, NULL, RDW_ERASE | RDW_INVALIDATE| RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN);
00494 }
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506 void SetKeyValuePairs (bool bClearMD3)
00507 {
00508 epair_t *pep;
00509 RECT rc;
00510 char sz[4096];
00511
00512 if (edit_entity == NULL)
00513 return;
00514
00515
00516
00517 GetWindowRect(hwndEnt[EntProps], &rc);
00518 SendMessage(hwndEnt[EntProps], LB_SETCOLUMNWIDTH, (rc.right - rc.left)/2, 0);
00519 SendMessage(hwndEnt[EntProps], LB_RESETCONTENT, 0, 0);
00520
00521
00522
00523 for (pep = edit_entity->epairs ; pep ; pep = pep->next)
00524 {
00525
00526 if (strlen(pep->key) > 8)
00527 sprintf (sz, "%s\t%s", pep->key, pep->value);
00528 else
00529 sprintf (sz, "%s\t\t%s", pep->key, pep->value);
00530 SendMessage(hwndEnt[EntProps], LB_ADDSTRING, 0, (LPARAM)sz);
00531 }
00532
00533 if (edit_entity->eclass->nShowFlags & ECLASS_MISCMODEL)
00534 {
00535
00536
00537 if (bClearMD3)
00538 {
00539 edit_entity->md3Class = NULL;
00540 }
00541
00542
00543
00544
00545
00546
00547
00548
00549 }
00550
00551 Sys_UpdateWindows(W_CAMERA | W_XY);
00552
00553 }
00554
00555
00556
00557
00558
00559 void SetSpawnFlags(void)
00560 {
00561 int f;
00562 int i;
00563 int v;
00564
00565 f = atoi(ValueForKey (edit_entity, "spawnflags"));
00566 for (i=0 ; i<12 ; i++)
00567 {
00568 v = !!(f&(1<<i));
00569 SendMessage(hwndEnt[EntCheck1+i], BM_SETCHECK, v, 0);
00570 }
00571 }
00572
00573
00574
00575
00576
00577
00578 void GetSpawnFlags(void)
00579 {
00580 int f;
00581 int i, v;
00582 char sz[32];
00583
00584 f = 0;
00585 for (i=0 ; i<12 ; i++)
00586 {
00587 v = SendMessage(hwndEnt[EntCheck1+i], BM_GETCHECK, 0, 0);
00588 f |= v<<i;
00589 }
00590
00591 sprintf (sz, "%i", f);
00592
00593 if (multiple_entities)
00594 {
00595 brush_t *b;
00596
00597 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
00598 SetKeyValue(b->owner, "spawnflags", sz);
00599 }
00600 else
00601 SetKeyValue (edit_entity, "spawnflags", sz);
00602 SetKeyValuePairs ();
00603 }
00604
00605
00606
00607
00608
00609 BOOL UpdateSel(int iIndex, eclass_t *pec)
00610 {
00611 int i;
00612 brush_t *b;
00613
00614 if (selected_brushes.next == &selected_brushes)
00615 {
00616 edit_entity = world_entity;
00617 multiple_entities = false;
00618 }
00619 else
00620 {
00621 edit_entity = selected_brushes.next->owner;
00622 for (b=selected_brushes.next->next ; b != &selected_brushes ; b=b->next)
00623 {
00624 if (b->owner != edit_entity)
00625 {
00626 multiple_entities = true;
00627 break;
00628 }
00629 }
00630 }
00631
00632 if (iIndex != LB_ERR)
00633 SendMessage(hwndEnt[EntList], LB_SETCURSEL, iIndex, 0);
00634
00635 if (pec == NULL)
00636 return TRUE;
00637
00638
00639
00640 SendMessage(hwndEnt[EntComment], WM_SETTEXT, 0,
00641 (LPARAM)TranslateString(pec->comments));
00642
00643 for (i=0 ; i<8 ; i++)
00644 {
00645 HWND hwnd = hwndEnt[EntCheck1+i];
00646 if (pec->flagnames[i] && pec->flagnames[i][0] != 0)
00647 {
00648 EnableWindow(hwnd, TRUE);
00649 SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)pec->flagnames[i]);
00650 } else {
00651
00652
00653 SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)" ");
00654 EnableWindow(hwnd, FALSE);
00655 }
00656 }
00657
00658 SetSpawnFlags();
00659 SetKeyValuePairs();
00660 return TRUE;
00661 }
00662
00663 BOOL UpdateEntitySel(eclass_t *pec)
00664 {
00665 int iIndex;
00666
00667 iIndex = (int)SendMessage(hwndEnt[EntList], LB_FINDSTRINGEXACT,
00668 (WPARAM)-1, (LPARAM)pec->name);
00669
00670 return UpdateSel(iIndex, pec);
00671 }
00672
00673
00674
00675
00676
00677
00678 void CreateEntity(void)
00679 {
00680 eclass_t *pecNew;
00681 entity_t *petNew;
00682 int i;
00683 HWND hwnd;
00684 char sz[1024];
00685
00686
00687
00688 if (selected_brushes.next == &selected_brushes)
00689 {
00690 MessageBox(g_qeglobals.d_hwndMain, "You must have a selected brush to create an entity"
00691 , "info", 0);
00692 return;
00693 }
00694
00695
00696
00697
00698 hwnd = hwndEnt[EntList];
00699
00700 i = SendMessage(hwndEnt[EntList], LB_GETCURSEL, 0, 0);
00701
00702 if (i < 0)
00703 {
00704 MessageBox(g_qeglobals.d_hwndMain, "You must have a selected class to create an entity"
00705 , "info", 0);
00706 return;
00707 }
00708
00709 SendMessage(hwnd, LB_GETTEXT, i, (LPARAM)sz);
00710
00711 if (!stricmp(sz, "worldspawn"))
00712 {
00713 MessageBox(g_qeglobals.d_hwndMain, "Can't create an entity with worldspawn.", "info", 0);
00714 return;
00715 }
00716
00717 pecNew = Eclass_ForName(sz, false);
00718
00719
00720
00721 petNew = Entity_Create(pecNew);
00722
00723 if (petNew == NULL)
00724 {
00725 MessageBox(g_qeglobals.d_hwndMain, "Failed to create entity.", "info", 0);
00726 return;
00727 }
00728
00729 if (selected_brushes.next == &selected_brushes)
00730 edit_entity = world_entity;
00731 else
00732 edit_entity = selected_brushes.next->owner;
00733
00734 SetKeyValuePairs();
00735 Select_Deselect ();
00736 Select_Brush (edit_entity->brushes.onext);
00737 Sys_UpdateWindows(W_ALL);
00738
00739 }
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749 void AddProp()
00750 {
00751 char key[4096];
00752 char value[4096];
00753
00754 if (edit_entity == NULL)
00755 return;
00756
00757
00758
00759 SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(key)-1, (LPARAM)key);
00760 SendMessage(hwndEnt[EntValueField], WM_GETTEXT, sizeof(value)-1, (LPARAM)value);
00761
00762 if (multiple_entities)
00763 {
00764 brush_t *b;
00765
00766 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
00767 SetKeyValue(b->owner, key, value);
00768 }
00769 else
00770 SetKeyValue(edit_entity, key, value);
00771
00772
00773 SetKeyValuePairs();
00774
00775
00776
00777
00778
00779 if (edit_entity->eclass->nShowFlags & ECLASS_PLUGINENTITY)
00780 {
00781 vec3_t mins, maxs;
00782 edit_entity->pPlugEnt->GetBounds( mins, maxs );
00783
00784
00785
00786 brush_t *b,*oldbrush;
00787 if (edit_entity->brushes.onext != &edit_entity->brushes)
00788 oldbrush = edit_entity->brushes.onext;
00789 b = Brush_Create (mins, maxs, &edit_entity->eclass->texdef);
00790 Entity_LinkBrush (edit_entity, b);
00791 Brush_Build( b, true );
00792 Select_Deselect();
00793 Brush_AddToList (edit_entity->brushes.onext, &selected_brushes);
00794 if (oldbrush)
00795 Brush_Free( oldbrush );
00796 }
00797
00798 }
00799
00800
00801
00802
00803
00804
00805
00806 void DelProp(void)
00807 {
00808 char sz[4096];
00809
00810 if (edit_entity == NULL)
00811 return;
00812
00813
00814
00815 SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(sz)-1, (LPARAM)sz);
00816
00817 if (multiple_entities)
00818 {
00819 brush_t *b;
00820
00821 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
00822 DeleteKey(b->owner, sz);
00823 }
00824 else
00825 DeleteKey(edit_entity, sz);
00826
00827
00828
00829 SetKeyValuePairs();
00830 }
00831
00832 BOOL GetSelectAllCriteria(CString &strKey, CString &strVal) {
00833 char sz[4096];
00834 HWND hwnd = hwndEnt[EntProps];
00835 int i = SendMessage(hwnd, LB_GETCURSEL, 0, 0);
00836 if (i >= 0 && inspector_mode == W_ENTITY) {
00837 SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(sz), (LPARAM)sz);
00838 strKey = sz;
00839 SendMessage(hwndEnt[EntValueField], WM_GETTEXT, sizeof(sz), (LPARAM)sz);
00840 strVal = sz;
00841 return TRUE;
00842 }
00843 return FALSE;
00844 }
00845
00846
00847
00848
00849
00850
00851
00852 void EditProp(void)
00853 {
00854 int i;
00855 HWND hwnd;
00856 char sz[4096];
00857 char *val;
00858
00859 if (edit_entity == NULL)
00860 return;
00861
00862 hwnd = hwndEnt[EntProps];
00863
00864
00865
00866 i = SendMessage(hwnd, LB_GETCURSEL, 0, 0);
00867
00868 if (i < 0)
00869 return;
00870
00871 SendMessage(hwnd, LB_GETTEXT, i, (LPARAM)sz);
00872
00873
00874
00875 for(i=0;sz[i] != '\t';i++)
00876 ;
00877
00878 sz[i] = '\0';
00879
00880 val = sz + i + 1;
00881 if (*val == '\t')
00882 val++;
00883
00884 SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)sz);
00885 SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)val);
00886 }
00887
00888
00889 HDWP defer;
00890 int col;
00891 void MOVE(HWND e, int x, int y, int w, int h, HWND hwndPlacement = HWND_TOP, int swp = SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOZORDER)
00892 {
00893
00894
00895 SetWindowPos (e, hwndPlacement, col+x, y, w, h, swp);
00896 }
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908 void SizeEntityDlg(int iWidth, int iHeight)
00909 {
00910 int y, x, xCheck, yCheck;
00911 int i, iRow;
00912 int w, h;
00913
00914 if (iWidth < 32 || iHeight < 32)
00915 return;
00916
00917 SendMessage( g_qeglobals.d_hwndEntity, WM_SETREDRAW, 0, 0);
00918 iHeight -= 24;
00919
00920
00921
00922
00923
00924
00925
00926
00927 if (inspector_mode == W_CONSOLE)
00928 {
00929 col = 0;
00930 }
00931 else
00932 {
00933 col = iWidth;
00934 }
00935
00936 if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
00937 MOVE(g_qeglobals.d_hwndEdit, DlgXBorder, DlgYBorder, iWidth - (2 * DlgXBorder), iHeight - (2 * DlgYBorder) );
00938
00939
00940
00941
00942
00943
00944 if (inspector_mode == W_TEXTURE)
00945 {
00946 col = 0;
00947 }
00948 else
00949 {
00950 col = iWidth;
00951 }
00952
00953 if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
00954 MOVE(g_qeglobals.d_hwndTexture, DlgXBorder, DlgYBorder, iWidth - (2 * DlgXBorder), iHeight - (2 * DlgYBorder) );
00955
00956 if (inspector_mode == W_GROUP)
00957 {
00958 col = 0;
00959 }
00960 else
00961 {
00962 col = iWidth;
00963 }
00964
00965 MOVE(g_qeglobals.d_hwndGroup, DlgXBorder, DlgYBorder, iWidth - (2 * DlgXBorder), iHeight - (2 * DlgYBorder) );
00966
00967
00968
00969
00970
00971
00972 if (inspector_mode == W_ENTITY)
00973 {
00974 col = 0;
00975 }
00976 else
00977 {
00978 col = iWidth;
00979 }
00980
00981
00982
00983
00984
00985
00986 y = iHeight/2;
00987 y -= 2 * DlgYBorder;
00988 y = y / 3;
00989 w = iWidth - (2 * DlgXBorder);
00990 MOVE(hwndEnt[EntList], DlgXBorder, DlgYBorder, w, 2 * y);
00991
00992 MOVE(hwndEnt[EntComment], DlgXBorder, 2 * DlgYBorder + 2 * y, w, y - (2 * DlgYBorder));
00993
00994
00995
00996
00997
00998
00999
01000 xCheck = (iWidth - (2 * DlgXBorder)) / 3;
01001 yCheck = 18;
01002
01003 x = DlgXBorder;
01004
01005 for (iRow = 0; iRow <= 12; iRow += 4)
01006 {
01007 y = iHeight/2;
01008
01009 for (i = 0; i < 4; i++)
01010 {
01011 MOVE(hwndEnt[EntCheck1 + i + iRow],
01012 x, y, xCheck, yCheck);
01013 y += yCheck;
01014 }
01015
01016 x += xCheck;
01017 }
01018
01019
01020
01021
01022 y = iHeight/2 + 4 * yCheck;
01023
01024 w = iWidth - (2 * DlgXBorder);
01025 h = (iHeight - (yCheck * 5 + 2 * DlgYBorder) ) - y;
01026
01027 MOVE(hwndEnt[EntProps], DlgXBorder, y, w, h);
01028
01029 y += h + DlgYBorder;
01030
01031
01032
01033
01034 w = iWidth-(DlgXBorder+45);
01035 MOVE(hwndEnt[EntKeyLabel], DlgXBorder, y, 40, yCheck);
01036 MOVE(hwndEnt[EntKeyField], DlgXBorder+40, y, w, yCheck);
01037 y += yCheck;
01038
01039 MOVE(hwndEnt[EntValueLabel], DlgXBorder, y, 40, yCheck);
01040 MOVE(hwndEnt[EntValueField], DlgXBorder+40, y, w, yCheck);
01041 y += yCheck;
01042
01043
01044
01045
01046 y += 2;
01047 i = y;
01048 x = DlgXBorder;
01049
01050 xCheck = yCheck*2;
01051
01052 MOVE(hwndEnt[EntDir135], x, y, xCheck, yCheck);
01053 y += yCheck;
01054
01055 MOVE(hwndEnt[EntDir180], x, y, xCheck, yCheck);
01056 y += yCheck;
01057
01058 MOVE(hwndEnt[EntDir225], x, y, xCheck, yCheck);
01059
01060 y = i;
01061 x += xCheck;
01062
01063
01064 MOVE(hwndEnt[EntDir90], x, y, xCheck, yCheck);
01065 y += yCheck;
01066 y += yCheck;
01067
01068 MOVE(hwndEnt[EntDir270], x, y, xCheck, yCheck);
01069
01070 y = i;
01071 x += xCheck;
01072
01073
01074 MOVE(hwndEnt[EntDir45], x, y, xCheck, yCheck);
01075 y += yCheck;
01076
01077 MOVE(hwndEnt[EntDir0], x, y, xCheck, yCheck);
01078 y += yCheck;
01079
01080 MOVE(hwndEnt[EntDir315], x, y, xCheck, yCheck);
01081
01082 y = i + yCheck/2;
01083 x += xCheck + xCheck/2;
01084
01085
01086 MOVE(hwndEnt[EntDirUp], x, y, xCheck, yCheck);
01087 y += yCheck;
01088
01089 MOVE(hwndEnt[EntDirDown], x, y, xCheck, yCheck);
01090
01091 y = i;
01092 x += 1.5 * xCheck;
01093
01094 MOVE(hwndEnt[EntDelProp], x, y, xCheck*2, yCheck);
01095 y += yCheck + 4;
01096
01097 MOVE(hwndEnt[EntAssignSounds], x, y, xCheck*2, yCheck);
01098 y += yCheck;
01099 MOVE(hwndEnt[EntAssignModels], x, y, xCheck*2, yCheck);
01100
01101
01102 col = 0;
01103 iHeight += 24;
01104 MOVE(hwndEnt[EntTab], 0,0,iWidth,iHeight, HWND_BOTTOM, SWP_NOACTIVATE | SWP_NOCOPYBITS);
01105
01106 SendMessage( g_qeglobals.d_hwndEntity, WM_SETREDRAW, 1, 0);
01107
01108 }
01109
01110 void AssignSound()
01111 {
01112 CString strBasePath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
01113 AddSlash(strBasePath);
01114 CString strPath = strBasePath;
01115 strPath += "sound\\";
01116
01117 CWaveOpen dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Sound files (*.wav)|*.wav||", g_pParentWnd);
01118 dlgFile.m_ofn.lpstrInitialDir = strPath;
01119 if (dlgFile.DoModal() == IDOK)
01120 {
01121 SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)"noise");
01122 CString str = dlgFile.GetPathName().GetBuffer(0);
01123 str.MakeLower();
01124 strBasePath.MakeLower();
01125 QE_ConvertDOSToUnixName(str.GetBuffer(0), str.GetBuffer(0));
01126 QE_ConvertDOSToUnixName(strBasePath.GetBuffer(0), strBasePath.GetBuffer(0));
01127 int n = str.Find(strBasePath);
01128 if (n == 0)
01129 {
01130 str = str.Right(str.GetLength() - strBasePath.GetLength());
01131 }
01132
01133 SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)str.GetBuffer(0));
01134 AddProp();
01135 g_pParentWnd->GetXYWnd()->SetFocus();
01136 }
01137 }
01138
01139 void AssignModel()
01140 {
01141 CString strBasePath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
01142 AddSlash(strBasePath);
01143 CString strPath = strBasePath;
01144 strPath += "models\\mapobjects\\";
01145
01146 CFileDialog dlgFile(TRUE, NULL, NULL, OFN_OVERWRITEPROMPT, "Model files (*.md3)|*.md3||", g_pParentWnd);
01147 dlgFile.m_ofn.lpstrInitialDir = strPath;
01148 if (dlgFile.DoModal() == IDOK)
01149 {
01150 SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)"model");
01151 CString str = dlgFile.GetPathName().GetBuffer(0);
01152 str.MakeLower();
01153 strBasePath.MakeLower();
01154 QE_ConvertDOSToUnixName(str.GetBuffer(0), str.GetBuffer(0));
01155 QE_ConvertDOSToUnixName(strBasePath.GetBuffer(0), strBasePath.GetBuffer(0));
01156 int n = str.Find(strBasePath);
01157 if (n == 0)
01158 {
01159 str = str.Right(str.GetLength() - strBasePath.GetLength());
01160 }
01161
01162 SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)str.GetBuffer(0));
01163 AddProp();
01164 edit_entity->md3Class = NULL;
01165 edit_entity->brushes.onext->bModelFailed = false;
01166 g_pParentWnd->GetXYWnd()->SetFocus();
01167 }
01168 }
01169
01170
01171
01172
01173
01174
01175
01176 BOOL CALLBACK EntityWndProc(
01177 HWND hwndDlg,
01178 UINT uMsg,
01179 WPARAM wParam,
01180 LPARAM lParam)
01181 {
01182 LPNMHDR lpnmh = NULL;
01183 RECT rc;
01184
01185 GetClientRect(hwndDlg, &rc);
01186
01187 switch (uMsg)
01188 {
01189
01190 case WM_CHAR :
01191 {
01192 char c = toupper(LOWORD(wParam));
01193
01194 if (c == 27)
01195 ShowWindow(hwndDlg, SW_HIDE);
01196 if (c == 'N')
01197 g_pParentWnd->PostMessage(WM_COMMAND, ID_VIEW_ENTITY, 0);
01198 else
01199 if (c == 'O')
01200 g_pParentWnd->PostMessage(WM_COMMAND, ID_VIEW_CONSOLE, 0);
01201 else
01202 if (c == 'T')
01203 g_pParentWnd->PostMessage(WM_COMMAND, ID_VIEW_TEXTURE, 0);
01204 else
01205 if (c == 'G')
01206 g_pParentWnd->PostMessage(WM_COMMAND, ID_VIEW_GROUPS, 0);
01207 else
01208 DefWindowProc (hwndDlg, uMsg, wParam, lParam);
01209 break;
01210 }
01211
01212 case WM_NOTIFY:
01213 lpnmh = reinterpret_cast<LPNMHDR>(lParam);
01214 if (lpnmh->hwndFrom == g_wndTabs.GetSafeHwnd()) {
01215 if ( lpnmh->code == TCN_SELCHANGE)
01216 {
01217 int n = g_wndTabs.GetCurSel();
01218 if (g_pParentWnd->CurrentStyle() == 2 || g_pParentWnd->CurrentStyle() == 1)
01219 {
01220 if (n == 0) {
01221 SetInspectorMode(W_ENTITY);
01222 } else if (n == 1) {
01223 SetInspectorMode(W_TEXTURE);
01224 } else if (n == 2) {
01225 SetInspectorMode(W_CONSOLE);
01226 } else {
01227 SetInspectorMode(W_GROUP);
01228 }
01229 }
01230 else
01231 {
01232 if (n == 0) {
01233 SetInspectorMode(W_ENTITY);
01234 } else if (n == 1) {
01235 SetInspectorMode(W_GROUP);
01236 }
01237 }
01238 }
01239 }
01240 break;
01241
01242 case WM_SIZE:
01243
01244 DefWindowProc (hwndDlg, uMsg, wParam, lParam);
01245 break;
01246
01247 case WM_DESTROY:
01248 SaveWindowPlacement(g_qeglobals.d_hwndEntity, "EntityWindowPlace");
01249 DefWindowProc(hwndDlg, uMsg, wParam, lParam);
01250 break;
01251
01252 case WM_GETMINMAXINFO:
01253 {
01254 LPMINMAXINFO lpmmi;
01255
01256 lpmmi = (LPMINMAXINFO) lParam;
01257 lpmmi->ptMinTrackSize.x = 320;
01258 lpmmi->ptMinTrackSize.y = 500;
01259 }
01260 return 0;
01261
01262 case WM_WINDOWPOSCHANGING:
01263 {
01264 LPWINDOWPOS lpwp;
01265 lpwp = (LPWINDOWPOS) lParam;
01266
01267 DefWindowProc (hwndDlg, uMsg, wParam, lParam);
01268
01269 lpwp->flags |= SWP_NOCOPYBITS;
01270 SizeEntityDlg(lpwp->cx-8, lpwp->cy-32);
01271 return 0;
01272
01273 }
01274 return 0;
01275
01276
01277 case WM_COMMAND:
01278 switch (LOWORD(wParam)) {
01279
01280 case IDC_BTN_ASSIGNSOUND:
01281 AssignSound();
01282 break;
01283
01284 case IDC_BTN_ASSIGNMODEL:
01285 AssignModel();
01286 break;
01287
01288 case IDC_E_DELPROP:
01289 DelProp();
01290 SetFocus (g_qeglobals.d_hwndCamera);
01291 break;
01292
01293 case IDC_E_0:
01294 SetKeyValue (edit_entity, "angle", "360");
01295 SetFocus (g_qeglobals.d_hwndCamera);
01296 SetKeyValuePairs ();
01297 break;
01298 case IDC_E_45:
01299 SetKeyValue (edit_entity, "angle", "45");
01300 SetFocus (g_qeglobals.d_hwndCamera);
01301 SetKeyValuePairs ();
01302 break;
01303 case IDC_E_90:
01304 SetKeyValue (edit_entity, "angle", "90");
01305 SetFocus (g_qeglobals.d_hwndCamera);
01306 SetKeyValuePairs ();
01307 break;
01308 case IDC_E_135:
01309 SetKeyValue (edit_entity, "angle", "135");
01310 SetFocus (g_qeglobals.d_hwndCamera);
01311 SetKeyValuePairs ();
01312 break;
01313 case IDC_E_180:
01314 SetKeyValue (edit_entity, "angle", "180");
01315 SetFocus (g_qeglobals.d_hwndCamera);
01316 SetKeyValuePairs ();
01317 break;
01318 case IDC_E_225:
01319 SetKeyValue (edit_entity, "angle", "225");
01320 SetFocus (g_qeglobals.d_hwndCamera);
01321 SetKeyValuePairs ();
01322 break;
01323 case IDC_E_270:
01324 SetKeyValue (edit_entity, "angle", "270");
01325 SetFocus (g_qeglobals.d_hwndCamera);
01326 SetKeyValuePairs ();
01327 break;
01328 case IDC_E_315:
01329 SetKeyValue (edit_entity, "angle", "315");
01330 SetFocus (g_qeglobals.d_hwndCamera);
01331 SetKeyValuePairs ();
01332 break;
01333 case IDC_E_UP:
01334 SetKeyValue (edit_entity, "angle", "-1");
01335 SetFocus (g_qeglobals.d_hwndCamera);
01336 SetKeyValuePairs ();
01337 break;
01338 case IDC_E_DOWN:
01339 SetKeyValue (edit_entity, "angle", "-2");
01340 SetFocus (g_qeglobals.d_hwndCamera);
01341 SetKeyValuePairs ();
01342 break;
01343
01344 case IDC_BTN_HIDE:
01345 ::PostMessage(g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_CAMERATOGGLE, 0);
01346 break;
01347
01348 case IDC_CHECK1:
01349 case IDC_CHECK2:
01350 case IDC_CHECK3:
01351 case IDC_CHECK4:
01352 case IDC_CHECK5:
01353 case IDC_CHECK6:
01354 case IDC_CHECK7:
01355 case IDC_CHECK8:
01356 case IDC_CHECK9:
01357 case IDC_CHECK10:
01358 case IDC_CHECK11:
01359 case IDC_CHECK12:
01360 GetSpawnFlags();
01361 SetFocus (g_qeglobals.d_hwndCamera);
01362 break;
01363
01364
01365 case IDC_E_PROPS:
01366 switch (HIWORD(wParam))
01367 {
01368 case LBN_SELCHANGE:
01369
01370 EditProp();
01371 return TRUE;
01372 }
01373 break;
01374
01375 case IDC_E_LIST:
01376
01377 switch (HIWORD(wParam)) {
01378
01379 case LBN_SELCHANGE:
01380 {
01381 int iIndex;
01382 eclass_t *pec;
01383
01384 iIndex = SendMessage(hwndEnt[EntList], LB_GETCURSEL, 0, 0);
01385 pec = (eclass_t *)SendMessage(hwndEnt[EntList], LB_GETITEMDATA,
01386 iIndex, 0);
01387
01388 UpdateSel(iIndex, pec);
01389
01390 return TRUE;
01391 break;
01392 }
01393
01394 case LBN_DBLCLK:
01395 CreateEntity ();
01396 SetFocus (g_qeglobals.d_hwndCamera);
01397 break;
01398 }
01399 break;
01400
01401
01402 default:
01403 return DefWindowProc( hwndDlg, uMsg, wParam, lParam );
01404 }
01405
01406 return 0;
01407 }
01408
01409 return DefWindowProc (hwndDlg, uMsg, wParam, lParam);
01410 }
01411