naev 0.12.6
player_gui.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
10#include "physfsrwops.h"
11
12#include "naev.h"
14
15#include "player_gui.h"
16
17#include "array.h"
18#include "log.h"
19#ifdef DEBUGGING
20#include "ndata.h"
21#endif /* DEBUGGING */
22
23static char **gui_list = NULL;
24
29{
30 for ( int i = 0; i < array_size( gui_list ); i++ )
31 free( gui_list[i] );
33 gui_list = NULL;
34}
35
39int player_guiAdd( const char *name )
40{
41 char **new;
42
43 /* Name must not be NULL. */
44 if ( name == NULL )
45 return -1;
46
47 /* Create new array. */
48 if ( gui_list == NULL )
49 gui_list = array_create( char * );
50
51 /* Check if already exists. */
52 if ( player_guiCheck( name ) )
53 return 1;
54
55#ifdef DEBUGGING
56 /* Make sure the GUI is vaild. */
57 SDL_RWops *rw;
58 char buf[PATH_MAX];
59 snprintf( buf, sizeof( buf ), GUI_PATH "%s.lua", name );
60 rw = PHYSFSRWOPS_openRead( buf );
61 if ( rw == NULL ) {
62 WARN( _( "GUI '%s' does not exist as a file: '%s' not found." ), name,
63 buf );
64 return -1;
65 }
66 SDL_RWclose( rw );
67#endif /* DEBUGGING */
68
69 /* Add. */
70 new = &array_grow( &gui_list );
71 new[0] = strdup( name );
72 return 0;
73}
74
78void player_guiRm( const char *name )
79{
80 (void)name;
81 if ( gui_list == NULL )
82 return;
83}
84
88int player_guiCheck( const char *name )
89{
90 if ( name == NULL )
91 return 0;
92
93 for ( int i = 0; i < array_size( gui_list ); i++ )
94 if ( strcmp( gui_list[i], name ) == 0 )
95 return 1;
96
97 return 0;
98}
99
103const char **player_guiList( void )
104{
105 return (const char **)gui_list;
106}
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
Definition array.h:170
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:179
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
Definition array.h:122
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Definition array.h:93
Header file with generic functions and naev-specifics.
#define PATH_MAX
Definition naev.h:57
const char ** player_guiList(void)
Gets the list of GUIs.
Definition player_gui.c:103
void player_guiRm(const char *name)
Removes a player GUI.
Definition player_gui.c:78
static char ** gui_list
Definition player_gui.c:23
int player_guiAdd(const char *name)
Adds a gui to the player.
Definition player_gui.c:39
int player_guiCheck(const char *name)
Check if player has a GUI.
Definition player_gui.c:88
void player_guiCleanup(void)
Cleans up the player's GUI list.
Definition player_gui.c:28