From 2172a630b11320bafe213804cbcf30d7742a2f01 Mon Sep 17 00:00:00 2001 From: xolatile Date: Mon, 19 Feb 2024 16:20:38 -0500 Subject: [PATCH] Added entity count, menu centering, refactoring... --- source/attribute.ads | 2 ++ source/construction.ads | 2 ++ source/core.adb | 10 ++-------- source/deity.ads | 2 ++ source/effect.ads | 2 ++ source/faction.ads | 2 ++ source/item.ads | 2 ++ source/magic.ads | 2 ++ source/main.adb | 9 +++++---- source/menu.adb | 41 ++++++++++++++++++++++------------------- source/menu.ads | 2 +- source/might.ads | 2 ++ source/resource.ads | 2 ++ source/skill.ads | 2 ++ source/unit.ads | 2 ++ 15 files changed, 52 insertions(+), 32 deletions(-) diff --git a/source/attribute.ads b/source/attribute.ads index 34738ca..751799a 100644 --- a/source/attribute.ads +++ b/source/attribute.ads @@ -25,6 +25,8 @@ package attribute is icon : sprite_array; + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("Attack ", 0), ("Defense ", 0), diff --git a/source/construction.ads b/source/construction.ads index b0725bf..70b260e 100644 --- a/source/construction.ads +++ b/source/construction.ads @@ -58,6 +58,8 @@ package construction is ------------------------------------------------------------------------------------------ + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( -- Remove me later... Lv Gr Gold Wd Mr Or Sl Cr Gm ("Boar Glen ", faction.neutral, 1, 1, ( 90, 0, 0, 0, 0, 0, 0), 1, effect.none, menu.none), diff --git a/source/core.adb b/source/core.adb index 2d7b953..754331f 100644 --- a/source/core.adb +++ b/source/core.adb @@ -211,17 +211,11 @@ package body core is loop line ((x, offset_y + horizontal * base), (width, 0)); -- - for vertical in 0 .. width / base + for vertical in 0 .. width / base - 1 loop line ((offset_x + vertical * base - base / 2, crop_offset + 2 * base * (horizontal / 2) + base), (0, base)); + line ((offset_x + vertical * base, crop_offset + 2 * base * (horizontal / 2)), (0, base)); end loop; - -- - if horizontal > 1 then - for vertical in 0 .. width / base - 1 - loop - line ((offset_x + vertical * base, crop_offset + 2 * base * (horizontal / 2)), (0, base)); - end loop; - end if; end loop; -- for vertical in 0 .. width / base - 1 diff --git a/source/deity.ads b/source/deity.ads index 61bef59..54a8d3c 100644 --- a/source/deity.ads +++ b/source/deity.ads @@ -23,6 +23,8 @@ package deity is ------------------------------------------------------------------------------------------ + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("Svarog the Lawful ", 3), -- Serbia ("Dabog the Lonely ", -3), diff --git a/source/effect.ads b/source/effect.ads index 295fe2f..54e8ad6 100644 --- a/source/effect.ads +++ b/source/effect.ads @@ -20,6 +20,8 @@ package effect is ------------------------------------------------------------------------------------------ + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("- ", true), ("- ", true) diff --git a/source/faction.ads b/source/faction.ads index c316592..c301f98 100644 --- a/source/faction.ads +++ b/source/faction.ads @@ -23,6 +23,8 @@ package faction is ------------------------------------------------------------------------------------------ + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("Neutral ", attribute.attack, skill.tactics, resource.gold), ("Castle ", attribute.attack, skill.archery, resource.ore), diff --git a/source/item.ads b/source/item.ads index 380aa4d..3f13197 100644 --- a/source/item.ads +++ b/source/item.ads @@ -51,6 +51,8 @@ package item is ------------------------------------------------------------------------------------------ + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("Admiral's Hat ", head, 0, effect.none), ("Ambassador's Sash ", full_body, 0, effect.none), diff --git a/source/magic.ads b/source/magic.ads index 5796818..59adecf 100644 --- a/source/magic.ads +++ b/source/magic.ads @@ -51,6 +51,8 @@ package magic is ------------------------------------------------------------------------------------------ + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("Magic Arrow ", neutral, 0, effect.none), ("Chain Magic Arrow ", neutral, 0, effect.none), diff --git a/source/main.adb b/source/main.adb index 4c7c31e..08bc07f 100644 --- a/source/main.adb +++ b/source/main.adb @@ -90,8 +90,8 @@ begin --~construction.draw (this, 128 * (construction.codex'pos (this) mod 12) + 32, 128 * (construction.codex'pos (this) / 12) + 32); --~end loop; -- - core.draw_central_grid (preview_x, preview_y, preview_width - 2 * preview_x, preview_height - 2 * preview_y); - core.draw_squared_grid (preview_x, preview_y, preview_width - 2 * preview_x, preview_height - 2 * preview_y); + --~core.draw_central_grid (preview_x, preview_y, preview_width - 2 * preview_x, preview_height - 2 * preview_y); + --~core.draw_squared_grid (preview_x, preview_y, preview_width - 2 * preview_x, preview_height - 2 * preview_y); -- ui.draw_menu (0, 0, preview_width, preview_height, false); ui.draw_tiny_menu (preview_width, 0, side_panel, preview_height, true); @@ -111,8 +111,9 @@ begin -- core.draw_state_box (preview_width + 32, 32); -- - menu.draw (menu.attribute_information, 100, 100); - menu.draw (menu.resource_information, 600, 100); + menu.draw (menu.resource_information, 420, 100, false); + menu.draw (menu.skill_information, 740, 100, false); + menu.draw (menu.attribute_information, 100, 100, true); end loop gameplay; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/menu.adb b/source/menu.adb index 962e526..ee07ba1 100644 --- a/source/menu.adb +++ b/source/menu.adb @@ -12,53 +12,56 @@ package body menu is trait (skill_information).title := "Skill Information "; trait (resource_information).title := "Resource Information "; -- - trait (attribute_information).elements := new element_array (0 .. attribute.codex'pos (attribute.codex'last)); - trait (skill_information).elements := new element_array (0 .. skill.codex'pos (skill.codex'last)); - trait (resource_information).elements := new element_array (0 .. resource.codex'pos (resource.codex'last)); + trait (attribute_information).elements := new element_array (0 .. attribute.count - 1); + trait (skill_information).elements := new element_array (0 .. skill.count - 1); + trait (resource_information).elements := new element_array (0 .. resource.count - 1); -- - trait (attribute_information).length := attribute.codex'pos (attribute.codex'last) + 1; - trait (skill_information).length := skill.codex'pos (skill.codex'last) + 1; - trait (resource_information).length := resource.codex'pos (resource.codex'last) + 1; + trait (attribute_information).length := attribute.count; + trait (skill_information).length := skill.count; + trait (resource_information).length := resource.count; -- - for index in 0 .. attribute.codex'pos (attribute.codex'last) + for index in attribute.codex loop - trait (attribute_information).elements (index) := (button, index, attribute.trait (attribute.codex'val (index)).name, attribute.icon (attribute.codex'val (index))); + trait (attribute_information).elements (attribute.codex'pos (index)) := (button, 0, attribute.trait (index).name, attribute.icon (index)); end loop; -- - for index in 0 .. skill.codex'pos (skill.codex'last) + for index in skill.codex loop - trait (skill_information).elements (index) := (button, index, skill.trait (skill.codex'val (index)).name, skill.icon (skill.codex'val (index))); + trait (skill_information).elements (skill.codex'pos (index)) := (button, 0, skill.trait (index).name, skill.icon (index)); end loop; -- - for index in 0 .. resource.codex'pos (resource.codex'last) + for index in resource.codex loop - trait (resource_information).elements (index) := (button, index, resource.trait (resource.codex'val (index)).name, resource.icon (resource.codex'val (index))); + trait (resource_information).elements (resource.codex'pos (index)) := (button, 0, resource.trait (index).name, resource.icon (index)); end loop; end configure; ------------------------------------------------------------------------------------------ - procedure draw (index : in codex; x, y : in integer) is + procedure draw (index : in codex; x, y : in integer; center : in boolean) is draw_offset : constant integer := 16; icon_offset : constant integer := 4; icon_size : constant integer := 32; offset : constant integer := icon_size + 2 * icon_offset; - width : constant integer := 300; + width : constant integer := 240; height : constant integer := trait (index).length * offset + 2 * draw_offset; + -- + offset_x : constant integer := (if center then (core.window_width - width) / 2 else x); + offset_y : constant integer := (if center then (core.window_height - height) / 2 else y); begin if index = none then return; end if; -- - ui.draw_title_bar (x, y, width, trait (index).title); - ui.draw_tiny_menu (x, y, width, height, true); + ui.draw_title_bar (offset_x, offset_y, width, trait (index).title); + ui.draw_tiny_menu (offset_x, offset_y, width, height, true); -- for element_index in 0 .. trait (index).length - 1 loop - ui.draw_frame (x + draw_offset, y + draw_offset + element_index * offset, offset, offset); + ui.draw_frame (offset_x + draw_offset, offset_y + draw_offset + element_index * offset, offset, offset); -- - core.draw (trait (index).elements (element_index).icon, x + draw_offset + icon_offset, y + draw_offset + icon_offset + element_index * offset); - core.write (trait (index).elements (element_index).text, x + draw_offset + icon_offset + offset, y + draw_offset + icon_offset + element_index * offset); + core.draw (trait (index).elements (element_index).icon, offset_x + draw_offset + icon_offset, offset_y + draw_offset + icon_offset + element_index * offset); + core.write (trait (index).elements (element_index).text, offset_x + draw_offset + icon_offset + offset, offset_y + draw_offset + icon_offset + element_index * offset); end loop; end draw; diff --git a/source/menu.ads b/source/menu.ads index 426a1a5..a400c84 100644 --- a/source/menu.ads +++ b/source/menu.ads @@ -41,7 +41,7 @@ package menu is procedure configure; - procedure draw (index : in codex; x, y : in integer); + procedure draw (index : in codex; x, y : in integer; center : in boolean); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/might.ads b/source/might.ads index c15f5ab..4117f15 100644 --- a/source/might.ads +++ b/source/might.ads @@ -50,6 +50,8 @@ package might is ------------------------------------------------------------------------------------------ + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("Cover ", archery, 0, effect.none), ("Evasive Maneuvers ", archery, 0, effect.none), diff --git a/source/resource.ads b/source/resource.ads index 348dc28..bd5d007 100644 --- a/source/resource.ads +++ b/source/resource.ads @@ -28,6 +28,8 @@ package resource is icon : sprite_array; + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("Gold ", 1), ("Wood ", 3), diff --git a/source/skill.ads b/source/skill.ads index 14a962c..cc5bbe9 100644 --- a/source/skill.ads +++ b/source/skill.ads @@ -31,6 +31,8 @@ package skill is icon : sprite_array; + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("Archery ", 0, 0), ("Offense ", 0, 0), diff --git a/source/unit.ads b/source/unit.ads index 40ab37a..caa0786 100644 --- a/source/unit.ads +++ b/source/unit.ads @@ -72,6 +72,8 @@ package unit is ------------------------------------------------------------------------------------------ + count : constant natural := codex'pos (codex'last) + 1; + trait : constant trait_array := ( ("Azure Dragon ", faction.neutral, 1, 2, 1, 9, effect.none), ("Boar ", faction.neutral, 1, 2, 1, 9, effect.none),