Skip to content

Commit

Permalink
Saber: Properly set list box selection
Browse files Browse the repository at this point in the history
  • Loading branch information
redsaurus committed Jul 2, 2020
1 parent ce011d3 commit 6ea441f
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 52 deletions.
57 changes: 57 additions & 0 deletions code/ui/ui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ static void UI_GetCharacterCvars ( void );
static void UI_UpdateSaberCvars ( void );
static void UI_GetSaberCvars ( void );
static void UI_ResetSaberCvars ( void );
static void UI_SetSaberFeeders(void);
static void UI_InitAllocForcePowers ( const char *forceName );
static void UI_AffectForcePowerLevel ( const char *forceName );
static void UI_ShowForceLevelDesc ( const char *forceName );
Expand Down Expand Up @@ -2064,6 +2065,10 @@ static qboolean UI_RunMenuScript ( const char **args )
}
}
}
else if (Q_stricmp(name, "setsaberfeeders") == 0)
{
UI_SetSaberFeeders();
}
else
{
Com_Printf("unknown UI script %s\n", name);
Expand Down Expand Up @@ -7912,7 +7917,59 @@ static void UI_GetSaberCvars ( void )
Cvar_Set ( "ui_hilt2_color_red", Cvar_VariableString ( "g_hilt2_color_red" ) );
Cvar_Set ( "ui_hilt2_color_blue", Cvar_VariableString ( "g_hilt2_color_blue" ) );
Cvar_Set ( "ui_hilt2_color_green", Cvar_VariableString ( "g_hilt2_color_green" ) );
}

static void UI_SetSaberFeeders(void)
{
const char* saber1 = Cvar_VariableString("ui_saber");
const char* saber2 = Cvar_VariableString("ui_saber2");
menuDef_t* menu;
itemDef_t* item;
menu = Menu_GetFocused(); // Get current menu

if (!menu)
return;

for (int i = 0; i < MAX_SABER_HILTS; i++) // Set first saber
{
if (saberSingleHiltInfo[i] && !Q_stricmp(saberSingleHiltInfo[i], saber1))
{
item = (itemDef_t*)Menu_FindItemByName((menuDef_t*)menu, "hiltbut");
if (item)
{
item->cursorPos = i;
}
item = (itemDef_t*)Menu_FindItemByName((menuDef_t*)menu, "hiltbut1");
if (item)
{
item->cursorPos = i;
}
break;
}

if (saberStaffHiltInfo[i] && !Q_stricmp(saberStaffHiltInfo[i], saber1))
{
item = (itemDef_t*)Menu_FindItemByName((menuDef_t*)menu, "hiltbut_staves");
if (item)
{
item->cursorPos = i;
}
break;
}
}

for (int j = 0; j < MAX_SABER_HILTS; j++) //Set second saber
{
if (saberSingleHiltInfo[j] && !Q_stricmp(saberSingleHiltInfo[j], saber2))
{
item = (itemDef_t*)Menu_FindItemByName((menuDef_t*)menu, "hiltbut2");
if (item)
{
item->cursorPos = j;
}
break;
}
}
}

static void UI_ResetSaberCvars ( void )
Expand Down
111 changes: 59 additions & 52 deletions code/ui/ui_saber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,59 @@ float UI_SaberBladeRadiusForSaber( const char *saberName, int bladeNum )
return radius;
}

void UI_SaberLoadParms( void )
{
int len, totallen, saberExtFNLen, fileCnt, i;
char *buffer, *holdChar, *marker;
char saberExtensionListBuf[2048]; // The list of file names read in

//ui.Printf( "UI Parsing *.sab saber definitions\n" );

ui_saber_parms_parsed = qtrue;
UI_CacheSaberGlowGraphics();

//set where to store the first one
totallen = 0;
marker = SaberParms;
marker[0] = '\0';

//now load in the sabers
fileCnt = ui.FS_GetFileList("ext_data/sabers", ".sab", saberExtensionListBuf, sizeof(saberExtensionListBuf) );

holdChar = saberExtensionListBuf;
for ( i = 0; i < fileCnt; i++, holdChar += saberExtFNLen + 1 )
{
saberExtFNLen = strlen( holdChar );

len = ui.FS_ReadFile( va( "ext_data/sabers/%s", holdChar), (void **) &buffer );

if ( len == -1 )
{
ui.Printf( "UI_SaberLoadParms: error reading %s\n", holdChar );
}
else
{
if ( totallen && *(marker-1) == '}' )
{//don't let it end on a } because that should be a stand-alone token
strcat( marker, " " );
totallen++;
marker++;
}
len = COM_Compress( buffer );

if ( totallen + len >= MAX_SABER_DATA_SIZE ) {
Com_Error( ERR_FATAL, "UI_SaberLoadParms: ran out of space before reading %s\n(you must make the .npc files smaller)", holdChar );
}
strcat( marker, buffer );
ui.FS_FreeFile( buffer );

totallen += len;
marker += len;
}
}
}


qboolean UI_SaberValidForPlayerInSP(const char* saberName)
{
char allowed[8] = { 0 };
Expand Down Expand Up @@ -453,6 +506,12 @@ void UI_SaberGetHiltInfo(const char* singleHilts[MAX_SABER_HILTS], const char* s
const char* token;
const char* p;

//check the sabers have been loaded
if (!ui_saber_parms_parsed)
{
UI_SaberLoadParms();
}

//go through all the loaded sabers and put the valid ones in the proper list
p = SaberParms;
COM_BeginParseSession();
Expand Down Expand Up @@ -512,58 +571,6 @@ void UI_SaberGetHiltInfo(const char* singleHilts[MAX_SABER_HILTS], const char* s
COM_EndParseSession();
}

void UI_SaberLoadParms( void )
{
int len, totallen, saberExtFNLen, fileCnt, i;
char *buffer, *holdChar, *marker;
char saberExtensionListBuf[2048]; // The list of file names read in

//ui.Printf( "UI Parsing *.sab saber definitions\n" );

ui_saber_parms_parsed = qtrue;
UI_CacheSaberGlowGraphics();

//set where to store the first one
totallen = 0;
marker = SaberParms;
marker[0] = '\0';

//now load in the sabers
fileCnt = ui.FS_GetFileList("ext_data/sabers", ".sab", saberExtensionListBuf, sizeof(saberExtensionListBuf) );

holdChar = saberExtensionListBuf;
for ( i = 0; i < fileCnt; i++, holdChar += saberExtFNLen + 1 )
{
saberExtFNLen = strlen( holdChar );

len = ui.FS_ReadFile( va( "ext_data/sabers/%s", holdChar), (void **) &buffer );

if ( len == -1 )
{
ui.Printf( "UI_SaberLoadParms: error reading %s\n", holdChar );
}
else
{
if ( totallen && *(marker-1) == '}' )
{//don't let it end on a } because that should be a stand-alone token
strcat( marker, " " );
totallen++;
marker++;
}
len = COM_Compress( buffer );

if ( totallen + len >= MAX_SABER_DATA_SIZE ) {
Com_Error( ERR_FATAL, "UI_SaberLoadParms: ran out of space before reading %s\n(you must make the .npc files smaller)", holdChar );
}
strcat( marker, buffer );
ui.FS_FreeFile( buffer );

totallen += len;
marker += len;
}
}
}

void UI_DoSFXSaber( vec3_t blade_muz, vec3_t blade_dir, float lengthMax, float radius, saber_colors_t color, saber_crystals_t crystals, int whichSaber )
{
vec3_t mid;
Expand Down

0 comments on commit 6ea441f

Please sign in to comment.