xhads/source/unit.adb

118 lines
5.2 KiB
Ada

with core, ui, effect, attribute, faction, unit;
use unit;
package body unit is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type sprite_array is array (codex) of core.sprite;
view_width : constant integer := 48;
view_height : constant integer := 64;
sprite : sprite_array;
icon_sprite : sprite_array;
view_sprite : sprite_array;
------------------------------------------------------------------------------------------
procedure configure is
begin
core.echo (core.comment, "Configuring unit components...");
--
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.import_sprite ("./sprite/unit/" & folder & "/" & file & ".png", 6, 6);
icon_sprite (index) := core.import_sprite ("./sprite/unit/icon/" & file & ".png", 1, 1);
view_sprite (index) := core.import_sprite ("./sprite/unit/view/" & file & ".png", 1, 1);
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 (trait (index).text, x, y);
end icon;
------------------------------------------------------------------------------------------
procedure view (index : in codex; x, y : in integer) is
offset : constant integer := 4;
begin
core.draw (view_sprite (index), x + offset, y + offset);
ui.draw_icon_menu (trait (index).text, x, y, view_width + 2 * offset, view_height + 2 * offset);
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);
move : integer := 0;
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
move := faction.codex'pos (trait (index).kind) * 168;
--
icon (index, move_x + offset + move, move_y + offset + (codex'pos (index) mod 14) * core.icon);
core.write (trait (index).name, move_x + offset + move + core.icon, move_y + offset + (codex'pos (index) mod 14) * core.icon, ui.font (ui.active));
end loop;
end menu;
------------------------------------------------------------------------------------------
procedure stat (index : in codex; x, y : in integer; center : in boolean) is
offset : constant integer := 16;
width : constant integer := 10 + offset + 6 * (sprite (index).width + 8);
height : constant integer := attribute.count * core.icon + 2 * offset + 10 + sprite (index).height;
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);
move : integer := 0;
begin
ui.draw_tiny_menu (move_x, move_y, width, height, true);
ui.draw_title_bar (move_x, move_y, width, trait (index).name);
--
view (index, move_x + offset, move_y + offset);
--
for data in attribute.codex
loop
move := attribute.codex'pos (data) * core.icon;
--
ui.draw_icon (attribute.trait (data).text, move_x + view_width + 12 + offset, move_y + offset + move);
attribute.draw (data, move_x + view_width + 12 + offset, move_y + offset + move);
--
core.write (integer'image (trait (index).attributes (data)), move_x + view_width + 12 + offset + core.icon, move_y + offset + move, ui.font (ui.active));
end loop;
--
for animate in animation
loop
draw (index, animate, move_x + offset + animation'pos (animate) * (sprite (index).width + 8), move_y + offset + 8 + core.icon * attribute.count);
ui.draw_icon_menu (trait (index).text, move_x + offset + animation'pos (animate) * (sprite (index).width + 8), move_y + offset + 8 + core.icon * attribute.count, sprite (index).width, sprite (index).height);
end loop;
end stat;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end unit;