Added NSInteractiveSurface. Make voting display which bindings to press for yes/no.
This commit is contained in:
parent
beb6f49620
commit
6982043380
24 changed files with 535 additions and 36 deletions
BIN
base/test_maps.pk3dir/maps/test_ui.bsp
Normal file
BIN
base/test_maps.pk3dir/maps/test_ui.bsp
Normal file
Binary file not shown.
109
base/test_maps.pk3dir/maps/test_ui.map
Normal file
109
base/test_maps.pk3dir/maps/test_ui.map
Normal file
|
@ -0,0 +1,109 @@
|
|||
|
||||
// entity 0
|
||||
{
|
||||
"classname" "worldspawn"
|
||||
// brush 0
|
||||
{
|
||||
( 248 192 -64 ) ( 248 -192 -64 ) ( -264 192 -64 ) measure/floor [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( 256 192 8 ) ( -256 192 8 ) ( 256 192 0 ) measure/floor [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( 256 192 8 ) ( 256 192 0 ) ( 256 -192 8 ) measure/floor [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -256 -192 -128 ) ( 256 -192 -128 ) ( -256 192 -128 ) measure/floor [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( -256 -192 0 ) ( -256 -192 8 ) ( 256 -192 0 ) measure/floor [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -256 -192 0 ) ( -256 192 0 ) ( -256 -192 8 ) measure/floor [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
}
|
||||
// brush 1
|
||||
{
|
||||
( 248 192 192 ) ( 248 -192 192 ) ( -264 192 192 ) measure/floor [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( 256 192 264 ) ( -256 192 264 ) ( 256 192 256 ) measure/floor [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( 256 192 264 ) ( 256 192 256 ) ( 256 -192 264 ) measure/floor [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -256 -192 128 ) ( 256 -192 128 ) ( -256 192 128 ) measure/floor [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( -256 -192 256 ) ( -256 -192 264 ) ( 256 -192 256 ) measure/floor [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -256 -192 256 ) ( -256 192 256 ) ( -256 -192 264 ) measure/floor [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
}
|
||||
// brush 2
|
||||
{
|
||||
( 184 192 192 ) ( 184 -192 192 ) ( -328 192 192 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( 192 192 264 ) ( -320 192 264 ) ( 192 192 256 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -256 192 8 ) ( -256 192 0 ) ( -256 -192 8 ) measure/wall128gr [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -768 -192 -128 ) ( -256 -192 -128 ) ( -768 192 -128 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( -320 -192 256 ) ( -320 -192 264 ) ( 192 -192 256 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -320 -192 256 ) ( -320 192 256 ) ( -320 -192 264 ) measure/wall128gr [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
}
|
||||
// brush 3
|
||||
{
|
||||
( 760 192 192 ) ( 760 -192 192 ) ( 248 192 192 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( 768 192 264 ) ( 256 192 264 ) ( 768 192 256 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( 320 192 8 ) ( 320 192 0 ) ( 320 -192 8 ) measure/wall128gr [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -192 -192 -128 ) ( 320 -192 -128 ) ( -192 192 -128 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( 256 -192 256 ) ( 256 -192 264 ) ( 768 -192 256 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( 256 -192 256 ) ( 256 192 256 ) ( 256 -192 264 ) measure/wall128gr [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
}
|
||||
// brush 4
|
||||
{
|
||||
( 184 -192 192 ) ( 184 -576 192 ) ( -328 -192 192 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( 192 -192 264 ) ( -320 -192 264 ) ( 192 -192 256 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( 320 96 8 ) ( 320 96 0 ) ( 320 -288 8 ) measure/wall128gr [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -768 -576 -128 ) ( -256 -576 -128 ) ( -768 -192 -128 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( 272 -256 256 ) ( 272 -256 264 ) ( 784 -256 256 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -320 -576 256 ) ( -320 -192 256 ) ( -320 -576 264 ) measure/wall128gr [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
}
|
||||
// brush 5
|
||||
{
|
||||
( 184 256 192 ) ( 184 -128 192 ) ( -328 256 192 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( 192 256 264 ) ( -320 256 264 ) ( 192 256 256 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( 320 544 8 ) ( 320 544 0 ) ( 320 160 8 ) measure/wall128gr [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -768 -128 -128 ) ( -256 -128 -128 ) ( -768 256 -128 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -1 -0 0 ] -0 0.5 0.5 0 0 0
|
||||
( 272 192 256 ) ( 272 192 264 ) ( 784 192 256 ) measure/wall128gr [ 1 0 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
( -320 -128 256 ) ( -320 256 256 ) ( -320 -128 264 ) measure/wall128gr [ 0 1 0 0 ] [ -0 -0 -1 0 ] -0 0.5 0.5 0 0 0
|
||||
}
|
||||
}
|
||||
// entity 1
|
||||
{
|
||||
"classname" "info_player_start"
|
||||
"origin" "0.000000 0.000000 -24.000000"
|
||||
}
|
||||
// entity 2
|
||||
{
|
||||
"classname" "info_player_deathmatch"
|
||||
"origin" "0.000000 0.000000 -24.000000"
|
||||
}
|
||||
// entity 3
|
||||
{
|
||||
"classname" "light"
|
||||
"origin" "0.000000 0.000000 96.000000"
|
||||
"light" "500"
|
||||
}
|
||||
// entity 4
|
||||
{
|
||||
"classname" "NSInteractiveSurface"
|
||||
"origin" "128.000000 0.000000 -8.000000"
|
||||
}
|
||||
// entity 5
|
||||
{
|
||||
"classname" "env_explosion"
|
||||
"targetname" "testtrigger"
|
||||
"origin" "0.000000 0.000000 0.000000"
|
||||
"iMagnitude" "1024"
|
||||
}
|
||||
// entity 6
|
||||
{
|
||||
"classname" "NSInteractiveSurface"
|
||||
"origin" "-128.000000 0.000000 -8.000000"
|
||||
"angles" "0 180 0"
|
||||
"ui_res" "512 512"
|
||||
}
|
||||
// entity 6
|
||||
{
|
||||
"classname" "NSInteractiveSurface"
|
||||
"origin" "0.000000 128.000000 -8.000000"
|
||||
"angles" "0 90 0"
|
||||
"ui_scale" "0.25"
|
||||
}
|
||||
// entity 6
|
||||
{
|
||||
"classname" "NSInteractiveSurface"
|
||||
"origin" "0.000000 -128.000000 -8.000000"
|
||||
"angles" "0 -90 0"
|
||||
"ui_scale" "0.1"
|
||||
}
|
||||
|
|
@ -50,11 +50,11 @@ Chat_Draw(void)
|
|||
Font_DrawText(temppos, tempstr, g_fntChat);
|
||||
|
||||
tempstr = sprintf(
|
||||
"^2Yes: %s ^1No: %s",
|
||||
serverkey("votes_y"),
|
||||
serverkey("votes_n")
|
||||
"^2Yes (%s): %s ^1No (%s): %s",
|
||||
Util_GetKeyString("vote yes"), serverkey("votes_y"),
|
||||
Util_GetKeyString("vote no"), serverkey("votes_n")
|
||||
);
|
||||
temppos[0] = (g_hudres[0]/2) - (stringwidth(tempstr, TRUE, [12,12]) / 2);
|
||||
temppos[0] = (g_hudres[0]/2) - (Font_StringWidth(tempstr, TRUE, g_fntChat) / 2);
|
||||
Font_DrawText(temppos + [0,16], tempstr, g_fntChat);
|
||||
}
|
||||
|
||||
|
|
|
@ -239,4 +239,8 @@ struct
|
|||
|
||||
/* new XR helpers */
|
||||
bool m_bMoveForward;
|
||||
|
||||
bool m_bInterfaceFocused;
|
||||
} g_seats[4], *pSeat;
|
||||
|
||||
var vector g_vecMousePos;
|
||||
|
|
|
@ -481,6 +481,21 @@ CSQC_InputEvent(float fEventType, float fKey, float fCharacter, float fDeviceID)
|
|||
return (1);
|
||||
}
|
||||
|
||||
pSeat->m_bInterfaceFocused = false;
|
||||
|
||||
for (entity e = world; (e = find(e, ::classname, "NSInteractiveSurface"));) {
|
||||
vector vecPos = pSeat->m_ePlayer.origin + pSeat->m_ePlayer.view_ofs;
|
||||
NSInteractiveSurface surf = (NSInteractiveSurface) e;
|
||||
|
||||
if (surf.FocusCheck(vecPos, view_angles)) {
|
||||
pSeat->m_bInterfaceFocused = true;
|
||||
surf.Input(fEventType, fKey, fCharacter, fDeviceID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_vecMousePos = getmousepos();
|
||||
|
||||
VGUI_Input(fEventType, fKey, fCharacter, fDeviceID);
|
||||
|
||||
if (g_vguiWidgetCount) {
|
||||
|
@ -516,7 +531,6 @@ CSQC_Input_Frame(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=================
|
||||
CSQC_Parse_Event
|
||||
|
|
|
@ -15,3 +15,5 @@ float Client_IsPlayer(NSClient cl);
|
|||
|
||||
/* Are we in an intermission? (Match ending screen) */
|
||||
float Client_InIntermission(void);
|
||||
|
||||
string Util_GetKeyString(string);
|
||||
|
|
|
@ -31,3 +31,32 @@ Client_IsPlayer(NSClient cl)
|
|||
{
|
||||
return cl.IsPlayer();
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Util_GetKeyString
|
||||
=================
|
||||
*/
|
||||
string
|
||||
Util_GetKeyString(string strBind)
|
||||
{
|
||||
float flBindKey = tokenize(findkeysforcommand(strBind));
|
||||
string strBindTx = "";
|
||||
float j, k;
|
||||
|
||||
for (j = 0; j < flBindKey; ++j) {
|
||||
k = stof(argv(j));
|
||||
|
||||
if (k != -1) {
|
||||
if (strBindTx != "")
|
||||
strBindTx = strcat(strBindTx, ", ");
|
||||
|
||||
strBindTx = strcat(strBindTx, keynumtostring(k));
|
||||
}
|
||||
}
|
||||
|
||||
if (!strBindTx)
|
||||
strBindTx = "UNBOUND";
|
||||
|
||||
return strtoupper(strBindTx);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ class env_sprite:NSRenderableEntity
|
|||
string m_strMaterial;
|
||||
|
||||
virtual float(void) predraw;
|
||||
virtual void(void) Init;
|
||||
virtual void(float,float) ReceiveEntity;
|
||||
virtual void(void) think;
|
||||
};
|
||||
|
@ -108,12 +107,9 @@ env_sprite::ReceiveEntity(float flNew, float flChanged)
|
|||
|
||||
/* make sure we're not spawning on the client-side */
|
||||
void
|
||||
env_sprite::Init(void)
|
||||
{
|
||||
}
|
||||
void
|
||||
env_sprite::env_sprite(void)
|
||||
{
|
||||
isCSQC = false;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -182,6 +182,8 @@ env_sprite::SpawnKey(string strKey, string strValue)
|
|||
void
|
||||
env_sprite::Spawned(void)
|
||||
{
|
||||
super::Spawned();
|
||||
|
||||
m_iToggled = (HasSpawnFlags(ENVS_STARTON) > 0) ? TRUE : FALSE;
|
||||
|
||||
/* how pointless this would be otherwise. */
|
||||
|
|
|
@ -15,6 +15,7 @@ shared/NSVehicle.qc
|
|||
shared/NSMonster.qc
|
||||
shared/NSTalkMonster.qc
|
||||
shared/NSProjectile.qc
|
||||
shared/NSInteractiveSurface.qc
|
||||
shared/ambient_generic.qc
|
||||
shared/decals.qc
|
||||
shared/spraylogo.qc
|
||||
|
|
298
src/gs-entbase/shared/NSInteractiveSurface.qc
Normal file
298
src/gs-entbase/shared/NSInteractiveSurface.qc
Normal file
|
@ -0,0 +1,298 @@
|
|||
/*
|
||||
* Copyright (c) 2016-2022 Marco Cawthorne <marco@icculus.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*QUAKED NSInteractiveSurface (1 0 0) (-8 -8 -8) (8 8 8)
|
||||
Fully interactive surface
|
||||
|
||||
-------- KEYS --------
|
||||
"angles" : Sets the pitch, yaw and roll angles of the sprite.
|
||||
"ui_class" : Which UI class to use
|
||||
"ui_res" : Resolution of the interface
|
||||
"ui_size" : Size of the interface in world coordinates
|
||||
|
||||
-------- SPAWNFLAGS --------
|
||||
None
|
||||
|
||||
-------- NOTES --------
|
||||
Similar to surfaces in Doom III and Duke 4
|
||||
|
||||
-------- TRIVIA --------
|
||||
This entity was introduced in Nuclide (2022).
|
||||
*/
|
||||
|
||||
#ifdef CLIENT
|
||||
class
|
||||
NSInteractiveSurface:NSEntity
|
||||
{
|
||||
CUIWidget m_UIChain;
|
||||
string m_strSurfaceMat;
|
||||
bool m_bInFocus;
|
||||
float m_flSurfaceMat;
|
||||
vector m_vecCursorPos;
|
||||
bool m_bCached;
|
||||
float m_flScale;
|
||||
|
||||
string m_strUIClass;
|
||||
vector m_vecUIRes;
|
||||
vector m_vecWorldSize;
|
||||
float m_flUseDistance;
|
||||
|
||||
void(void) NSInteractiveSurface;
|
||||
|
||||
virtual float(void) predraw;
|
||||
virtual void(void) postdraw;
|
||||
|
||||
virtual bool(float,float,float,float) Input;
|
||||
virtual void(void) Spawned;
|
||||
virtual void(string, string) SpawnKey;
|
||||
virtual void(void) RenderScene;
|
||||
|
||||
virtual bool(vector, vector) FocusCheck;
|
||||
|
||||
virtual void(void) RendererRestarted;
|
||||
};
|
||||
|
||||
bool
|
||||
NSInteractiveSurface::FocusCheck(vector vecViewPos, vector vecViewAng)
|
||||
{
|
||||
vector vecPlayerForward;
|
||||
vector vecNormal, vecTangent, vecBitTangent;
|
||||
vector vecNear, vecFar, vecImpact;
|
||||
vector vecTestOrg;
|
||||
float fs, fe, f, s, t;
|
||||
|
||||
/* are we within the use-distance of our UI even? */
|
||||
if (vlen(origin - vecViewPos) > m_flUseDistance) {
|
||||
/* cancel out early */
|
||||
m_bInFocus = false;
|
||||
return m_bInFocus;
|
||||
}
|
||||
|
||||
/* get client forward vector */
|
||||
makevectors(vecViewAng);
|
||||
vecPlayerForward = v_forward;
|
||||
|
||||
/* get surface normals etc. */
|
||||
makevectors(angles);
|
||||
vecNormal = v_forward;
|
||||
vecTangent = v_right;
|
||||
vecBitTangent = v_up;
|
||||
|
||||
/* get our reference points, near being the corner */
|
||||
vecNear = vecViewPos - (origin - (vecTangent * (m_vecWorldSize[0]/2)) + vecBitTangent * (m_vecWorldSize[1]/2));
|
||||
vecFar = vecNear + vecPlayerForward * 512;
|
||||
|
||||
/* calculate our impact, which in turns gives us surface/texture coordinates */
|
||||
fs = dotproduct(vecNear, vecNormal);
|
||||
fe = dotproduct(vecFar, vecNormal);
|
||||
f = fs / (fs - fe);
|
||||
vecImpact = vecNear + (vecFar - vecNear) * f;
|
||||
s = dotproduct(vecImpact, vecTangent);
|
||||
t = dotproduct(vecImpact, vecBitTangent);
|
||||
|
||||
/* our aim-pos in world units */
|
||||
vecTestOrg = [s,-t,0];
|
||||
|
||||
/* bounds check for our in-world aim-pos */
|
||||
if (vecTestOrg[0] >= 0 && vecTestOrg[0] <= m_vecWorldSize[0]) {
|
||||
if (vecTestOrg[1] >= 0 && vecTestOrg[1] <= m_vecWorldSize[1]) {
|
||||
m_bInFocus = true;
|
||||
|
||||
/* cursors need to be scaled according to the UI */
|
||||
m_vecCursorPos = [s, -t, 0] / m_flScale;
|
||||
|
||||
/* widgets query this instead of getmousepos() */
|
||||
g_vecMousePos = m_vecCursorPos;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
m_bInFocus = false;
|
||||
return m_bInFocus;
|
||||
}
|
||||
|
||||
void
|
||||
NSInteractiveSurface::RendererRestarted(void)
|
||||
{
|
||||
m_flSurfaceMat = shaderforname(m_strSurfaceMat, sprintf("{\nsurfaceParm nolightmap\n{\nmap $rt:%s\n}\n}", m_strSurfaceMat));
|
||||
m_bCached = true;
|
||||
}
|
||||
|
||||
void
|
||||
NSInteractiveSurface::postdraw(void)
|
||||
{
|
||||
RenderScene();
|
||||
}
|
||||
|
||||
float
|
||||
NSInteractiveSurface::predraw(void)
|
||||
{
|
||||
vector fsize = m_vecWorldSize / 2;
|
||||
|
||||
if (m_bCached == false)
|
||||
return (PREDRAW_NEXT);
|
||||
|
||||
makevectors(angles);
|
||||
R_BeginPolygon(strtolower(m_strSurfaceMat), 0, 0);
|
||||
R_PolygonVertex(origin + v_right * fsize[0] - v_up * fsize[1],
|
||||
[1,1], [1,0,0], 1.0f);
|
||||
R_PolygonVertex(origin - v_right * fsize[0] - v_up * fsize[1],
|
||||
[0,1], [1,1,1], 1.0f);
|
||||
R_PolygonVertex(origin - v_right * fsize[0] + v_up * fsize[1],
|
||||
[0,0], [1,1,1], 1.0f);
|
||||
R_PolygonVertex(origin + v_right * fsize[0] + v_up * fsize[1],
|
||||
[1,0], [1,1,1], 1.0f);
|
||||
R_EndPolygon();
|
||||
|
||||
addentity(this);
|
||||
return (PREDRAW_NEXT);
|
||||
}
|
||||
|
||||
/* we just forward input events to our UI chain */
|
||||
bool
|
||||
NSInteractiveSurface::Input(float flEVType, float flKey, float flChar, float flDevID)
|
||||
{
|
||||
if (m_UIChain)
|
||||
m_UIChain.Input(flEVType, flKey, flChar, flDevID);
|
||||
}
|
||||
|
||||
/* called whenever we are in the proximity of a surface */
|
||||
void
|
||||
NSInteractiveSurface::RenderScene(void)
|
||||
{
|
||||
if (m_bCached == false)
|
||||
return;
|
||||
|
||||
clearscene();
|
||||
|
||||
setviewprop(VF_RT_DESTCOLOUR, m_strSurfaceMat, 1, m_vecUIRes);
|
||||
setviewprop(VF_SIZE, m_vecUIRes);
|
||||
setviewprop(VF_DRAWENGINESBAR, 0);
|
||||
setviewprop(VF_ORIGIN, [0,0,0]);
|
||||
setviewprop(VF_ANGLES, [0,0,0]);
|
||||
setviewprop(VF_AFOV, 90.0f);
|
||||
|
||||
drawfill([0,0], m_vecUIRes, [sin(cltime),sin(cltime*2),sin(cltime*0.5f)], 1.0f);
|
||||
|
||||
/* draw the chain */
|
||||
if (m_UIChain)
|
||||
m_UIChain.Draw();
|
||||
|
||||
/* render cursor */
|
||||
if (m_bInFocus)
|
||||
drawpic(m_vecCursorPos, "gfx/cursor", [32,32], [1,1,1], 1.0f);
|
||||
|
||||
/* reset */
|
||||
setviewprop(VF_RT_DESTCOLOUR, "");
|
||||
}
|
||||
|
||||
void
|
||||
NSInteractiveSurface::SpawnKey(string strKey, string strValue)
|
||||
{
|
||||
switch (strKey) {
|
||||
case "ui_class":
|
||||
m_strUIClass = strValue;
|
||||
break;
|
||||
case "ui_res":
|
||||
m_vecUIRes = stov(strValue);
|
||||
break;
|
||||
case "ui_scale":
|
||||
m_flScale = stof(strValue);
|
||||
break;
|
||||
case "ui_dist":
|
||||
m_flUseDistance = stof(strValue);
|
||||
break;
|
||||
default:
|
||||
super::SpawnKey(strKey, strValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* once all spawn parms have been initialized */
|
||||
void
|
||||
NSInteractiveSurface::Spawned(void)
|
||||
{
|
||||
CUIWidget child;
|
||||
|
||||
super::Spawned();
|
||||
m_vecWorldSize = m_vecUIRes * m_flScale;
|
||||
|
||||
RendererRestarted();
|
||||
|
||||
/* initialize UI panel here */
|
||||
m_UIChain = spawn(CUIWidget);
|
||||
|
||||
child = UIClass_Spawn(m_strUIClass);
|
||||
|
||||
if (m_UIChain)
|
||||
m_UIChain.Add(child);
|
||||
else
|
||||
error("Unable to allocate NSInteractiveSurface");
|
||||
}
|
||||
|
||||
void
|
||||
NSInteractiveSurface::NSInteractiveSurface(void)
|
||||
{
|
||||
m_UIChain = __NULL__;
|
||||
m_strUIClass = "TestUI";
|
||||
m_vecUIRes = [320, 240];
|
||||
m_flScale = 0.25f;
|
||||
m_flUseDistance = 64;
|
||||
m_strSurfaceMat = sprintf("UISurface%d", num_for_edict(this));
|
||||
print(sprintf("Surface mat: %S\n", m_strSurfaceMat));
|
||||
drawmask = MASK_ENGINE;
|
||||
m_bCached = false;
|
||||
isCSQC = true;
|
||||
}
|
||||
|
||||
/* test interface */
|
||||
class
|
||||
TestUI:CUIWindow
|
||||
{
|
||||
CUIButton testbutton;
|
||||
|
||||
void(void) TestUI;
|
||||
|
||||
virtual void(void) TestTrigger;
|
||||
virtual void(void) Spawned;
|
||||
};
|
||||
|
||||
void
|
||||
TestUI::TestTrigger(void)
|
||||
{
|
||||
sendevent("TriggerTarget", "s", "testtrigger");
|
||||
}
|
||||
|
||||
void
|
||||
TestUI::Spawned(void)
|
||||
{
|
||||
testbutton = spawn(CUIButton);
|
||||
testbutton.SetPos([32,48]);
|
||||
testbutton.SetTitle("Test Button!");
|
||||
testbutton.SetFunc(TestTrigger);
|
||||
Add(testbutton);
|
||||
testbutton.Show();
|
||||
SetSize([256,200]);
|
||||
SetTitle("Test Window Interface");
|
||||
}
|
||||
|
||||
void
|
||||
TestUI::TestUI(void)
|
||||
{
|
||||
m_vecSize = [512,512];
|
||||
m_iFlags |= WINDOW_VISIBLE;
|
||||
}
|
||||
#endif
|
|
@ -137,7 +137,6 @@ light_dynamic::ReceiveEntity(float flNew, float flFlags)
|
|||
origin[1] = readcoord();
|
||||
origin[2] = readcoord();
|
||||
setorigin(this, origin);
|
||||
print(sprintf("received %v\n", origin));
|
||||
}
|
||||
|
||||
if (flFlags & DLIGHTFL_CHANGED_ANGLES) {
|
||||
|
@ -230,7 +229,6 @@ light_dynamic::SendEntity(entity ePEnt, float flFlags)
|
|||
WriteCoord(MSG_ENTITY, origin[0]);
|
||||
WriteCoord(MSG_ENTITY, origin[1]);
|
||||
WriteCoord(MSG_ENTITY, origin[2]);
|
||||
print(sprintf("sending %v\n", origin));
|
||||
}
|
||||
|
||||
if (flFlags & DLIGHTFL_CHANGED_ANGLES) {
|
||||
|
@ -376,7 +374,6 @@ light_dynamic::Spawned(void)
|
|||
return;
|
||||
}
|
||||
|
||||
RendererRestarted();
|
||||
#else
|
||||
/* the client-side will handle dlights without targetnames */
|
||||
if (!targetname) {
|
||||
|
|
|
@ -62,3 +62,15 @@ Client_ShakeOnce(vector pos, float radius, float duration, float frequency, floa
|
|||
multicast([0,0,0], MULTICAST_ONE);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
CSEv_TriggerTarget_s(string tname)
|
||||
{
|
||||
if (tname)
|
||||
for (entity a = world; (a = find(a, ::targetname, tname));) {
|
||||
NSEntity t = (NSEntity)a;
|
||||
|
||||
if (t.Trigger)
|
||||
t.Trigger(self, TRIG_TOGGLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ NSClientPlayer::ClientInputFrame(void)
|
|||
}
|
||||
|
||||
/* If we are inside a VGUI, don't let the client do stuff outside */
|
||||
if (VGUI_Active()) {
|
||||
if (VGUI_Active() || pSeat->m_bInterfaceFocused) {
|
||||
input_impulse = 0;
|
||||
input_buttons = 0;
|
||||
return;
|
||||
|
|
|
@ -53,6 +53,8 @@ class CUIWidget
|
|||
CUIWidget m_parent;
|
||||
int m_iFlags;
|
||||
|
||||
void(void) CUIWidget;
|
||||
|
||||
virtual void(CUIWidget) Add;
|
||||
virtual void(int) FlagAdd;
|
||||
virtual void(int) FlagRemove;
|
||||
|
@ -63,6 +65,7 @@ class CUIWidget
|
|||
virtual void(void) Draw;
|
||||
virtual void(void) Reposition;
|
||||
virtual bool(float, float, float, float) Input;
|
||||
virtual void(void) Spawned;
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -176,6 +179,17 @@ CUIWidget::Input(float flEVType, float flKey, float flChar, float flDevID)
|
|||
return (false);
|
||||
}
|
||||
|
||||
void
|
||||
CUIWidget::Spawned(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
CUIWidget::CUIWidget(void)
|
||||
{
|
||||
Spawned();
|
||||
}
|
||||
|
||||
void
|
||||
UISystem_Init(void)
|
||||
{
|
||||
|
@ -216,3 +230,24 @@ UISystem_Init(void)
|
|||
precache_pic("textures/ui/steam/icon_up");
|
||||
precache_pic("textures/ui/steam/icon_close");
|
||||
}
|
||||
|
||||
CUIWidget
|
||||
UIClass_Spawn(string cname)
|
||||
{
|
||||
string func = strcat("spawnfunc_", cname);
|
||||
|
||||
if (isfunction(func)) {
|
||||
entity oldself = self;
|
||||
void(void) vFunc;
|
||||
vFunc = externvalue(-2, func);
|
||||
CUIWidget new_uiclass = spawn(CUIWidget);
|
||||
self = new_uiclass;
|
||||
vFunc();
|
||||
self = oldself;
|
||||
return (new_uiclass);
|
||||
} else {
|
||||
error("UIClass_Spawn: failed loading designated UI class\n");
|
||||
}
|
||||
|
||||
return __NULL__;
|
||||
}
|
||||
|
|
|
@ -198,7 +198,7 @@ CUIButton::Input(float flEVType, float flKey, float flChar, float flDevID)
|
|||
if (flEVType == IE_KEYDOWN) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
FlagRemove(BUTTON_LASTACTIVE);
|
||||
if (Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
FlagAdd(BUTTON_DOWN);
|
||||
FlagAdd(BUTTON_LASTACTIVE);
|
||||
ret = true;
|
||||
|
@ -206,7 +206,7 @@ CUIButton::Input(float flEVType, float flKey, float flChar, float flDevID)
|
|||
}
|
||||
} else if (flEVType == IE_KEYUP) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (m_iFlags & BUTTON_DOWN && Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (m_iFlags & BUTTON_DOWN && Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (m_vFunc)
|
||||
m_vFunc();
|
||||
if (m_strExec)
|
||||
|
|
|
@ -113,14 +113,14 @@ bool CUICheckbox::Input (float flEVType, float flKey, float flChar, float flDevI
|
|||
|
||||
if (flEVType == IE_KEYDOWN) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
m_iFlags |= CHECKBOX_DOWN;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
} else if (flEVType == IE_KEYUP) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (m_iFlags & CHECKBOX_DOWN && Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (m_iFlags & CHECKBOX_DOWN && Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
SetValue(!GetValue());
|
||||
ret = true;
|
||||
}
|
||||
|
|
|
@ -100,14 +100,14 @@ bool CUIList::Input (float flEVType, float flKey, float flChar, float flDevID)
|
|||
{
|
||||
bool ret = false;
|
||||
int iMaxDisplay;
|
||||
int iMouseOver = Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize);
|
||||
int iMouseOver = Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize);
|
||||
iMaxDisplay = bound(0, m_iItemCount, floor(m_vecSize[1] / 20));
|
||||
|
||||
vector vecOffset = [8,8];
|
||||
if (flEVType == IE_KEYDOWN) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
for (int i = m_iDrawOffset; i < iMaxDisplay + m_iDrawOffset; i++) {
|
||||
if (Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin + vecOffset, [m_vecSize[0] - 16, 20])) {
|
||||
if (Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin + vecOffset, [m_vecSize[0] - 16, 20])) {
|
||||
m_iSelected = i;
|
||||
ret = true;
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ bool CUIListBox::Input (float flEVType, float flKey, float flChar, float flDevID
|
|||
if (flEVType == IE_KEYDOWN) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
for (int i = m_iDrawOffset; i < iMaxDisplay + m_iDrawOffset; i++) {
|
||||
if (Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin + vecOffset, [m_vecSize[0] - 16, 20])) {
|
||||
if (Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin + vecOffset, [m_vecSize[0] - 16, 20])) {
|
||||
m_iSelected = i;
|
||||
ret = true;
|
||||
}
|
||||
|
|
|
@ -118,14 +118,14 @@ bool CUIMenuButton::Input (float flEVType, float flKey, float flChar, float flDe
|
|||
|
||||
if (flEVType == IE_KEYDOWN) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
m_iFlags |= MBUTTON_DOWN;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
} else if (flEVType == IE_KEYUP) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (m_iFlags & MBUTTON_DOWN && Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (m_iFlags & MBUTTON_DOWN && Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (m_vFunc) {
|
||||
m_vFunc();
|
||||
}
|
||||
|
|
|
@ -118,14 +118,14 @@ bool CUIRadio::Input (float flEVType, float flKey, float flChar, float flDevID)
|
|||
|
||||
if (flEVType == IE_KEYDOWN) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
m_iFlags |= RADIO_DOWN;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
} else if (flEVType == IE_KEYUP) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (m_iFlags & RADIO_DOWN && Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (m_iFlags & RADIO_DOWN && Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (m_vFunc) {
|
||||
m_vFunc();
|
||||
}
|
||||
|
|
|
@ -176,26 +176,26 @@ bool CUIScrollbar::Input (float flEVType, float flKey, float flChar, float flDev
|
|||
|
||||
if (flEVType == IE_KEYDOWN) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (Util_MouseAbove(getmousepos(), vecUpPos, [20,20])) {
|
||||
if (Util_MouseAbove(g_vecMousePos, vecUpPos, [20,20])) {
|
||||
m_iFlags |= SCROLLBAR_UP_DOWN;
|
||||
ret = true;
|
||||
} else if (Util_MouseAbove(getmousepos(), vecDownPos, [20,20])) {
|
||||
} else if (Util_MouseAbove(g_vecMousePos, vecDownPos, [20,20])) {
|
||||
m_iFlags |= SCROLLBAR_DN_DOWN;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
} else if (flEVType == IE_KEYUP) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (m_iFlags & SCROLLBAR_UP_DOWN && Util_MouseAbove(getmousepos(), vecUpPos, [20,20])) {
|
||||
if (m_iFlags & SCROLLBAR_UP_DOWN && Util_MouseAbove(g_vecMousePos, vecUpPos, [20,20])) {
|
||||
SetValue(GetValue() - GetStep(), TRUE);
|
||||
} else if (m_iFlags & SCROLLBAR_DN_DOWN && Util_MouseAbove(getmousepos(), vecDownPos, [20,20])) {
|
||||
} else if (m_iFlags & SCROLLBAR_DN_DOWN && Util_MouseAbove(g_vecMousePos, vecDownPos, [20,20])) {
|
||||
SetValue(GetValue() + GetStep(), TRUE);
|
||||
}
|
||||
m_iFlags -= (m_iFlags & SCROLLBAR_UP_DOWN);
|
||||
m_iFlags -= (m_iFlags & SCROLLBAR_DN_DOWN);
|
||||
} else if (flKey == K_MWHEELDOWN && Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, [20, m_iLength])) {
|
||||
} else if (flKey == K_MWHEELDOWN && Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, [20, m_iLength])) {
|
||||
SetValue(GetValue() + GetStep(), TRUE);
|
||||
} else if (flKey == K_MWHEELUP && Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, [20, m_iLength])) {
|
||||
} else if (flKey == K_MWHEELUP && Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, [20, m_iLength])) {
|
||||
SetValue(GetValue() - GetStep(), TRUE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ bool CUITextBox::Input (float flEVType, float flKey, float flChar, float flDevID
|
|||
if (flEVType == IE_KEYDOWN) {
|
||||
switch (flKey) {
|
||||
case K_MOUSE1 :
|
||||
if (Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
m_iFlags |= TEXTBOX_DOWN;
|
||||
ret = true;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ bool CUITextBox::Input (float flEVType, float flKey, float flChar, float flDevID
|
|||
}
|
||||
} else if (flEVType == IE_KEYUP) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (m_iFlags & TEXTBOX_DOWN && Util_MouseAbove(getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
if (m_iFlags & TEXTBOX_DOWN && Util_MouseAbove(g_vecMousePos, m_parent.m_vecOrigin + m_vecOrigin, m_vecSize)) {
|
||||
m_iFlags |= TEXTBOX_FOCUS;
|
||||
} else {
|
||||
m_iFlags -= (m_iFlags & TEXTBOX_FOCUS);
|
||||
|
|
|
@ -226,11 +226,11 @@ bool CUIWindow::Input (float flEVType, float flKey, float flChar, float flDevID)
|
|||
|
||||
if (flEVType == IE_KEYDOWN) {
|
||||
if (flKey == K_MOUSE1) {
|
||||
if (m_iFlags & WINDOW_CANRESIZE && Util_MouseAbove(getmousepos(), m_vecOrigin + (m_vecSize - [16,16]), [16,16])) {
|
||||
if (m_iFlags & WINDOW_CANRESIZE && Util_MouseAbove(g_vecMousePos, m_vecOrigin + (m_vecSize - [16,16]), [16,16])) {
|
||||
m_iFlags |= WINDOW_RESIZING;
|
||||
} else if (Util_MouseAbove(getmousepos(), m_vecOrigin, [m_vecSize[0] - 32, 16])) {
|
||||
} else if (Util_MouseAbove(g_vecMousePos, m_vecOrigin, [m_vecSize[0] - 32, 16])) {
|
||||
m_iFlags |= WINDOW_DRAGGING;
|
||||
m_vecDragOffset = m_vecOrigin - getmousepos();
|
||||
m_vecDragOffset = m_vecOrigin - g_vecMousePos;
|
||||
}
|
||||
}
|
||||
} else if (flEVType == IE_KEYUP) {
|
||||
|
|
Loading…
Reference in a new issue