Finishing the tile switcher

This commit is contained in:
AnonymusRaccoon
2020-03-11 16:14:44 +01:00
parent 30cc01b9ea
commit 76435739ce
8 changed files with 57 additions and 3 deletions
+2 -1
View File
@@ -10,7 +10,8 @@
typedef enum display_type
{
HAPPINESS_DISPLAY,
STUPIDITY_DISPLAY
STUPIDITY_DISPLAY,
SELECT_TILE_DISPLAY
} display_type;
struct game_display
+2 -1
View File
@@ -31,4 +31,5 @@ bool vertex_select(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool up_down(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool reset(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool rotate(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool texture(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool texture(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool switch_texture(gc_engine *engine, gc_entity *entity, gc_vector2 _);
+9
View File
@@ -25,6 +25,9 @@
<tiles>
<tile name="cobblestone" />
<tile name="command_block" />
<tile name="comparator_on" />
<tile name="crafting_table" />
<tile name="mossy_cobblestone" />
</tiles>
</data>
<gc_entities>
@@ -58,6 +61,12 @@
<button sprite="rotate" x="19%" y="3%" width="%" height="3%" tooltip="Rotate a texture" tooltip_y="-5" size="15" click="rotate" />
<button sprite="texture" x="23%" y="3%" width="%" height="3%" tooltip="Change the texture of a tile" tooltip_y="-5" size="15" click="texture" />
<panel src="panel" x="30%" y="3%" width="%" height="6%"/>
<button sprite="texture" x="30%" y="3%" width="%" height="3%" tooltip="Select the texture to draw." tooltip_y="-5" size="15" click="switch_texture">
<game_display stats="selected_tile" />
</button>
<panel src="panel" x="100%" y="50%" width="50%" height="120%"/>
<text text="TEAMS" x="88%" y="40"/>
+4
View File
@@ -27,6 +27,10 @@ static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
struct renderer *rend = GETCMP(entity, renderer);
char *display_type = xml_gettempprop(n, "stats");
if (!my_strcmp(display_type, "selected_tile")) {
cmp->type = SELECT_TILE_DISPLAY;
return;
}
if (!my_strcmp(display_type, "happiness"))
cmp->type = HAPPINESS_DISPLAY;
else
+1
View File
@@ -40,6 +40,7 @@ const struct callback callbacks[] = {
{"reset", &reset},
{"rotate", &rotate},
{"texture", &texture},
{"switch_texture", &switch_texture},
{NULL, NULL}
};
+18
View File
@@ -10,9 +10,23 @@
#include <stddef.h>
#include "components/game_display.h"
#include "components/game_manager.h"
#include "components/isometry/map_manager_component.h"
#include "text.h"
#include "components/renderer.h"
#include <malloc.h>
#include "sprite.h"
void display_current_texture(gc_scene *scene, struct renderer *rend)
{
gc_list *li = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *map;
if (!li)
return;
map = GETCMP(li->data, map_manager_component);
((gc_sprite *)rend->data)->texture = map->selected_texture;
}
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
@@ -26,6 +40,10 @@ float dtime)
if (!entities)
return;
manager = GETCMP(entities->data, game_manager);
if (disp->type == SELECT_TILE_DISPLAY && rend->type == GC_TEXTUREREND){
display_current_texture(scene, rend);
return;
}
if (rend->type != GC_TXTREND)
return;
if (disp->type == HAPPINESS_DISPLAY)
+20
View File
@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <components/isometry/map_manager_component.h>
#include <utility.h>
#include "engine.h"
#include "entity.h"
@@ -57,4 +58,23 @@ bool texture(gc_engine *engine, gc_entity *entity, gc_vector2 _)
manager = GETCMP(list->data, map_manager_component);
manager->brush = TEXTURE;
return (true);
}
bool switch_texture(gc_engine *engine, gc_entity *entity, gc_vector2 _)
{
gc_scene *scene = engine->scene;
gc_list *list = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *manager;
void **data = scene->get_data(scene, "tiles", NULL);
static int index = 0;
void *next = NULL;
if (!list)
return (false);
manager = GETCMP(list->data, map_manager_component);
index++;
if (data)
next = data[index % (arraylen(data) - 1)];
manager->selected_texture = next;
return (true);
}