diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-09-01 05:54:00 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-09-01 05:54:00 +0000 |
| commit | 9c704c6a0510e9c5f8af8e9c1f810e9688345111 (patch) | |
| tree | dc8e7598702963ca4d4ff260824c031ed4e66ce3 /src/game/client/components | |
| parent | 04eddacd65fd3da680e3d896368cb766b377e6e2 (diff) | |
| download | zcatch-9c704c6a0510e9c5f8af8e9c1f810e9688345111.tar.gz zcatch-9c704c6a0510e9c5f8af8e9c1f810e9688345111.zip | |
added mapimages component
Diffstat (limited to 'src/game/client/components')
| -rw-r--r-- | src/game/client/components/mapimages.cpp | 45 | ||||
| -rw-r--r-- | src/game/client/components/mapimages.hpp | 15 | ||||
| -rw-r--r-- | src/game/client/components/maplayers.cpp | 11 | ||||
| -rw-r--r-- | src/game/client/components/menus.cpp | 2 |
4 files changed, 63 insertions, 10 deletions
diff --git a/src/game/client/components/mapimages.cpp b/src/game/client/components/mapimages.cpp new file mode 100644 index 00000000..d13524cd --- /dev/null +++ b/src/game/client/components/mapimages.cpp @@ -0,0 +1,45 @@ +#include <game/client/component.hpp> +#include <game/mapitems.hpp> + +#include "mapimages.hpp" + +MAPIMAGES::MAPIMAGES() +{ + count = 0; +} + +void MAPIMAGES::on_reset() +{ + // unload all textures + for(int i = 0; i < count; i++) + { + gfx_unload_texture(textures[i]); + textures[i] = -1; + } + count = 0; + + int start; + map_get_type(MAPITEMTYPE_IMAGE, &start, &count); + + // load new textures + for(int i = 0; i < count; i++) + { + textures[i] = 0; + + MAPITEM_IMAGE *img = (MAPITEM_IMAGE *)map_get_item(start+i, 0, 0); + if(img->external) + { + char buf[256]; + char *name = (char *)map_get_data(img->image_name); + str_format(buf, sizeof(buf), "data/mapres/%s.png", name); + textures[i] = gfx_load_texture(buf, IMG_AUTO, 0); + } + else + { + void *data = map_get_data(img->image_data); + textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data, IMG_RGBA, 0); + map_unload_data(img->image_data); + } + } +} + diff --git a/src/game/client/components/mapimages.hpp b/src/game/client/components/mapimages.hpp new file mode 100644 index 00000000..e1e0063d --- /dev/null +++ b/src/game/client/components/mapimages.hpp @@ -0,0 +1,15 @@ +#include <game/client/component.hpp> + +class MAPIMAGES : public COMPONENT +{ + int textures[64]; + int count; +public: + MAPIMAGES(); + + int get(int index) const { return textures[index]; } + int num() const { return count; } + + virtual void on_reset(); +}; + diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 1c72a200..e1518036 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -1,15 +1,10 @@ - -extern "C" { - #include <engine/e_config.h> -} - #include <game/layers.hpp> #include <game/client/gameclient.hpp> #include <game/client/component.hpp> #include <game/client/gc_render.hpp> -#include <game/client/gc_map_image.hpp> #include <game/client/components/camera.hpp> +#include <game/client/components/mapimages.hpp> #include "maplayers.hpp" @@ -125,7 +120,7 @@ void MAPLAYERS::on_render() if(tmap->image == -1) gfx_texture_set(-1); else - gfx_texture_set(img_get(tmap->image)); + gfx_texture_set(gameclient.mapimages->get(tmap->image)); TILE *tiles = (TILE *)map_get_data(tmap->data); gfx_blend_none(); @@ -139,7 +134,7 @@ void MAPLAYERS::on_render() if(qlayer->image == -1) gfx_texture_set(-1); else - gfx_texture_set(img_get(qlayer->image)); + gfx_texture_set(gameclient.mapimages->get(qlayer->image)); QUAD *quads = (QUAD *)map_get_data_swapped(qlayer->data); diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 6d0cbf38..70fdc767 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -530,8 +530,6 @@ int MENUS::render_menubar(RECT r) if (ui_do_button(&favorites_button, "Favorites", active_page==PAGE_FAVORITES, &button, ui_draw_menu_tab_button, 0)) new_page = PAGE_FAVORITES; } - - } else { |