xhads/source/menu.adb

106 lines
4.8 KiB
Ada
Raw Normal View History

2024-02-16 09:59:19 -05:00
with core, ui, effect, attribute, skill, resource, faction, might, magic, item, unit, construction, world, menu;
2024-02-15 21:03:09 -05:00
use menu;
package body menu is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2024-02-19 18:01:52 -05:00
draw_offset : constant integer := 16;
icon_offset : constant integer := 4;
icon_size : constant integer := 32;
offset : constant integer := icon_size + 2 * icon_offset;
------------------------------------------------------------------------------------------
2024-02-15 21:03:09 -05:00
procedure configure is
begin
2024-02-19 18:01:52 -05:00
trait (attribute_information) := ("Attribute Information ", attribute.count, 10, 100, 64, new element_array (0 .. attribute.count - 1));
trait (skill_information) := ("Skill Information ", skill.count, 10, 700, 64, new element_array (0 .. skill.count - 1));
trait (resource_information) := ("Resource Information ", resource.count, 10, 400, 64, new element_array (0 .. resource.count - 1));
2024-02-19 19:17:43 -05:00
trait (none) := ("-- ", 2, 10, 0, 0, new element_array (0 .. 1));
2024-02-16 09:59:19 -05:00
--
for index in attribute.codex
2024-02-16 09:59:19 -05:00
loop
trait (attribute_information).elements (attribute.codex'pos (index)) := (button, attribute.codex'pos (index), attribute.trait (index).name, attribute.icon (index));
2024-02-16 09:59:19 -05:00
end loop;
--
for index in skill.codex
2024-02-16 09:59:19 -05:00
loop
trait (skill_information).elements (skill.codex'pos (index)) := (button, skill.codex'pos (index), skill.trait (index).name, skill.icon (index));
2024-02-16 09:59:19 -05:00
end loop;
--
for index in resource.codex
2024-02-16 09:59:19 -05:00
loop
trait (resource_information).elements (resource.codex'pos (index)) := (button, resource.codex'pos (index), resource.trait (index).name, resource.icon (index));
2024-02-16 09:59:19 -05:00
end loop;
2024-02-19 19:17:43 -05:00
--
for index in 0 .. 1
loop
trait (none).elements (index) := (button, index, "-- ", resource.icon (resource.gold));
end loop;
2024-02-15 21:03:09 -05:00
end configure;
2024-02-16 09:59:19 -05:00
------------------------------------------------------------------------------------------
2024-02-19 18:01:52 -05:00
procedure synchronize is
limitation : integer;
2024-02-19 18:01:52 -05:00
begin
2024-02-19 19:17:43 -05:00
mouse_over_menu := none;
mouse_over_menu_element := 0;
--
2024-02-19 18:01:52 -05:00
for index in codex
loop
limitation := (if trait (index).length < trait (index).height then trait (index).length else trait (index).height);
--
if core.cursor_x > trait (index).x
and core.cursor_x < trait (index).x + 2 * draw_offset + offset + 24 * 8
and core.cursor_y > trait (index).y
and core.cursor_y < trait (index).y + limitation * offset + 2 * draw_offset then
mouse_over_menu := index;
2024-02-19 19:17:43 -05:00
end if;
--
if mouse_over_menu /= none then
for element_index in 0 .. limitation - 1
loop
if core.cursor_y > trait (index).y + draw_offset + element_index * offset
and core.cursor_y < trait (index).y + draw_offset + element_index * offset + offset then
mouse_over_menu_element := element_index;
end if;
end loop;
2024-02-19 18:01:52 -05:00
return;
end if;
end loop;
end synchronize;
------------------------------------------------------------------------------------------
procedure draw (index : in codex; x, y : in integer; center : in boolean) is
2024-02-19 18:01:52 -05:00
scroll_bar : constant boolean := (if trait (index).length < trait (index).height then false else true);
2024-02-19 16:46:28 -05:00
limitation : constant integer := (if trait (index).length < trait (index).height then trait (index).length else trait (index).height);
2024-02-19 18:01:52 -05:00
width : constant integer := 2 * draw_offset + offset + 24 * 8;
2024-02-19 16:46:28 -05:00
height : constant integer := limitation * offset + 2 * draw_offset;
2024-02-15 21:03:09 -05:00
begin
2024-02-16 09:59:19 -05:00
if index = none then
return;
end if;
--
trait (index).x := (if center then (core.window_width - width) / 2 else x);
trait (index).y := (if center then (core.window_height - height) / 2 else y);
--
ui.draw_title_bar (trait (index).x, trait (index).y, width, trait (index).title);
ui.draw_tiny_menu (trait (index).x, trait (index).y, width, height, true);
2024-02-16 09:59:19 -05:00
--
2024-02-19 16:46:28 -05:00
for element_index in 0 .. limitation - 1
2024-02-16 09:59:19 -05:00
loop
ui.draw_frame (trait (index).x + draw_offset, trait (index).y + draw_offset + element_index * offset, width - 2 * draw_offset, offset);
2024-02-16 09:59:19 -05:00
--
core.draw (trait (index).elements (element_index).icon, trait (index).x + draw_offset + icon_offset, trait (index).y + draw_offset + icon_offset + element_index * offset);
core.write (trait (index).elements (element_index).text, trait (index).x + draw_offset + offset, trait (index).y + draw_offset + 2 * icon_offset + element_index * offset);
2024-02-16 09:59:19 -05:00
end loop;
2024-02-15 21:03:09 -05:00
end draw;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end menu;