From 7511055f56663d9b920f42042c74f4c5830098a6 Mon Sep 17 00:00:00 2001 From: xolatile Date: Sun, 10 Mar 2024 16:41:31 -0400 Subject: [PATCH] Remade menus to be entity-specific... --- source/attribute.adb | 19 +++++++++++--- source/attribute.ads | 4 +-- source/core.adb | 2 +- source/core.ads | 3 ++- source/main.adb | 4 +++ source/resource.adb | 19 +++++++++++--- source/resource.ads | 4 +-- source/skill.adb | 19 +++++++++++--- source/skill.ads | 4 +-- source/ui.adb | 71 ++++++++++++++++++++-------------------------------- source/ui.ads | 6 ++--- 11 files changed, 87 insertions(+), 68 deletions(-) diff --git a/source/attribute.adb b/source/attribute.adb index c84cd9c..c079cb0 100644 --- a/source/attribute.adb +++ b/source/attribute.adb @@ -23,9 +23,22 @@ package body attribute is ------------------------------------------------------------------------------------------ - function name (index : in integer) return core.short_string is begin return trait (codex'val (index)).name; end name; - function base (index : in integer) return base_limit is begin return trait (codex'val (index)).base; end base; - function icon (index : in integer) return core.sprite is begin return sprite (codex'val (index)); end icon; + procedure menu (x, y : in integer; center : in boolean) is + offset : constant integer := 16; + width : constant integer := 180 + 2 * offset; + height : constant integer := count * core.icon + 2 * offset; + move_x : constant integer := (if center then (core.window_width - width) / 2 else x); + move_y : constant integer := (if center then (core.window_height - height) / 2 else y); + begin + ui.draw_tiny_menu (move_x, move_y, width, height, true); + ui.draw_title_bar (move_x, move_y, width, "Attributes"); + -- + for index in codex + loop + ui.draw_icon (sprite (index), move_x + offset, move_y + offset + codex'pos (index) * core.icon); + core.write (trait (index).name, move_x + offset + core.icon, move_y + offset + codex'pos (index) * core.icon); + end loop; + end menu; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/attribute.ads b/source/attribute.ads index f449ae6..fe039b0 100644 --- a/source/attribute.ads +++ b/source/attribute.ads @@ -41,9 +41,7 @@ package attribute is procedure draw (index : in codex; x, y : in integer); - function name (index : in integer) return core.short_string; - function base (index : in integer) return base_limit; - function icon (index : in integer) return core.sprite; + procedure menu (x, y : in integer; center : in boolean); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/core.adb b/source/core.adb index 50ce1ef..64e22ea 100644 --- a/source/core.adb +++ b/source/core.adb @@ -159,7 +159,7 @@ package body core is ------------------------------------------------------------------------------------------ - procedure write (text : in string; x, y : in integer; colour : in integer := 16#CCCCCC#) is + procedure write (text : in string; x, y : in integer; colour : in integer := 16#A37A28#) is begin render_string (c_string (text), x, y, colour, 0); end write; diff --git a/source/core.ads b/source/core.ads index df40b3d..274dc42 100644 --- a/source/core.ads +++ b/source/core.ads @@ -45,6 +45,7 @@ package core is ------------------------------------------------------------------------------------------ + icon : constant natural := 32; base : constant natural := 32; gameplay_framerate : constant natural := 60; animation_framerate : constant natural := 6; @@ -108,7 +109,7 @@ package core is procedure line (origin, offset : in vector_2); - procedure write (text : in string; x, y : in integer; colour : in integer := 16#CCCCCC#); + procedure write (text : in string; x, y : in integer; colour : in integer := 16#A37A28#); procedure debug (text : in string); procedure hexagonal_grid (x, y, width, height : in integer; fill : in boolean); diff --git a/source/main.adb b/source/main.adb index e727d0e..0e957d7 100644 --- a/source/main.adb +++ b/source/main.adb @@ -81,6 +81,10 @@ begin --~for index in skill.codex loop skill.draw (index, 32 * skill.codex'pos (index) + 64, 128); end loop; -- core.draw_state_box (preview_width + 32, 32); + -- + attribute.menu (300, 200, false); + skill.menu (600, 300, true); + resource.menu (300, 500, false); end loop gameplay; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/resource.adb b/source/resource.adb index 68d577e..7b39230 100644 --- a/source/resource.adb +++ b/source/resource.adb @@ -23,9 +23,22 @@ package body resource is ------------------------------------------------------------------------------------------ - function name (index : in integer) return core.short_string is begin return trait (codex'val (index)).name; end name; - function base (index : in integer) return base_limit is begin return trait (codex'val (index)).base; end base; - function icon (index : in integer) return core.sprite is begin return sprite (codex'val (index)); end icon; + procedure menu (x, y : in integer; center : in boolean) is + offset : constant integer := 16; + width : constant integer := 180 + 2 * offset; + height : constant integer := count * core.icon + 2 * offset; + move_x : constant integer := (if center then (core.window_width - width) / 2 else x); + move_y : constant integer := (if center then (core.window_height - height) / 2 else y); + begin + ui.draw_tiny_menu (move_x, move_y, width, height, true); + ui.draw_title_bar (move_x, move_y, width, "Skills"); + -- + for index in codex + loop + ui.draw_icon (sprite (index), move_x + offset, move_y + offset + codex'pos (index) * core.icon); + core.write (trait (index).name, move_x + offset + core.icon, move_y + offset + codex'pos (index) * core.icon); + end loop; + end menu; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/resource.ads b/source/resource.ads index 0f2ba7f..e5e0354 100644 --- a/source/resource.ads +++ b/source/resource.ads @@ -45,9 +45,7 @@ package resource is procedure draw (index : in codex; x, y : in integer); - function name (index : in integer) return core.short_string; - function base (index : in integer) return base_limit; - function icon (index : in integer) return core.sprite; + procedure menu (x, y : in integer; center : in boolean); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/skill.adb b/source/skill.adb index 31362dc..c1dce6b 100644 --- a/source/skill.adb +++ b/source/skill.adb @@ -23,9 +23,22 @@ package body skill is ------------------------------------------------------------------------------------------ - function name (index : in integer) return core.short_string is begin return trait (codex'val (index)).name; end name; - function base (index : in integer) return base_limit is begin return trait (codex'val (index)).base; end base; - function icon (index : in integer) return core.sprite is begin return sprite (codex'val (index)); end icon; + procedure menu (x, y : in integer; center : in boolean) is + offset : constant integer := 16; + width : constant integer := 180 + 2 * offset; + height : constant integer := count * core.icon + 2 * offset; + move_x : constant integer := (if center then (core.window_width - width) / 2 else x); + move_y : constant integer := (if center then (core.window_height - height) / 2 else y); + begin + ui.draw_tiny_menu (move_x, move_y, width, height, true); + ui.draw_title_bar (move_x, move_y, width, "Skills"); + -- + for index in codex + loop + ui.draw_icon (sprite (index), move_x + offset, move_y + offset + codex'pos (index) * core.icon); + core.write (trait (index).name, move_x + offset + core.icon, move_y + offset + codex'pos (index) * core.icon); + end loop; + end menu; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/skill.ads b/source/skill.ads index 6580762..cec124f 100644 --- a/source/skill.ads +++ b/source/skill.ads @@ -64,9 +64,7 @@ package skill is procedure draw (index : in codex; x, y : in integer); - function name (index : in integer) return core.short_string; - function base (index : in integer) return base_limit; - function icon (index : in integer) return core.sprite; + procedure menu (x, y : in integer; center : in boolean); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/ui.adb b/source/ui.adb index 34b33a7..25838a7 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -1,4 +1,3 @@ ---~with core, attribute, skill, menu; with core, ui; use ui; @@ -7,24 +6,6 @@ package body ui is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - procedure configure is - procedure load_ui (index : in style; folder_path : in string) is - begin - for this in codex - loop - sprite (index, this) := core.load_sprite ("./sprite/ui/" & folder_path & core.lowercase (codex'image (this)) & ".png", 1, 1); - end loop; - end load_ui; - begin - load_ui (default, "default/"); - load_ui (steam, "steam/"); - --~load_ui (yd, "yd/"); - -- - active := default; - end configure; - - ------------------------------------------------------------------------------------------ - procedure draw (index : in codex; x, y : in integer) is begin core.draw (sprite (active, index), x, y); @@ -91,37 +72,39 @@ package body ui is ------------------------------------------------------------------------------------------ + procedure configure is + procedure load_ui (index : in style; folder_path : in string) is + begin + for this in codex + loop + sprite (index, this) := core.load_sprite ("./sprite/ui/" & folder_path & core.lowercase (codex'image (this)) & ".png", 1, 1); + end loop; + end load_ui; + begin + load_ui (default, "default/"); + load_ui (steam, "steam/"); + -- + active := default; + end configure; + + ------------------------------------------------------------------------------------------ + + procedure draw_icon (data : in core.sprite; x, y : in integer) is + begin + draw (icon, x, y); + core.draw (data, x, y); + end draw_icon; + + ------------------------------------------------------------------------------------------ + procedure draw_frame (x, y, width, height : in integer) is offset_x : constant integer := sprite (active, frame_middle).width; offset_y : constant integer := sprite (active, frame_middle).height; begin - if height < 2 * offset_y then - draw_horizontally (frame_upper, x + offset_x, y, width - 2 * offset_x); - draw_horizontally (frame_lower, x + offset_x, y + height - offset_y, width - 2 * offset_x); - -- - crop (frame_upper_left, x, y, 0, 0, sprite (active, frame_upper_left).width, height / 2); - crop (frame_upper_right, x + width - offset_x, y, 0, 0, sprite (active, frame_upper_right).width, height / 2); - crop (frame_lower_left, x, y + height / 2, 0, offset_y - height / 2, sprite (active, frame_lower_left).width, height / 2); - crop (frame_lower_right, x + width - offset_x, y + height / 2, 0, offset_y - height / 2, sprite (active, frame_lower_right).width, height / 2); + if height < core.icon or width < core.icon then return; end if; -- - --~if width < 2 * offset_x then - --~crop (frame_upper_left, x, y, 0, 0, width / 2, height / 2); - --~crop (frame_upper_right, x + width / 2, y, offset_x - width / 2, 0, width / 2, height / 2); - --~crop (frame_lower_left, x, y + height / 2, 0, offset_y - height / 2, width / 2, height / 2); - --~crop (frame_lower_right, x + width / 2, y + height / 2, offset_x - width / 2, offset_y - height / 2, width / 2, height / 2); - --~return; - --~end if; - --~-- - --~if width < 2 * offset_x or height < 2 * offset_y then - --~crop (frame_upper_left, x, y, 0, 0, width / 2, height / 2); - --~crop (frame_upper_right, x + width / 2, y, offset_x - width / 2, 0, width / 2, height / 2); - --~crop (frame_lower_left, x, y + height / 2, 0, offset_y - height / 2, width / 2, height / 2); - --~crop (frame_lower_right, x + width / 2, y + height / 2, offset_x - width / 2, offset_y - height / 2, width / 2, height / 2); - --~return; - --~end if; - -- draw_background (frame_middle, x + offset_x, y + offset_y, width - 2 * offset_x, height - 2 * offset_y); -- draw_horizontally (frame_upper, x + offset_x, y, width - 2 * offset_x); @@ -145,7 +128,7 @@ package body ui is -- draw_horizontally (title_bar_middle, x + sprite (active, title_bar_left).width, y - sprite (active, title_bar_middle).height, middle_width); -- - core.write (title, x + sprite (active, title_bar_left).width - 12, y - sprite (active, title_bar_middle).height + 24, 16#CCCCCC#); + core.write (title, x + sprite (active, title_bar_left).width - 12, y - sprite (active, title_bar_middle).height + 24, 16#C9952D#); end draw_title_bar; ------------------------------------------------------------------------------------------ diff --git a/source/ui.ads b/source/ui.ads index c1f2e4d..6ec2d71 100644 --- a/source/ui.ads +++ b/source/ui.ads @@ -18,7 +18,7 @@ package ui is frame_upper_left, frame_upper, frame_upper_right, frame_left, frame_middle, frame_right, frame_lower_left, frame_lower, frame_lower_right, - cursor, + cursor, icon, fill_bar_left, fill_bar_horizontal, fill_bar_right, fill_horizontal, scroll_bar_lower, scroll_bar_middle, scroll_bar_upper, title_bar_left, title_bar_middle, title_bar_right @@ -37,9 +37,7 @@ package ui is procedure configure; - procedure draw (index : in codex; x, y : in integer); - - procedure draw_background (index : in codex; x, y, width, height : in integer); + procedure draw_icon (data : in core.sprite; x, y : in integer); procedure draw_frame (x, y, width, height : in integer);