xhads/source/resource.adb

94 lines
4.0 KiB
Ada

-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
--
-- GNU General Public Licence (version 3 or later)
with core, ui;
package body resource is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
procedure configure is
procedure define (index : in enumeration; minimum, maximum : in integer; name, text : in string) is
begin
description (index).base := (minimum, maximum);
description (index).name := core.unbound (name);
description (index).text := core.unbound (text);
end define;
--
structure : ui.structure;
--
time : float := 0.0;
begin
time := core.time;
--
core.echo (core.comment, "Configuring" & count'image & " resource components...");
--
description := new description_array (enumeration'range);
icon := new icon_array (enumeration'range);
--
define (gold, 24, 480, "Gold", "Gold is precious yellowish shiny metal, valued since ancient times.");
define (wood, 12, 240, "Wood", "Wood is just bundle of lignin and cellulose, nothing more.");
define (stone, 12, 240, "Stone", "Stone is essential building block for most constructions in this world.");
define (metal, 12, 240, "Metal", "Metal as a resource is mixture of commonly found metalic elements.");
define (leather, 12, 240, "Leather", "Leather is general purpose resource, used for armours and decorations.");
define (gem, 12, 240, "Gem", "Gem as a resource is same as metal, just mixture of various gems.");
--
structure.title := "Resource Menu ";
structure.toggle := core.signal_r;
structure.show := false;
structure.center := false;
structure.resize := true;
structure.x := 60;
structure.y := 500;
structure.gui_n := count;
--
ui.add_structure (structure);
--
for index in enumeration loop
icon (index) := core.import_sprite (core.folder & "/icon/resource/" & core.lowercase (enumeration'image (index)) & ".png", 1, 1);
--
ui.add_structure_button (icon (index), description (index).name, description (index).text);
end loop;
--
core.echo (core.success, "Successfully configured resource information in" & natural'image (natural (1_000_000.0 * (core.time - time))) & " microseconds.");
end configure;
------------------------------------------------------------------------------------------
procedure draw_points (data : in points; x, y : in integer) is
frame_width : constant integer := 4 * core.icon;
begin
for index in enumeration loop
ui.draw_icon (icon (index), core.bound (description (index).text), x + (core.icon + frame_width) * enumeration'pos (index), y);
ui.draw_frame (core.bound (description (index).text), x + (core.icon + frame_width) * enumeration'pos (index) + core.icon, y, frame_width, core.icon);
--
ui.write (text => data (index).value'image & " /" & data (index).limit'image,
x => x + (core.icon + frame_width) * enumeration'pos (index) + core.icon - 1,
y => y + 7,
size => 18);
end loop;
end draw_points;
------------------------------------------------------------------------------------------
procedure save_points (here : in core.io.file_type; data : in points) is
begin
for index in enumeration loop
core.save_point (here, data (index));
end loop;
end save_points;
------------------------------------------------------------------------------------------
procedure load_points (here : in core.io.file_type; data : out points) is
begin
for index in enumeration loop
core.load_point (here, data (index));
end loop;
end load_points;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end resource;