* add HLWeapoNSelect class

This commit is contained in:
Marco Cawthorne 2024-08-14 16:12:30 -07:00
parent 34d7d48967
commit ed877bf2bb
Signed by: eukara
GPG key ID: CE2032F0A2882A22
20 changed files with 351 additions and 122 deletions

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 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.
*/
class
HLWeaponSelect
{
public:
void HLWeaponSelect(void);
virtual void Draw(void);
virtual void SelectSlot(int, bool);
virtual void SelectNext(bool);
virtual void SelectPrevious(bool);
virtual bool Active(void);
virtual void Trigger(void);
virtual void Deactivate(void);
virtual void DrawSlotNum(vector, float);
private:
float m_flHUDWeaponSelectTime;
HLWeapon m_selectedWeapon;
HLWeapon m_firstWeapon;
int m_iWantSlot;
int m_iWantSlotPos;
};

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2020 Marco Cawthorne <marco@icculus.org>
* Copyright (c) 2024 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
@ -14,50 +14,170 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
class
HLWeaponSelect
{
void HLWeaponSelect(void);
virtual void Draw(void);
virtual void SelectSlot(bool);
virtual void SelectNext(bool);
virtual void SelectPrevious(bool);
virtual void SelectBest(bool);
};
void NSWeapon_SelectWeapon(NSWeapon nextWeapon);
void
HLWeaponSelect::HLWeaponSelect(void)
{
m_selectedWeapon = __NULL__;
m_flHUDWeaponSelectTime = 0.0f;
}
bool
HLWeaponSelect::Active(void)
{
return (m_flHUDWeaponSelectTime > time) ? (true) : (false);
}
void
HLWeaponSelect::Trigger(void)
{
NSWeapon_SelectWeapon(m_selectedWeapon);
Deactivate();
}
void
HLWeaponSelect::Deactivate(void)
{
m_selectedWeapon = __NULL__;
m_flHUDWeaponSelectTime = 0.0f;
}
void
HLWeaponSelect::Draw(void)
{
NSClientPlayer pl = (NSClientPlayer)pSeat->m_ePlayer;
if (!pl.m_activeWeapon) {
return;
}
if (m_flHUDWeaponSelectTime < time) {
m_selectedWeapon = __NULL__;
return;
}
vector vecPos = g_hudmins + [16,16];
float lastSlot = -1;
float currentSlot;
HLWeapon linkedList = __NULL__;
/* since we have something in the inventory, start there */
linkedList = m_firstWeapon;
/* iterate through the inventory*/
while (linkedList) {
/* only iterate over weapons */
if (linkedList.IsWeapon() == true) {
currentSlot = linkedList. m_iHudSlot;
/* new slot started, reset Y axis */
if (lastSlot != currentSlot) {
/* new slot, new offset */
if (lastSlot == m_iWantSlot) {
vecPos[0] += 175;
} else {
vecPos[0] += 25;
}
/* quick hack to re-adjust */
if (lastSlot == -1) {
vecPos[0] = g_hudmins[0] + 16;
}
/* slot number icon at the top */
vecPos[1] = g_hudmins[1] + 16;
DrawSlotNum(vecPos, currentSlot + 1);
vecPos[1] += 20;
}
lastSlot = currentSlot;
/* selected slot VS unselected slot */
if (m_iWantSlot == currentSlot) {
if (linkedList == m_selectedWeapon) {
HLSprite_Draw_RGB(linkedList.m_iconSel, vecPos, g_hud_color, true);
HLSprite_Draw_RGB("selection", vecPos, g_hud_color, true);
} else {
HLSprite_Draw_RGB(linkedList.m_icon, vecPos, g_hud_color, true);
}
vecPos[1] += 50;
} else {
DrawSlotNum(vecPos, 0);
vecPos[1] += 25;
}
}
linkedList = (HLWeapon)linkedList.GetNextWeapon();
}
}
static string g_HLWeaponSelectBuckets[] =
{
"bucket0",
"bucket1",
"bucket2",
"bucket3",
"bucket4",
"bucket5",
"bucket6",
"bucket7",
"bucket8",
};
void
HLWeaponSelect::DrawSlotNum(vector vecPos, float fValue)
{
HLSprite_Draw_RGB(g_HLWeaponSelectBuckets[fValue], vecPos, g_hud_color, true);
}
void
HLWeaponSelect::SelectSlot(bool fastSwitch)
HLWeaponSelect::SelectSlot(int wantedSlot, bool fastSwitch)
{
}
void
HLWeaponSelect::SelectNext(bool fastSwitch)
{
NSClient ourPlayer = (NSClient)pSeat->m_ePlayer;
m_firstWeapon = (HLWeapon)ourPlayer.SortWeaponChain();
if (!m_selectedWeapon) {
m_selectedWeapon = (HLWeapon)ourPlayer.m_activeWeapon.GetNextWeapon();
} else {
m_selectedWeapon = (HLWeapon)m_selectedWeapon.GetNextWeapon();
}
/* wrap around */
if (!m_selectedWeapon) {
m_selectedWeapon = m_firstWeapon;
}
m_flHUDWeaponSelectTime = time + 3;
m_iWantSlot = m_selectedWeapon.m_iHudSlot;
m_iWantSlotPos = m_selectedWeapon.m_iHudSlotPos;
}
void
HLWeaponSelect::SelectPrevious(bool fastSwitch)
{
NSClient ourPlayer = (NSClient)pSeat->m_ePlayer;
}
void
HLWeaponSelect::SelectBest(bool fastSwitch)
{
m_firstWeapon = (HLWeapon)ourPlayer.SortWeaponChain();
if (!m_selectedWeapon) {
m_selectedWeapon = (HLWeapon)ourPlayer.m_activeWeapon.GetPreviousWeapon();
} else {
m_selectedWeapon = (HLWeapon)m_selectedWeapon.GetPreviousWeapon();
}
/* wrap around */
if (!m_selectedWeapon) {
m_selectedWeapon = m_firstWeapon;
}
m_flHUDWeaponSelectTime = time + 3;
m_iWantSlot = m_selectedWeapon.m_iHudSlot;
m_iWantSlotPos = m_selectedWeapon.m_iHudSlotPos;
}

