naev 0.10.4
player_gui.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4
13#include "physfsrwops.h"
14
15#include "naev.h"
18#include "player_gui.h"
19
20#include "array.h"
21#include "log.h"
22#ifdef DEBUGGING
23#include "ndata.h"
24#endif /* DEBUGGING */
25#include "nstring.h"
26
27
28static char** gui_list = NULL;
36{
37 int i;
38 for (i=0; i<array_size(gui_list); i++)
39 free( gui_list[i] );
41 gui_list = NULL;
42}
43
44
48int player_guiAdd( char* name )
49{
50 char **new;
51
52 /* Name must not be NULL. */
53 if (name == NULL)
54 return -1;
55
56 /* Create new array. */
57 if (gui_list == NULL)
58 gui_list = array_create( char* );
59
60 /* Check if already exists. */
61 if (player_guiCheck(name))
62 return 1;
63
64#ifdef DEBUGGING
65 /* Make sure the GUI is vaild. */
66 SDL_RWops *rw;
67 char buf[PATH_MAX];
68 snprintf( buf, sizeof(buf), GUI_PATH"%s.lua", name );
69 rw = PHYSFSRWOPS_openRead( buf );
70 if (rw == NULL) {
71 WARN(_("GUI '%s' does not exist as a file: '%s' not found."), name, buf );
72 return -1;
73 }
74 SDL_RWclose(rw);
75#endif /* DEBUGGING */
76
77 /* Add. */
78 new = &array_grow( &gui_list );
79 new[0] = strdup(name);
80 return 0;
81}
82
83
87void player_guiRm( char* name )
88{
89 (void) name;
90 if (gui_list == NULL)
91 return;
92}
93
94
98int player_guiCheck( char* name )
99{
100 int i;
101
102 if (name == NULL)
103 return 0;
104
105 for (i=0; i<array_size(gui_list); i++)
106 if (strcmp(gui_list[i], name)==0)
107 return 1;
108
109 return 0;
110}
111
112
116char** player_guiList (void)
117{
118 return gui_list;
119}
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
static char ** gui_list
Definition: player_gui.c:28
void player_guiRm(char *name)
Removes a player GUI.
Definition: player_gui.c:87
int player_guiAdd(char *name)
Adds a gui to the player.
Definition: player_gui.c:48
char ** player_guiList(void)
Gets the list of GUIs.
Definition: player_gui.c:116
int player_guiCheck(char *name)
Check if player has a GUI.
Definition: player_gui.c:98
void player_guiCleanup(void)
Cleans up the player's GUI list.
Definition: player_gui.c:35