diff --git a/src/client/base/defs.h b/src/client/base/defs.h index 698af0af..e1083e80 100644 --- a/src/client/base/defs.h +++ b/src/client/base/defs.h @@ -68,6 +68,9 @@ struct int m_iHUDWeaponSelected; float m_flHUDWeaponSelectTime; + /* saturn controller */ + int m_iSaturnMenu; + /* centerprint related */ float m_flCenterprintAlpha; float m_flCenterprintTime; diff --git a/src/client/cstrike/defs.h b/src/client/cstrike/defs.h index 2da0bb80..b0448d5c 100644 --- a/src/client/cstrike/defs.h +++ b/src/client/cstrike/defs.h @@ -91,6 +91,9 @@ struct int m_iHUDWeaponSelected; float m_flHUDWeaponSelectTime; + /* saturn controller */ + int m_iSaturnMenu; + /* centerprint related */ float m_flCenterprintAlpha; float m_flCenterprintTime; diff --git a/src/client/entry.c b/src/client/entry.c index 1ebced5c..0c71993a 100644 --- a/src/client/entry.c +++ b/src/client/entry.c @@ -38,6 +38,9 @@ CSQC_Init(float apilevel, string enginename, float engineversion) registercommand("-duck"); registercommand("vote"); + registercommand("+saturn_menu"); + registercommand("-saturn_menu"); + /* Requested by Slacer */ registercommand("+zoomin"); registercommand("-zoomin"); @@ -325,7 +328,7 @@ CSQC_UpdateView(float w, float h, float focus) } Fade_Update((int)video_mins[0],(int)video_mins[1], (int)w, (int)h); - + IN_Saturn_DrawMenu(); #if 0 Cstrike_PostDraw((int)video_mins[0],(int)video_mins[1], (int)w, (int)h); #endif @@ -480,6 +483,8 @@ CSQC_Input_Frame(void) if (pSeat->m_flCameraTime > time) { /* TODO: Supress the changing of view_angles/input_angles. */ } + + IN_Saturn_InputFrame(); } @@ -733,6 +738,12 @@ CSQC_ConsoleCommand(string sCMD) case "slot10": HUD_SlotSelect(9); break; + case "+saturn_menu": + pSeat->m_iSaturnMenu = TRUE; + break; + case "-saturn_menu": + pSeat->m_iSaturnMenu = FALSE; + break; case "way_menu": Textmenu_Call("WAY_MENU"); break; diff --git a/src/client/in_saturn.c b/src/client/in_saturn.c new file mode 100644 index 00000000..45e8a749 --- /dev/null +++ b/src/client/in_saturn.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2016-2020 Marco Hladik + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* these are the key mapping for a SEGA Saturn controller in X360 mode */ +#define K_SATURN_DPAD_UP 251 +#define K_SATURN_DPAD_DOWN 252 +#define K_SATURN_DPAD_LEFT 253 +#define K_SATURN_DPAD_RIGHT 254 + +#define K_SATURN_A 190 +#define K_SATURN_B 191 +#define K_SATURN_C 197 + +#define K_SATURN_X 192 +#define K_SATURN_Y 193 +#define K_SATURN_Z 196 + +#define K_SATURN_LSHOULDER 194 +#define K_SATURN_RSHOULDER 195 + +#define K_SATURN_START 199 + +var int autocvar_in_saturnmode = FALSE; + +vector dots[12] = { + [0, 32], + [32, 32], + [32, 0], + [64, 0], + [64, 32], + [96, 32], + [96, 64], + [64, 64], + [64, 96], + [32, 96], + [32, 64], + [0, 64] +} + +void +IN_Saturn_DrawMenu(void) +{ + if (!pSeat->m_iSaturnMenu) + return; + + vector col = autocvar_con_color / 255; + vector center; + center = (g_hudmins + (g_hudres / 2)) - [48, 48]; + drawline(2, center + dots[0], center + dots[1], col, 1.0f); + drawline(2, center + dots[1], center + dots[2], col, 1.0f); + drawline(2, center + dots[2], center + dots[3], col, 1.0f); + drawline(2, center + dots[3], center + dots[4], col, 1.0f); + drawline(2, center + dots[4], center + dots[5], col, 1.0f); + drawline(2, center + dots[5], center + dots[6], col, 1.0f); + drawline(2, center + dots[6], center + dots[7], col, 1.0f); + drawline(2, center + dots[7], center + dots[8], col, 1.0f); + drawline(2, center + dots[8], center + dots[9], col, 1.0f); + drawline(2, center + dots[9], center + dots[10], col, 1.0f); + drawline(2, center + dots[10], center + dots[11], col, 1.0f); + drawline(2, center + dots[11], center + dots[0], col, 1.0f); + + string textup = "RELOAD"; + string textdown = "FLASHLIGHT"; + string textleft = "PREVIOUS ITEM"; + string textright = "NEXT ITEM"; + drawfont = FONT_CON; + center = (g_hudmins + (g_hudres / 2)); + drawstring(center + [0, -64] - [(stringwidth(textup, FALSE, [12,12]) / 2), 0], textup, [12,12], col, 1.0f, 0); + drawstring(center + [0, 64] - [(stringwidth(textdown, FALSE, [12,12]) / 2), 0], textdown, [12,12], col, 1.0f, 0); + drawstring(center + [-64, 0] - [stringwidth(textleft, FALSE, [12,12]), 0], textleft, [12,12], col, 1.0f, 0); + drawstring(center + [64, 0], textright, [12,12], col, 1.0f, 0); +} + +void +IN_Saturn_InputFrame(void) +{ + int s = (float)getproperty(VF_ACTIVESEAT); + pSeat = &g_seats[s]; + + if (!autocvar_in_saturnmode) + return; + + if (pSeat->m_iSaturnMenu) { + if (input_movevalues[0] > 0) { + localcmd("+reload;wait;wait;wait;-reload\n"); + pSeat->m_iSaturnMenu = FALSE; + } else if (input_movevalues[0] < 0) { + localcmd("impulse 100\n"); + pSeat->m_iSaturnMenu = FALSE; + } else if (input_movevalues[1] > 0) { + localcmd("invnext\n"); + pSeat->m_iSaturnMenu = FALSE; + } else if (input_movevalues[1] < 0) { + localcmd("invprev\n"); + pSeat->m_iSaturnMenu = FALSE; + } + input_movevalues = [0,0,0]; + } + + if (input_buttons & INPUT_BUTTON5) { + vector dir = input_movevalues; + dir[0] *= -0.5f; + dir[1] *= -0.5f; + input_angles += clframetime * dir; + input_movevalues = [0,0,0]; + setproperty(VF_CL_VIEWANGLES, input_angles); + } +} diff --git a/src/client/include.src b/src/client/include.src index c7abb727..01d1105f 100644 --- a/src/client/include.src +++ b/src/client/include.src @@ -20,5 +20,6 @@ textmenu.c vgui.cpp vox.c way.c +in_saturn.c entry.c #endlist diff --git a/src/client/valve/defs.h b/src/client/valve/defs.h index c25bda74..cbc28e59 100644 --- a/src/client/valve/defs.h +++ b/src/client/valve/defs.h @@ -85,6 +85,9 @@ struct int m_iHUDWeaponSelected; float m_flHUDWeaponSelectTime; + /* saturn controller */ + int m_iSaturnMenu; + /* centerprint related */ float m_flCenterprintAlpha; float m_flCenterprintTime;