View file

@ -27,13 +27,13 @@ ClientGame_ConsoleCommand(void)
sendevent("HLDM_Chooseteam", "s", argv(1));
break;
case "invnext":
HUD_DrawWeaponSelect_Back();
pSeatLocal->weaponSelectionHUD.SelectNext(false);
break;
case "invprev":
HUD_DrawWeaponSelect_Forward();
pSeatLocal->weaponSelectionHUD.SelectPrevious(false);
break;
case "lastinv":
HUD_DrawWeaponSelect_Last();
//HUD_DrawWeaponSelect_Last();
break;
case "slot1":
HUD_SlotSelect(0);

View file

@ -14,9 +14,11 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "../shared/defs.h"
#include "obituary.h"
#include "particles.h"
#include "hud_sprite.h"
#include "HLWeaponSelect.h"
var int autocvar_cl_autoweaponswitch = TRUE;
@ -60,6 +62,8 @@ struct
float m_flDamageIndicator;
float m_flTitleAlpha;
HLWeaponSelect weaponSelectionHUD;
} g_seatslocal[4], *pSeatLocal;
void HUD_DrawAmmo1(void);

View file

@ -493,7 +493,7 @@ HUD_Draw(void)
}
HUD_DrawDamageIndicator();
HUD_DrawWeaponSelect();
pSeatLocal->weaponSelectionHUD.Draw();
Obituary_Draw();
Textmenu_Draw();
@ -509,6 +509,7 @@ HUD_Draw(void)
HUD_DrawFlashlight();
HUD_DrawNotify();
Damage_Draw();
}
/* specatator main entry */

View file

