From 8a183c2e2271e3cb15e867e09e7fbc3297174f8f Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Wed, 9 Apr 2014 21:33:30 +0100
Subject: [PATCH] [Add] Licences are viewable through outfits menu.

---
 src/menu.c   | 40 +++++++++++++++++++++++++++++++++++++++-
 src/player.c | 10 ++++++++++
 src/player.h |  1 +
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/src/menu.c b/src/menu.c
index e441049..935b8f4 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -36,6 +36,9 @@
 #define OUTFITS_WIDTH       400   /**< Outfit menu width. */
 #define OUTFITS_HEIGHT      200   /**< Outfit menu height. */
 
+#define LICENSES_WIDTH      300   /**< Licenses menu width. */
+#define LICENSES_HEIGHT     300   /**< Licenses menu height. */
+
 #define CARGO_WIDTH         300   /**< Cargo menu width. */
 #define CARGO_HEIGHT        300   /**< Cargo menu height. */
 
@@ -45,7 +48,7 @@
 #define DEATH_WIDTH         130   /**< Death menu width. */
 #define DEATH_HEIGHT        150   /**< Death menu height. */
 
-#define OPTIONS_WIDTH       260   /**< Options menu width. */
+#define OPTIONS_WIDTH       360   /**< Options menu width. */
 #define OPTIONS_HEIGHT       90   /**< Options menu height. */
 
 #define BUTTON_WIDTH        90    /**< Button width, standard across menus. */
@@ -68,6 +71,8 @@ static void exit_game(void);
 static void menu_info_close(unsigned int wid, char* str);
 /* Outfits submenu. */
 static void info_outfits_menu(unsigned int parent, char* str);
+/* Licences submenu. */
+static void info_licenses_menu(unsigned int parent, char* str);
 /* Cargo submenu. */
 static void info_cargo_menu(unsigned int parent, char* str);
 static void cargo_update(unsigned int wid, char* str);
@@ -381,6 +386,39 @@ static void info_outfits_menu(unsigned int parent, char* str) {
   window_addButton(wid, -20, 20,
                    BUTTON_WIDTH, BUTTON_HEIGHT,
                    "closeOutfits", "Close", window_close);
+
+  window_addButton(wid, -20-BUTTON_WIDTH-20, 20,
+      BUTTON_WIDTH, BUTTON_HEIGHT,
+      "btnLicenses", "Licenses", info_licenses_menu);
+}
+
+/**
+ * @brief Open the licences menu.
+ */
+static void info_licenses_menu(unsigned int parent, char* str) {
+  (void)str;
+  (void)parent;
+  unsigned int wid;
+  char** licenses;
+  int nlicenses;
+  int i;
+  char** buf;
+
+  /* Create window. */
+  wid = window_create("Licenses", -1, -1, LICENSES_WIDTH, LICENSES_HEIGHT);
+
+  /* List. */
+  buf = player_getLicenses(&nlicenses);
+  licenses = malloc(sizeof(char*)*nlicenses);
+  for(i = 0; i < nlicenses; i++)
+    licenses[i] = strdup(buf[i]);
+  window_addList(wid, 20, -40, LICENSES_WIDTH-40, LICENSES_HEIGHT-80-BUTTON_HEIGHT,
+      "lstLicenses", licenses, nlicenses, 0, NULL);
+
+  /* Buttons. */
+  window_addButton(wid, -20, 20,
+      BUTTON_WIDTH, BUTTON_HEIGHT,
+      "closeLicenses", "Close", window_close);
 }
 
 /**
diff --git a/src/player.c b/src/player.c
index 7c75571..91211c6 100644
--- a/src/player.c
+++ b/src/player.c
@@ -2362,6 +2362,16 @@ void player_addLicense(char* license) {
   player_licenses[player_nlicenses-1] = strdup(license);
 }
 
+/**
+ * @brief Get the players licenses.
+ *    @param nlicenses Amount of licenses the player has.
+ *    @return Name of the licenses she has.
+ */
+char** player_getLicenses(int* nlicenses) {
+  *nlicenses = player_nlicenses;
+  return player_licenses;
+}
+
 /* Save the player in a freaking xmlfile. */
 int player_save(xmlTextWriterPtr writer) {
   int i;
diff --git a/src/player.h b/src/player.h
index 293c0d2..e2469e0 100644
--- a/src/player.h
+++ b/src/player.h
@@ -74,6 +74,7 @@ int player_missionAlreadyDone(int id);
 /* Licenses. */
 void player_addLicense(char* license);
 int player_hasLicense(char* license);
+char** player_getLicenses(int* nlicenses);
 
 /* Keybind actions. */
 void player_targetHostile(void);