2024-04-25 00:27:13 -04:00
|
|
|
-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
|
|
|
|
--
|
|
|
|
-- GNU General Public Licence (version 3 or later)
|
|
|
|
|
2024-03-11 15:35:56 -04:00
|
|
|
with core, ui, effect, attribute, faction, unit;
|
2024-02-15 21:03:09 -05:00
|
|
|
|
|
|
|
package body unit is
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2024-03-11 15:35:56 -04:00
|
|
|
view_width : constant integer := 48;
|
|
|
|
view_height : constant integer := 64;
|
|
|
|
|
2024-04-26 16:05:48 -04:00
|
|
|
sprite : array (enumeration) of core.sprite;
|
|
|
|
icon_sprite : array (enumeration) of core.sprite;
|
|
|
|
view_sprite : array (enumeration) of core.sprite;
|
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-04-27 10:01:54 -04:00
|
|
|
for index in enumeration loop
|
|
|
|
declare folder : constant string := core.lowercase (faction.enumeration'image (trait (index).kind));
|
|
|
|
file : constant string := core.lowercase (enumeration'image (index));
|
2024-02-15 21:03:09 -05:00
|
|
|
begin
|
2024-04-25 03:46:07 -04:00
|
|
|
sprite (index) := core.import_sprite ("./sprite/unit/" & folder & "/" & file & ".png", 4, 6);
|
2024-03-17 16:45:46 -04:00
|
|
|
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);
|
2024-02-15 21:03:09 -05:00
|
|
|
end;
|
|
|
|
end loop;
|
|
|
|
end configure;
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-26 16:05:48 -04:00
|
|
|
procedure draw (index : in enumeration; state : in animation; x, y : in integer) is
|
2024-02-15 21:03:09 -05:00
|
|
|
begin
|
2024-04-26 18:25:29 -04:00
|
|
|
core.draw (sprite (index), x, y, 6, animation'pos (state));
|
2024-02-15 21:03:09 -05:00
|
|
|
end draw;
|
|
|
|
|
2024-03-11 12:50:29 -04:00
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-26 16:05:48 -04:00
|
|
|
procedure icon (index : in enumeration; x, y : in integer) is
|
2024-03-11 12:50:29 -04:00
|
|
|
begin
|
|
|
|
core.draw (icon_sprite (index), x + 2, y + 2);
|
2024-03-13 14:07:17 -04:00
|
|
|
ui.draw_overicon (trait (index).text, x, y);
|
2024-03-11 12:50:29 -04:00
|
|
|
end icon;
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-26 16:05:48 -04:00
|
|
|
procedure view (index : in enumeration; x, y : in integer) is
|
2024-03-11 15:35:56 -04:00
|
|
|
offset : constant integer := 4;
|
2024-03-11 12:50:29 -04:00
|
|
|
begin
|
2024-03-11 15:35:56 -04:00
|
|
|
core.draw (view_sprite (index), x + offset, y + offset);
|
2024-03-13 14:07:17 -04:00
|
|
|
ui.draw_icon_menu (trait (index).text, x, y, view_width + 2 * offset, view_height + 2 * offset);
|
2024-03-11 12:50:29 -04:00
|
|
|
end view;
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
procedure menu (x, y : in integer; center : in boolean) is
|
|
|
|
offset : constant integer := 16;
|
|
|
|
width : constant integer := 168 * faction.count + 2 * offset;
|
2024-03-11 16:36:42 -04:00
|
|
|
height : constant integer := 14 * core.icon + 2 * offset;
|
2024-03-11 12:50:29 -04:00
|
|
|
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);
|
2024-03-11 16:36:42 -04:00
|
|
|
move : integer := 0;
|
2024-03-11 12:50:29 -04:00
|
|
|
begin
|
|
|
|
ui.draw_tiny_menu (move_x, move_y, width, height, true);
|
|
|
|
ui.draw_title_bar (move_x, move_y, width, "Units");
|
|
|
|
--
|
2024-04-27 10:01:54 -04:00
|
|
|
for index in enumeration loop
|
2024-04-26 16:05:48 -04:00
|
|
|
move := faction.enumeration'pos (trait (index).kind) * 168;
|
2024-03-11 16:36:42 -04:00
|
|
|
--
|
2024-04-26 16:05:48 -04:00
|
|
|
icon (index, move_x + offset + move, move_y + offset + (enumeration'pos (index) mod 14) * core.icon);
|
|
|
|
ui.write (trait (index).name, move_x + offset + move + core.icon, move_y + offset + (enumeration'pos (index) mod 14) * core.icon);
|
2024-03-11 12:50:29 -04:00
|
|
|
end loop;
|
|
|
|
end menu;
|
|
|
|
|
2024-03-11 15:35:56 -04:00
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-26 16:05:48 -04:00
|
|
|
procedure stat (index : in enumeration; x, y : in integer; center : in boolean) is
|
2024-03-11 15:35:56 -04:00
|
|
|
offset : constant integer := 16;
|
2024-03-13 11:28:18 -04:00
|
|
|
width : constant integer := 10 + offset + 6 * (sprite (index).width + 8);
|
|
|
|
height : constant integer := attribute.count * core.icon + 2 * offset + 10 + sprite (index).height;
|
2024-03-11 15:35:56 -04:00
|
|
|
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);
|
|
|
|
--
|
2024-04-26 16:05:48 -04:00
|
|
|
--~for data in attribute.enumeration
|
2024-04-25 09:26:08 -04:00
|
|
|
--~loop
|
2024-04-26 16:05:48 -04:00
|
|
|
--~move := attribute.enumeration'pos (data) * core.icon;
|
2024-04-25 09:26:08 -04:00
|
|
|
--~--
|
|
|
|
--~ui.draw_icon (attribute.sprite (data), attribute.trait (data).text, move_x + view_width + 12 + offset, move_y + offset + move);
|
|
|
|
--~--
|
|
|
|
--~ui.write (trait (index).attributes (data)'image, move_x + view_width + 12 + offset + core.icon, move_y + offset + move);
|
|
|
|
--~end loop;
|
2024-03-14 14:40:05 -04:00
|
|
|
--
|
2024-04-27 10:01:54 -04:00
|
|
|
for animate in animation loop
|
2024-03-13 11:28:18 -04:00
|
|
|
draw (index, animate, move_x + offset + animation'pos (animate) * (sprite (index).width + 8), move_y + offset + 8 + core.icon * attribute.count);
|
2024-03-13 14:07:17 -04:00
|
|
|
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);
|
2024-03-11 15:35:56 -04:00
|
|
|
end loop;
|
|
|
|
end stat;
|
|
|
|
|
2024-02-15 21:03:09 -05:00
|
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
end unit;
|