@ -30,6 +30,8 @@ ClientGame_Init(float apilevel, string enginename, float engineversion)
registercommand("lastinv");
registercommand("invnext");
registercommand("invprev");
pSeatLocal->weaponSelectionHUD = spawn(HLWeaponSelect);
}
void VGUI_ShowMOTD();

View file

@ -9,8 +9,8 @@
#includelist
../../../src/shared/fteextensions.qc
../../../src/shared/defs.h
../../../valve/src/client/defs.h
../../../src/client/defs.h
../../../valve/src/client/defs.h
../../../src/vgui/include.src
../../../src/gs-entbase/client.src
../../../src/gs-entbase/shared.src
@ -30,6 +30,7 @@
../../../valve/src/client/hud_dmgnotify.qc
../../../valve/src/client/hud_ammonotify.qc
../../../valve/src/client/hud.qc
../../../valve/src/client/HLWeaponSelect.qc
../../../valve/src/client/hud_weaponselect.qc
../../../valve/src/client/scoreboard.qc
../../../src/client/include.src

View file

@ -14,6 +14,7 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "../shared/defs.h"
#include "gamerules.h"
#include "items.h"
#include "flashlight.h"

63
src/shared/HLWeapon.h Normal file
View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2024 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.
*/
/*! \brief Half-Life weapon base class. */
/*!QUAKED HLWeapon (0 0.8 0.8) (-16 -16 0) (16 16 72)
# OVERVIEW
Half-Life specific weapon based on NSWeapon.
# NEW KEYS
- "ammoIcon" - Which sprites/ image to use. See notes.
- "crosshair" - Which sprites/ image to use as a crosshair. See notes.
- "hudSlot" - In which weapon selection slot this weapon belongs to.
- "hudSlotPos" - The position of the weapon in the respective weapon selection slot.
# NOTES
Both `ammoIcon` and `crosshair` refer to sprite declarations inside the sprites/ directory. FreeHL scans the `sprites/hud.txt` file and and weapon specific files.
Since the weapon specific files only contain short names like `ammo` and `crosshair` you have to refer to them with a prefix separated by a `.` period symbol.
For example, `ammoIcon` being set to `weapon_foobar.ammo` will look up `ammo` inside `sprites/weapon_foobar.txt`.
*/
class
HLWeapon:NSWeapon
{
public:
void HLWeapon(void);
virtual void AddedToInventory(void);
#ifdef SERVER
virtual void SpawnKey(string, string);
#endif
#ifdef CLIENT
virtual void UpdateGUI(void);
nonvirtual void DrawLaser(void);
#endif
private:
#ifdef CLIENT
int m_iHudSlot;
int m_iHudSlotPos;
string m_ammoIcon;
string m_ammo2Icon;
string m_crossHair;
string m_icon;
string m_iconSel;
NSWeapon m_nextWeapon;
#endif
bool m_bAltModeLaser;
};

View file

