win_ent.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 1,391 行 · 第 1/3 页
CPP
1,391 行
// InvalidateRect(entwindow, NULL, true);
// ShowWindow (entwindow, SW_SHOW);
// UpdateWindow (entwindow);
HWND hFlag = (g_pParentWnd->CurrentStyle() == QR_QE4) ? HWND_TOP : HWND_TOPMOST;
SetWindowPos( g_qeglobals.d_hwndEntity, hFlag, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOSIZE | SWP_NOMOVE );
RedrawWindow (g_qeglobals.d_hwndEntity, NULL, NULL, RDW_ERASE | RDW_INVALIDATE| RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN);
}
// SetKeyValuePairs
//
// Reset the key/value (aka property) listbox and fill it with the
// k/v pairs from the entity being edited.
//
void SetKeyValuePairs (bool bClearMD3)
{
epair_t *pep;
RECT rc;
char sz[4096];
if (edit_entity == NULL)
return;
// set key/value pair list
GetWindowRect(hwndEnt[EntProps], &rc);
SendMessage(hwndEnt[EntProps], LB_SETCOLUMNWIDTH, (rc.right - rc.left)/2, 0);
SendMessage(hwndEnt[EntProps], LB_RESETCONTENT, 0, 0);
// Walk through list and add pairs
for (pep = edit_entity->epairs ; pep ; pep = pep->next)
{
// if the key is less than 8 chars, add a tab for alignment
if (strlen(pep->key) > 8)
sprintf (sz, "%s\t%s", pep->key, pep->value);
else
sprintf (sz, "%s\t\t%s", pep->key, pep->value);
SendMessage(hwndEnt[EntProps], LB_ADDSTRING, 0, (LPARAM)sz);
}
if (edit_entity->eclass->nShowFlags & ECLASS_MISCMODEL)
{
// if this is a misc_model
// cache the md3 for display later
if (bClearMD3)
{
edit_entity->md3Class = NULL;
}
//char *pModel = ValueForKey(edit_entity, "model");
/*
if (pModel != NULL)
{
GetCachedModel(pModel, vMin, vMax);
}
*/
}
Sys_UpdateWindows(W_CAMERA | W_XY);
}
// SetSpawnFlags
//
// Update the checkboxes to reflect the flag state of the entity
//
void SetSpawnFlags(void)
{
int f;
int i;
int v;
f = atoi(ValueForKey (edit_entity, "spawnflags"));
for (i=0 ; i<12 ; i++)
{
v = !!(f&(1<<i));
SendMessage(hwndEnt[EntCheck1+i], BM_SETCHECK, v, 0);
}
}
// GetSpawnFlags
//
// Update the entity flags to reflect the state of the checkboxes
//
void GetSpawnFlags(void)
{
int f;
int i, v;
char sz[32];
f = 0;
for (i=0 ; i<12 ; i++)
{
v = SendMessage(hwndEnt[EntCheck1+i], BM_GETCHECK, 0, 0);
f |= v<<i;
}
sprintf (sz, "%i", f);
if (multiple_entities)
{
brush_t *b;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
SetKeyValue(b->owner, "spawnflags", sz);
}
else
SetKeyValue (edit_entity, "spawnflags", sz);
SetKeyValuePairs ();
}
// UpdateSel
//
// Update the listbox, checkboxes and k/v pairs to reflect the new selection
//
BOOL UpdateSel(int iIndex, eclass_t *pec)
{
int i;
brush_t *b;
if (selected_brushes.next == &selected_brushes)
{
edit_entity = world_entity;
multiple_entities = false;
}
else
{
edit_entity = selected_brushes.next->owner;
for (b=selected_brushes.next->next ; b != &selected_brushes ; b=b->next)
{
if (b->owner != edit_entity)
{
multiple_entities = true;
break;
}
}
}
if (iIndex != LB_ERR)
SendMessage(hwndEnt[EntList], LB_SETCURSEL, iIndex, 0);
if (pec == NULL)
return TRUE;
// Set up the description
SendMessage(hwndEnt[EntComment], WM_SETTEXT, 0,
(LPARAM)TranslateString(pec->comments));
for (i=0 ; i<8 ; i++)
{
HWND hwnd = hwndEnt[EntCheck1+i];
if (pec->flagnames[i] && pec->flagnames[i][0] != 0)
{
EnableWindow(hwnd, TRUE);
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)pec->flagnames[i]);
} else {
// disable check box
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)" ");
EnableWindow(hwnd, FALSE);
}
}
SetSpawnFlags();
SetKeyValuePairs();
return TRUE;
}
BOOL UpdateEntitySel(eclass_t *pec)
{
int iIndex;
iIndex = (int)SendMessage(hwndEnt[EntList], LB_FINDSTRINGEXACT,
(WPARAM)-1, (LPARAM)pec->name);
return UpdateSel(iIndex, pec);
}
// CreateEntity
//
// Creates a new entity based on the currently selected brush and entity type.
//
void CreateEntity(void)
{
eclass_t *pecNew;
entity_t *petNew;
int i;
HWND hwnd;
char sz[1024];
// check to make sure we have a brush
if (selected_brushes.next == &selected_brushes)
{
MessageBox(g_qeglobals.d_hwndMain, "You must have a selected brush to create an entity"
, "info", 0);
return;
}
// find out what type of entity we are trying to create
hwnd = hwndEnt[EntList];
i = SendMessage(hwndEnt[EntList], LB_GETCURSEL, 0, 0);
if (i < 0)
{
MessageBox(g_qeglobals.d_hwndMain, "You must have a selected class to create an entity"
, "info", 0);
return;
}
SendMessage(hwnd, LB_GETTEXT, i, (LPARAM)sz);
if (!stricmp(sz, "worldspawn"))
{
MessageBox(g_qeglobals.d_hwndMain, "Can't create an entity with worldspawn.", "info", 0);
return;
}
pecNew = Eclass_ForName(sz, false);
// create it
petNew = Entity_Create(pecNew);
if (petNew == NULL)
{
MessageBox(g_qeglobals.d_hwndMain, "Failed to create entity.", "info", 0);
return;
}
if (selected_brushes.next == &selected_brushes)
edit_entity = world_entity;
else
edit_entity = selected_brushes.next->owner;
SetKeyValuePairs();
Select_Deselect ();
Select_Brush (edit_entity->brushes.onext);
Sys_UpdateWindows(W_ALL);
}
/*
===============
AddProp
===============
*/
void AddProp()
{
char key[4096];
char value[4096];
if (edit_entity == NULL)
return;
// Get current selection text
SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(key)-1, (LPARAM)key);
SendMessage(hwndEnt[EntValueField], WM_GETTEXT, sizeof(value)-1, (LPARAM)value);
if (multiple_entities)
{
brush_t *b;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
SetKeyValue(b->owner, key, value);
}
else
SetKeyValue(edit_entity, key, value);
// refresh the prop listbox
SetKeyValuePairs();
// if it's a plugin entity, perhaps we need to update some drawing parameters
// NOTE: perhaps moving this code to a seperate func would help if we need it in other places
// TODO: we need to call some update func in the IPluginEntity in case model name changes etc.
// ( for the moment only bounding brush is updated ), see UpdateModelBrush in Ritual's Q3Radiant
if (edit_entity->eclass->nShowFlags & ECLASS_PLUGINENTITY)
{
vec3_t mins, maxs;
edit_entity->pPlugEnt->GetBounds( mins, maxs );
// replace old bounding brush by newly computed one
// NOTE: this part is similar to Entity_BuildModelBrush in Ritual's Q3Radiant, it can be
// usefull moved into a seperate func
brush_t *b,*oldbrush;
if (edit_entity->brushes.onext != &edit_entity->brushes)
oldbrush = edit_entity->brushes.onext;
b = Brush_Create (mins, maxs, &edit_entity->eclass->texdef);
Entity_LinkBrush (edit_entity, b);
Brush_Build( b, true );
Select_Deselect();
Brush_AddToList (edit_entity->brushes.onext, &selected_brushes);
if (oldbrush)
Brush_Free( oldbrush );
}
}
/*
===============
DelProp
===============
*/
void DelProp(void)
{
char sz[4096];
if (edit_entity == NULL)
return;
// Get current selection text
SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(sz)-1, (LPARAM)sz);
if (multiple_entities)
{
brush_t *b;
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
DeleteKey(b->owner, sz);
}
else
DeleteKey(edit_entity, sz);
// refresh the prop listbox
SetKeyValuePairs();
}
BOOL GetSelectAllCriteria(CString &strKey, CString &strVal) {
char sz[4096];
HWND hwnd = hwndEnt[EntProps];
int i = SendMessage(hwnd, LB_GETCURSEL, 0, 0);
if (i >= 0 && inspector_mode == W_ENTITY) {
SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(sz), (LPARAM)sz);
strKey = sz;
SendMessage(hwndEnt[EntValueField], WM_GETTEXT, sizeof(sz), (LPARAM)sz);
strVal = sz;
return TRUE;
}
return FALSE;
}
/*
===============
EditProp
===============
*/
void EditProp(void)
{
int i;
HWND hwnd;
char sz[4096];
char *val;
if (edit_entity == NULL)
return;
hwnd = hwndEnt[EntProps];
// Get current selection text
i = SendMessage(hwnd, LB_GETCURSEL, 0, 0);
if (i < 0)
return;
SendMessage(hwnd, LB_GETTEXT, i, (LPARAM)sz);
// strip it down to the key name
for(i=0;sz[i] != '\t';i++)
;
sz[i] = '\0';
val = sz + i + 1;
if (*val == '\t')
val++;
SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)sz);
SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)val);
}
HDWP defer;
int col;
void MOVE(HWND e, int x, int y, int w, int h, HWND hwndPlacement = HWND_TOP, int swp = SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOZORDER)
{
// defer=DeferWindowPos(defer,e,HWND_TOP,col+(x),y,w,h,SWP_SHOWWINDOW);
// MoveWindow (e, col+x, y, w, h, FALSE);
SetWindowPos (e, hwndPlacement, col+x, y, w, h, swp);
}
/*
===============
SizeEnitityDlg
Positions all controls so that the active inspector
is displayed correctly and the inactive ones are
off the side
===============
*/
void SizeEntityDlg(int iWidth, int iHeight)
{
int y, x, xCheck, yCheck;
int i, iRow;
int w, h;
if (iWidth < 32 || iHeight < 32)
return;
SendMessage( g_qeglobals.d_hwndEntity, WM_SETREDRAW, 0, 0);
iHeight -= 24;
//==========================================
//
// console
//
if (inspector_mode == W_CONSOLE)
{
col = 0;
}
else
{
col = iWidth;
}
if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
MOVE(g_qeglobals.d_hwndEdit, DlgXBorder, DlgYBorder, iWidth - (2 * DlgXBorder), iHeight - (2 * DlgYBorder) );
//==========================================
//
// texture controls
//
if (inspector_mode == W_TEXTURE)
{
col = 0;
}
else
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?