aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-01-27 17:09:39 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-01-27 17:38:12 +0100
commitcd2b58b5619bf33deb99b0765f2d69969c61ed74 (patch)
tree19a594c4b2be73d9e34d3d017f0c62d4611564a6
parent27553f8ed1d062c4d8175e7376f5b16cf2c8f9ef (diff)
Add btn_small
-rw-r--r--res/CMakeLists.txt9
-rw-r--r--src/game/src/res.c12
-rw-r--r--src/gui/inc/gui/button.h1
-rw-r--r--src/gui/src/button_type1.c2
-rw-r--r--src/player/src/human_player.c1
-rw-r--r--src/player/src/human_player_gui.c24
6 files changed, 43 insertions, 6 deletions
diff --git a/res/CMakeLists.txt b/res/CMakeLists.txt
index c5ec5e6..87da184 100644
--- a/res/CMakeLists.txt
+++ b/res/CMakeLists.txt
@@ -56,6 +56,14 @@ sprite(NAME btn_right
CY 48
TRANSPARENT TRUE)
+sprite(NAME btn_small
+ X 384
+ Y 0
+ BPP 4
+ CX 384
+ CY 48
+ TRANSPARENT TRUE)
+
level(NAME city1)
container(NAME jancity
@@ -67,4 +75,5 @@ container(NAME jancity
btn_left
btn_mid
btn_right
+ btn_small
)
diff --git a/src/game/src/res.c b/src/game/src/res.c
index 6489d30..cb3060e 100644
--- a/src/game/src/res.c
+++ b/src/game/src/res.c
@@ -19,36 +19,48 @@ static const struct container c[] =
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &terrain_sprites[SIDEWALK]
},
+
{
.path = "roof1",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &terrain_sprites[ROOF1]
},
+
{
.path = "roof2",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &terrain_sprites[ROOF2]
},
+
{
.path = "cursor",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &cursor_sprite
},
+
{
.path = "btn_left",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &gui_button_sprites[GUI_BUTTON_LEFT]
},
+
{
.path = "btn_mid",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &gui_button_sprites[GUI_BUTTON_MID]
},
+
{
.path = "btn_right",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &gui_button_sprites[GUI_BUTTON_RIGHT]
},
+
+ {
+ .path = "btn_small",
+ .type = CONTAINER_TYPE_SPRITE,
+ .data.sprite = &gui_button_sprites[GUI_BUTTON_SMALL]
+ },
};
static bool init;
diff --git a/src/gui/inc/gui/button.h b/src/gui/inc/gui/button.h
index b712e29..b15faaa 100644
--- a/src/gui/inc/gui/button.h
+++ b/src/gui/inc/gui/button.h
@@ -50,6 +50,7 @@ enum
GUI_BUTTON_LEFT,
GUI_BUTTON_MID,
GUI_BUTTON_RIGHT,
+ GUI_BUTTON_SMALL,
MAX_GUI_BUTTON_SPRITES
};
diff --git a/src/gui/src/button_type1.c b/src/gui/src/button_type1.c
index da59d8b..2f91b4c 100644
--- a/src/gui/src/button_type1.c
+++ b/src/gui/src/button_type1.c
@@ -71,7 +71,7 @@ static int render_mid(const struct gui_button *const b,
}
else
{
- fprintf(stderr, "%s: unexpected negative size for button %p\n",
+ fprintf(stderr, "%s: unexpected zero or negative size for button %p\n",
__func__, (void *)b);
return -1;
}
diff --git a/src/player/src/human_player.c b/src/player/src/human_player.c
index 7f67ec7..6083ef3 100644
--- a/src/player/src/human_player.c
+++ b/src/player/src/human_player.c
@@ -462,6 +462,7 @@ int human_player_render(const struct human_player *const h,
if (render_target(h)
|| render_own_units(h)
|| render_own_buildings(h)
+ || human_player_gui_render(h)
|| input_render(&h->in, h->periph))
return -1;
diff --git a/src/player/src/human_player_gui.c b/src/player/src/human_player_gui.c
index 3f79848..e985d9c 100644
--- a/src/player/src/human_player_gui.c
+++ b/src/player/src/human_player_gui.c
@@ -5,6 +5,7 @@
#include <unit.h>
#include <gui.h>
#include <gui/bar.h>
+#include <gui/button.h>
#include <gui/container.h>
#include <gui/label.h>
#include <gui/progress_bar.h>
@@ -96,6 +97,19 @@ static int render_sel_multiple(const struct human_player *const h,
return gui_render(r);
}
+static int render_top(const struct human_player *const h)
+{
+ struct gui_button b;
+
+ gui_button_init(&b, GUI_BUTTON_TYPE_SPRITE);
+ b.on_pressed = NULL;
+ b.arg = NULL;
+ b.u.sprite.s = &gui_button_sprites[GUI_BUTTON_SMALL];
+ b.common.x = screen_w - b.u.sprite.s->w;
+
+ return gui_render(&b.common);
+}
+
static int render_sel(const struct human_player *const h)
{
struct gui_rounded_rect r;
@@ -106,15 +120,15 @@ static int render_sel(const struct human_player *const h)
r.h = screen_h / 4;
r.common.y = screen_h - r.h;
- if (h->n_sel == 1)
- return render_sel_single(h, &r.common);
-
- return render_sel_multiple(h, &r.common);
+ return h->n_sel == 1 ? render_sel_single(h, &r.common)
+ : render_sel_multiple(h, &r.common);
}
int human_player_gui_render(const struct human_player *const h)
{
- if (h->n_sel && render_sel(h))
+ if (render_top(h))
+ return -1;
+ else if (h->n_sel && render_sel(h))
return -1;
return 0;