@ -14,52 +14,6 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*! \brief Half-Life weapon base class. */
/*!QUAKED HLWeapon (0 0.8 0.8) (-16 -16 0) (16 16 72)
# OVERVIEW
Half-Life specific weapon based on NSWeapon.
# NEW KEYS
- "ammoIcon" - Which sprites/ image to use. See notes.
- "crosshair" - Which sprites/ image to use as a crosshair. See notes.
- "hudSlot" - In which weapon selection slot this weapon belongs to.
- "hudSlotPos" - The position of the weapon in the respective weapon selection slot.
# NOTES
Both `ammoIcon` and `crosshair` refer to sprite declarations inside the sprites/ directory. FreeHL scans the `sprites/hud.txt` file and and weapon specific files.
Since the weapon specific files only contain short names like `ammo` and `crosshair` you have to refer to them with a prefix separated by a `.` period symbol.
For example, `ammoIcon` being set to `weapon_foobar.ammo` will look up `ammo` inside `sprites/weapon_foobar.txt`.
*/
class
HLWeapon:NSWeapon
{
public:
void HLWeapon(void);
virtual void AddedToInventory(void);
#ifdef SERVER
virtual void SpawnKey(string, string);
#endif
#ifdef CLIENT
virtual void UpdateGUI(void);
nonvirtual void DrawLaser(void);
#endif
private:
#ifdef CLIENT
int m_iHudSlot;
int m_iHudSlotPos;
string m_ammoIcon;
string m_ammo2Icon;
string m_crossHair;
NSWeapon m_nextWeapon;
#endif
bool m_bAltModeLaser;
};
void
HLWeapon::HLWeapon(void)
{
@ -109,6 +63,18 @@ HLWeapon::AddedToInventory(void)
m_crossHair = sprintf("%s.crosshair", strtolower(classname));
}
m_icon = GetDefString("icon");
if (m_icon == "") {
m_icon = sprintf("%s.weapon", strtolower(classname));
}
m_iconSel = GetDefString("iconSelected");
if (m_iconSel == "") {
m_iconSel = sprintf("%s.weapon_s", strtolower(classname));
}
if (m_ammoIcon == "none") {
m_ammoIcon = __NULL__;
}
@ -121,6 +87,15 @@ HLWeapon::AddedToInventory(void)
m_crossHair = __NULL__;
}
if (m_icon == "none") {
m_icon = __NULL__;
}
if (m_iconSel == "none") {
m_iconSel = __NULL__;
}
m_iHudSlot = GetDefInt("hudSlot");
m_iHudSlotPos = GetDefInt("hudSlotPos");
#endif
@ -133,13 +108,14 @@ void
HLWeapon::UpdateGUI(void)
{
NSClientPlayer ourOwner = __NULL__;
vector ammoPos;
/* draw crosshair */
HLSprite_DrawCrosshair(m_crossHair);
/* draw ammo icon */
if (m_ammoIcon) {
vector ammoPos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42];
ammoPos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42];
HLSprite_Draw_RGBA(m_ammoIcon, ammoPos, g_hud_color, pSeatLocal->m_flAmmo2Alpha, true);
}
@ -193,7 +169,7 @@ HLWeapon::UpdateGUI(void)
/* draw ammo icon */
if (m_ammo2Icon) {
vector ammoPos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 74];
ammoPos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 74];
HLSprite_Draw_RGBA(m_ammo2Icon, ammoPos, g_hud_color, pSeatLocal->m_flAmmo2Alpha, true);
}
}

1
src/shared/defs.h Normal file
View file

@ -0,0 +1 @@
#include "HLWeapon.h"

View file

@ -44,6 +44,7 @@ class HLPlayer:NSClientPlayer
virtual void PredictPreFrame(void);
virtual void PredictPostFrame(void);
virtual void UpdateAliveCam(void);
virtual void ClientInputFrame(void);
#else
virtual void EvaluateEntity(void);
virtual float SendEntity(entity, float);
@ -78,6 +79,22 @@ HLPlayer::UpdatePlayerAnimation(float timelength)
}
#ifdef CLIENT
void
HLPlayer::ClientInputFrame(void)
{
if (pSeatLocal->weaponSelectionHUD.Active()) {
if (input_buttons & INPUT_PRIMARY) {
pSeatLocal->weaponSelectionHUD.Trigger();
} else if (input_buttons & INPUT_SECONDARY) {
pSeatLocal->weaponSelectionHUD.Deactivate();
}
pSeat->m_flInputBlockTime = time + 0.2;
}
super::ClientInputFrame();
}
void Camera_RunPosBob(vector angles, __inout vector camera_pos);
void Camera_StrafeRoll(__inout vector camera_angle);
void Shake_Update(NSClientPlayer);

View file

