win_ent.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 1,391 行 · 第 1/3 页
CPP
1,391 行
#include "stdafx.h"
#include "qe3.h"
#include "entityw.h"
#include "TexWnd.h"
#include "WaveOpen.h"
int rgIds[EntLast] = {
IDC_E_LIST,
IDC_E_COMMENT,
IDC_CHECK1,
IDC_CHECK2,
IDC_CHECK3,
IDC_CHECK4,
IDC_CHECK5,
IDC_CHECK6,
IDC_CHECK7,
IDC_CHECK8,
IDC_CHECK9,
IDC_CHECK10,
IDC_CHECK11,
IDC_CHECK12,
IDC_E_PROPS,
IDC_E_0,
IDC_E_45,
IDC_E_90,
IDC_E_135,
IDC_E_180,
IDC_E_225,
IDC_E_270,
IDC_E_315,
IDC_E_UP,
IDC_E_DOWN,
IDC_E_DELPROP,
IDC_STATIC_KEY,
IDC_E_KEY_FIELD,
IDC_STATIC_VALUE,
IDC_E_VALUE_FIELD,
IDC_E_COLOR,
IDC_BTN_ASSIGNSOUND,
IDC_BTN_ASSIGNMODEL
};
HWND hwndEnt[EntLast];
CTabCtrl g_wndTabs;
int inspector_mode; // W_TEXTURE, W_ENTITY, or W_CONSOLE
qboolean multiple_entities;
entity_t *edit_entity;
BOOL CALLBACK EntityWndProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam); // second message parameter
void SizeEntityDlg(int iWidth, int iHeight);
void AddProp();
void GetTexMods(void);
LRESULT (CALLBACK* OldFieldWindowProc) (HWND, UINT, WPARAM, LPARAM);
LRESULT (CALLBACK* OldEntityListWindowProc) (HWND, UINT, WPARAM, LPARAM);
/*
=========================
FieldWndProc
Just to handle tab and enter...
=========================
*/
BOOL CALLBACK FieldWndProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_CHAR:
if (LOWORD(wParam) == VK_TAB)
return FALSE;
if (LOWORD(wParam) == VK_RETURN)
return FALSE;
if (LOWORD(wParam) == VK_ESCAPE)
{
SetFocus (g_qeglobals.d_hwndCamera);
return FALSE;
}
break;
case WM_KEYDOWN:
if (LOWORD(wParam) == VK_TAB)
{
if (hwnd == hwndEnt[EntKeyField])
{
SendMessage (hwndEnt[EntValueField], WM_SETTEXT, 0, (long)"");
SetFocus (hwndEnt[EntValueField]);
}
else
SetFocus (hwndEnt[EntKeyField]);
}
if (LOWORD(wParam) == VK_RETURN)
{
if (hwnd == hwndEnt[EntKeyField])
{
SendMessage (hwndEnt[EntValueField], WM_SETTEXT, 0, (long)"");
SetFocus (hwndEnt[EntValueField]);
}
else
{
AddProp ();
SetFocus (g_qeglobals.d_hwndCamera);
}
}
break;
// case WM_NCHITTEST:
case WM_LBUTTONDOWN:
SetFocus (hwnd);
break;
}
return CallWindowProc (OldFieldWindowProc, hwnd, uMsg, wParam, lParam);
}
/*
=========================
EntityListWndProc
Just to handle enter...
=========================
*/
BOOL CALLBACK EntityListWndProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_KEYDOWN:
if (LOWORD(wParam) == VK_RETURN)
{
SendMessage ( g_qeglobals.d_hwndEntity,
WM_COMMAND,
(LBN_DBLCLK<<16) + IDC_E_LIST,
0 );
return 0;
}
break;
}
return CallWindowProc (OldEntityListWindowProc, hwnd, uMsg, wParam, lParam);
}
/*
================
GetEntityControls
Finds the controls from the dialog and
moves them to the window
================
*/
void GetEntityControls(HWND ghwndEntity)
{
int i;
for (i = 0; i < EntLast; i++)
{
if (i == EntList || i == EntProps || i == EntComment)
continue;
if (i == EntKeyField || i == EntValueField)
continue;
hwndEnt[i] = GetDlgItem(ghwndEntity, rgIds[i]);
if (hwndEnt[i])
{
SetParent (hwndEnt[i], g_qeglobals.d_hwndEntity );
SendMessage(hwndEnt[i], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
}
}
// SetParent apears to not modify some internal state
// on listboxes, so create it from scratch...
hwndEnt[EntList] = CreateWindow ("listbox", NULL,
LBS_STANDARD | LBS_NOINTEGRALHEIGHT | LBS_WANTKEYBOARDINPUT
| WS_VSCROLL | WS_CHILD | WS_VISIBLE,
5, 5, 180, 99,
g_qeglobals.d_hwndEntity,
(HMENU)IDC_E_LIST,
g_qeglobals.d_hInstance,
NULL);
if (!hwndEnt[EntList])
Error ("CreateWindow failed");
hwndEnt[EntProps] = CreateWindow ("listbox", NULL,
LBS_STANDARD | LBS_NOINTEGRALHEIGHT | LBS_USETABSTOPS
| WS_VSCROLL | WS_CHILD | WS_VISIBLE,
5, 100, 180, 99,
g_qeglobals.d_hwndEntity,
(HMENU)IDC_E_PROPS,
g_qeglobals.d_hInstance,
NULL);
if (!hwndEnt[EntProps])
Error ("CreateWindow failed");
hwndEnt[EntComment] = CreateWindow ("edit", NULL,
ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER,
5, 100, 180, 99,
g_qeglobals.d_hwndEntity,
(HMENU)IDC_E_COMMENT,
g_qeglobals.d_hInstance,
NULL);
if (!hwndEnt[EntComment])
Error ("CreateWindow failed");
hwndEnt[EntKeyField] = CreateWindow ("edit", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
5, 100, 180, 99,
g_qeglobals.d_hwndEntity,
(HMENU)IDC_E_KEY_FIELD,
g_qeglobals.d_hInstance,
NULL);
if (!hwndEnt[EntKeyField])
Error ("CreateWindow failed");
hwndEnt[EntValueField] = CreateWindow ("edit", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
5, 100, 180, 99,
g_qeglobals.d_hwndEntity,
(HMENU)IDC_E_VALUE_FIELD,
g_qeglobals.d_hInstance,
NULL);
if (!hwndEnt[EntValueField])
Error ("CreateWindow failed");
g_wndTabs.SubclassDlgItem(IDC_TAB_MODE, CWnd::FromHandle(ghwndEntity));
hwndEnt[EntTab] = g_wndTabs.GetSafeHwnd();
g_wndTabs.InsertItem(0, "Groups");
::SetParent(g_wndTabs.GetSafeHwnd(), g_qeglobals.d_hwndEntity);
if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
{
g_qeglobals.d_hwndEdit = CreateWindow ("edit", NULL, ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER,
5, 100, 180, 99, g_qeglobals.d_hwndEntity, (HMENU)IDC_E_STATUS,
g_qeglobals.d_hInstance, NULL);
if (!g_qeglobals.d_hwndEdit)
Error ("CreateWindow failed");
g_wndTabs.InsertItem(0, "Console");
g_wndTabs.InsertItem(0, "Textures");
}
g_wndTabs.InsertItem(0, "Entities");
g_wndTabs.ShowWindow(SW_SHOW);
#if 0
for (i=0 ; i<12 ; i++)
{
hwndEnt[EntCheck1 + i] = CreateWindow ("button", NULL,
BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE,
5, 100, 180, 99,
entwindow,
(HMENU)IDC_E_STATUS,
main_instance,
NULL);
if (!hwndEnt[EntCheck1 + i])
Error ("CreateWindow failed");
}
#endif
SendMessage(hwndEnt[EntList], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
SendMessage(hwndEnt[EntProps], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
SendMessage(hwndEnt[EntComment], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
SendMessage(hwndEnt[EntKeyField], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
SendMessage(hwndEnt[EntValueField], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
SendMessage(hwndEnt[EntTab], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
SendMessage(g_qeglobals.d_hwndEdit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
}
/*
===============================================================
ENTITY WINDOW
===============================================================
*/
void FillClassList (void)
{
eclass_t *pec;
int iIndex;
SendMessage(hwndEnt[EntList], LB_RESETCONTENT, 0 , 0);
for (pec = eclass ; pec ; pec = pec->next)
{
iIndex = SendMessage(hwndEnt[EntList], LB_ADDSTRING, 0 , (LPARAM)pec->name);
SendMessage(hwndEnt[EntList], LB_SETITEMDATA, iIndex, (LPARAM)pec);
}
}
/*
==============
WEnt_Create
==============
*/
void WEnt_Create (HINSTANCE hInstance)
{
WNDCLASS wc;
/* Register the camera class */
memset (&wc, 0, sizeof(wc));
wc.style = CS_NOCLOSE | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)EntityWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = LoadCursor (NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject (LTGRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = ENT_WINDOW_CLASS;
RegisterClass (&wc);
int nStyle = (g_pParentWnd->CurrentStyle() == QR_QE4) ? QE3_STYLE : QE3_STYLE2;
g_qeglobals.d_hwndEntity = CreateWindow (ENT_WINDOW_CLASS ,
"Entity",
nStyle,
20,
20,
100,
480, // size
g_qeglobals.d_hwndMain, // parent
0, // no menu
hInstance,
NULL);
if (!g_qeglobals.d_hwndEntity )
Error ("Couldn't create Entity window");
}
/*
==============
CreateEntityWindow
==============
*/
BOOL CreateEntityWindow(HINSTANCE hInstance)
{
HWND hwndEntityPalette;
inspector_mode = W_ENTITY;
WEnt_Create (hInstance);
hwndEntityPalette = CreateDialog(hInstance, (char *)IDD_ENTITY, g_qeglobals.d_hwndMain, (DLGPROC)NULL);
if (!hwndEntityPalette)
Error ("CreateDialog failed");
GetEntityControls (hwndEntityPalette);
DestroyWindow (hwndEntityPalette);
OldFieldWindowProc = (WNDPROC)GetWindowLong (hwndEnt[EntKeyField], GWL_WNDPROC);
SetWindowLong (hwndEnt[EntKeyField], GWL_WNDPROC, (long)FieldWndProc);
SetWindowLong (hwndEnt[EntValueField], GWL_WNDPROC, (long)FieldWndProc);
OldEntityListWindowProc = (WNDPROC)GetWindowLong (hwndEnt[EntList], GWL_WNDPROC);
SetWindowLong (hwndEnt[EntList], GWL_WNDPROC, (long)EntityListWndProc);
FillClassList ();
LoadWindowPlacement(g_qeglobals.d_hwndEntity, "EntityWindowPlace");
ShowWindow (g_qeglobals.d_hwndEntity, SW_HIDE);
SetInspectorMode (W_CONSOLE);
return TRUE;
}
/*
==============
SetInspectorMode
==============
*/
void SetInspectorMode(int iType)
{
RECT rc;
HMENU hMenu = GetMenu( g_qeglobals.d_hwndMain );
if ((g_pParentWnd->CurrentStyle() == QR_SPLIT || g_pParentWnd->CurrentStyle() == QR_SPLITZ) && (iType == W_TEXTURE || iType == W_CONSOLE))
return;
// Is the caller asking us to cycle to the next window?
if (iType == -1)
{
if (inspector_mode == W_ENTITY)
iType = W_TEXTURE;
else if (inspector_mode == W_TEXTURE)
iType = W_CONSOLE;
else if (inspector_mode == W_CONSOLE)
iType = W_GROUP;
else
iType = W_ENTITY;
}
inspector_mode = iType;
switch(iType)
{
case W_ENTITY:
SetWindowText(g_qeglobals.d_hwndEntity, "Entity");
EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_ENABLED | MF_BYCOMMAND );
// entity is always first in the inspector
g_wndTabs.SetCurSel(0);
break;
case W_TEXTURE:
SetWindowText(g_qeglobals.d_hwndEntity, "Textures");
g_pParentWnd->GetTexWnd()->FocusEdit();
EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
g_wndTabs.SetCurSel(1);
break;
case W_CONSOLE:
SetWindowText(g_qeglobals.d_hwndEntity, "Console");
EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
g_wndTabs.SetCurSel(2);
break;
case W_GROUP:
SetWindowText(g_qeglobals.d_hwndEntity, "Groups");
EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
g_wndTabs.SetCurSel(3);
else
g_wndTabs.SetCurSel(1);
break;
default:
break;
}
GetWindowRect (g_qeglobals.d_hwndEntity, &rc);
SizeEntityDlg( rc.right - rc.left - 8, rc.bottom - rc.top - 20);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?