From 8b76e4613c8d18281a902eb812039cf43993ecb7 Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Wed, 6 Mar 2013 21:34:22 +0000
Subject: [PATCH] [Add] Rough outlines for shipyards and outfits.

---
 dat/planet.xml |  2 +-
 src/land.c     | 41 +++++++++++++++++++++++++++++++++++++----
 src/toolkit.c  | 25 ++++++++++++++++++++-----
 src/toolkit.h  |  1 +
 4 files changed, 59 insertions(+), 10 deletions(-)

diff --git a/dat/planet.xml b/dat/planet.xml
index 911a9a8..735e04a 100644
--- a/dat/planet.xml
+++ b/dat/planet.xml
@@ -10,7 +10,7 @@
       <description>The surface of the planet is predominantly covered with water and the planetary climate is characterised by abundant precipitation and strong winds, yet tolerable enough to make special and expensive weather control measurements unnecessary. Habitable land is characterised by soft meadows, swamps and dense forests. The resource base of KonoSphere consits mainly of agriculture and biomass, with the locally bred and grown kono rice being its main export, and fishing a traditional source of sustenance for its people. Other traditional products include wine, and various livestock, most prominently cattle. Cuisine on KonoSphere is rather refined, with most dishes containing meat.</description>
       <bar>The bar is just off the starport with a fantastic view of the harbour. You could watch the fishermen run frantically about attending their duties for hours.</bar>
       <faction>Independent</faction>
-			<services>7</services>
+			<services>15</services>
 			<tech>0</tech>
 			<commodities>1</commodities>
 		</general>
diff --git a/src/land.c b/src/land.c
index 9da3b92..e8dcca0 100644
--- a/src/land.c
+++ b/src/land.c
@@ -10,6 +10,20 @@
 #define BUTTON_WIDTH  200
 #define BUTTON_HEIGHT 40
 
+// Commodity window.
+#define COMMODITY_WIDTH   400
+#define COMMODITY_HEIGHT  400
+
+// Outfits.
+#define OUTFITS_WIDTH			600
+#define OUTFITS_HEIGHT		500
+
+// Shipyard.
+#define SHIPYARD_WIDTH		700
+#define SHIPYARD_HEIGHT		600
+#define SHIPYARD_XPOS			(gl_screen.w-SHIPYARD_WIDTH)/2+100
+#define SHIPYARD_YPOS			(gl_screen.h-SHIPYARD_HEIGHT)/2-25
+
 // News window.
 #define NEWS_WIDTH    400
 #define NEWS_HEIGHT   400
@@ -18,10 +32,6 @@
 #define BAR_WIDTH     600
 #define BAR_HEIGHT    400
 
-// Commodity window.
-#define COMMODITY_WIDTH   400
-#define COMMODITY_HEIGHT  400
-
 #define MUSIC_TAKEOFF		"liftoff"
 #define MUSIC_LAND			"agriculture"
 
@@ -34,7 +44,9 @@ static Planet* planet = NULL;
 static void commodity_exchange(void);
 static void commodity_exchange_close(char* str);
 static void outfits(void);
+static void outfits_close(char* str);
 static void shipyard(void);
+static void shipyard_close(char* str);
 static void spaceport_bar(void);
 static void spaceport_bar_close(char* str);
 static void news(void);
@@ -67,11 +79,32 @@ static void commodity_exchange_close(char* str) {
 }
 
 static void outfits(void) {
+	secondary_wid = window_create("Outfits", -1, -1,
+				OUTFITS_WIDTH, OUTFITS_HEIGHT);
+	
+	window_addButton(secondary_wid, -20, 20,
+				BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseOutfits",
+				"Close", outfits_close);
+}
 
+static void outfits_close(char* str) {
+	if(strcmp(str, "btnCloseOutfits")==0)
+		window_destroy(secondary_wid);
 }
 
 static void shipyard(void) {
+	secondary_wid = window_create("Shipyard",
+				SHIPYARD_XPOS, SHIPYARD_YPOS,
+				SHIPYARD_WIDTH, SHIPYARD_HEIGHT);
+	
+	window_addButton(secondary_wid, -20, 20,
+				BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseShipyard",
+				"Close", shipyard_close);
+}
 
+static void shipyard_close(char* str) {
+	if(strcmp(str, "btnCloseShipyard")==0)
+		window_destroy(secondary_wid);
 }
 
 // Spaceport bar.
diff --git a/src/toolkit.c b/src/toolkit.c
index 8279209..bfeb4bd 100644
--- a/src/toolkit.c
+++ b/src/toolkit.c
@@ -284,14 +284,20 @@ unsigned int window_create(char* name, const int x, const int y, const int w, co
 
   windows[nwindows].w = (double) w;
   windows[nwindows].h = (double) h;
-  if((x == -1) && (y == -1)) {
+	// x pos.
+	if(x == -1)
     // Center.
     windows[nwindows].x = gl_screen.w/2. - windows[nwindows].w/2.;
+	else if(x < 0)
+		windows[nwindows].x = gl_screen.w - windows[nwindows].w + (double)x;
+	else windows[nwindows].x = (double)x;
+	// y pos.
+	if(y == -1)
+		// Center.
     windows[nwindows].y = gl_screen.h/2. - windows[nwindows].h/2.;
-  } else {
-    windows[nwindows].x = (double) x;
-    windows[nwindows].y = (double) y;
-  }
+	else if(y < 0)
+		windows[nwindows].x = gl_screen.h - windows[nwindows].h + (double)y;
+	else windows[nwindows].y = (double)y;
   
   windows[nwindows].widgets = NULL;
   windows[nwindows].nwidgets = 0;
@@ -961,6 +967,15 @@ static void toolkit_listFocus(Widget* lst, double bx, double by) {
 	toolkit_listScroll(lst, 0); // Check boundaries and trigger callback.
 }
 
+char* toolkit_getList(const unsigned int wid, char* name) {
+	Widget* wgt = window_getwgt(wid, name);
+
+	if((wgt->type != WIDGET_LIST) || (wgt->dat.lst.selected != -1))
+		return NULL;
+	
+	return wgt->dat.lst.options[wgt->dat.lst.selected];
+}
+
 // Return the focused widget.
 static Widget* toolkit_getFocus(void) {
 	Window* wdw;
diff --git a/src/toolkit.h b/src/toolkit.h
index dfc06b9..3ff1df6 100644
--- a/src/toolkit.h
+++ b/src/toolkit.h
@@ -32,6 +32,7 @@ void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
 // Get the window by name.
 int window_exists(const char* wdwname);
 unsigned int window_get(const char* wdwname);
+char* toolkit_getList(const unsigned int wid, char* name);
 
 // Destroy window.
 void window_destroy(const unsigned int wid);