@ -1,7 +1,7 @@
func_door.move_0
{
follow
sample misc/null.wav
sample common/null.wav
}
func_door.move_1
{
@ -56,7 +56,7 @@ func_door.move_10
func_door.stop_0
{
sample misc/null.wav
sample common/null.wav
}
func_door.stop_1
{

View file

@ -1,6 +1,6 @@
func_door_rotating.move_0
{
sample misc/null.wav
sample common/null.wav
}
func_door_rotating.move_1
{
@ -45,7 +45,7 @@ func_door_rotating.move_10
func_door_rotating.stop_0
{
sample misc/null.wav
sample common/null.wav
}
func_door_rotating.stop_1
{

View file

@ -1,7 +1,7 @@
func_plat.move_0
{
follow
sample misc/null.wav
sample common/null.wav
}
func_plat.move_1
{
@ -71,7 +71,7 @@ func_plat.move_13
func_plat.stop_0
{
sample misc/null.wav
sample common/null.wav
}
func_plat.stop_1
{

View file

@ -15,12 +15,12 @@ Player.Death
Player.GaspLight
{
sample misc/null.wav
sample common/null.wav
}
Player.GaspHeavy
{
sample misc/null.wav
sample common/null.wav
}
Player.WaterExit

View file

@ -1,41 +1,2 @@
unbindall
bind CTRL "+duck"
bind DOWNARROW "+back"
bind ESCAPE "togglemenu"
bind F1 "vote yes"
bind F2 "vote no"
bind LEFTARROW "+left"
bind MOUSE1 "+attack"
bind MOUSE2 "+attack2"
bind MWHEELDOWN "weapnext"
bind MWHEELUP "weapprev"
bind RIGHTARROW "+right"
bind SHIFT "+speed"
bind SPACE "+jump"
bind TAB "+showscores"
bind UPARROW "+forward"
bind 0 "slot10"
bind 1 "slot1"
bind 2 "slot2"
bind 3 "slot3"
bind 4 "slot4"
bind 5 "slot5"
bind 6 "slot6"
bind 7 "slot7"
bind 8 "slot8"
bind 9 "slot9"
bind ` "toggleconsole"
bind a "+moveleft"
bind d "+moveright"
bind e "+use"
bind f "impulse 100"
bind r "+reload"
bind s "+back"
bind t "impulse 201"
bind u "messagemode2"
bind w "+forward"
bind y "messagemode"
bind q "weaplast"
bind ~ "toggleconsole"
exec default_controls.cfg
exec cvar_defaults.cfg

View file

@ -0,0 +1,39 @@
unbindall
bind CTRL "+duck"
bind DOWNARROW "+back"
bind ESCAPE "togglemenu"
bind F1 "vote yes"
bind F2 "vote no"
bind LEFTARROW "+left"
bind MOUSE1 "+attack"
bind MOUSE2 "+attack2"
bind MWHEELDOWN "invnext"
bind MWHEELUP "invprev"
bind RIGHTARROW "+right"
bind SHIFT "+speed"
bind SPACE "+jump"
bind TAB "+showscores"
bind UPARROW "+forward"
bind 0 "slot10"
bind 1 "slot1"
bind 2 "slot2"
bind 3 "slot3"
bind 4 "slot4"
bind 5 "slot5"
bind 6 "slot6"
bind 7 "slot7"
bind 8 "slot8"
bind 9 "slot9"
bind ` "toggleconsole"
bind a "+moveleft"
bind d "+moveright"
bind e "+use"
bind f "impulse 100"
bind r "+reload"
bind s "+back"
bind t "impulse 201"
bind u "messagemode2"
bind w "+forward"
bind y "messagemode"
bind q "weaplast"
bind ~ "toggleconsole"

View file

@ -4,6 +4,8 @@
!!samps diffuse reflectcube normalmap
!!permu FAKESHADOWS
!!permu BUMP
!!permu REFLECTCUBEMASK
!!cvardf r_glsl_pcf
!!samps =FAKESHADOWS shadowmap

View file

@ -221,4 +221,4 @@ slime
bulletimpact "sfx_impact.slosh"
stepleft "step_slosh.left"
stepright "step_slosh.right"
}
}