From 97ea5e620886b10921b0131c66ebf8c45f4708c6 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Sat, 3 Aug 2019 10:40:34 -0700 Subject: [PATCH] Initial commit of the new VGUI replacement code. This dates back to the days of TW 1.2 (the version that never got released) and besides some primitive windowing is usable enough in its current state. Misc fixes to FreeCS as well. --- Source/client/chat.c | 4 + Source/client/cstrike.src | 16 +- Source/client/cstrike/defs.h | 51 +++ Source/client/cstrike/event.c | 14 +- Source/client/cstrike/hudorbituaries.c | 8 +- Source/client/cstrike/init.c | 10 +- Source/client/cstrike/vgui.c | 101 ------ Source/client/cstrike/vgui_buymenu.cpp | 34 ++ Source/client/cstrike/vgui_motd.cpp | 27 ++ Source/client/cstrike/vguibuymenu.c | 293 ------------------ Source/client/cstrike/vguimotd.c | 38 --- Source/client/cstrike/vguiobjects.c | 221 ------------- Source/client/cstrike/vguiradio.c | 135 -------- Source/client/cstrike/vguiscoreboard.c | 142 --------- Source/client/cstrike/vguispectator.c | 42 --- Source/client/cstrike/vguiteamselect.c | 215 ------------- Source/client/entry.c | 28 +- Source/client/rewolf.src | 6 +- Source/client/scihunt.src | 6 +- Source/client/scihunt/init.c | 6 +- Source/client/sound.c | 56 ++-- Source/client/valve.src | 6 +- Source/client/valve/hud_weaponselect.c | 47 +-- Source/client/vgui.cpp | 27 ++ Source/client/vgui.h | 54 ---- Source/events.h | 7 + Source/gs-entbase/client.src | 1 + Source/gs-entbase/materials.h | 22 ++ Source/gs-entbase/server.src | 1 + .../gs-entbase/server/env_fog_controller.cpp | 0 Source/materials.h | 15 - Source/menu-fn/progs.src | 1 - Source/server/cstrike/main.c | 2 +- Source/shared/cstrike/weaponc4bomb.c | 17 +- Source/shared/spraylogo.cpp | 10 +- Source/vgui/font.cpp | 80 +++++ Source/vgui/include.src | 17 + Source/vgui/ui.cpp | 143 +++++++++ Source/vgui/ui_3dview.cpp | 106 +++++++ Source/vgui/ui_button.cpp | 128 ++++++++ Source/vgui/ui_checkbox.cpp | 104 +++++++ Source/vgui/ui_label.cpp | 45 +++ Source/vgui/ui_list.cpp | 187 +++++++++++ Source/vgui/ui_listbox.cpp | 131 ++++++++ Source/vgui/ui_menubutton.cpp | 132 ++++++++ Source/vgui/ui_pic.cpp | 64 ++++ Source/vgui/ui_radio.cpp | 113 +++++++ Source/vgui/ui_scrollbar.cpp | 199 ++++++++++++ Source/vgui/ui_slider.cpp | 73 +++++ Source/vgui/ui_tabview.cpp | 70 +++++ Source/vgui/ui_textbox.cpp | 106 +++++++ Source/vgui/ui_window.cpp | 223 +++++++++++++ 52 files changed, 2224 insertions(+), 1360 deletions(-) delete mode 100755 Source/client/cstrike/vgui.c create mode 100644 Source/client/cstrike/vgui_buymenu.cpp create mode 100644 Source/client/cstrike/vgui_motd.cpp delete mode 100755 Source/client/cstrike/vguibuymenu.c delete mode 100755 Source/client/cstrike/vguimotd.c delete mode 100755 Source/client/cstrike/vguiobjects.c delete mode 100755 Source/client/cstrike/vguiradio.c delete mode 100755 Source/client/cstrike/vguiscoreboard.c delete mode 100755 Source/client/cstrike/vguispectator.c delete mode 100755 Source/client/cstrike/vguiteamselect.c create mode 100644 Source/client/vgui.cpp delete mode 100755 Source/client/vgui.h create mode 100644 Source/gs-entbase/materials.h create mode 100644 Source/gs-entbase/server/env_fog_controller.cpp create mode 100644 Source/vgui/font.cpp create mode 100644 Source/vgui/include.src create mode 100644 Source/vgui/ui.cpp create mode 100644 Source/vgui/ui_3dview.cpp create mode 100644 Source/vgui/ui_button.cpp create mode 100644 Source/vgui/ui_checkbox.cpp create mode 100644 Source/vgui/ui_label.cpp create mode 100644 Source/vgui/ui_list.cpp create mode 100644 Source/vgui/ui_listbox.cpp create mode 100644 Source/vgui/ui_menubutton.cpp create mode 100644 Source/vgui/ui_pic.cpp create mode 100644 Source/vgui/ui_radio.cpp create mode 100644 Source/vgui/ui_scrollbar.cpp create mode 100644 Source/vgui/ui_slider.cpp create mode 100644 Source/vgui/ui_tabview.cpp create mode 100644 Source/vgui/ui_textbox.cpp create mode 100644 Source/vgui/ui_window.cpp diff --git a/Source/client/chat.c b/Source/client/chat.c index 32c9b11a..215ad48b 100644 --- a/Source/client/chat.c +++ b/Source/client/chat.c @@ -65,4 +65,8 @@ void Chat_Parse(string msg) g_chattime = time + CHAT_TIME; localsound("misc/talk.wav"); + + /* Log to client console */ + print(msg); + print("\n"); } diff --git a/Source/client/cstrike.src b/Source/client/cstrike.src index 93d95af8..3d1c5d32 100755 --- a/Source/client/cstrike.src +++ b/Source/client/cstrike.src @@ -14,7 +14,8 @@ ../entities.h cstrike/defs.h defs.h -vgui.h + +../vgui/include.src voice.c sound.c @@ -66,14 +67,6 @@ predict.c events.c cstrike/view.c view.c -cstrike/vguiobjects.c -cstrike/vguispectator.c -cstrike/vguiscoreboard.c -cstrike/vguimotd.c -cstrike/vguibuymenu.c -cstrike/vguiteamselect.c -cstrike/vguiradio.c -cstrike/vgui.c damage.c chat.c cstrike/nightvision.c @@ -82,6 +75,11 @@ cstrike/hudscope.c cstrike/hudweaponselect.c cstrike/hudorbituaries.c cstrike/hud.c + +vgui.cpp +cstrike/vgui_buymenu.cpp +cstrike/vgui_motd.cpp + cstrike/draw.c cstrike/entities.c cstrike/event.c diff --git a/Source/client/cstrike/defs.h b/Source/client/cstrike/defs.h index b077ce3e..6aa809d4 100755 --- a/Source/client/cstrike/defs.h +++ b/Source/client/cstrike/defs.h @@ -151,3 +151,54 @@ float fWeaponEventPlayer; void Animation_ShootWeapon( entity ePlayer ); void Animation_ReloadWeapon( entity ePlayer ); + +/* +==================== +HUD_GetChatColor + +Returns an RGB color vector for the specified team +==================== +*/ +vector HUD_GetChatColor( float fTeam ) { + if ( fTeam == TEAM_CT ) { + return '0.45 0.60 0.75'; + } else if ( fTeam == TEAM_T ) { + return '0.75 0.1875 0.1875'; + } else { + return '0.75 0.75 0.75'; + } +} + +/* +==================== +HUD_GetChatColor + +Returns a HEX color string prefix for the specified team +==================== +*/ +string HUD_GetChatColorHEX( float fTeam ) { + if ( fTeam == TEAM_CT ) { + return "^x7AC"; + } else if ( fTeam == TEAM_T ) { + return "^xC33"; + } else { + return "^xCCC"; + } +} + +/* +==================== +HUD_GetChatColor + +Returns a HEX color string prefix with teamname +==================== +*/ +string HUD_GetChatColorHEXTeam( float fTeam ) { + if ( fTeam == TEAM_CT ) { + return "^x7AC(Counter-Terrorist) "; + } else if ( fTeam == TEAM_T ) { + return "^xC33(Terrorist) "; + } else { + return "^xCCC(Spectator) "; + } +} diff --git a/Source/client/cstrike/event.c b/Source/client/cstrike/event.c index fce6e52a..8807e4df 100755 --- a/Source/client/cstrike/event.c +++ b/Source/client/cstrike/event.c @@ -21,6 +21,7 @@ void CSQC_ConsoleCommand_Init(void) registercommand("overview_test"); registercommand("buy"); + registercommand("motd"); registercommand("chooseteam"); registercommand("drop"); @@ -109,13 +110,16 @@ float Game_ConsoleCommand(void) case "overview_test": pSeat.iOverview = 1 - pSeat.iOverview; break; + case "motd": + VGUI_MessageOfTheDay(); + break; case "buy": if(getstatf(STAT_BUYZONE) == TRUE) { - pSeat->fVGUI_Display = VGUI_BM_MAIN; + VGUI_BuyMenu(); } break; case "chooseteam": - pSeat->fVGUI_Display = VGUI_TEAMSELECT; + //pSeat->fVGUI_Display = VGUI_TEAMSELECT; break; case "nightvision": Nightvision_Toggle(); @@ -282,13 +286,13 @@ float Game_ConsoleCommand(void) sendevent("RadioMessage", "f", RADIO_ENEMYDOWN); break; case "radio1": - VGUI_Radio_Toggle(VGUI_RADIO1); + //VGUI_Radio_Toggle(VGUI_RADIO1); break; case "radio2": - VGUI_Radio_Toggle(VGUI_RADIO2); + //VGUI_Radio_Toggle(VGUI_RADIO2); break; case "radio3": - VGUI_Radio_Toggle(VGUI_RADIO3); + //VGUI_Radio_Toggle(VGUI_RADIO3); break; default: return FALSE; diff --git a/Source/client/cstrike/hudorbituaries.c b/Source/client/cstrike/hudorbituaries.c index 06e8dc20..6c2b1d46 100755 --- a/Source/client/cstrike/hudorbituaries.c +++ b/Source/client/cstrike/hudorbituaries.c @@ -90,7 +90,7 @@ void HUD_DrawOrbituaries( void ) { vOrbPos[0] = video_mins[0] + video_res[0] - ( orbBuffer[ i ].fOffset1 + orbBuffer[ i ].fOffset2 + orbBuffer[ i ].fOffset3 ) - 16; // Draw the attacker's name, shadow first - drawstring( vOrbPos, orbBuffer[ i ].sAttacker, '12 12', orbBuffer[ i ].vColor1, VGUI_WINDOW_FGALPHA, 0 ); + //drawstring( vOrbPos, orbBuffer[ i ].sAttacker, '12 12', orbBuffer[ i ].vColor1, VGUI_WINDOW_FGALPHA, 0 ); // Draw the weapon icon if ( orbBuffer[ i ].fHeadShot == TRUE ) { @@ -100,7 +100,7 @@ void HUD_DrawOrbituaries( void ) { } // Draw the victim's name - drawstring( vOrbPos + [ orbBuffer[ i ].fOffset2 + orbBuffer[ i ].fOffset1, 0 ], orbBuffer[ i ].sVictim, '12 12', orbBuffer[ i ].vColor2, VGUI_WINDOW_FGALPHA, 0 ); + //drawstring( vOrbPos + [ orbBuffer[ i ].fOffset2 + orbBuffer[ i ].fOffset1, 0 ], orbBuffer[ i ].sVictim, '12 12', orbBuffer[ i ].vColor2, VGUI_WINDOW_FGALPHA, 0 ); vOrbPos[1] += 18; } } @@ -117,9 +117,9 @@ void HUD_AddOrbituaries( float fAttacker, float fAttackerTeam, float fVictim, fl if ( iOrbituaryScroll < ( ORBITUARY_LINES - 1 ) ) { // Fill up the buffer orbBuffer[ iOrbituaryScroll + 1 ].sAttacker = getplayerkeyvalue( fAttacker, "name" ); - orbBuffer[ iOrbituaryScroll + 1 ].vColor1 = HUD_GetChatColor( fAttackerTeam ); + //orbBuffer[ iOrbituaryScroll + 1 ].vColor1 = HUD_GetChatColor( fAttackerTeam ); orbBuffer[ iOrbituaryScroll + 1 ].sVictim = getplayerkeyvalue( fVictim, "name" ); - orbBuffer[ iOrbituaryScroll + 1 ].vColor2 = HUD_GetChatColor( fVictimTeam ); + //orbBuffer[ iOrbituaryScroll + 1 ].vColor2 = HUD_GetChatColor( fVictimTeam ); orbBuffer[ iOrbituaryScroll + 1 ].fWeapon = fWeapon; orbBuffer[ iOrbituaryScroll + 1 ].fHeadShot = fHeadshot; diff --git a/Source/client/cstrike/init.c b/Source/client/cstrike/init.c index 078b18a5..d5aa3b41 100755 --- a/Source/client/cstrike/init.c +++ b/Source/client/cstrike/init.c @@ -17,11 +17,6 @@ void Client_Init(float apilevel, string enginename, float engineversion) { precache_model("sprites/fexplo.spr"); precache_model("sprites/muzzleflash1.spr"); - - precache_sound("common/wpn_hudon.wav"); - precache_sound("common/wpn_hudoff.wav"); - precache_sound("common/wpn_moveselect.wav"); - precache_sound("common/wpn_select.wav"); precache_sound("player/pl_pain2.wav"); precache_model("sprites/iplayerred.spr"); @@ -35,13 +30,12 @@ void Client_Init(float apilevel, string enginename, float engineversion) precache_model("models/shotgunshell.mdl"); precache_pic( sprintf( "overviews/%s.bmp", mapname ) ); - PARTICLE_SMOKEGRENADE = particleeffectnum("smokegren"); + PARTICLE_SMOKEGRENADE = particleeffectnum("smokegren"); Radio_InitSounds(); CSQC_ConsoleCommand_Init(); - CSQC_VGUI_Init(); Overview_Init(); - + pSeat.iOverview = FALSE; } diff --git a/Source/client/cstrike/vgui.c b/Source/client/cstrike/vgui.c deleted file mode 100755 index c6cb54ea..00000000 --- a/Source/client/cstrike/vgui.c +++ /dev/null @@ -1,101 +0,0 @@ -/*** -* -* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. -* -* See the file LICENSE attached with the sources for usage details. -* -****/ - -// Menus with their window titles and draw functions -vguiwindow_t vguiMenus[11] = { - { _("VGUI_TITLE_MOTD"), VGUI_MessageOfTheDay }, - { _("VGUI_TITLE_TEAMS"), VGUI_TeamSelect_Main }, - { _("VGUI_TITLE_TSEL"), VGUI_TeamSelect_T }, - { _("VGUI_TITLE_CTSEL"), VGUI_TeamSelect_CT }, - { _("VGUI_TITLE_BUY"), VGUI_BuyMenu_Main }, - { _("VGUI_TITLE_HANDGUN"), VGUI_BuyMenu_Handguns }, - { _("VGUI_TITLE_SHOTGUN"), VGUI_BuyMenu_Shotguns }, - { _("VGUI_TITLE_SMG"), VGUI_BuyMenu_SMGs }, - { _("VGUI_TITLE_RIFLE"), VGUI_BuyMenu_Rifles }, - { _("VGUI_TITLE_MG"), VGUI_BuyMenu_Machineguns }, - { _("VGUI_TITLE_EQUIPMENT"), VGUI_BuyMenu_Equipment } -}; - -/* -================= -CSQC_VGUI_Draw - -This is the entry point for FreeCS own "VGUI" implementation -Run every frame -================= -*/ -float CSQC_VGUI_Draw( void ) { - if ( pSeat->fVGUI_Display == VGUI_NONE ) { - setcursormode( FALSE ); - return FALSE; - } - - vVGUIColor = autocvar_vgui_color * ( 1 / 255 ); - - if ( pSeat->fVGUI_Display >= VGUI_RADIO1 ) { - VGUI_Radio_Draw(); - return FALSE; - } - - // Align the window to the center - vVGUIWindowPos = video_mins; - vVGUIWindowPos[0] += ( video_res[0] / 2 ) - 320; - vVGUIWindowPos[1] += ( video_res[1] / 2 ) - 240; - VGUI_Window( vguiMenus[ pSeat->fVGUI_Display - 1 ].sTitle, vVGUIWindowPos, '640 480 0' ); - - iVGUIKey = 48; - // Display the contents of whatever we have selected - vguiMenus[ pSeat->fVGUI_Display - 1 ].vDraw( vVGUIWindowPos ); - - return TRUE; -} - -/* -================= -CSQC_VGUI_Init - -Initialize all there is -================= -*/ -void CSQC_VGUI_Init( void ) { - string sTemp; - int iMOTDLength; - filestream fmMapDescr; - - // First load the MESSAGE OF THE DAY - // TODO: Move this to the server and put strings into infokeys - - iMOTDLength = stof( serverkey( "motdlength" ) ); - for ( int i = 0; i < iMOTDLength; i++ ) { - sMOTDString[ i ] = serverkey( sprintf( "motdline%i", i ) ); - } - - // Now load the MAP DESCRIPTION - fmMapDescr = fopen( sprintf( "maps/%s.txt", mapname ), FILE_READ ); - if ( fmMapDescr != -1 ) { - for ( int i = 0; i < 35; i++ ) { - sTemp = fgets( fmMapDescr ); - if not ( sTemp ) { - break; - } - sMapString[ i ] = sTemp; - } - fclose( fmMapDescr ); - } - - if (serverkeyfloat("slots") == 1) { - pSeat->fVGUI_Display = VGUI_NONE; - return; - } - // We start on the MOTD, always - for (int s = 0; s < seats.length; s++) - { - pSeat = &seats[s]; - pSeat->fVGUI_Display = VGUI_MOTD; - } -} diff --git a/Source/client/cstrike/vgui_buymenu.cpp b/Source/client/cstrike/vgui_buymenu.cpp new file mode 100644 index 00000000..781f85e4 --- /dev/null +++ b/Source/client/cstrike/vgui_buymenu.cpp @@ -0,0 +1,34 @@ + + +void VGUI_BuyMenu(void) +{ + static int initialized; + static CUIWindow winMusicPlayer; + static CUIButton btnPlay; + static CUIButton btnStop; + + if ( !initialized ) { + initialized = TRUE; + winMusicPlayer = spawn( CUIWindow ); + winMusicPlayer.SetTitle( "Music Player" ); + winMusicPlayer.SetSize( '256 180' ); + winMusicPlayer.SetIcon( "textures/ui/icons/cd" ); + + btnPlay = spawn( CUIButton ); + btnPlay.SetTitle( "Play" ); + btnPlay.SetPos( '8 132' ); + //btnPlay.SetFunc( MusicPlayer_Play ); + + btnStop = spawn( CUIButton ); + btnStop.SetTitle( "Stop" ); + btnStop.SetPos( '96 132' ); + //btnStop.SetFunc( MusicPlayer_Stop ); + + g_uiDesktop.Add( winMusicPlayer ); + winMusicPlayer.Add( btnPlay ); + winMusicPlayer.Add( btnStop ); + } + + winMusicPlayer.Show(); + winMusicPlayer.SetPos( ( video_res / 2 ) - ( winMusicPlayer.GetSize() / 2 ) ); +} diff --git a/Source/client/cstrike/vgui_motd.cpp b/Source/client/cstrike/vgui_motd.cpp new file mode 100644 index 00000000..0312a1b5 --- /dev/null +++ b/Source/client/cstrike/vgui_motd.cpp @@ -0,0 +1,27 @@ + + +void VGUI_MessageOfTheDay(void) +{ + static int initialized; + static CUIWindow winMOTD; + static CUIButton btnOK; + + if ( !initialized ) { + initialized = TRUE; + winMOTD = spawn( CUIWindow ); + winMOTD.SetTitle( "Message Of The Day" ); + winMOTD.SetSize( '420 320' ); + winMOTD.SetIcon( "textures/ui/icons/cd" ); + + btnOK = spawn( CUIButton ); + btnOK.SetTitle( "Play" ); + btnOK.SetPos( '8 132' ); + //btnPlay.SetFunc( MusicPlayer_Play ); + + g_uiDesktop.Add( winMOTD ); + winMOTD.Add( btnOK ); + } + + winMOTD.Show(); + winMOTD.SetPos( ( video_res / 2 ) - ( winMOTD.GetSize() / 2 ) ); +} diff --git a/Source/client/cstrike/vguibuymenu.c b/Source/client/cstrike/vguibuymenu.c deleted file mode 100755 index ddc10485..00000000 --- a/Source/client/cstrike/vguibuymenu.c +++ /dev/null @@ -1,293 +0,0 @@ -/*** -* -* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. -* -* See the file LICENSE attached with the sources for usage details. -* -****/ - -vguiweaponobject_t vguiWeaponTable[CS_WEAPON_COUNT] = { - { _("WEAPON_NONE"), "" }, - { _("WEAPON_KNIFE"), "" }, - { _("WEAPON_USP"), "gfx/vgui/640_usp" }, - { _("WEAPON_GLOCK18"), "gfx/vgui/640_glock18" }, - { _("WEAPON_DEAGLE"), "gfx/vgui/640_deagle" }, - { _("WEAPON_P228"), "gfx/vgui/640_p228" }, - { _("WEAPON_ELITES"), "gfx/vgui/640_elite" }, - { _("WEAPON_FIVESEVEN"), "gfx/vgui/640_fiveseven" }, - { _("WEAPON_M3"), "gfx/vgui/640_m3" }, - { _("WEAPON_XM1014"), "gfx/vgui/640_xm1014" }, - { _("WEAPON_MP5"), "gfx/vgui/640_mp5" }, - { _("WEAPON_P90"), "gfx/vgui/640_p90" }, - { _("WEAPON_UMP45"), "gfx/vgui/640_ump45" }, - { _("WEAPON_MAC10"), "gfx/vgui/640_mac10" }, - { _("WEAPON_TMP"), "gfx/vgui/640_tmp" }, - { _("WEAPON_AK47"), "gfx/vgui/640_ak47" }, - { _("WEAPON_SG552"), "gfx/vgui/640_sg552" }, - { _("WEAPON_M4A1"), "gfx/vgui/640_m4a1" }, - { _("WEAPON_AUG"), "gfx/vgui/640_aug" }, - { _("WEAPON_SCOUT"), "gfx/vgui/640_scout" }, - { _("WEAPON_AWP"), "gfx/vgui/640_awp" }, - { _("WEAPON_G3SG1"), "gfx/vgui/640_g3sg1" }, - { _("WEAPON_SG550"), "gfx/vgui/640_sg550" }, - { _("WEAPON_PARA"), "gfx/vgui/640_m249" } -}; - -vguiequipobject_t vguiEquipmentTable[7] = { - { EQUIPMENT_KEVLAR, _("EQUIPMENT_KEVLAR"), "gfx/vgui/640_kevlar" }, - { EQUIPMENT_HELMET, _("EQUIPMENT_HELMET"), "gfx/vgui/640_kevlar_helmet" }, - { WEAPON_FLASHBANG, _("WEAPON_FLASHBANG"), "gfx/vgui/640_flashbang" }, - { WEAPON_HEGRENADE, _("WEAPON_HEGRENADE"), "gfx/vgui/640_hegrenade" }, - { WEAPON_SMOKEGRENADE, _("WEAPON_SMOKEGRENADE"), "gfx/vgui/640_smokegrenade" }, - { EQUIPMENT_DEFUSALKIT, _("EQUIPMENT_DEFUSALKIT"), "gfx/vgui/640_defuser" }, - { EQUIPMENT_NIGHTVISION, _("EQUIPMENT_NIGHTVISION"), "gfx/vgui/640_nightvision" }, -}; - -// TODO: Clean this up -void VGUI_BuyMenu_Main(vector vPos) { - static void BuyMenu_Main_1(void) { - pSeat->fVGUI_Display = VGUI_BM_HANDGUNS; - } - static void BuyMenu_Main_2(void) { - pSeat->fVGUI_Display = VGUI_BM_SHOTGUNS; - } - static void BuyMenu_Main_3(void) { - pSeat->fVGUI_Display = VGUI_BM_SMG; - } - static void BuyMenu_Main_4(void) { - pSeat->fVGUI_Display = VGUI_BM_RIFLES; - } - static void BuyMenu_Main_5(void) { - pSeat->fVGUI_Display = VGUI_BM_MGS; - } - static void BuyMenu_Main_6(void) { - sendevent("GamePlayerBuyAmmo", "f", 0); - pSeat->fVGUI_Display = VGUI_NONE; - } - static void BuyMenu_Main_7(void) { - sendevent("GamePlayerBuyAmmo", "f", 1); - pSeat->fVGUI_Display = VGUI_NONE; - } - static void BuyMenu_Main_8(void) { - pSeat->fVGUI_Display = VGUI_BM_EQUIPMENT; - } - static void BuyMenu_Main_9(void) { - pSeat->fVGUI_Display = VGUI_NONE; - } - - VGUI_Button(_("VGUI_TITLE_HANDGUN"), BuyMenu_Main_1, vPos + [16,116], [180,24]); - VGUI_Button(_("VGUI_TITLE_SHOTGUN"), BuyMenu_Main_2, vPos + [16,148], [180,24]); - VGUI_Button(_("VGUI_TITLE_SMG"), BuyMenu_Main_3, vPos + [16,180], [180,24]); - VGUI_Button(_("VGUI_TITLE_RIFLE"), BuyMenu_Main_4, vPos + [16,212], [180,24]); - VGUI_Button(_("VGUI_TITLE_MG"), BuyMenu_Main_5, vPos + [16,244], [180,24]); - - VGUI_Button(_("VGUI_TITLE_AMMO1"), BuyMenu_Main_6, vPos + [16,308], [180,24]); - VGUI_Button(_("VGUI_TITLE_AMMO2"), BuyMenu_Main_7, vPos + [16,340], [180,24]); - VGUI_Button(_("VGUI_TITLE_EQUIPMENT"), BuyMenu_Main_8, vPos + [16,372], [180,24]); - - VGUI_Button(_("VGUI_EXIT"), BuyMenu_Main_9, vPos + [16,440], [180,24]); -} - -void VGUI_BuyMenu_Back(void) { - pSeat->fVGUI_Display = VGUI_BM_MAIN; -} - -/* -==================== -VGUI_BuyMenu_BuyWeapon - -This is kinda ugly, but it will work for now -==================== -*/ -float iLastSelected; -void VGUI_BuyMenu_BuyWeapon(void) { - if(iLastSelected) { - sendevent("PlayerBuyWeapon", "f", iLastSelected); - pSeat->fVGUI_Display = VGUI_NONE; - } -} - -/* -==================== -VGUI_BuyMenu_BuyEquipment -==================== -*/ -void VGUI_BuyMenu_BuyEquipment(void) { - sendevent("PlayerBuyEquipment", "f", iLastSelected); - pSeat->fVGUI_Display = VGUI_NONE; -} - -/* -==================== -VGUI_BuyMenu_WeaponButton - -Draws a button that displays whether or not you can purchase said weapon etc. -==================== -*/ -void VGUI_BuyMenu_WeaponButton(float fWeapon) { - iLastSelected = fWeapon; - - if (wptTable[fWeapon].iPrice <= getstatf(STAT_MONEY)) { - if (VGUI_Button(vguiWeaponTable[fWeapon].sName, VGUI_BuyMenu_BuyWeapon, vVGUIButtonPos, [264,24]) == TRUE) { - drawpic(vVGUIWindowPos + [328,116], vguiWeaponTable[fWeapon].sImage, [256,64], [1,1,1], 1); - VGUI_Text(sprintf(_("BUY_PRICETAG"), wptTable[fWeapon].iPrice), vVGUIWindowPos + [328,250], [12,12], FONT_CON); - VGUI_Text(sprintf(_("BUY_CALIBER"), wptTable[fWeapon].iCaliber), vVGUIWindowPos + [328,260], [12,12], FONT_CON); - VGUI_Text(sprintf(_("BUY_RPM"), (wptTable[fWeapon].fAttackFinished) * 3600), vVGUIWindowPos + [328,270], [12,12], FONT_CON); - } - } else { - VGUI_FakeButton(vguiWeaponTable[fWeapon].sName, vVGUIButtonPos, [264,24]); - } - - vVGUIButtonPos[1] += 32; -} - -/* -==================== -VGUI_BuyMenu_EquipmentButton - -Draws a button that displays whether or not you can purchase said equipment -==================== -*/ -void VGUI_BuyMenu_EquipmentButton(float fID) { - iLastSelected = fID; - - if (eqptTable[fID].iPrice <= getstatf(STAT_MONEY)) { - if (VGUI_Button(vguiEquipmentTable[fID].sName, VGUI_BuyMenu_BuyEquipment, vVGUIButtonPos, [180,24]) == TRUE) { - drawpic(vVGUIWindowPos + [290,116], vguiEquipmentTable[fID].sImage, [256,64], [1,1,1], 1); - VGUI_Text(sprintf(_("BUY_PRICETAG"), eqptTable[fID].iPrice) , vVGUIWindowPos + [256,250], [12,12], FONT_CON); - } - } else { - VGUI_FakeButton(vguiEquipmentTable[fID].sName, vVGUIButtonPos, [180,24]); - } - - vVGUIButtonPos[1] += 32; -} - -/* -==================== -VGUI_BuyMenu_Handguns -==================== -*/ -void VGUI_BuyMenu_Handguns(vector vPos) { - vVGUIButtonPos = vPos + [16,116]; - - VGUI_BuyMenu_WeaponButton(WEAPON_USP45); - VGUI_BuyMenu_WeaponButton(WEAPON_GLOCK18); - VGUI_BuyMenu_WeaponButton(WEAPON_DEAGLE); - VGUI_BuyMenu_WeaponButton(WEAPON_P228); - - vVGUIButtonPos[1] += 32; - - if (stof(getplayerkeyvalue(player_localnum, "*team")) == TEAM_T) { - VGUI_BuyMenu_WeaponButton(WEAPON_ELITES); - } else if (stof(getplayerkeyvalue(player_localnum, "*team")) == TEAM_CT) { - VGUI_BuyMenu_WeaponButton(WEAPON_FIVESEVEN); - } - - VGUI_Button(_("VGUI_BACK"), VGUI_BuyMenu_Back, vPos + [16,440], [180,24]); -} - -/* -==================== -VGUI_BuyMenu_Shotguns -==================== -*/ -void VGUI_BuyMenu_Shotguns(vector vPos) { - vVGUIButtonPos = vPos + [16,116]; - - VGUI_BuyMenu_WeaponButton(WEAPON_M3); - VGUI_BuyMenu_WeaponButton(WEAPON_XM1014); - - VGUI_Button(_("VGUI_BACK"), VGUI_BuyMenu_Back, vPos + [16,440], [180,24]); -} - -/* -==================== -VGUI_BuyMenu_SMGs -==================== -*/ -void VGUI_BuyMenu_SMGs(vector vPos) { - vVGUIButtonPos = vPos + [16,116]; - - - VGUI_BuyMenu_WeaponButton(WEAPON_MP5); - VGUI_BuyMenu_WeaponButton(WEAPON_P90); - VGUI_BuyMenu_WeaponButton(WEAPON_UMP45); - - vVGUIButtonPos[1] += 32; - - if (stof(getplayerkeyvalue(player_localnum, "*team")) == TEAM_T) { - VGUI_BuyMenu_WeaponButton(WEAPON_MAC10); - } else if (stof(getplayerkeyvalue(player_localnum, "*team")) == TEAM_CT) { - VGUI_BuyMenu_WeaponButton(WEAPON_TMP); - } - - VGUI_Button(_("VGUI_BACK"), VGUI_BuyMenu_Back, vPos + [16,440], [180,24]); -} - -/* -==================== -VGUI_BuyMenu_Rifles -==================== -*/ -void VGUI_BuyMenu_Rifles(vector vPos) { - vVGUIButtonPos = vPos + [16,116]; - - if (stof(getplayerkeyvalue(player_localnum, "*team")) == TEAM_T) { - VGUI_BuyMenu_WeaponButton(WEAPON_AK47); - VGUI_BuyMenu_WeaponButton(WEAPON_SG552); - - VGUI_BuyMenu_WeaponButton(WEAPON_SCOUT); - VGUI_BuyMenu_WeaponButton(WEAPON_AWP); - - VGUI_BuyMenu_WeaponButton(WEAPON_G3SG1); - } - - if (stof(getplayerkeyvalue(player_localnum, "*team")) == TEAM_CT) { - VGUI_BuyMenu_WeaponButton(WEAPON_M4A1); - VGUI_BuyMenu_WeaponButton(WEAPON_AUG); - - VGUI_BuyMenu_WeaponButton(WEAPON_SCOUT); - VGUI_BuyMenu_WeaponButton(WEAPON_AWP); - - VGUI_BuyMenu_WeaponButton(WEAPON_SG550); - } - - VGUI_Button(_("VGUI_BACK"), VGUI_BuyMenu_Back, vPos + [16,440], [180,24]); -} - -/* -==================== -VGUI_BuyMenu_Machineguns -==================== -*/ -void VGUI_BuyMenu_Machineguns(vector vPos) { - vVGUIButtonPos = vPos + [16,116]; - - VGUI_BuyMenu_WeaponButton(WEAPON_PARA); - - VGUI_Button(_("VGUI_BACK"), VGUI_BuyMenu_Back, vPos + [16,440], [180,24]); -} - -/* -==================== -VGUI_BuyMenu_Equipment -==================== -*/ -void VGUI_BuyMenu_Equipment(vector vPos) { - vVGUIButtonPos = vPos + [16,116]; - - VGUI_BuyMenu_EquipmentButton(0); - VGUI_BuyMenu_EquipmentButton(1); - VGUI_BuyMenu_EquipmentButton(2); - VGUI_BuyMenu_EquipmentButton(3); - VGUI_BuyMenu_EquipmentButton(4); - - if (stof(getplayerkeyvalue(player_localnum, "*team")) == TEAM_CT) { - VGUI_BuyMenu_EquipmentButton(5); - } - - VGUI_BuyMenu_EquipmentButton(6); - - VGUI_Button(_("VGUI_BACK"), VGUI_BuyMenu_Back, vPos + [16,440], [180,24]); -} diff --git a/Source/client/cstrike/vguimotd.c b/Source/client/cstrike/vguimotd.c deleted file mode 100755 index 8a1f4542..00000000 --- a/Source/client/cstrike/vguimotd.c +++ /dev/null @@ -1,38 +0,0 @@ -/*** -* -* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. -* -* See the file LICENSE attached with the sources for usage details. -* -****/ - -/* -==================== -VGUI_MessageOfTheDay - -The MOTD screen. - -TODO: Networking still needs to be done. -You can't store motds in infokey strings because -newline chars are not supported. You could hack it to use -an array of infokeys, but that'll clutter things up -==================== -*/ -void VGUI_MessageOfTheDay( vector vPos ) { - static void MessageOfTheDay_ButtonOK( void ) { - pSeat->fVGUI_Display = VGUI_TEAMSELECT; - } - - VGUI_Text( serverkey( "hostname" ), vPos + '16 64 0', '12 12', FONT_CON ); - - vector vTextPos = vPos + '16 116 0'; - - for ( int i = 0; i < 25; i++ ) { - if ( sMOTDString[ i ] != "/" ) { - VGUI_Text( sMOTDString[ i ], vTextPos, '12 12', FONT_CON ); - } - vTextPos[1] += 14; - } - - VGUI_Button( _("VGUI_OK"), MessageOfTheDay_ButtonOK, vPos + '16 440 0', '80 24 0' ); -} diff --git a/Source/client/cstrike/vguiobjects.c b/Source/client/cstrike/vguiobjects.c deleted file mode 100755 index 6f7e9dec..00000000 --- a/Source/client/cstrike/vguiobjects.c +++ /dev/null @@ -1,221 +0,0 @@ -/*** -* -* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. -* -* See the file LICENSE attached with the sources for usage details. -* -****/ - -/* -==================== -HUD_GetChatColor - -Returns an RGB color vector for the specified team -==================== -*/ -vector HUD_GetChatColor( float fTeam ) { - if ( fTeam == TEAM_CT ) { - return '0.45 0.60 0.75'; - } else if ( fTeam == TEAM_T ) { - return '0.75 0.1875 0.1875'; - } else { - return '0.75 0.75 0.75'; - } -} - -/* -==================== -HUD_GetChatColor - -Returns a HEX color string prefix for the specified team -==================== -*/ -string HUD_GetChatColorHEX( float fTeam ) { - if ( fTeam == TEAM_CT ) { - return "^x7AC"; - } else if ( fTeam == TEAM_T ) { - return "^xC33"; - } else { - return "^xCCC"; - } -} - -/* -==================== -HUD_GetChatColor - -Returns a HEX color string prefix with teamname -==================== -*/ -string HUD_GetChatColorHEXTeam( float fTeam ) { - if ( fTeam == TEAM_CT ) { - return "^x7AC(Counter-Terrorist) "; - } else if ( fTeam == TEAM_T ) { - return "^xC33(Terrorist) "; - } else { - return "^xCCC(Spectator) "; - } -} - -/* -==================== -VGUI_CheckMouse - -Returns whether or not our mouse cursor hovers over a region -==================== -*/ -float VGUI_CheckMouse( vector vPos, vector vReg ) { - vector vSMins, vSMaxs; - - vSMins = vPos; - vSMaxs = vPos; - vSMins[0] = vPos[0]; - vSMaxs[1] = vPos[1] - 1; - - vSMaxs[0] = vPos[0] + vReg[0]; - vSMaxs[1] = vPos[1] + vReg[1]; - - if ( mouse_pos[0] >= vSMins[0] && mouse_pos[0] <= vSMaxs[0] ) { - if (mouse_pos[1] >= vSMins[1] && mouse_pos[1] <= vSMaxs[1] ) { - return 1; - } - } - - return 0; -} - - -/* -==================== -VGUI_Window - -Draws window with outline, border and title -==================== -*/ -void VGUI_Window( string sTitle, vector vPosition, vector vSize ) { - // Draw the background - drawfill( vPosition, vSize, VGUI_WINDOW_BGCOLOR, VGUI_WINDOW_BGALPHA ); - - // Sides - drawfill( vPosition, [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( [vPosition[0], vPosition[1] + vSize[1] - 1], [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( vPosition, [1, vSize[1]], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( [vPosition[0] + vSize[0] - 1, vPosition[1]], [1, vSize[1]], vVGUIColor, VGUI_WINDOW_FGALPHA ); - - // Draw the window title - CSQC_DrawText( vPosition + '16 16', sTitle, '12 12', vVGUIColor, VGUI_WINDOW_FGALPHA, DRAWFLAG_ADDITIVE, FONT_CON ); - drawfill( vPosition + '0 48', [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); -} - - -/* -==================== -VGUI_WindowSmall - -Draws smaller window with outline, border and title -==================== -*/ -void VGUI_WindowSmall( string sTitle, vector vPosition, vector vSize ) { - // Draw the background - drawfill( vPosition, vSize, VGUI_WINDOW_BGCOLOR, VGUI_WINDOW_BGALPHA ); - - // Sides - drawfill( vPosition, [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( [vPosition[0], vPosition[1] + vSize[1] - 1], [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( vPosition, [1, vSize[1]], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( [vPosition[0] + vSize[0] - 1, vPosition[1]], [1, vSize[1]], vVGUIColor, VGUI_WINDOW_FGALPHA ); - - // Draw the window title - CSQC_DrawText( vPosition + '8 8', sTitle, '12 12', vVGUIColor, VGUI_WINDOW_FGALPHA, DRAWFLAG_ADDITIVE, FONT_CON ); - drawfill( vPosition + '0 24', [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); -} - -/* -==================== -VGUI_WindowSmall - -Draws a button, returns whether or not a mouse is hovering over it (for inheritance' sake) -==================== -*/ -float VGUI_Button( string sLabel, void() vFunction, vector vPosition, vector vSize ) { - vector vLabelPos; - - if ( iVGUIKey < 57 ) { - iVGUIKey++; - } - - drawfill( vPosition, [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( [vPosition[0], vPosition[1] + vSize[1] - 1], [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( vPosition, [1, vSize[1]], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( [vPosition[0] + vSize[0] - 1, vPosition[1]], [1, vSize[1]], vVGUIColor, VGUI_WINDOW_FGALPHA ); - - // Draw the button label - vLabelPos[0] = vPosition[0] + 16; - vLabelPos[1] = vPosition[1] + ( ( vSize[1] / 2 ) - 4 ); - - if ( ( iVGUIKey == pSeat->fInputKeyCode ) ) { - vFunction(); - pSeat->fInputKeyCode = 0; - return TRUE; - } - - if ( VGUI_CheckMouse( vPosition, vSize ) ) { - if ( fMouseClick == TRUE ) { - vFunction(); - fMouseClick = FALSE; - } - - CSQC_DrawText( vLabelPos, sLabel, '12 12', vVGUIColor, VGUI_WINDOW_FGALPHA, DRAWFLAG_ADDITIVE, FONT_CON ); - drawfill( vLabelPos + '0 10 0', [ stringwidth( sLabel, TRUE, '12 12' ), 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); - return TRUE; - } else { - CSQC_DrawText( vLabelPos, sLabel, '12 12', vVGUIColor * 0.8, VGUI_WINDOW_FGALPHA, DRAWFLAG_ADDITIVE, FONT_CON ); - } - - return FALSE; -} - -/* -==================== -VGUI_FakeButton - -Looks like a button, doesn't function though. Meant for dead buttons -==================== -*/ -void VGUI_FakeButton( string sLabel, vector vPosition, vector vSize ) { - vector vLabelPos; - - drawfill( vPosition, [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( [vPosition[0], vPosition[1] + vSize[1] - 1], [vSize[0], 1], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( vPosition, [1, vSize[1]], vVGUIColor, VGUI_WINDOW_FGALPHA ); - drawfill( [vPosition[0] + vSize[0] - 1, vPosition[1]], [1, vSize[1]], vVGUIColor, VGUI_WINDOW_FGALPHA ); - - // Draw the button label - vLabelPos[0] = vPosition[0] + 16; - vLabelPos[1] = vPosition[1] + ( ( vSize[1] / 2 ) - 4 ); - - CSQC_DrawText( vLabelPos, sLabel, '12 12', vVGUIColor * 0.5, VGUI_WINDOW_FGALPHA, DRAWFLAG_ADDITIVE, FONT_CON ); -} - -/* -==================== -VGUI_Text - -Wrapper for simple GUI text labels -==================== -*/ -void VGUI_Text( string sText, vector vPos, vector vSize, float fFont ) { - CSQC_DrawText( vPos, sText, vSize, vVGUIColor, VGUI_WINDOW_FGALPHA, DRAWFLAG_ADDITIVE, fFont ); -} - -/* -==================== -VGUI_RightText - -Right-aligned version of above -==================== -*/ -void VGUI_RightText( vector vPos, string sText, vector vSize, vector vColor, float fFont ) { - vPos[0] -= stringwidth( sText, FALSE, vSize ); - CSQC_DrawText( vPos, sText, vSize, vColor, 1, 0, fFont ); -} diff --git a/Source/client/cstrike/vguiradio.c b/Source/client/cstrike/vguiradio.c deleted file mode 100755 index 594142fe..00000000 --- a/Source/client/cstrike/vguiradio.c +++ /dev/null @@ -1,135 +0,0 @@ -/*** -* -* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. -* -* See the file LICENSE attached with the sources for usage details. -* -****/ - -// Radio Commands -#define VGUIRADIO_COMMANDS 6 -float fRadioCommands[ VGUIRADIO_COMMANDS ] = { - RADIO_CT_COVERME, - RADIO_CT_POINT, - RADIO_POSITION, - RADIO_REGROUP, - RADIO_FOLLOWME, - RADIO_FIREASSIS -}; - -// Group Radio Commands -#define VGUIRADIO_GROUPCOMMANDS 6 -float fRadioGroupCommands[ VGUIRADIO_GROUPCOMMANDS ] = { - RADIO_GO, - RADIO_FALLBACK, - RADIO_STICKTOG, - RADIO_CT_INPOS, - RADIO_STORMFRONT, - RADIO_COM_REPORTIN -}; - -// Radio Responses -#define VGUIRADIO_RESPONSES 9 -float fRadioResponses[ VGUIRADIO_RESPONSES ] = { - RADIO_CT_AFFIRM, - RADIO_CT_ENEMYS, - RADIO_CT_BACKUP, - RADIO_CLEAR, - RADIO_CT_INPOS, - RADIO_CT_REPORTINGIN, - RADIO_BLOW, - RADIO_NEGATIVE, - RADIO_ENEMYDOWN -}; - -/* -==================== -VGUI_Radio_DrawCommand - -Prints and acts as an input check for a single command -==================== -*/ -void VGUI_Radio_DrawCommand( float fIndex, float fMessage, vector vPos ) { - VGUI_Text( sprintf( "%d) %s", fIndex + 1, sRadioChat[ fMessage ] ), vPos, '12 12', FONT_CON ); - - if ( pSeat->fInputKeyCode == ( fIndex + 49 ) ) { - sendevent( "RadioMessage", "f", fMessage ); - pSeat->fVGUI_Display = VGUI_NONE; - } -} - -/* -==================== -VGUI_Radio_Draw - -Main drawing routine for the radio menus -==================== -*/ -void VGUI_Radio_Draw( void ) { - vector vSize, vPos; - - if ( pSeat->fVGUI_Display == VGUI_RADIO1 ) { - vSize[0] = 312; - vSize[1] = ( 10 * VGUIRADIO_COMMANDS ) + 64; - vPos = video_mins + [ 16, video_res[1] - 148 - vSize[1] ]; - - VGUI_WindowSmall( _("RADIO_TITLE1"), vPos, vSize ); - - vPos[1] += 24; - vPos[0] += 8; - for ( float i = 0; i < VGUIRADIO_COMMANDS; i++ ) { - vPos[1] += 10; - VGUI_Radio_DrawCommand( i, fRadioCommands[ i ], vPos ); - } - } else if ( pSeat->fVGUI_Display == VGUI_RADIO2 ) { - vSize[0] = 312; - vSize[1] = ( 10 * VGUIRADIO_GROUPCOMMANDS ) + 64; - vPos = video_mins + [ 16, video_res[1] - 148 - vSize[1] ]; - - VGUI_WindowSmall( _("RADIO_TITLE2"), vPos, vSize ); - - vPos[1] += 24; - vPos[0] += 8; - for ( float i = 0; i < VGUIRADIO_GROUPCOMMANDS; i++ ) { - vPos[1] += 10; - VGUI_Radio_DrawCommand( i, fRadioGroupCommands[ i ], vPos ); - } - } else { - vSize[0] = 312; - vSize[1] = ( 10 * VGUIRADIO_RESPONSES ) + 64; - vPos = video_mins + [ 16, video_res[1] - 148 - vSize[1] ]; - - VGUI_WindowSmall( _("RADIO_TITLE3"), vPos, vSize ); - - vPos[1] += 24; - vPos[0] += 8; - for ( float i = 0; i < VGUIRADIO_RESPONSES; i++ ) { - vPos[1] += 10; - VGUI_Radio_DrawCommand( i, fRadioResponses[ i ], vPos ); - } - } - - vPos[1] += 20; - VGUI_Text( sprintf( "0) %s", _("VGUI_BACK") ), vPos, '12 12', FONT_CON ); - - if ( pSeat->fInputKeyCode == 48 ) { - pSeat->fVGUI_Display = VGUI_NONE; - } -} - -/* -==================== -VGUI_Radio_Toggle -==================== -*/ -void VGUI_Radio_Toggle( float fMenu ) { - if ( getstatf( STAT_HEALTH ) <= 0 ) { - return; - } - - if ( pSeat->fVGUI_Display == fMenu ) { - pSeat->fVGUI_Display = VGUI_NONE; - } else { - pSeat->fVGUI_Display = fMenu; - } -} diff --git a/Source/client/cstrike/vguiscoreboard.c b/Source/client/cstrike/vguiscoreboard.c deleted file mode 100755 index 3f6deba8..00000000 --- a/Source/client/cstrike/vguiscoreboard.c +++ /dev/null @@ -1,142 +0,0 @@ -/*** -* -* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. -* -* See the file LICENSE attached with the sources for usage details. -* -****/ - -string sScoreTeams[4] = { - _("SCORE_TITLE_SPECTATOR"), - _("SCORE_TITLE_T"), - _("SCORE_TITLE_CT"), - _("SCORE_TITLE_VIP"), -}; - -/* -==================== -VGUI_Scores_DrawTeam -==================== -*/ -vector VGUI_Scores_DrawTeam( vector vPos, float fTeam ) { - - vector vColor; - // Preserve the old vector so we can draw the amount of players per team later on - vector vNewPos = vPos; - - int iPlayerCount = 0; - - vNewPos += '0 32'; - - // Player loop, this one goes through ALL players but only prints the one from fTeam - for ( int i = -1; i > -32; i-- ) { - if ( stof( getplayerkeyvalue( i, "*team" ) ) == fTeam ) { - if ( getplayerkeyvalue( i, "name" ) ) { - vColor = HUD_GetChatColor( fTeam ); - - if ( getplayerkeyvalue( i, "name" ) == getplayerkeyvalue( player_localnum, "name" ) ) { - drawfill( vNewPos + '19 -2', '493 16', vColor, VGUI_WINDOW_BGALPHA, DRAWFLAG_ADDITIVE ); - vColor = '1 1 1'; - } - - if ( getplayerkeyvalue( i, "*dead" ) == "1" ) { - CSQC_DrawText( vNewPos + '38 0', sprintf( _("SCORE_DEAD"), getplayerkeyvalue( i, "name" ) ), '12 12', vColor, 1.0f, 0, FONT_CON ); - } else if ( getplayerkeyvalue( i, "*dead" ) == "2" ) { - CSQC_DrawText( vNewPos + '38 0', sprintf( _("SCORE_VIP"), getplayerkeyvalue( i, "name" ) ), '12 12', vColor, 1.0f, 0, FONT_CON ); - } else { - CSQC_DrawText( vNewPos + '38 0', getplayerkeyvalue( i, "name" ), '12 12', vColor, 1.0f, 0, FONT_CON ); - } - - - // Spectators don't have stats worth caring about - if ( fTeam != TEAM_SPECTATOR ) { - VGUI_RightText( vNewPos + '320 0', getplayerkeyvalue( i, INFOKEY_P_FRAGS ), '12 12', vColor, FONT_CON ); - VGUI_RightText( vNewPos + '384 0', getplayerkeyvalue( i, "*deaths" ), '12 12', vColor, FONT_CON ); - } - VGUI_RightText( vNewPos + '456 0', getplayerkeyvalue( i, INFOKEY_P_PING ), '12 12', vColor, FONT_CON ); - - if ( getplayerkeyvalue( i, INFOKEY_P_VOIPSPEAKING ) == "0" ) { - VGUI_RightText( vNewPos + '508 0', "N", '12 12', '1 1 1', FONT_CON ); - } else { - VGUI_RightText( vNewPos + '508 0', "Y", '12 12', '1 1 1', FONT_CON ); - } - - vNewPos += '0 16'; - iPlayerCount++; - } - } - } - - // Reset in case it was changed - vColor = HUD_GetChatColor( fTeam ); - - // If we've got no spectators, don't draw them. - if ( ( fTeam != TEAM_SPECTATOR ) || ( fTeam == TEAM_SPECTATOR && iPlayerCount > 0 ) ) { - // The name/title of the team - CSQC_DrawText( vPos + '24 0', sScoreTeams[ fTeam ], '12 12', vColor, 1.0f, 0, FONT_CON ); - drawfill( vPos + '19 24', '493 1', vColor, 1.0f ); - - // Draw the amount of rounds we've von - if ( fTeam == TEAM_CT ) { - VGUI_RightText( vPos + '320 0', sprintf( "%i", getstati( STAT_WON_CT ) ), '12 12', vColor, FONT_CON ); - } else if ( fTeam == TEAM_T ) { - VGUI_RightText( vPos + '320 0', sprintf( "%i", getstati( STAT_WON_T ) ), '12 12', vColor, FONT_CON ); - } - - // Now we know the playercount, so let's calculate the position next to the Teamname String and print it - vector vCountPos = vPos + '24 6'; - vCountPos[0] += stringwidth( sScoreTeams[ fTeam ], FALSE, '12 12' ) + 8; - CSQC_DrawText( vCountPos, sprintf( _("SCORE_PLAYERS"), iPlayerCount ), '12 12', vColor, 1.0f, 0, FONT_CON ); - } - return vNewPos + '0 24'; -} - -/* -==================== -VGUI_Scores_Show -==================== -*/ -void VGUI_Scores_Show( void ) { - vector vMainPos; - vector vSize; - - vSize[0] = 540; - vSize[1] = video_res[1] - 112; - - vMainPos = video_mins; - vMainPos[0] += ( video_res[0] / 2 ) - (vSize[0] / 2); - vMainPos[1] += 56; - - // Draw the background - drawfill( vMainPos, vSize, VGUI_WINDOW_BGCOLOR, VGUI_WINDOW_BGALPHA ); - - // Sides - drawfill( vMainPos, [vSize[0], 1], '0.35 0.35 0.35', 1.0f ); - drawfill( [vMainPos[0], vMainPos[1] + vSize[1] - 1], [vSize[0], 1], '0.35 0.35 0.35', 1.0f ); - drawfill( vMainPos, [1, vSize[1]], '0.35 0.35 0.35', 1.0f ); - drawfill( [vMainPos[0] + vSize[0] - 1, vMainPos[1]], [1, vSize[1]], '0.35 0.35 0.35', 1.0f ); - - // Server title - CSQC_DrawText( vMainPos + '24 13', serverkey( "hostname" ), '12 12', VGUI_WINDOW_FGCOLOR, 1.0f, 0, FONT_CON ); - - // Tabs like Score, Ping etc. - CSQC_DrawText( vMainPos + '280 32', _("SCORE_SCORE"), '12 12', VGUI_WINDOW_FGCOLOR, 1.0f, 0, FONT_CON ); - CSQC_DrawText( vMainPos + '336 32', _("SCORE_DEATHS"), '12 12', VGUI_WINDOW_FGCOLOR, 1.0f, 0, FONT_CON ); - CSQC_DrawText( vMainPos + '400 32', _("SCORE_LATENCY"), '12 12', VGUI_WINDOW_FGCOLOR, 1.0f, 0, FONT_CON ); - CSQC_DrawText( vMainPos + '472 32', _("SCORE_VOICE"), '12 12', VGUI_WINDOW_FGCOLOR, 1.0f, 0, FONT_CON ); - - vector vOffset = VGUI_Scores_DrawTeam( vMainPos + '0 50', TEAM_CT ); - vOffset = VGUI_Scores_DrawTeam( vOffset, TEAM_T ); - vOffset = VGUI_Scores_DrawTeam( vOffset, 0 ); -} - -void Scores_Init(void) -{ - -} - -void Scores_Draw(void) -{ - VGUI_Scores_Show(); -} - diff --git a/Source/client/cstrike/vguispectator.c b/Source/client/cstrike/vguispectator.c deleted file mode 100755 index 8e563151..00000000 --- a/Source/client/cstrike/vguispectator.c +++ /dev/null @@ -1,42 +0,0 @@ -/*** -* -* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. -* -* See the file LICENSE attached with the sources for usage details. -* -****/ - -/* -==================== -VGUI_DrawSpectatorHUD -==================== -*/ -void VGUI_DrawSpectatorHUD( void ) { - vHUDColor = autocvar_con_color * ( 1 / 255 ); - - // Draw the borders - drawfill( video_mins, [ video_res[0], 40 ], '0 0 0', 1 ); - drawfill( video_mins + [ 0, video_res[1] - 40], [ video_res[0], 40 ], '0 0 0', 1 ); - - // Draw the timer - int iMinutes, iSeconds, iTens, iUnits; - iMinutes = getstatf( STAT_GAMETIME ) / 60; - iSeconds = getstatf( STAT_GAMETIME ) - 60 * iMinutes; - iTens = iSeconds / 10; - iUnits = iSeconds - 10 * iTens; - - - drawpic( video_mins + [ video_res[0] - 70, 20 ], "gfx/vgui/640_timer", '14 14', '1 1 1', 1 ); - VGUI_RightText( video_mins + [ video_res[0] - 16, 23 ], sprintf( "%i:%i%i", iMinutes, iTens, iUnits ), '12 12', '0.56 0.56 0.21', FONT_CON ); - - // Draw the money - CSQC_DrawText( video_mins + [ video_res[0] - 67, 6 ], "$", '12 12', '0.56 0.56 0.21', 1, 0, FONT_CON ); - VGUI_RightText( video_mins + [ video_res[0] - 16, 6 ], sprintf( "%d", getstatf( STAT_MONEY ) ), '12 12', '0.56 0.56 0.21', FONT_CON ); - - // Seperator - drawfill( video_mins + [ video_res[0] - 85, 6 ], [ 2, 28 ], '0.56 0.56 0.21', 1 ); - - // Team Stats - VGUI_RightText( video_mins + [ video_res[0] - 96, 6 ], sprintf( _("VGUI_SPEC_TCOUNTER"), getstatf( STAT_WON_T ) ), '12 12', '0.56 0.56 0.21', FONT_CON ); - VGUI_RightText( video_mins + [ video_res[0] - 96, 23 ], sprintf( _("VGUI_SPEC_CTCOUNTER"), getstatf( STAT_WON_CT ) ), '12 12', '0.56 0.56 0.21', FONT_CON ); -} diff --git a/Source/client/cstrike/vguiteamselect.c b/Source/client/cstrike/vguiteamselect.c deleted file mode 100755 index ba807b29..00000000 --- a/Source/client/cstrike/vguiteamselect.c +++ /dev/null @@ -1,215 +0,0 @@ -/*** -* -* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. -* -* See the file LICENSE attached with the sources for usage details. -* -****/ - -string sClassInfo[64] = { - _("VGUI_T1_TITLE"), "gfx/vgui/640_terror", - _("VGUI_T1_TXT1"), - _("VGUI_T1_TXT2"), - _("VGUI_T1_TXT3"), - _("VGUI_T1_TXT4"), - _("VGUI_T1_TXT5"), - _("VGUI_T1_TXT6"), - - _("VGUI_T2_TITLE"), "gfx/vgui/640_leet", - _("VGUI_T2_TXT1"), - _("VGUI_T2_TXT2"), - _("VGUI_T2_TXT3"), - _("VGUI_T2_TXT4"), - _("VGUI_T2_TXT5"), - _("VGUI_T2_TXT6"), - - _("VGUI_T3_TITLE"), "gfx/vgui/640_arctic", - _("VGUI_T3_TXT1"), - _("VGUI_T3_TXT2"), - _("VGUI_T3_TXT3"), - _("VGUI_T3_TXT4"), - _("VGUI_T3_TXT5"), - _("VGUI_T3_TXT6"), - - _("VGUI_T4_TITLE"), "gfx/vgui/640_guerilla", - _("VGUI_T4_TXT1"), - _("VGUI_T4_TXT2"), - _("VGUI_T4_TXT3"), - _("VGUI_T4_TXT4"), - _("VGUI_T4_TXT5"), - _("VGUI_T4_TXT6"), - - _("VGUI_CT1_TITLE"), "gfx/vgui/640_urban", - _("VGUI_CT1_TXT1"), - _("VGUI_CT1_TXT2"), - _("VGUI_CT1_TXT3"), - _("VGUI_CT1_TXT4"), - _("VGUI_CT1_TXT5"), - _("VGUI_CT1_TXT6"), - - _("VGUI_CT2_TITLE"), "gfx/vgui/640_gsg9", - _("VGUI_CT2_TXT1"), - _("VGUI_CT2_TXT2"), - _("VGUI_CT2_TXT3"), - _("VGUI_CT2_TXT4"), - _("VGUI_CT2_TXT5"), - _("VGUI_CT2_TXT6"), - - _("VGUI_CT3_TITLE"), "gfx/vgui/640_sas", - _("VGUI_CT3_TXT1"), - _("VGUI_CT3_TXT2"), - _("VGUI_CT3_TXT3"), - _("VGUI_CT3_TXT4"), - _("VGUI_CT3_TXT5"), - _("VGUI_CT3_TXT6"), - - _("VGUI_CT4_TITLE"), "gfx/vgui/640_gign", - _("VGUI_CT4_TXT1"), - _("VGUI_CT4_TXT2"), - _("VGUI_CT4_TXT3"), - _("VGUI_CT4_TXT4"), - _("VGUI_CT4_TXT5"), - _("VGUI_CT4_TXT6") -}; - -/* -==================== -VGUI_TeamSelect_Main -==================== -*/ -void VGUI_TeamSelect_Main( vector vPos ) { - static void TeamSelect_Main_ButtonT( void ) { - pSeat->fVGUI_Display = VGUI_TEAM_T; - } - static void TeamSelect_Main_ButtonCT( void ) { - pSeat->fVGUI_Display = VGUI_TEAM_CT; - } - static void TeamSelect_Main_ButtonAuto( void ) { - int iPlayersT = 0; - int iPlayersCT = 0; - - for ( int i = 0; i < 32; i++ ) { - if ( stof( getplayerkeyvalue( i, "*team" ) ) == TEAM_T ) { - iPlayersT++; - } else if ( stof( getplayerkeyvalue( i, "*team" ) ) == TEAM_CT ) { - iPlayersCT++; - } - } - - if ( iPlayersCT > iPlayersT ) { - pSeat->fVGUI_Display = VGUI_TEAM_T; - } else { - pSeat->fVGUI_Display = VGUI_TEAM_CT; - } - } - static void TeamSelect_Main_ButtonSpectate( void ) { - sendevent( "GamePlayerSpawn", "f", 0 ); - pSeat->fVGUI_Display = VGUI_NONE; - } - static void TeamSelect_Main_Exit( void ) { - pSeat->fVGUI_Display = VGUI_NONE; - } - - VGUI_Text( sMapString[ 0 ], vPos + '16 64 0', '12 12', FONT_CON); - - vector vTextPos = vPos + '224 116 0'; - for ( int i = 1; i < 35; i++ ) { - VGUI_Text( sMapString[ i ], vTextPos, '12 12', FONT_CON ); - vTextPos[1] += 14; - } - - VGUI_Button( _("VGUI_TEAM_T"), TeamSelect_Main_ButtonT, vPos + '16 116 0', '180 24 0' ); - VGUI_Button( _("VGUI_TEAM_CT"), TeamSelect_Main_ButtonCT, vPos + '16 148 0', '180 24 0' ); - - VGUI_Button( _("VGUI_TEAM_AUTO"), TeamSelect_Main_ButtonAuto, vPos + '16 336 0', '180 24 0' ); - VGUI_Button( _("VGUI_TEAM_SPEC"), TeamSelect_Main_ButtonSpectate, vPos + '16 368 0', '180 24 0' ); - - VGUI_Button( _("VGUI_EXIT"), TeamSelect_Main_Exit, vPos + '16 440 0', '120 24 0' ); -} - -/* -==================== -VGUI_TeamSelect_Back -==================== -*/ -void VGUI_TeamSelect_Back( void ) { - pSeat->fVGUI_Display = VGUI_TEAMSELECT; -} - -/* -==================== -VGUI_TeamSelect_Button -==================== -*/ -void VGUI_TeamSelect_Button( float fNumber, void() vFunc, vector vPos, vector vSize ) { - if( VGUI_Button( sClassInfo[ 8 * fNumber ] , vFunc, vPos, vSize ) == TRUE ) { - drawpic( vVGUIWindowPos + '356 64', sClassInfo[ 8 * fNumber + 1 ], '128 256', '1 1 1', 1 ); - - VGUI_Text( sClassInfo[ 8 * fNumber + 2 ], vVGUIWindowPos + '232 336', '12 12', FONT_CON ); - VGUI_Text( sClassInfo[ 8 * fNumber + 3 ], vVGUIWindowPos + '232 346', '12 12', FONT_CON ); - VGUI_Text( sClassInfo[ 8 * fNumber + 4 ], vVGUIWindowPos + '232 356', '12 12', FONT_CON ); - VGUI_Text( sClassInfo[ 8 * fNumber + 5 ], vVGUIWindowPos + '232 366', '12 12', FONT_CON ); - VGUI_Text( sClassInfo[ 8 * fNumber + 6 ], vVGUIWindowPos + '232 376', '12 12', FONT_CON ); - VGUI_Text( sClassInfo[ 8 * fNumber + 7 ], vVGUIWindowPos + '232 386', '12 12', FONT_CON ); - } -} - -/* -==================== -VGUI_TeamSelect_T -==================== -*/ -void VGUI_TeamSelect_T( vector vPos ) { - static void TeamSelect_T1( void ) { - sendevent( "GamePlayerSpawn", "f", 1 ); - pSeat->fVGUI_Display = VGUI_NONE; - } - static void TeamSelect_T2( void ) { - sendevent( "GamePlayerSpawn", "f", 2 ); - pSeat->fVGUI_Display = VGUI_NONE; - } - static void TeamSelect_T3( void ) { - sendevent( "GamePlayerSpawn", "f", 3 ); - pSeat->fVGUI_Display = VGUI_NONE; - } - static void TeamSelect_T4( void ) { - sendevent( "GamePlayerSpawn", "f", 4 ); - pSeat->fVGUI_Display = VGUI_NONE; - } - - VGUI_TeamSelect_Button( 0, TeamSelect_T1, vPos + '16 160 0', '180 24 0' ); - VGUI_TeamSelect_Button( 1, TeamSelect_T2, vPos + '16 192 0', '180 24 0' ); - VGUI_TeamSelect_Button( 2, TeamSelect_T3, vPos + '16 224 0', '180 24 0' ); - VGUI_TeamSelect_Button( 3, TeamSelect_T4, vPos + '16 256 0', '180 24 0' ); - VGUI_Button( _("VGUI_BACK"), VGUI_TeamSelect_Back, vPos + '16 440 0', '120 24 0' ); -} - -/* -==================== -VGUI_TeamSelect_CT -==================== -*/ -void VGUI_TeamSelect_CT ( vector vPos ) { - static void TeamSelect_CT1( void ) { - sendevent( "GamePlayerSpawn", "f", 5 ); - pSeat->fVGUI_Display = VGUI_NONE; - } - static void TeamSelect_CT2( void ) { - sendevent( "GamePlayerSpawn", "f", 6 ); - pSeat->fVGUI_Display = VGUI_NONE; - } - static void TeamSelect_CT3( void ) { - sendevent( "GamePlayerSpawn", "f", 7 ); - pSeat->fVGUI_Display = VGUI_NONE; - } - static void TeamSelect_CT4( void ) { - sendevent( "GamePlayerSpawn", "f", 8 ); - pSeat->fVGUI_Display = VGUI_NONE; - } - - VGUI_TeamSelect_Button( 4, TeamSelect_CT1, vPos + '16 160 0', '180 24 0' ); - VGUI_TeamSelect_Button( 5, TeamSelect_CT2, vPos + '16 192 0', '180 24 0' ); - VGUI_TeamSelect_Button( 6, TeamSelect_CT3, vPos + '16 224 0', '180 24 0' ); - VGUI_TeamSelect_Button( 7, TeamSelect_CT4, vPos + '16 256 0', '180 24 0' ); - VGUI_Button( _("VGUI_BACK"), VGUI_TeamSelect_Back, vPos + '16 440 0', '120 24 0' ); -} diff --git a/Source/client/entry.c b/Source/client/entry.c index 257babcc..8af96071 100644 --- a/Source/client/entry.c +++ b/Source/client/entry.c @@ -83,9 +83,18 @@ void CSQC_Init(float apilevel, string enginename, float engineversion) Effects_Init(); precache_sound("misc/talk.wav"); + precache_sound("common/wpn_hudon.wav"); + precache_sound("common/wpn_hudoff.wav"); + precache_sound("common/wpn_moveselect.wav"); + precache_sound("common/wpn_select.wav"); + + /* VGUI */ + VGUI_Init(); + /* Game specific inits */ HUD_Init(); - Scores_Init(); + + //Scores_Init(); Client_Init(apilevel, enginename, engineversion); DSP_Init(); } @@ -126,7 +135,6 @@ void CSQC_UpdateView(float w, float h, float focus) for (s = seats.length; s-- > numclientseats;) { pSeat = &seats[s]; - pSeat->fVGUI_Display = VGUI_MOTD; pSeat->ePlayer = world; } @@ -241,12 +249,12 @@ void CSQC_UpdateView(float w, float h, float focus) #endif View_PostDraw(); - if(focus == TRUE) { + if (focus == TRUE) { GameText_Draw(); // The spectator sees things... differently if (getplayerkeyvalue(player_localnum, "*spec") != "0") { - VGUI_DrawSpectatorHUD(); + //VGUI_DrawSpectatorHUD(); } else { HUD_Draw(); } @@ -258,12 +266,10 @@ void CSQC_UpdateView(float w, float h, float focus) // Don't even try to draw centerprints and VGUI menus when scores are shown if (pSeat->iShowScores == TRUE) { - Scores_Draw(); + //Scores_Draw(); } else { CSQC_DrawCenterprint(); -#ifdef CSTRIKE - needcursor |= CSQC_VGUI_Draw(); -#endif + needcursor |= VGUI_Draw(); } } @@ -337,6 +343,8 @@ float CSQC_InputEvent(float fEventType, float fKey, float fCharacter, float fDev default: return TRUE; } + + VGUI_Input(fEventType, fKey, fCharacter, fDeviceID); return FALSE; } @@ -354,9 +362,7 @@ void CSQC_Input_Frame(void) // If we are inside a VGUI, don't let the client do stuff outside - if ((pSeat->fVGUI_Display != VGUI_NONE)) { - pSeat->fInputSendNext = time + 0.2; - } else if ((pSeat->fHUDWeaponSelected) && (input_buttons & INPUT_BUTTON0)) { + if ((pSeat->fHUDWeaponSelected) && (input_buttons & INPUT_BUTTON0)) { HUD_DrawWeaponSelect_Trigger(); input_buttons = 0; pSeat->fInputSendNext = time + 0.2; diff --git a/Source/client/rewolf.src b/Source/client/rewolf.src index e23b9305..80ec5e45 100755 --- a/Source/client/rewolf.src +++ b/Source/client/rewolf.src @@ -14,7 +14,8 @@ ../entities.h valve/defs.h defs.h -vgui.h + +../vgui/include.src util.c rewolf/init.c @@ -66,6 +67,9 @@ valve/view.c view.c damage.c chat.c + +vgui.cpp + rewolf/hud.c valve/hud_weaponselect.c valve/scoreboard.c diff --git a/Source/client/scihunt.src b/Source/client/scihunt.src index 26d51b13..36fb24ea 100644 --- a/Source/client/scihunt.src +++ b/Source/client/scihunt.src @@ -13,7 +13,8 @@ ../entities.h valve/defs.h defs.h -vgui.h + +../vgui/include.src util.c scihunt/init.c @@ -67,6 +68,9 @@ valve/view.c view.c damage.c chat.c + +vgui.cpp + valve/hud.c valve/hud_weaponselect.c valve/scoreboard.c diff --git a/Source/client/scihunt/init.c b/Source/client/scihunt/init.c index 4f88c33f..c125964a 100644 --- a/Source/client/scihunt/init.c +++ b/Source/client/scihunt/init.c @@ -6,11 +6,7 @@ * ****/ -/* FIXME: Remove this once the builtin exists */ -float getchannellevel(entity foo, float chanid) -{ - return bound(0, cos(time), 1) * 100; -} +float(entity foo, float chanid) getchannellevel = #0; /* This really shouldn't be here, but it'll be fine for the time being */ .int initedsci; diff --git a/Source/client/sound.c b/Source/client/sound.c index 57a83adf..349a338c 100644 --- a/Source/client/sound.c +++ b/Source/client/sound.c @@ -6,49 +6,49 @@ * ****/ +var int g_voxcount; +var int g_voxpos; +var float g_voxtime = 0.0f; + typedef struct { - string sSample; - float fLength; + string sample; + float len; } sound_t; -sound_t *sndVOX; -var int iVOXCount; -var int iVOXPos; -var float fSampleTime = 0.0f; +sound_t *g_voxque; void Sound_PlayVOX(string msg) { - if (iVOXCount) { + if (g_voxcount) { return; } - - iVOXCount = tokenize(msg); - sndVOX = memalloc(sizeof(sound_t) * iVOXCount); - - for (int i = 0; i < iVOXCount; i++) { - sndVOX[i].sSample = sprintf("vox/%s.wav", argv(i)); - sndVOX[i].fLength = soundlength(sndVOX[i].sSample); + + g_voxcount = tokenize(msg); + g_voxque = memalloc(sizeof(sound_t) * g_voxcount); + + for (int i = 0; i < g_voxcount; i++) { + g_voxque[i].sample = sprintf("vox/%s.wav", argv(i)); + g_voxque[i].len = soundlength(g_voxque[i].sample); } - fSampleTime = time; + g_voxtime = time; } void Sound_ProcessWordQue(void) { - if (cltime < 2) { + if (cltime < 2 || !g_voxcount) { return; } - if (iVOXCount) { - if (fSampleTime < time) { - localcmd(sprintf("play %s\n", sndVOX[ iVOXPos ].sSample)); - iVOXPos++; - - if (iVOXPos == iVOXCount) { - memfree(sndVOX); - iVOXCount = 0; - iVOXPos = 0; - } else { - fSampleTime = time + sndVOX[ iVOXPos - 1 ].fLength; - } + + if (g_voxtime < time) { + localcmd(sprintf("play %s\n", g_voxque[g_voxpos].sample)); + g_voxpos++; + + if (g_voxpos == g_voxcount) { + memfree(g_voxque); + g_voxcount = 0; + g_voxpos = 0; + } else { + g_voxtime = time + g_voxque[g_voxpos - 1].len; } } } diff --git a/Source/client/valve.src b/Source/client/valve.src index 819b0b2a..3a4243c7 100755 --- a/Source/client/valve.src +++ b/Source/client/valve.src @@ -13,7 +13,8 @@ ../entities.h valve/defs.h defs.h -vgui.h + +../vgui/include.src util.c valve/init.c @@ -63,6 +64,9 @@ valve/view.c view.c damage.c chat.c + +vgui.cpp + valve/hud.c valve/hud_weaponselect.c valve/scoreboard.c diff --git a/Source/client/valve/hud_weaponselect.c b/Source/client/valve/hud_weaponselect.c index a0b30cb1..d262a3a1 100644 --- a/Source/client/valve/hud_weaponselect.c +++ b/Source/client/valve/hud_weaponselect.c @@ -6,7 +6,8 @@ * ****/ -vector vHUDSlotNumPos[6] = { +vector vHUDSlotNumPos[6] = +{ [168 / 255,72 / 128], [188 / 255,72 / 128], [208 / 255,72 / 128], @@ -18,11 +19,11 @@ vector vHUDSlotNumPos[6] = { void HUD_DrawWeaponSelect_Forward(void) { player pl = (player)pSeat->ePlayer; - + if (!pl.activeweapon) { return; } - + if (pSeat->fHUDWeaponSelectTime < time) { pSeat->fHUDWeaponSelected = pl.activeweapon; sound(pSeat->ePlayer, CHAN_ITEM, "common/wpn_hudon.wav", 0.5, ATTN_NONE); @@ -35,7 +36,7 @@ void HUD_DrawWeaponSelect_Forward(void) } pSeat->fHUDWeaponSelectTime = time + 3; - + if (!(pl.g_items & g_weapons[pSeat->fHUDWeaponSelected].id)) { HUD_DrawWeaponSelect_Forward(); } @@ -84,7 +85,7 @@ void HUD_DrawWeaponSelect_Num(vector vPos, float fValue) drawsubpic(vPos, [20,20], "sprites/640hud7.spr_0.tga", vHUDSlotNumPos[fValue], [20/255, 20/128], g_hud_color, 1, DRAWFLAG_ADDITIVE); } -int Weapon_InSlotPos(int slot, int pos) +int HUD_InSlotPos(int slot, int pos) { player pl = (player)pSeat->ePlayer; for (int i = 1; i < g_weapons.length; i++) { @@ -98,6 +99,7 @@ int Weapon_InSlotPos(int slot, int pos) } return -1; } + void HUD_DrawWeaponSelect(void) { player pl = (player)pSeat->ePlayer; @@ -112,41 +114,40 @@ void HUD_DrawWeaponSelect(void) return; } - vector vSelectPos = video_mins + [16,16]; + vector vecPos = video_mins + [16,16]; + int b; int wantslot = g_weapons[pSeat->fHUDWeaponSelected].slot; int wantpos = g_weapons[pSeat->fHUDWeaponSelected].slot_pos; - int b; for (int i = 0; i < 5; i++) { int slot_selected = 0; - vSelectPos[1] = video_mins[1] + 16; - HUD_DrawWeaponSelect_Num(vSelectPos, i); - vSelectPos[1] += 20; + vecPos[1] = video_mins[1] + 16; + HUD_DrawWeaponSelect_Num(vecPos, i); + vecPos[1] += 20; for (int x = 0; x < 32; x++) { if (i == wantslot) { slot_selected = TRUE; if (x == wantpos) { // Selected Sprite - Weapons_HUDPic(pSeat->fHUDWeaponSelected, 1, vSelectPos); - drawsubpic(vSelectPos, [170,45], "sprites/640hud3.spr_0.tga", + Weapons_HUDPic(pSeat->fHUDWeaponSelected, 1, vecPos); + drawsubpic(vecPos, [170,45], "sprites/640hud3.spr_0.tga", [0,180/256], [170/256,45/256], g_hud_color, 1, DRAWFLAG_ADDITIVE); - vSelectPos[1] += 50; - } else if ((b=Weapon_InSlotPos(i, x)) != -1) { + vecPos[1] += 50; + } else if ((b=HUD_InSlotPos(i, x)) != -1) { // Unselected Sprite - Weapons_HUDPic(b, 0, vSelectPos); - vSelectPos[1] += 50; + Weapons_HUDPic(b, 0, vecPos); + vecPos[1] += 50; } - } else if (Weapon_InSlotPos(i, x) != -1) { - HUD_DrawWeaponSelect_Num(vSelectPos, 5); - vSelectPos[1] += 25; + } else if (HUD_InSlotPos(i, x) != -1) { + HUD_DrawWeaponSelect_Num(vecPos, 5); + vecPos[1] += 25; } } - + if (slot_selected == TRUE) { - vSelectPos[0] += 175; + vecPos[0] += 175; } else { - vSelectPos[0] += 25; + vecPos[0] += 25; } } } - diff --git a/Source/client/vgui.cpp b/Source/client/vgui.cpp new file mode 100644 index 00000000..9e32a691 --- /dev/null +++ b/Source/client/vgui.cpp @@ -0,0 +1,27 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +CUIWidget g_uiDesktop; + +void VGUI_Init(void) +{ + g_uiDesktop = spawn( CUIWidget ); + g_uiDesktop.FlagAdd( 1 ); +} + +int VGUI_Draw(void) +{ + g_uiDesktop.Draw(); + return 1; +} + +int VGUI_Input(float flEvType, float flScanX, float flCharY, float flDevID) +{ + g_uiDesktop.Input( flEvType, flScanX, flCharY, flDevID ); + return 1; +} diff --git a/Source/client/vgui.h b/Source/client/vgui.h deleted file mode 100755 index c5430ce5..00000000 --- a/Source/client/vgui.h +++ /dev/null @@ -1,54 +0,0 @@ -/*** -* -* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. -* -* See the file LICENSE attached with the sources for usage details. -* -****/ - -#define VGUI_WINDOW_BGCOLOR '0.0 0.0 0.0' -#define VGUI_WINDOW_FGCOLOR '1.0 0.5 0.0' -#define VGUI_WINDOW_BGALPHA 0.8 -#define VGUI_WINDOW_FGALPHA 1.0 - -enum { - VGUI_NONE = 0, - VGUI_MOTD, - VGUI_TEAMSELECT, - VGUI_TEAM_T, - VGUI_TEAM_CT, - VGUI_BM_MAIN, - VGUI_BM_HANDGUNS, - VGUI_BM_SHOTGUNS, - VGUI_BM_SMG, - VGUI_BM_RIFLES, - VGUI_BM_MGS, - VGUI_BM_EQUIPMENT, - VGUI_RADIO1, - VGUI_RADIO2, - VGUI_RADIO3 -}; - -vector vVGUIWindowPos; -vector vVGUIButtonPos; - -string sMOTDString[25]; -string sMapString[35]; - -var int iVGUIKey; - -typedef struct { - string sTitle; - void( vector vPos ) vDraw; -} vguiwindow_t; - -typedef struct { - string sName; - string sImage; -} vguiweaponobject_t; - -typedef struct { - float fID; - string sName; - string sImage; -} vguiequipobject_t; diff --git a/Source/events.h b/Source/events.h index 2defda6a..b521fa48 100644 --- a/Source/events.h +++ b/Source/events.h @@ -1,3 +1,10 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ // Network Events enum { diff --git a/Source/gs-entbase/client.src b/Source/gs-entbase/client.src index eb91c12e..7ff06e79 100644 --- a/Source/gs-entbase/client.src +++ b/Source/gs-entbase/client.src @@ -1,4 +1,5 @@ #includelist +../gs-entbase/materials.h ../gs-entbase/client/sky.c ../gs-entbase/client/baseentity.cpp ../gs-entbase/client/fade.cpp diff --git a/Source/gs-entbase/materials.h b/Source/gs-entbase/materials.h new file mode 100644 index 00000000..2d7c51a6 --- /dev/null +++ b/Source/gs-entbase/materials.h @@ -0,0 +1,22 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +// Submodel materials +enum +{ + MATERIAL_GLASS, + MATERIAL_WOOD, + MATERIAL_METAL, + MATERIAL_FLESH, + MATERIAL_CINDER, + MATERIAL_TILE, + MATERIAL_COMPUTER, + MATERIAL_GLASS_UNBREAKABLE, + MATERIAL_ROCK, + MATERIAL_NONE +}; diff --git a/Source/gs-entbase/server.src b/Source/gs-entbase/server.src index 6e3276e1..f7d6dc3e 100644 --- a/Source/gs-entbase/server.src +++ b/Source/gs-entbase/server.src @@ -1,4 +1,5 @@ #includelist +../gs-entbase/materials.h ../gs-entbase/server/defs.h ../gs-entbase/server/baseentity.cpp ../gs-entbase/server/basetrigger.cpp diff --git a/Source/gs-entbase/server/env_fog_controller.cpp b/Source/gs-entbase/server/env_fog_controller.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Source/materials.h b/Source/materials.h index 60a43214..5d2dd579 100644 --- a/Source/materials.h +++ b/Source/materials.h @@ -6,21 +6,6 @@ * ****/ -// Submodel materials -enum -{ - MATERIAL_GLASS, - MATERIAL_WOOD, - MATERIAL_METAL, - MATERIAL_FLESH, - MATERIAL_CINDER, - MATERIAL_TILE, - MATERIAL_COMPUTER, - MATERIAL_GLASS_UNBREAKABLE, - MATERIAL_ROCK, - MATERIAL_NONE -}; - // Impact types enum { diff --git a/Source/menu-fn/progs.src b/Source/menu-fn/progs.src index 06114de8..851f43b1 100644 --- a/Source/menu-fn/progs.src +++ b/Source/menu-fn/progs.src @@ -1,6 +1,5 @@ #pragma target fte #pragma progs_dat "../../valve/data.pk3dir/menu.dat" - #define MENU #includelist diff --git a/Source/server/cstrike/main.c b/Source/server/cstrike/main.c index 6413805c..84caa6b2 100644 --- a/Source/server/cstrike/main.c +++ b/Source/server/cstrike/main.c @@ -54,7 +54,7 @@ void Game_ParseClientCommand(string sCommand) } } return; - } + } } else { if (argv(0) == "say") { localcmd(sprintf("echo [DEAD] %s: %s\n", self.netname, argv(1))); diff --git a/Source/shared/cstrike/weaponc4bomb.c b/Source/shared/cstrike/weaponc4bomb.c index 0ba171b4..b2eb0126 100755 --- a/Source/shared/cstrike/weaponc4bomb.c +++ b/Source/shared/cstrike/weaponc4bomb.c @@ -208,7 +208,15 @@ void WeaponC4BOMB_PrimaryFire( void ) { source = self.origin + self.view_ofs; makevectors( self.v_angle ); other = world; - traceline( source, source + ( v_forward * 64 ), MOVE_OTHERONLY, self ); + + /* Threshold */ + float vel = vlen(self.velocity); + if (!(self.flags & FL_ONGROUND) || vel > 5) { + WeaponC4BOMB_Release(); + return; + } + + traceline( source, source + [0,0,-64], MOVE_OTHERONLY, self ); // If we aren't aiming at a place or look in the wrong location... stop it if ( trace_fraction == 1 || self.fInBombZone == FALSE ) { @@ -232,6 +240,13 @@ void WeaponC4BOMB_PrimaryFire( void ) { WeaponC4BOMB_Drop( trace_endpos, trace_plane_normal ); } #else + /* Threshold */ + float vel = vlen(self.velocity); + if (!(self.flags & FL_ONGROUND) || vel > 5) { + WeaponC4BOMB_Release(); + return; + } + View_PlayAnimation( ANIM_C4_ENTERCODE ); #endif } diff --git a/Source/shared/spraylogo.cpp b/Source/shared/spraylogo.cpp index ea88e06e..2b58e822 100644 --- a/Source/shared/spraylogo.cpp +++ b/Source/shared/spraylogo.cpp @@ -99,7 +99,7 @@ float CSpraylogo::predraw(void) getplayerkeyvalue(m_iOwnerID, "name"))); shaderforname(m_strLogoname, - sprintf("{\ncull disable\npolygonOffset\n{\nmap $rt:%s\nblendFunc add}\n}\n", + sprintf("{\ncull disable\npolygonOffset\n{\nmap $rt:%s\nblendFunc add\n}\n}", m_strLogopath)); } else { makevectors(m_vecAngles); @@ -123,9 +123,9 @@ void Spraylogo_Parse(void) spSelf.m_vecAngles[2] = readcoord(); spSelf.m_iInitialized = FALSE; spSelf.m_iOwnerID = readentitynum() - 1; - spSelf.m_strLogoname = sprintf("spray_%s", - getplayerkeyvalue(spSelf.m_iOwnerID, "name")); - spSelf.m_strLogopath = sprintf("simg_%s", - getplayerkeyvalue(spSelf.m_iOwnerID, "name")); + spSelf.m_strLogoname = sprintf("spray_%i", + spSelf.m_iOwnerID); + spSelf.m_strLogopath = sprintf("simg_%i", + spSelf.m_iOwnerID); } #endif diff --git a/Source/vgui/font.cpp b/Source/vgui/font.cpp new file mode 100644 index 00000000..1f370ef3 --- /dev/null +++ b/Source/vgui/font.cpp @@ -0,0 +1,80 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + AF_RIGHT, + AF_TOP, + AF_LEFT, + AF_BOTTOM +}; + +typedef struct +{ + int iID; + int iScale; + vector vecColor; + float flAlpha; + int iFlags; +} font_s; + +void Font_Load ( string strFile, font_s &fntNew ) +{ + string strTemp; + string strFontPath; + filestream fileFont = fopen( strFile, FILE_READ ); + + fntNew.iID = FONT_DEFAULT; + fntNew.iScale = 8; + fntNew.vecColor = '1 1 1'; + fntNew.flAlpha = 1.0f; + fntNew.iFlags = 0; + + if ( fileFont >= 0 ) { + while ( ( strTemp = fgets( fileFont ) ) ) { + if ( tokenizebyseparator( strTemp, "=" ) == 2 ) { + switch ( argv( 0 ) ) { + case "COLOR": + fntNew.vecColor = stov( argv( 1 ) ) / 255; + break; + case "ALPHA": + fntNew.flAlpha = stof( argv( 1 ) ) / 255; + break; + case "SIZE": + fntNew.iScale = (int)stof( argv( 1 ) ); + break; + case "PATH": + strFontPath = argv( 1 ); + break; + case "FLAGS": + fntNew.iFlags = (int)stof( argv( 1 ) ); + break; + default: + break; + } + } + } + fclose( fileFont ); + } else { + error( sprintf( "[MENU] Cannot load font file %s!", strFile ) ); + } + + fntNew.iID = (int)loadfont( "", strFontPath, ftos( (float)fntNew.iScale ), -1, 0, 0 ); +} + +void Font_DrawText ( vector vecOrigin, string strText, font_s fnt ) +{ + drawfont = (float)fnt.iID; + drawstring( vecOrigin, strText, [ fnt.iScale, fnt.iScale ], fnt.vecColor, fnt.flAlpha, (float)fnt.iFlags ); +} + +void Font_DrawField ( vector vecOrigin, vector vecSize, string strText, font_s fnt, int iAlignFlags ) +{ + drawfont = (float)fnt.iID; + drawtextfield( vecOrigin, vecSize, (float)iAlignFlags, strText ); +} diff --git a/Source/vgui/include.src b/Source/vgui/include.src new file mode 100644 index 00000000..4e1b919b --- /dev/null +++ b/Source/vgui/include.src @@ -0,0 +1,17 @@ +#includelist +../vgui/font.cpp +../vgui/ui.cpp +../vgui/ui_button.cpp +../vgui/ui_menubutton.cpp +../vgui/ui_radio.cpp +../vgui/ui_checkbox.cpp +../vgui/ui_window.cpp +../vgui/ui_label.cpp +../vgui/ui_pic.cpp +../vgui/ui_3dview.cpp +../vgui/ui_scrollbar.cpp +../vgui/ui_list.cpp +../vgui/ui_listbox.cpp +../vgui/ui_textbox.cpp +../vgui/ui_tabview.cpp +#endlist diff --git a/Source/vgui/ui.cpp b/Source/vgui/ui.cpp new file mode 100644 index 00000000..e49ef37f --- /dev/null +++ b/Source/vgui/ui.cpp @@ -0,0 +1,143 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +font_s g_fntDefault; + +#if 0 + var vector UI_MAINCOLOR; + var float UI_MAINALPHA; +#else + #define UI_MAINCOLOR '76 88 68' / 255 + #define UI_MAINALPHA 255 +#endif + +int Util_MouseAbove(vector vecMousePos, vector vecPos, vector vecSize) +{ + if (vecMousePos[0] >= vecPos[0] && vecMousePos[0] <= vecPos[0] + vecSize[0]) { + if (vecMousePos[1] >= vecPos[1] && vecMousePos[1] <= vecPos[1] + vecSize[1]) { + return 1; + } + } + return 0; +} + +class CUIWidget +{ + vector m_vecOrigin; + CUIWidget m_next; + CUIWidget m_parent; + int m_iFlags; + + virtual void( CUIWidget ) Add; + virtual void( int ) FlagAdd; + virtual void( int ) FlagRemove; + virtual void( vector ) SetPos; + virtual vector() GetPos; + virtual int() GetPosWidth; + virtual int() GetPosHeight; + virtual void( ) Draw; + virtual void( float, float, float, float ) Input; +}; + + +void CUIWidget :: SetPos ( vector vecPos ) +{ + m_vecOrigin = vecPos; +} +vector CUIWidget :: GetPos ( void ) +{ + return m_vecOrigin; +} +int CUIWidget :: GetPosWidth ( void ) +{ + return m_vecOrigin[0]; +} +int CUIWidget :: GetPosHeight ( void ) +{ + return m_vecOrigin[1]; +} + +void CUIWidget :: FlagAdd ( int iFlag ) +{ + m_iFlags |= iFlag; +} +void CUIWidget :: FlagRemove ( int iFlag ) +{ + m_iFlags -= ( m_iFlags & iFlag ); +} + +void CUIWidget :: Add ( CUIWidget wNew ) +{ + CUIWidget wNext = this; + CUIWidget wParent; + do { + wParent = wNext; + wNext = wNext.m_next; + } while ( wNext ); + wParent.m_next = wNew; + wNew.m_parent = this; +} + +void CUIWidget :: Draw ( void ) +{ + CUIWidget wNext = this; + do { + wNext = wNext.m_next; + if ( wNext && wNext.m_iFlags & 1 && wNext.m_parent.m_iFlags & 1 ) { + wNext.Draw(); + } + } while ( wNext ); +} + +void CUIWidget :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ + CUIWidget wNext = this; + do { + wNext = wNext.m_next; + if ( wNext && wNext.m_iFlags & 1 && wNext.m_parent.m_iFlags & 1 ) { + wNext.Input( flEVType, flKey, flChar, flDevID ); + } + } while ( wNext ); +} + +void UISystem_Init ( void ) +{ + /*string strTemp; + string strUIFile = "scripts/ui_style.txt"; + filestream fileUI = fopen( strUIFile, FILE_READ ); + + UI_MAINCOLOR = '68 68 68' / 255; + UI_MAINALPHA = 1.0f; + + if ( fileUI >= 0 ) { + while ( ( strTemp = fgets( fileUI ) ) ) { + if ( tokenizebyseparator( strTemp, "=" ) == 2 ) { + switch ( argv( 0 ) ) { + case "COLOR": + UI_MAINCOLOR = stov( argv( 1 ) ) / 255; + break; + case "ALPHA": + UI_MAINALPHA = stof( argv( 1 ) ) / 255; + break; + } + } + } + fclose( fileUI ); + } else { + error( sprintf( "[MENU] Cannot load UI file %s!", strUIFile ) ); + }*/ + + Font_Load( "scripts/ui_font.txt", g_fntDefault ); + precache_pic( "textures/ui/steam/icon_radiosel" ); + precache_pic( "textures/ui/steam/icon_radiounsel" ); + precache_pic( "textures/ui/steam/icon_checked" ); + precache_pic( "textures/ui/steam/icon_emptybox" ); + precache_pic( "textures/ui/steam/icon_down" ); + precache_pic( "textures/ui/steam/icon_up" ); + precache_pic( "textures/ui/steam/icon_close" ); +} diff --git a/Source/vgui/ui_3dview.cpp b/Source/vgui/ui_3dview.cpp new file mode 100644 index 00000000..7d95a4ac --- /dev/null +++ b/Source/vgui/ui_3dview.cpp @@ -0,0 +1,106 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + VIEW_VISIBLE +}; + +class CUI3DView : CUIWidget +{ + vector m_vecSize; + vector m_vec3DPos; + vector m_vec3DAngles; + float m_flFOV; + + void() CUI3DView; + virtual void() m_vDrawFunc = 0; + virtual void( float, float, float, float ) m_vInputFunc = 0; + virtual void() Draw; + virtual void( vector ) SetSize; + virtual vector() GetSize; + virtual void( vector ) Set3DAngles; + virtual vector() Get3DAngles; + virtual void( vector ) Set3DPos; + virtual vector() Get3DPos; + virtual void( void() ) SetDrawFunc; + virtual void( void(float, float, float, float) ) SetInputFunc; + virtual void( float, float, float, float ) Input; +}; + +void CUI3DView :: CUI3DView ( void ) +{ + m_flFOV = 90; + m_vecSize = '64 64'; + m_vec3DPos = m_vec3DAngles = '0 0 0'; + m_iFlags = VIEW_VISIBLE; +} + +void CUI3DView :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +vector CUI3DView :: GetSize ( void) +{ + return m_vecSize; +} + +void CUI3DView :: Set3DAngles ( vector vecAngles ) +{ + m_vec3DAngles = vecAngles; +} +vector CUI3DView :: Get3DAngles ( void) +{ + return m_vec3DAngles; +} + +void CUI3DView :: Set3DPos ( vector vecPos ) +{ + m_vec3DPos = vecPos; +} +vector CUI3DView :: Get3DPos ( void) +{ + return m_vec3DPos; +} + +void CUI3DView :: SetDrawFunc ( void() vFunc ) +{ + m_vDrawFunc = vFunc; +} +void CUI3DView :: SetInputFunc ( void(float, float, float, float) vFunc ) +{ + m_vInputFunc = vFunc; +} + +noref .vector origin; +noref .vector angles; +noref .vector mins; +noref .vector maxs; +noref .string model; +noref .float frame, frame2, lerpfrac, renderflags, frame1time; + +void CUI3DView :: Draw ( void ) +{ + if ( m_vDrawFunc ) { + clearscene(); + setproperty( VF_VIEWPORT, m_vecOrigin + m_parent.m_vecOrigin, m_vecSize ); + setproperty( VF_AFOV, 90 ); + setproperty( VF_ORIGIN, m_vec3DPos ); + setproperty( VF_ANGLES, m_vec3DAngles ); + //setproperty( VF_PERSPECTIVE, 1 ); + m_vDrawFunc(); + renderscene(); + } +} + +void CUI3DView :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ + if ( m_vInputFunc ) { + m_vInputFunc( flEVType, flKey, flChar, flDevID ); + } +} diff --git a/Source/vgui/ui_button.cpp b/Source/vgui/ui_button.cpp new file mode 100644 index 00000000..12f0d74b --- /dev/null +++ b/Source/vgui/ui_button.cpp @@ -0,0 +1,128 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + BUTTON_VISIBLE, + BUTTON_HOVER, + BUTTON_DOWN, + BUTTON_LASTACTIVE +}; + +class CUIButton : CUIWidget +{ + vector m_vecColor; + float m_flAlpha; + vector m_vecSize; + string m_strTitle; + string m_strTitleActive; + string m_strIcon; + + void() CUIButton; + virtual void() m_vFunc = 0; + virtual void() Draw; + virtual void( vector ) SetSize; + virtual vector() GetSize; + virtual int() GetSizeWidth; + virtual int() GetSizeHeight; + virtual void( string ) SetTitle; + virtual void( string ) SetIcon; + virtual void( void() ) SetFunc; + virtual void( float, float, float, float ) Input; +}; + +void CUIButton :: CUIButton ( void ) +{ + m_vecColor = UI_MAINCOLOR; + m_flAlpha = 1.0f; + m_vecSize = '96 24'; + m_iFlags = BUTTON_VISIBLE; +} + +void CUIButton :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +vector CUIButton :: GetSize ( void ) +{ + return m_vecSize; +} +int CUIButton :: GetSizeWidth ( void ) +{ + return m_vecSize[0]; +} +int CUIButton :: GetSizeHeight ( void ) +{ + return m_vecSize[1]; +} + +void CUIButton :: SetTitle ( string strName ) +{ + m_strTitle = strName; + m_strTitleActive = sprintf( "^3%s", m_strTitle ); + SetSize( [ stringwidth( m_strTitle, TRUE, [ g_fntDefault.iScale, g_fntDefault.iScale ] ) + 16, 24 ] ); +} +void CUIButton :: SetIcon ( string strName ) +{ + m_strIcon = strName; +} +void CUIButton :: SetFunc ( void() vFunc ) +{ + m_vFunc = vFunc; +} + +void CUIButton :: Draw ( void ) +{ + drawfill( m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha ); + + if ( m_iFlags & BUTTON_DOWN ) { + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + } else { + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + } + + if ( m_strTitle ) { + if ( m_iFlags & BUTTON_LASTACTIVE ) { + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 8, 8 ], m_strTitleActive, g_fntDefault ); + } else { + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 8, 8 ], m_strTitle, g_fntDefault ); + } + } + if ( m_strIcon ) { + drawpic( m_parent.m_vecOrigin + m_vecOrigin + '2 2', m_strIcon, '16 16', '1 1 1', 1.0f ); + } +} + +void 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 ) ) { + //m_iFlags |= BUTTON_DOWN; + FlagAdd( BUTTON_DOWN ); + FlagAdd( BUTTON_LASTACTIVE ); + } + } + } 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_vFunc ) { + m_vFunc(); + } + } + FlagRemove( BUTTON_DOWN ); + } + } +} diff --git a/Source/vgui/ui_checkbox.cpp b/Source/vgui/ui_checkbox.cpp new file mode 100644 index 00000000..49b2e7f8 --- /dev/null +++ b/Source/vgui/ui_checkbox.cpp @@ -0,0 +1,104 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + CHECKBOX_VISIBLE, + CHECKBOX_HOVER, + CHECKBOX_DOWN, + CHECKBOX_CHECKED +}; + +class CUICheckbox : CUIWidget +{ + vector m_vecColor; + float m_flAlpha; + vector m_vecSize; + string m_strTitle; + + void() CUICheckbox; + virtual void() Draw; + virtual void( vector ) SetSize; + virtual void( string ) SetTitle; + virtual int() GetValue; + virtual void( int ) SetValue; + virtual void( float, float, float, float ) Input; +}; + +void CUICheckbox :: CUICheckbox ( void ) +{ + m_vecColor = UI_MAINCOLOR; + m_flAlpha = 1.0f; + m_vecSize = '96 18'; + m_iFlags = CHECKBOX_VISIBLE; +} + +void CUICheckbox :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +void CUICheckbox :: SetTitle ( string strName ) +{ + m_strTitle = strName; +} +int CUICheckbox :: GetValue ( void ) +{ + if ( m_iFlags & CHECKBOX_CHECKED ) { + return TRUE; + } else { + return FALSE; + } +} +void CUICheckbox :: SetValue ( int iValue ) +{ + if ( iValue == TRUE ) { + m_iFlags |= CHECKBOX_CHECKED; + } else { + m_iFlags -= ( m_iFlags & CHECKBOX_CHECKED ); + } +} + +void CUICheckbox :: Draw ( void ) +{ + drawfill( m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha ); + + if ( m_iFlags & CHECKBOX_DOWN ) { + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + } + + if ( m_iFlags & CHECKBOX_CHECKED ) { + drawpic( m_parent.m_vecOrigin + m_vecOrigin, "textures/ui/steam/icon_checked", '16 16', '1 1 1', 1.0f ); + } else { + drawpic( m_parent.m_vecOrigin + m_vecOrigin, "textures/ui/steam/icon_emptybox", '16 16', '1 1 1', 1.0f ); + } + + if ( m_strTitle ) { + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 24, 3 ], m_strTitle, g_fntDefault ); + } +} + +void CUICheckbox :: 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 ) ) { + m_iFlags |= CHECKBOX_DOWN; + } + } + } 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 ) ) { + SetValue( !GetValue() ); + } + m_iFlags -= ( m_iFlags & CHECKBOX_DOWN ); + } + } +} diff --git a/Source/vgui/ui_label.cpp b/Source/vgui/ui_label.cpp new file mode 100644 index 00000000..2b14d321 --- /dev/null +++ b/Source/vgui/ui_label.cpp @@ -0,0 +1,45 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +class CUILabel : CUIWidget +{ + vector m_vecSize; + string m_strTitle; + + void() CUILabel; + virtual void() Draw; + virtual void( vector ) SetSize; + virtual void( string ) SetTitle; + virtual void( float, float, float, float ) Input; +}; + +void CUILabel :: CUILabel ( void ) +{ + m_vecSize = '96 16'; + m_iFlags = BUTTON_VISIBLE; +} + +void CUILabel :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +void CUILabel :: SetTitle ( string strName ) +{ + m_strTitle = strName; + SetSize( [ stringwidth( m_strTitle, TRUE, [ g_fntDefault.iScale, g_fntDefault.iScale ] ), 16 ] ); +} +void CUILabel :: Draw ( void ) +{ + if ( m_strTitle ) { + Font_DrawField( m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, m_strTitle, g_fntDefault, 0 ); + } +} + +void CUILabel :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ +} diff --git a/Source/vgui/ui_list.cpp b/Source/vgui/ui_list.cpp new file mode 100644 index 00000000..de222390 --- /dev/null +++ b/Source/vgui/ui_list.cpp @@ -0,0 +1,187 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +class CUIList : CUIWidget +{ + vector m_vecSize; + string m_strTitle; + string *m_strItems; + int m_iItemCount; + int m_iSelected; + int m_iDrawOffset; + + void() CUIList; + + virtual void() m_vScrollCB = 0; + + virtual void( vector ) SetSize; + virtual void( int, int ) SetOffset; + + virtual void( int ) SetSelected; + virtual int() GetSelected; + + virtual int() GetMaxVisibleItems; + + virtual void( string ) AddItem; + virtual string( int ) GetItem; + + virtual void( int ) SetItemCount; + virtual int() GetItemCount; + + virtual void( void() ) CallOnScroll; + + virtual void() Draw; + virtual void( float, float, float, float ) Input; +}; + +void CUIList :: CUIList ( void ) +{ + m_vecSize = '96 16'; + m_iFlags = 1; + m_iSelected = -1; +} + +void CUIList :: Draw ( void ) +{ + int iMaxDisplay; + if ( !m_iItemCount ) { + return; + } + + drawfill( m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + + vector vecOffset = '8 8'; + + iMaxDisplay = bound( 0, m_iItemCount, floor( m_vecSize[1] / 20 ) ); + + drawsetcliparea( m_parent.m_vecOrigin[0] + m_vecOrigin[0],m_parent.m_vecOrigin[1] + m_vecOrigin[1], m_vecSize[0] - 1, m_vecSize[1] ); + for ( int i = m_iDrawOffset; i < iMaxDisplay + m_iDrawOffset; i++ ) { + if ( !m_strItems[i] ) { + break; + } + + if ( m_iSelected == i ) { + drawfill( m_parent.m_vecOrigin + m_vecOrigin + vecOffset + '-7 -3', [ m_vecSize[0] - 2, 18 ], '1 1 1', 0.5f ); + } else if ( i & 1 ) { + drawfill( m_parent.m_vecOrigin + m_vecOrigin + vecOffset + '-7 -3', [ m_vecSize[0] - 2, 18 ], '1 1 1', 0.1f ); + } + + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + vecOffset, m_strItems[i], g_fntDefault ); + vecOffset[1] += 20; + } + drawresetcliparea(); +} + +void CUIList :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ + int iMaxDisplay; + int iMouseOver = Util_MouseAbove( getmousepos(), 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 ] ) ) { + m_iSelected = i; + return; + } + vecOffset[1] += 20; + } + } else if ( flKey == K_MWHEELUP && iMouseOver ) { + SetOffset( m_iDrawOffset - ( iMaxDisplay / 4 ), TRUE ); + } else if ( flKey == K_MWHEELDOWN && iMouseOver ) { + SetOffset( m_iDrawOffset + ( iMaxDisplay / 4 ), TRUE ); + } + } +} + +void CUIList :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +vector CUIList :: GetSize ( void ) +{ + return m_vecSize; +} + +int CUIList :: GetMaxVisibleItems ( void ) +{ + int iMaxDisplay = bound( 0, m_iItemCount, floor( m_vecSize[1] / 20 ) ); + return m_iItemCount - iMaxDisplay; +} + +void CUIList :: SetOffset ( int iOffset, int iCallBack ) +{ + int iMaxDisplay = bound( 0, m_iItemCount, floor( m_vecSize[1] / 20 ) ); + m_iDrawOffset = bound( 0, iOffset, m_iItemCount - iMaxDisplay ); + + if ( m_vScrollCB && iCallBack ) { + m_vScrollCB(); + } +} +int CUIList :: GetOffset ( void ) +{ + return m_iDrawOffset; +} + +void CUIList :: SetItemCount ( int iCount ) +{ + if ( !m_iItemCount ) { + dprint( sprintf( "CUIList: Initialized with a maximum of %i entries\n", iCount ) ); + m_iItemCount = iCount; + m_strItems = memalloc( iCount * sizeof( string ) ); + } +} +int CUIList :: GetItemCount ( void ) +{ + return m_iItemCount; +} + +string CUIList :: GetItem ( int iIndex ) +{ + if ( m_iSelected < 0 || m_iItemCount <= 0 ) { + dprint( "CUIList: GetItem on empty/unselected list!\n" ); + return "ERROR"; + } + return m_strItems[ iIndex ]; +} + +void CUIList :: SetSelected ( int iVal ) +{ + m_iSelected = iVal; +} +int CUIList :: GetSelected ( void ) +{ + return m_iSelected; +} + +void CUIList :: AddItem ( string strItem ) +{ + if ( !m_iItemCount ) { + dprint( "CUIList: Can't add item to empty list!\n" ); + return; + } + + for ( int i = 0; i < m_iItemCount; i++ ) { + if ( !m_strItems[i] ) { + m_strItems[i] = strItem; + dprint( "CUIList: Item added\n" ); + break; + } + } +} + +void CUIList :: CallOnScroll ( void() vFunc ) +{ + m_vScrollCB = vFunc; +} diff --git a/Source/vgui/ui_listbox.cpp b/Source/vgui/ui_listbox.cpp new file mode 100644 index 00000000..1314e389 --- /dev/null +++ b/Source/vgui/ui_listbox.cpp @@ -0,0 +1,131 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +class CUIListBox : CUIWidget +{ + vector m_vecSize; + string m_strTitle; + string *m_strItems; + int m_iItemCount; + int m_iSelected; + int m_iDrawOffset; + + void() CUIListBox; + virtual void( vector ) SetSize; + virtual void( int ) SetOffset; + virtual void( string ) AddItem; + virtual void( int ) SetItemCount; + virtual string( int ) GetItem; + virtual int() GetSelected; + virtual void() Draw; + virtual void( float, float, float, float ) Input; +}; + +void CUIListBox :: CUIListBox ( void ) +{ + m_vecSize = '96 16'; + m_iFlags = 1; + m_iSelected = -1; +} + +void CUIListBox :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +void CUIListBox :: SetItemCount ( int iCount ) +{ + if ( !m_iItemCount ) { + dprint( sprintf( "CUIListBox: Initialized with a maximum of %i entries\n", iCount ) ); + m_iItemCount = iCount; + m_strItems = memalloc( iCount * sizeof( string ) ); + } +} +void CUIListBox :: SetOffset ( int iOffset ) +{ + int iMaxDisplay = bound( 0, m_iItemCount, floor( m_vecSize[1] / 20 ) ); + m_iDrawOffset = bound( 0, iOffset, m_iItemCount - iMaxDisplay ); +} + +string CUIListBox :: GetItem ( int iIndex ) +{ + return m_strItems[ iIndex ]; +} + +int CUIListBox :: GetSelected ( void ) +{ + return m_iSelected; +} + +void CUIListBox :: AddItem ( string strItem ) +{ + if ( !m_iItemCount ) { + dprint( "CUIListBox: Can't add item to empty list!\n" ); + return; + } + + for ( int i = 0; i < m_iItemCount; i++ ) { + if ( !m_strItems[i] ) { + m_strItems[i] = strItem; + dprint( "CUIListBox: Item added\n" ); + break; + } + } +} + +void CUIListBox :: Draw ( void ) +{ + int iMaxDisplay; + if ( !m_iItemCount ) { + return; + } + + drawfill( m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + + vector vecOffset = '8 8'; + + iMaxDisplay = bound( 0, m_iItemCount, floor( m_vecSize[1] / 20 ) ); + for ( int i = m_iDrawOffset; i < iMaxDisplay + m_iDrawOffset; i++ ) { + if ( !m_strItems[i] ) { + break; + } + + if ( m_iSelected == i ) { + drawfill( m_parent.m_vecOrigin + m_vecOrigin + vecOffset + '-7 -3', [ m_vecSize[0] - 2, 18 ], '1 1 1', 0.5f ); + } + + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + vecOffset, m_strItems[i], g_fntDefault ); + vecOffset[1] += 20; + } +} + +void CUIListBox :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ + int iMaxDisplay; + 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 ] ) ) { + m_iSelected = i; + return; + } + vecOffset[1] += 20; + } + } else if ( flKey == K_MWHEELUP ) { + SetOffset( --m_iDrawOffset ); + } else if ( flKey == K_MWHEELDOWN ) { + SetOffset( ++m_iDrawOffset ); + } + } +} diff --git a/Source/vgui/ui_menubutton.cpp b/Source/vgui/ui_menubutton.cpp new file mode 100644 index 00000000..0b6aba5d --- /dev/null +++ b/Source/vgui/ui_menubutton.cpp @@ -0,0 +1,132 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +#ifdef MENU +enumflags +{ + MBUTTON_VISIBLE, + MBUTTON_HOVER, + MBUTTON_DOWN, + MBUTTON_SHOWOFFLINE, + MBUTTON_SHOWSP, + MBUTTON_SHOWMP +}; + +class CUIMenuButton : CUIWidget +{ + vector m_vecColor; + float m_flAlpha; + vector m_vecSize; + string m_strTitle; + string m_strIcon; + + void() CUIMenuButton; + virtual void() m_vFunc = 0; + virtual void() Draw; + virtual void( vector ) SetSize; + virtual void( string ) SetTitle; + virtual void( string ) SetIcon; + virtual void( void() ) SetFunc; + virtual void( float, float, float, float ) Input; +}; + +void CUIMenuButton :: CUIMenuButton ( void ) +{ + m_vecColor = UI_MAINCOLOR; + m_flAlpha = 1.0f; + m_vecSize = '96 24'; + m_iFlags = MBUTTON_VISIBLE | MBUTTON_SHOWOFFLINE | MBUTTON_SHOWSP | MBUTTON_SHOWMP; +} + +void CUIMenuButton :: Draw ( void ) +{ + // If we're not ingame + if ( clientstate() != 2 ) { + if ( !( m_iFlags & MBUTTON_SHOWOFFLINE ) ) { + return; + } + } else { + if ( !( m_iFlags & MBUTTON_SHOWSP ) ) { + return; + } + } + + drawfill( m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha ); + if ( m_iFlags & MBUTTON_DOWN ) { + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + } else { + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + } + + + if ( m_strIcon ) { + drawpic( m_parent.m_vecOrigin + m_vecOrigin + [ 4, 4 ], m_strIcon, '16 16', '1 1 1', 1.0f ); + if ( m_strTitle ) { + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 26, 8 ], m_strTitle, g_fntDefault ); + } + } else { + if ( m_strTitle ) { + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 8, 8 ], m_strTitle, g_fntDefault ); + } + } +} + +void CUIMenuButton :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ + // If we're not ingame + if ( clientstate() != 2 ) { + if ( !( m_iFlags & MBUTTON_SHOWOFFLINE ) ) { + return; + } + } else { + if ( !( m_iFlags & MBUTTON_SHOWSP ) ) { + return; + } + } + + if ( flEVType == IE_KEYDOWN ) { + if ( flKey == K_MOUSE1 ) { + if ( Util_MouseAbove( getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, m_vecSize ) ) { + m_iFlags |= MBUTTON_DOWN; + } + } + } 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_vFunc ) { + m_vFunc(); + } + } + m_iFlags -= ( m_iFlags & MBUTTON_DOWN ); + } + } +} + +void CUIMenuButton :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +void CUIMenuButton :: SetTitle ( string strName ) +{ + m_strTitle = strName; +} +void CUIMenuButton :: SetIcon ( string strName ) +{ + m_strIcon = strName; +} +void CUIMenuButton :: SetFunc ( void() vFunc ) +{ + m_vFunc = vFunc; +} +#endif diff --git a/Source/vgui/ui_pic.cpp b/Source/vgui/ui_pic.cpp new file mode 100644 index 00000000..b1a63f2c --- /dev/null +++ b/Source/vgui/ui_pic.cpp @@ -0,0 +1,64 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + IMAGE_VISIBLE +}; + +class CUIPic : CUIWidget +{ + vector m_vecSize; + string m_strImage; + + void() CUIPic; + + virtual void( vector ) SetSize; + virtual vector() GetSize; + + virtual void( string ) SetImage; + virtual string() GetImage; + + virtual void() Draw; + virtual void( float, float, float, float ) Input; +}; + +void CUIPic :: CUIPic ( void ) +{ + m_vecSize = '16 16'; + m_iFlags = IMAGE_VISIBLE; +} + +void CUIPic :: Draw ( void ) +{ + if ( m_strImage ) { + drawpic( m_parent.m_vecOrigin + m_vecOrigin, m_strImage, m_vecSize, '1 1 1', 1.0f ); + } +} + +void CUIPic :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ +} + +void CUIPic :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +vector CUIPic :: GetSize ( void ) +{ + return m_vecSize; +} + +void CUIPic :: SetImage ( string strName ) +{ + m_strImage = strName; +} +string CUIPic :: GetImage ( void ) +{ + return m_strImage; +} diff --git a/Source/vgui/ui_radio.cpp b/Source/vgui/ui_radio.cpp new file mode 100644 index 00000000..b478c784 --- /dev/null +++ b/Source/vgui/ui_radio.cpp @@ -0,0 +1,113 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + RADIO_VISIBLE, + RADIO_HOVER, + RADIO_DOWN, + RADIO_ACTIVE +}; + +class CUIRadio : CUIWidget +{ + vector m_vecColor; + float m_flAlpha; + vector m_vecSize; + string m_strTitle; + virtual void() m_vFunc = 0; + + void() CUIRadio; + virtual void() Draw; + virtual void( vector ) SetSize; + virtual void( string ) SetTitle; + virtual int() GetValue; + virtual void( int ) SetValue; + virtual void( void() ) SetFunc; + virtual void( float, float, float, float ) Input; +}; + +void CUIRadio :: CUIRadio ( void ) +{ + m_vecColor = UI_MAINCOLOR; + m_flAlpha = 1.0f; + m_vecSize = '96 24'; + m_iFlags = RADIO_VISIBLE; +} + +void CUIRadio :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +void CUIRadio :: SetTitle ( string strName ) +{ + m_strTitle = strName; +} +int CUIRadio :: GetValue ( void ) +{ + if ( m_iFlags & RADIO_ACTIVE ) { + return TRUE; + } else { + return FALSE; + } +} +void CUIRadio :: SetValue ( int iValue ) +{ + if ( iValue == TRUE ) { + m_iFlags |= RADIO_ACTIVE; + } else { + m_iFlags -= ( m_iFlags & RADIO_ACTIVE ); + } +} +void CUIRadio :: SetFunc ( void() vFunc ) +{ + m_vFunc = vFunc; +} + +void CUIRadio :: Draw ( void ) +{ + drawfill( m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha ); + + if ( m_iFlags & RADIO_DOWN ) { + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + } + + if ( m_iFlags & RADIO_ACTIVE ) { + drawpic( m_parent.m_vecOrigin + m_vecOrigin, "textures/ui/steam/icon_radiosel", '16 16', '1 1 1', 1.0f ); + } else { + drawpic( m_parent.m_vecOrigin + m_vecOrigin, "textures/ui/steam/icon_radiounsel", '16 16', '1 1 1', 1.0f ); + } + + if ( m_strTitle ) { + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 24, 3 ], m_strTitle, g_fntDefault ); + } +} + +void 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 ) ) { + m_iFlags |= RADIO_DOWN; + } + } + } 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_vFunc ) { + m_vFunc(); + } + SetValue( TRUE ); + } + m_iFlags -= ( m_iFlags & RADIO_DOWN ); + } + } +} diff --git a/Source/vgui/ui_scrollbar.cpp b/Source/vgui/ui_scrollbar.cpp new file mode 100644 index 00000000..9f0f5d5d --- /dev/null +++ b/Source/vgui/ui_scrollbar.cpp @@ -0,0 +1,199 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + SCROLLBAR_VISIBLE, + SCROLLBAR_UP_DOWN, + SCROLLBAR_DN_DOWN, + SCROLLBAR_SLIDER_DOWN +}; + +class CUIScrollbar : CUIWidget +{ + vector m_vecColor; + float m_flAlpha; + + int m_iLength; + + float m_flMin; + float m_flMax; + float m_flStep; + float m_flValue; + + void() CUIScrollbar; + virtual void() m_vChangedCB = 0; + + virtual void( int ) SetLength; + virtual int() GetLength; + virtual void( float ) SetMin; + virtual float() GetMin; + virtual void( float ) SetMax; + virtual float() GetMax; + virtual void( float ) SetStep; + virtual float() GetStep; + virtual void( float, int ) SetValue; + virtual float() GetValue; + + virtual void( void() ) CallOnChange; + + virtual void( float, float, float, float ) Input; + virtual void() Draw; +}; + +void CUIScrollbar :: CUIScrollbar ( void ) +{ + m_vecColor = UI_MAINCOLOR; + m_flAlpha = 1.0f; + m_iFlags = SCROLLBAR_VISIBLE; +} + +void CUIScrollbar :: Draw ( void ) +{ + vector vecSize = [ 20, m_iLength ]; + + drawfill( m_parent.m_vecOrigin + m_vecOrigin, vecSize, '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, vecSize[1] - 1], [vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, vecSize[1] - 2], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ vecSize[0] - 1, 1], [1, vecSize[1] - 2], '1 1 1', 0.5f ); + + vector vecUpPos = m_parent.m_vecOrigin + m_vecOrigin; + vector vecDownPos = m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_iLength - 20 ]; + vector vecSliderPos = m_parent.m_vecOrigin + m_vecOrigin + [ 0, 20 ]; + + vecSliderPos[1] += ( m_iLength - 60 ) * ( m_flValue / m_flMax ); + + // Slider Button + drawfill( vecSliderPos, '20 20', m_vecColor, m_flAlpha ); + if ( m_iFlags & SCROLLBAR_SLIDER_DOWN ) { + drawfill( vecSliderPos, [20, 1], '0 0 0', 0.5f ); + drawfill( vecSliderPos + [ 0, 19], [20, 1], '1 1 1', 0.5f ); + drawfill( vecSliderPos + [ 0, 1], [1, 18], '0 0 0', 0.5f ); + drawfill( vecSliderPos + [ 19, 1], [1, 18], '1 1 1', 0.5f ); + } else { + drawfill( vecSliderPos, [20, 1], '1 1 1', 0.5f ); + drawfill( vecSliderPos + [ 0, 19], [20, 1], '0 0 0', 0.5f ); + drawfill( vecSliderPos + [ 0, 1], [1, 18], '1 1 1', 0.5f ); + drawfill( vecSliderPos + [ 19, 1], [1, 18], '0 0 0', 0.5f ); + } + + // Button UP + drawfill( vecUpPos, '20 20', m_vecColor, m_flAlpha ); + if ( m_iFlags & SCROLLBAR_UP_DOWN ) { + drawfill( vecUpPos, [20, 1], '0 0 0', 0.5f ); + drawfill( vecUpPos + [ 0, 19], [20, 1], '1 1 1', 0.5f ); + drawfill( vecUpPos + [ 0, 1], [1, 18], '0 0 0', 0.5f ); + drawfill( vecUpPos + [ 19, 1], [1, 18], '1 1 1', 0.5f ); + } else { + drawfill( vecUpPos, [20, 1], '1 1 1', 0.5f ); + drawfill( vecUpPos + [ 0, 19], [20, 1], '0 0 0', 0.5f ); + drawfill( vecUpPos + [ 0, 1], [1, 18], '1 1 1', 0.5f ); + drawfill( vecUpPos + [ 19, 1], [1, 18], '0 0 0', 0.5f ); + } + drawpic( vecUpPos + '2 2', "textures/ui/steam/icon_up", '16 16', '1 1 1', 1.0f ); + + // Button DOWN + drawfill( vecDownPos, '20 20', m_vecColor, m_flAlpha ); + if ( m_iFlags & SCROLLBAR_DN_DOWN ) { + drawfill( vecDownPos, [20, 1], '0 0 0', 0.5f ); + drawfill( vecDownPos + [ 0, 19], [20, 1], '1 1 1', 0.5f ); + drawfill( vecDownPos + [ 0, 1], [1, 18], '0 0 0', 0.5f ); + drawfill( vecDownPos + [ 19, 1], [1, 18], '1 1 1', 0.5f ); + } else { + drawfill( vecDownPos, [20, 1], '1 1 1', 0.5f ); + drawfill( vecDownPos+ [ 0, 19], [20, 1], '0 0 0', 0.5f ); + drawfill( vecDownPos + [ 0, 1], [1, 18], '1 1 1', 0.5f ); + drawfill( vecDownPos + [ 19, 1], [1, 18], '0 0 0', 0.5f ); + } + drawpic( vecDownPos + '2 2', "textures/ui/steam/icon_down", '16 16', '1 1 1', 1.0f ); +} + +void CUIScrollbar :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ + vector vecUpPos = m_parent.m_vecOrigin + m_vecOrigin; + vector vecDownPos = m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_iLength - 20 ]; + + if ( flEVType == IE_KEYDOWN ) { + if ( flKey == K_MOUSE1 ) { + if ( Util_MouseAbove( getmousepos(), vecUpPos, '20 20' ) ) { + m_iFlags |= SCROLLBAR_UP_DOWN; + } else if ( Util_MouseAbove( getmousepos(), vecDownPos, '20 20' ) ) { + m_iFlags |= SCROLLBAR_DN_DOWN; + } + } + } else if ( flEVType == IE_KEYUP ) { + if ( flKey == K_MOUSE1 ) { + if ( m_iFlags & SCROLLBAR_UP_DOWN && Util_MouseAbove( getmousepos(), vecUpPos, '20 20' ) ) { + SetValue( GetValue() - GetStep(), TRUE ); + } else if ( m_iFlags & SCROLLBAR_DN_DOWN && Util_MouseAbove( getmousepos(), 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 ] ) ) { + SetValue( GetValue() + GetStep(), TRUE ); + } else if ( flKey == K_MWHEELUP && Util_MouseAbove( getmousepos(), m_parent.m_vecOrigin + m_vecOrigin, [ 20, m_iLength ] ) ) { + SetValue( GetValue() - GetStep(), TRUE ); + } + } +} + +void CUIScrollbar :: SetLength ( int iLength ) +{ + m_iLength = iLength; +} +int CUIScrollbar :: GetLength ( void ) +{ + return m_iLength; +} + +void CUIScrollbar :: SetMin ( float flVal ) +{ + m_flMin = flVal; +} +float CUIScrollbar :: GetMin ( void ) +{ + return m_flMin; +} + +void CUIScrollbar :: SetMax ( float flVal ) +{ + m_flMax = flVal; +} +float CUIScrollbar :: GetMax ( void ) +{ + return m_flMax; +} + +void CUIScrollbar :: SetStep ( float flVal ) +{ + m_flStep = flVal; +} +float CUIScrollbar :: GetStep ( void ) +{ + return m_flStep; +} + +void CUIScrollbar :: SetValue ( float flVal, int iCallBack ) +{ + m_flValue = bound( m_flMin, flVal, m_flMax ); + + if ( m_vChangedCB && iCallBack ) { + m_vChangedCB(); + } +} +float CUIScrollbar :: GetValue ( void ) +{ + return m_flValue; +} + +void CUIScrollbar :: CallOnChange ( void() vFunc ) +{ + m_vChangedCB = vFunc; +} diff --git a/Source/vgui/ui_slider.cpp b/Source/vgui/ui_slider.cpp new file mode 100644 index 00000000..c1dd8c61 --- /dev/null +++ b/Source/vgui/ui_slider.cpp @@ -0,0 +1,73 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + SLIDER_VISIBLE, + SLIDER_HOVER, + SLIDER_DOWN, +}; + +class CUISlider : CUIWidget +{ + float m_flAlpha; + vector m_vecSize; + vector m_vecColor; + + void() CUISlider; + virtual void() Draw; + virtual void( float, float, float, float ) Input; + virtual void( vector ) SetSize; + virtual void( string ) SetTitle; +}; + +void CUISlider :: CUISlider ( void ) +{ + m_vecColor = '76 88 68' / 255; + m_flAlpha = 1.0f; + m_vecSize = '96 24'; + m_iFlags = BUTTON_VISIBLE; +} + +void CUISlider :: Draw ( void ) +{ + drawfill( m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha ); + + if ( m_iFlags & BUTTON_DOWN ) { + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + } else { + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + } + + if ( m_strTitle ) { + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 8, 8 ], m_strTitle, g_fntDefault ); + } + if ( m_strIcon ) { + drawpic( m_parent.m_vecOrigin + m_vecOrigin + '2 2', m_strIcon, '16 16', '1 1 1', 1.0f ); + } +} + +void CUISlider :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ + +} + +void CUISlider :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +void CUISlider :: SetTitle ( string strName ) +{ + m_strTitle = strName; +} diff --git a/Source/vgui/ui_tabview.cpp b/Source/vgui/ui_tabview.cpp new file mode 100644 index 00000000..58aca1d4 --- /dev/null +++ b/Source/vgui/ui_tabview.cpp @@ -0,0 +1,70 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +class CUITabView : CUIWidget +{ + vector m_vecSize; + vector m_vecOutlineSize; + vector m_vecOutlinePos; + string m_strTitle; + + void() CUITabView; + virtual void() Draw; + virtual void( vector ) SetPos; + virtual vector() GetPos; + virtual void( vector ) SetSize; + virtual vector() GetSize; + virtual void( string ) SetTitle; + virtual void( float, float, float, float ) Input; +}; + +void CUITabView :: CUITabView ( void ) +{ + m_vecSize = '96 16'; + m_iFlags = BUTTON_VISIBLE; +} + +void CUITabView :: SetPos ( vector vecSize ) +{ + m_vecOrigin = vecSize; + m_vecOutlinePos = m_vecOrigin + [ 0, 20 ]; +} +vector CUITabView :: GetPos ( void ) +{ + return m_vecOrigin; +} + +void CUITabView :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; + m_vecOutlineSize = m_vecSize - [ 0, 20 ]; +} +vector CUITabView :: GetSize ( void ) +{ + return m_vecSize; +} + +void CUITabView :: SetTitle ( string strName ) +{ + m_strTitle = strName; + SetSize( [ stringwidth( m_strTitle, TRUE, [ g_fntDefault.iScale, g_fntDefault.iScale ] ), 16 ] ); +} +void CUITabView :: Draw ( void ) +{ + + //drawfill( m_parent.m_vecOrigin + m_vecOutlinePos, [m_vecOutlineSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOutlinePos + [ 0, m_vecOutlineSize[1] - 1], [m_vecOutlineSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOutlinePos + [ 0, 1], [1, m_vecOutlineSize[1] - 2], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOutlinePos + [ m_vecOutlineSize[0] - 1, 1], [1, m_vecOutlineSize[1] - 2], '0 0 0', 0.5f ); + + //Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 8, 8 ], m_strTitle, g_fntDefault ); +} + +void CUITabView :: Input ( float flEVType, float flKey, float flChar, float flDevID ) +{ +} diff --git a/Source/vgui/ui_textbox.cpp b/Source/vgui/ui_textbox.cpp new file mode 100644 index 00000000..3280a565 --- /dev/null +++ b/Source/vgui/ui_textbox.cpp @@ -0,0 +1,106 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + TEXTBOX_VISIBLE, + TEXTBOX_HOVER, + TEXTBOX_DOWN, + TEXTBOX_FOCUS, +}; + +class CUITextBox : CUIWidget +{ + vector m_vecColor; + float m_flAlpha; + vector m_vecSize; + string m_strText; + float m_flTime; + + void() CUITextBox; + virtual void() Draw; + virtual void( vector ) SetSize; + virtual void( string ) SetText; + virtual string() GetText; + virtual void( float, float, float, float ) Input; +}; + +void CUITextBox :: CUITextBox ( void ) +{ + m_vecColor = UI_MAINCOLOR; + m_flAlpha = 1.0f; + m_vecSize = '96 24'; + m_iFlags = BUTTON_VISIBLE; +} + +void CUITextBox :: SetSize ( vector vecSize ) +{ + m_vecSize = vecSize; +} +void CUITextBox :: SetText ( string strName ) +{ + m_strText = strName; +} +string CUITextBox :: GetText ( void ) +{ + return m_strText; +} + +void CUITextBox :: Draw ( void ) +{ + drawfill( m_parent.m_vecOrigin + m_vecOrigin, m_vecSize, '0 0 0', 0.25f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin, [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + drawfill( m_parent.m_vecOrigin + m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + + m_flTime += frametime * 2; + + // blinking cursor + if ( m_iFlags & TEXTBOX_FOCUS ) { + if ( rint( m_flTime ) & 1 ) { + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 8, 8 ], sprintf( "%s|", m_strText ), g_fntDefault ); + return; + } + } + + if ( m_strText ) { + Font_DrawText( m_parent.m_vecOrigin + m_vecOrigin + [ 8, 8 ], m_strText, g_fntDefault ); + } +} + +void 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 ) ) { + m_iFlags |= TEXTBOX_DOWN; + } + break; + case K_BACKSPACE: + if ( m_iFlags & TEXTBOX_FOCUS ) { + m_strText = substring( m_strText, 0, strlen( m_strText ) - 1 ); + } + break; + default: + if ( m_iFlags & TEXTBOX_FOCUS ) { + m_strText = sprintf( "%s%s", m_strText, chr2str( flChar ) ); + } + } + } 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 ) ) { + m_iFlags |= TEXTBOX_FOCUS; + } else { + m_iFlags -= ( m_iFlags & TEXTBOX_FOCUS ); + } + m_iFlags -= ( m_iFlags & TEXTBOX_DOWN ); + } + } +} diff --git a/Source/vgui/ui_window.cpp b/Source/vgui/ui_window.cpp new file mode 100644 index 00000000..e1e96bdb --- /dev/null +++ b/Source/vgui/ui_window.cpp @@ -0,0 +1,223 @@ +/*** +* +* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved. +* +* See the file LICENSE attached with the sources for usage details. +* +****/ + +enumflags +{ + WINDOW_VISIBLE, + WINDOW_DRAGGING, + WINDOW_RESIZING, + WINDOW_CANRESIZE +}; + +class CUIWindow : CUIWidget +{ + vector m_vecOrigin; + vector m_vecColor; + float m_flAlpha; + vector m_vecSize; + vector m_vecMinSize; + vector m_vecMaxSize; + vector m_vecDragOffset; + string m_strTitle; + string m_strIcon; + + CUIButton m_btnClose; + + virtual void() m_vResizeCB = 0; + virtual void() m_vMoveCB = 0; + + void() CUIWindow; + + virtual void( string ) SetTitle; + virtual string() GetTitle; + + virtual void( string ) SetIcon; + virtual string() GetIcon; + + virtual void( vector ) SetSize; + virtual vector() GetSize; + + virtual void( vector ) SetMinSize; + virtual vector() GetMinSize; + + virtual void( vector ) SetMaxSize; + virtual vector() GetMaxSize; + + + virtual void( void() vFunc ) CallOnResize; + virtual void( void() vFunc ) CallOnMove; + + virtual void() Draw; + virtual void() Hide; + virtual void( float, float, float, float ) Input; +}; + +void CUIWindow :: CUIWindow ( void ) +{ + static void WindowButtonClose ( void ) { + m_parent.m_iFlags -= ( m_parent.m_iFlags & WINDOW_VISIBLE ); + } + m_vecColor = UI_MAINCOLOR; + m_flAlpha = 1.0f; + + m_vecMinSize = '64 64'; + m_vecMaxSize = '640 480'; // TODO: Make this the screen res + + m_strTitle = "Window"; + + SetIcon( "textures/gfx/icon" ); + + m_btnClose = spawn( CUIButton ); + m_btnClose.SetTitle( __NULL__ ); + m_btnClose.m_strIcon = "textures/ui/steam/icon_close"; + m_btnClose.SetFunc( WindowButtonClose ); + m_btnClose.SetSize( '20 20' ); + Add( m_btnClose ); + SetSize( '320 240' ); +} + +void CUIWindow :: SetTitle ( string strName ) +{ + m_strTitle = strName; +} +string CUIWindow :: GetTitle ( void ) +{ + return m_strTitle; +} + +void CUIWindow :: SetIcon ( string strName ) +{ + m_strIcon = strName; +} +string CUIWindow :: GetIcon ( void ) +{ + return m_strIcon; +} + +void CUIWindow :: SetSize ( vector vecNewSize ) +{ + m_vecSize[0] = bound( m_vecMinSize[0], vecNewSize[0], m_vecMaxSize[0] ); + m_vecSize[1] = bound( m_vecMinSize[1], vecNewSize[1], m_vecMaxSize[1] ); + m_btnClose.SetPos( [ m_vecSize[0] - 24, 4 ] ); +} +vector CUIWindow :: GetSize ( void ) +{ + return m_vecSize; +} + +void CUIWindow :: SetMinSize ( vector vecNewSize ) +{ + m_vecMinSize = vecNewSize; +} +vector CUIWindow :: GetMinSize ( void ) +{ + return m_vecMinSize; +} + +void CUIWindow :: SetMaxSize ( vector vecNewSize ) +{ + m_vecMaxSize = vecNewSize; +} +vector CUIWindow :: GetMaxSize ( void ) +{ + return m_vecMaxSize; +} + +void CUIWindow :: SetPos ( vector vecNewPos ) +{ + m_vecOrigin[0] = bound( 0, vecNewPos[0], video_res[0] - 32 ); + m_vecOrigin[1] = bound( 0, vecNewPos[1], video_res[1] - 32 ); +} +vector CUIWindow :: GetPos ( void ) +{ + return m_vecOrigin; +} + +void CUIWindow :: CallOnMove ( void() vFunc ) +{ + m_vMoveCB = vFunc; +} +void CUIWindow :: CallOnResize ( void() vFunc ) +{ + m_vResizeCB = vFunc; +} + +void CUIWindow :: Hide ( void ) +{ + m_iFlags -= ( m_iFlags & WINDOW_VISIBLE ); +} +void CUIWindow :: Show ( void ) +{ + m_iFlags |= WINDOW_VISIBLE; +} + +void CUIWindow :: Draw ( void ) +{ + drawfill( m_vecOrigin, m_vecSize, m_vecColor, m_flAlpha ); + drawfill( m_vecOrigin, [m_vecSize[0], 1], '1 1 1', 0.5f ); + drawfill( m_vecOrigin + [ 0, m_vecSize[1] - 1], [m_vecSize[0], 1], '0 0 0', 0.5f ); + drawfill( m_vecOrigin + [ 0, 1], [1, m_vecSize[1] - 2], '1 1 1', 0.5f ); + drawfill( m_vecOrigin + [ m_vecSize[0] - 1, 1], [1, m_vecSize[1] - 2], '0 0 0', 0.5f ); + + if ( m_strTitle ) { + Font_DrawText( m_vecOrigin + [ 26, 8 ], m_strTitle, g_fntDefault ); + drawpic( m_vecOrigin + [ 4, 4 ], m_strIcon, '16 16', '1 1 1', 1.0f ); + } + + if ( m_iFlags & WINDOW_CANRESIZE ) { + drawpic( m_vecOrigin + m_vecSize - '16 16', "textures/ui/steam/icon_resizer", '16 16', '1 1 1', 1.0f ); + } + +#ifdef UI_DEVELOPER + if ( m_iFlags & WINDOW_DRAGGING ) { + Font_DrawText( [ 8, video_res[1] - 18 ], sprintf( "Window Position: %d, %d\n", m_vecOrigin[0], m_vecOrigin[1] ), g_fntDefault ); + } + if ( m_iFlags & WINDOW_RESIZING ) { + Font_DrawText( [ 8, video_res[1] - 18 ], sprintf( "Window Size: %d, %d\n", m_vecSize[0], m_vecSize[1] ), g_fntDefault ); + } +#endif +} + +void 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' ) ) { + m_iFlags |= WINDOW_RESIZING; + } else if ( Util_MouseAbove( getmousepos(), m_vecOrigin, [ m_vecSize[0] - 32, 16 ] ) ) { + m_iFlags |= WINDOW_DRAGGING; + m_vecDragOffset = m_vecOrigin - getmousepos(); + } + } + } else if ( flEVType == IE_KEYUP ) { + if ( flKey == K_MOUSE1 ) { + m_iFlags -= ( m_iFlags & WINDOW_DRAGGING ); + m_iFlags -= ( m_iFlags & WINDOW_RESIZING ); + } + } + + if ( m_iFlags & WINDOW_RESIZING ) { + if ( flEVType == IE_MOUSEABS ) { + vector vNewScale = [ flKey, flChar ] - m_vecOrigin - m_vecSize; + SetSize( GetSize() + vNewScale ); + + if ( m_vResizeCB ) { + m_vResizeCB(); + } + } + } else if ( m_iFlags & WINDOW_DRAGGING ) { + if ( flEVType == IE_MOUSEABS ) { + vector vNewPos = [ flKey, flChar ] - m_vecOrigin; + SetPos( GetPos() + vNewPos + m_vecDragOffset ); + + if ( m_vMoveCB ) { + m_vMoveCB(); + } + } + } +}