naev 0.11.5
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"
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#include "nstring.h"
23
24static char** gui_list = NULL;
30{
31 for (int i=0; i<array_size(gui_list); i++)
32 free( gui_list[i] );
34 gui_list = NULL;
35}
36
40int player_guiAdd( const char* name )
41{
42 char **new;
43
44 /* Name must not be NULL. */
45 if (name == NULL)
46 return -1;
47
48 /* Create new array. */
49 if (gui_list == NULL)
50 gui_list = array_create( char* );
51
52 /* Check if already exists. */
53 if (player_guiCheck(name))
54 return 1;
55
56#ifdef DEBUGGING
57 /* Make sure the GUI is vaild. */
58 SDL_RWops *rw;
59 char buf[PATH_MAX];
60 snprintf( buf, sizeof(buf), GUI_PATH"%s.lua", name );
61 rw = PHYSFSRWOPS_openRead( buf );
62 if (rw == NULL) {
63 WARN(_("GUI '%s' does not exist as a file: '%s' not found."), name, 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:158
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:168
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
Definition array.h:119
#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:50
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:24
int player_guiAdd(const char *name)
Adds a gui to the player.
Definition player_gui.c:40
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:29