mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
fixed naming of images
This commit is contained in:
parent
6f2b43af9b
commit
b5a6dacfa3
|
@ -270,6 +270,9 @@ void *datafile_get_data_swapped(DATAFILE *df, int index)
|
|||
|
||||
void datafile_unload_data(DATAFILE *df, int index)
|
||||
{
|
||||
if(index < 0)
|
||||
return;
|
||||
|
||||
/* */
|
||||
mem_free(df->data_ptrs[index]);
|
||||
df->data_ptrs[index] = 0x0;
|
||||
|
@ -446,12 +449,17 @@ int datafile_add_item(DATAFILE_OUT *df, int type, int id, int size, void *data)
|
|||
int datafile_add_data(DATAFILE_OUT *df, int size, void *data)
|
||||
{
|
||||
DATA_INFO *info = &df->datas[df->num_datas];
|
||||
unsigned long s = size*2;
|
||||
unsigned long s = compressBound(size);
|
||||
void *compdata = mem_alloc(s, 1); /* temporary buffer that we use duing compression */
|
||||
|
||||
info->uncompressed_size = size;
|
||||
if(compress((Bytef*)compdata, &s, (Bytef*)data, size) != Z_OK)
|
||||
int result = compress((Bytef*)compdata, &s, (Bytef*)data, size);
|
||||
if(result != Z_OK)
|
||||
{
|
||||
dbg_msg("datafile", "compression error %d", result);
|
||||
dbg_assert(0, "zlib error");
|
||||
}
|
||||
|
||||
info->uncompressed_size = size;
|
||||
info->compressed_size = (int)s;
|
||||
info->compressed_data = mem_alloc(info->compressed_size, 1);
|
||||
mem_copy(info->compressed_data, compdata, info->compressed_size);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue