about summary refs log tree commit diff
path: root/src/game/editor
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-01-19 13:02:22 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-01-19 13:02:22 +0000
commitb5a6dacfa30d8f7a9714f2ea4694234b5d7c09bf (patch)
tree2dc8ff1ac4ef40e4a6f73e473439f00a78a84688 /src/game/editor
parent6f2b43af9b83c69134a7a5ecb6e5820c42fcb135 (diff)
downloadzcatch-b5a6dacfa30d8f7a9714f2ea4694234b5d7c09bf.tar.gz
zcatch-b5a6dacfa30d8f7a9714f2ea4694234b5d7c09bf.zip
fixed naming of images
Diffstat (limited to 'src/game/editor')
-rw-r--r--src/game/editor/ed_editor.cpp39
-rw-r--r--src/game/editor/ed_io.cpp8
-rw-r--r--src/game/editor/ed_popups.cpp4
3 files changed, 45 insertions, 6 deletions
diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp
index b6869a33..e23611a6 100644
--- a/src/game/editor/ed_editor.cpp
+++ b/src/game/editor/ed_editor.cpp
@@ -1209,7 +1209,7 @@ int EDITOR::do_properties(RECT *toolbox, PROPERTY *props, int *ids, int *new_val
 			if(props[i].value < 0)
 				strcpy(buf, "None");
 			else
-				sprintf(buf, "%d",  props[i].value);
+				sprintf(buf, "%s",  editor.map.images[props[i].value]->name);
 			
 			if(do_editor_button(&ids[i], buf, 0, &shifter, draw_editor_button, 0, 0))
 				popup_select_image_invoke(props[i].value, ui_mouse_x(), ui_mouse_y());
@@ -1315,6 +1315,38 @@ static void render_layers(RECT toolbox, RECT toolbar, RECT view)
 	
 }
 
+static void extract_name(const char *filename, char *name)
+{
+	int len = strlen(filename);
+	int start = len;
+	int end = len;
+	
+	while(start > 0)
+	{
+		start--;
+		if(filename[start] == '/' || filename[start] == '\\')
+		{
+			start++;
+			break;
+		}
+	}
+	
+	end = start;
+	for(int i = start; i < len; i++)
+	{
+		if(filename[i] == '.')
+			end = i;
+	}
+	
+	if(end == start)
+		end = len;
+	
+	int final_len = end-start;
+	mem_copy(name, &filename[start], final_len);
+	name[final_len] = 0;
+	dbg_msg("", "%s %s %d %d", filename, name, start, end);
+}
+
 static void replace_image(const char *filename)
 {
 	IMAGE imginfo;
@@ -1324,6 +1356,7 @@ static void replace_image(const char *filename)
 	IMAGE *img = editor.map.images[editor.selected_image];
 	gfx_unload_texture(img->tex_id);
 	*img = imginfo;
+	extract_name(filename, img->name);
 	img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO);
 }
 
@@ -1333,6 +1366,8 @@ static void add_image(const char *filename)
 	if(!gfx_load_png(&imginfo, filename))
 		return;
 
+	//gfx_unload_texture
+
 	IMAGE *img = new IMAGE;
 	*img = imginfo;
 	img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO);
@@ -1383,7 +1418,7 @@ static void render_images(RECT toolbox, RECT toolbar, RECT view)
 	for(int i = 0; i < editor.map.images.len(); i++)
 	{
 		char buf[128];
-		sprintf(buf, "#%d %dx%d", i, editor.map.images[i]->width, editor.map.images[i]->height);
+		sprintf(buf, "%s", editor.map.images[i]->name);
 		RECT slot;
 		ui_hsplit_t(&toolbox, 12.0f, &slot, &toolbox);
 		
diff --git a/src/game/editor/ed_io.cpp b/src/game/editor/ed_io.cpp
index 77ae8242..653e84b2 100644
--- a/src/game/editor/ed_io.cpp
+++ b/src/game/editor/ed_io.cpp
@@ -1,3 +1,4 @@
+#include <string.h>
 #include "ed_editor.hpp"
 
 template<typename T>
@@ -214,7 +215,7 @@ int EDITOR::save(const char *filename)
 		item.width = img->width;
 		item.height = img->height;
 		item.external = 0;
-		item.image_name = -1;
+		item.image_name = datafile_add_data(df, strlen(img->name)+1, img->name);
 		item.image_data = datafile_add_data(df, item.width*item.height*4, img->data);
 		datafile_add_item(df, MAPITEMTYPE_IMAGE, i, sizeof(item), &item);
 	}
@@ -353,12 +354,16 @@ int EDITOR::load(const char *filename)
 			{
 				MAPITEM_IMAGE *item = (MAPITEM_IMAGE *)datafile_get_item(df, start+i, 0, 0);
 				void *data = datafile_get_data(df, item->image_data);
+				char *name = (char *)datafile_get_data(df, item->image_name);
 				
 				IMAGE *img = new IMAGE;
 				img->width = item->width;
 				img->height = item->height;
 				img->format = IMG_RGBA;
 				
+				if(name)
+					strncpy(img->name, name, 128);
+				
 				// copy image data
 				img->data = mem_alloc(img->width*img->height*4, 1);
 				mem_copy(img->data, data, img->width*img->height*4);
@@ -367,6 +372,7 @@ int EDITOR::load(const char *filename)
 				
 				// unload image
 				datafile_unload_data(df, item->image_data);
+				datafile_unload_data(df, item->image_name);
 			}
 		}
 		
diff --git a/src/game/editor/ed_popups.cpp b/src/game/editor/ed_popups.cpp
index e06637e1..a3fabcd6 100644
--- a/src/game/editor/ed_popups.cpp
+++ b/src/game/editor/ed_popups.cpp
@@ -343,9 +343,7 @@ int popup_select_image(RECT view)
 		}
 		else
 		{
-			char buf[64];
-			sprintf(buf, "%d", i);
-			if(do_editor_button(&editor.map.images[i], buf, i==select_image_current, &button, draw_editor_button_menuitem, 0, 0))
+			if(do_editor_button(&editor.map.images[i], editor.map.images[i]->name, i==select_image_current, &button, draw_editor_button_menuitem, 0, 0))
 				select_image_selected = i;
 		}
 	}