xhads/source/unit.adb

79 lines
3.2 KiB
Ada
Raw Normal View History

with core, ui, effect, faction, unit;
2024-02-15 21:03:09 -05:00
use unit;
package body unit is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type sprite_array is array (codex) of core.sprite;
sprite : sprite_array;
icon_sprite : sprite_array;
view_sprite : sprite_array;
2024-02-15 21:03:09 -05:00
------------------------------------------------------------------------------------------
procedure configure is
begin
2024-03-11 08:42:25 -04:00
core.echo (core.comment, "Configuring unit components...");
--
2024-02-15 21:03:09 -05:00
for index in codex
loop
declare
folder : constant string := core.lowercase (faction.codex'image (trait (index).kind));
file : constant string := core.lowercase (codex'image (index));
begin
sprite (index) := core.load_sprite ("./sprite/unit/" & folder & "/" & file & ".png", 6, 6);
icon_sprite (index) := core.load_sprite ("./sprite/unit/icon/" & file & ".png", 1, 1);
view_sprite (index) := core.load_sprite ("./sprite/unit/view/" & file & ".png", 1, 1);
2024-02-15 21:03:09 -05:00
end;
end loop;
end configure;
------------------------------------------------------------------------------------------
procedure draw (index : in codex; state : in animation; x, y : in integer) is
begin
core.move (sprite (index), x, y, 6, animation'pos (state));
end draw;
------------------------------------------------------------------------------------------
procedure icon (index : in codex; x, y : in integer) is
begin
core.draw (icon_sprite (index), x + 2, y + 2);
ui.draw_overicon (x, y);
end icon;
------------------------------------------------------------------------------------------
procedure view (index : in codex; x, y : in integer) is
begin
core.draw (view_sprite (index), x, y);
--~ui.draw_tiny_frame ();
end view;
------------------------------------------------------------------------------------------
procedure menu (x, y : in integer; center : in boolean) is
offset : constant integer := 16;
width : constant integer := 168 * faction.count + 2 * offset;
height : constant integer := 14 * 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, "Units");
--
for index in codex
loop
icon (index, move_x + offset + faction.codex'pos (trait (index).kind) * 168, move_y + offset + (codex'pos (index) mod 14) * core.icon);
core.write (trait (index).name, move_x + offset + faction.codex'pos (trait (index).kind) * 168 + core.icon, move_y + offset + (codex'pos (index) mod 14) * core.icon);
end loop;
end menu;
2024-02-15 21:03:09 -05:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end unit;