xhads/source/menu.adb
2024-02-19 17:17:19 -05:00

64 lines
3.0 KiB
Ada

with core, ui, effect, attribute, skill, resource, faction, might, magic, item, unit, construction, world, menu;
use menu;
package body menu is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
procedure configure is
begin
trait (attribute_information) := ("Attribute Information ", attribute.count, 10, new element_array (0 .. attribute.count - 1));
trait (skill_information) := ("Skill Information ", skill.count, 10, new element_array (0 .. skill.count - 1));
trait (resource_information) := ("Resource Information ", resource.count, 10, new element_array (0 .. resource.count - 1));
--
for index in attribute.codex
loop
trait (attribute_information).elements (attribute.codex'pos (index)) := (button, 0, attribute.trait (index).name, attribute.icon (index));
end loop;
--
for index in skill.codex
loop
trait (skill_information).elements (skill.codex'pos (index)) := (button, 0, skill.trait (index).name, skill.icon (index));
end loop;
--
for index in resource.codex
loop
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; 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;
limitation : constant integer := (if trait (index).length < trait (index).height then trait (index).length else trait (index).height);
width : constant integer := 240;
height : constant integer := limitation * 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 (offset_x, offset_y, width, trait (index).title);
ui.draw_tiny_menu (offset_x, offset_y, width, height, true);
--
for element_index in 0 .. limitation - 1
loop
ui.draw_frame (offset_x + draw_offset, offset_y + draw_offset + element_index * offset, width - 2 * draw_offset, 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;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end menu;