Refactored some core and UI code...
This commit is contained in:
parent
a493ea7d61
commit
faad7fac15
136
source/main.adb
136
source/main.adb
@ -7,6 +7,8 @@ pragma ada_2012;
|
|||||||
--~with core, ui, effect, attribute, skill, resource, faction, might, magic, item, unit, construction, chad, deity, world, ai;
|
--~with core, ui, effect, attribute, skill, resource, faction, might, magic, item, unit, construction, chad, deity, world, ai;
|
||||||
with core, ui, effect, attribute, skill, resource, faction, item, unit, construction, chad, world;
|
with core, ui, effect, attribute, skill, resource, faction, item, unit, construction, chad, world;
|
||||||
|
|
||||||
|
use core;
|
||||||
|
|
||||||
procedure main is
|
procedure main is
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -24,17 +26,17 @@ procedure main is
|
|||||||
map_preview_panel, status_preview_panel, text_box_panel
|
map_preview_panel, status_preview_panel, text_box_panel
|
||||||
);
|
);
|
||||||
|
|
||||||
view_icon : array (view) of core.sprite := (others => (others => 0));
|
view_icon : array (view) of sprite := (others => (others => 0));
|
||||||
view_list : array (view) of boolean := (others => true);
|
view_list : array (view) of boolean := (others => true);
|
||||||
view_text : array (view) of core.long_string := (
|
view_text : array (view) of long_string := (
|
||||||
"Toggle map preview panel. ",
|
"Toggle map preview panel. ",
|
||||||
"Toggle status preview panel. ",
|
"Toggle status preview panel. ",
|
||||||
"Toggle text box panel. "
|
"Toggle text box panel. "
|
||||||
);
|
);
|
||||||
|
|
||||||
procedure swap_map_preview_panel is begin view_list (map_preview_panel) := (if view_list (map_preview_panel) then false else true); end swap_map_preview_panel;
|
procedure swap_map_preview_panel is begin view_list (map_preview_panel) := not view_list (map_preview_panel); end swap_map_preview_panel;
|
||||||
procedure swap_status_preview_panel is begin view_list (status_preview_panel) := (if view_list (status_preview_panel) then false else true); end swap_status_preview_panel;
|
procedure swap_status_preview_panel is begin view_list (status_preview_panel) := not view_list (status_preview_panel); end swap_status_preview_panel;
|
||||||
procedure swap_text_box_panel is begin view_list (text_box_panel) := (if view_list (text_box_panel) then false else true); end swap_text_box_panel;
|
procedure swap_text_box_panel is begin view_list (text_box_panel) := not view_list (text_box_panel); end swap_text_box_panel;
|
||||||
|
|
||||||
view_show : array (view) of access procedure := (
|
view_show : array (view) of access procedure := (
|
||||||
swap_map_preview_panel'access,
|
swap_map_preview_panel'access,
|
||||||
@ -44,59 +46,59 @@ procedure main is
|
|||||||
|
|
||||||
------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
procedure move_camera_up is
|
procedure check_move_camera_up is
|
||||||
begin
|
begin
|
||||||
core.move_camera_up;
|
move_camera_up;
|
||||||
core.camera.y := core.clip (core.camera.y, 0, world.map.height - 1);
|
camera.y := clip (camera.y, 0, world.map.height - 1);
|
||||||
if world.map.clips (core.camera.x, core.camera.y) then
|
if world.map.clips (camera.x, camera.y) then
|
||||||
core.increment (core.camera.y);
|
increment (camera.y);
|
||||||
end if;
|
end if;
|
||||||
end move_camera_up;
|
end check_move_camera_up;
|
||||||
|
|
||||||
procedure move_camera_down is
|
procedure check_move_camera_down is
|
||||||
begin
|
begin
|
||||||
core.move_camera_down;
|
move_camera_down;
|
||||||
core.camera.y := core.clip (core.camera.y, 0, world.map.height - 1);
|
camera.y := clip (camera.y, 0, world.map.height - 1);
|
||||||
if world.map.clips (core.camera.x, core.camera.y) then
|
if world.map.clips (camera.x, camera.y) then
|
||||||
core.decrement (core.camera.y);
|
decrement (camera.y);
|
||||||
end if;
|
end if;
|
||||||
end move_camera_down;
|
end check_move_camera_down;
|
||||||
|
|
||||||
procedure move_camera_left is
|
procedure check_move_camera_left is
|
||||||
begin
|
begin
|
||||||
core.move_camera_left;
|
move_camera_left;
|
||||||
core.camera.x := core.clip (core.camera.x, 0, world.map.width - 1);
|
camera.x := clip (camera.x, 0, world.map.width - 1);
|
||||||
if world.map.clips (core.camera.x, core.camera.y) then
|
if world.map.clips (camera.x, camera.y) then
|
||||||
core.increment (core.camera.x);
|
increment (camera.x);
|
||||||
end if;
|
end if;
|
||||||
end move_camera_left;
|
end check_move_camera_left;
|
||||||
|
|
||||||
procedure move_camera_right is
|
procedure check_move_camera_right is
|
||||||
begin
|
begin
|
||||||
core.move_camera_right;
|
move_camera_right;
|
||||||
core.camera.x := core.clip (core.camera.x, 0, world.map.width - 1);
|
camera.x := clip (camera.x, 0, world.map.width - 1);
|
||||||
if world.map.clips (core.camera.x, core.camera.y) then
|
if world.map.clips (camera.x, camera.y) then
|
||||||
core.decrement (core.camera.x);
|
decrement (camera.x);
|
||||||
end if;
|
end if;
|
||||||
end move_camera_right;
|
end check_move_camera_right;
|
||||||
|
|
||||||
procedure ui_main_style is
|
procedure ui_main_style is
|
||||||
begin
|
begin
|
||||||
ui.active := ui.style'val ((ui.style'pos (ui.active) + 1) mod (ui.style'pos (ui.style'last) + 1));
|
ui.active := ui.style'val ((ui.style'pos (ui.active) + 1) mod (ui.style'pos (ui.style'last) + 1));
|
||||||
end ui_main_style;
|
end ui_main_style;
|
||||||
|
|
||||||
procedure zoom_in is begin core.zoom := 2; end zoom_in;
|
procedure zoom_in is begin zoom := 2; end zoom_in;
|
||||||
procedure zoom_out is begin core.zoom := 1; end zoom_out;
|
procedure zoom_out is begin zoom := 1; end zoom_out;
|
||||||
|
|
||||||
signal_list : constant array (core.signal_code) of access procedure := (
|
signal_list : constant array (signal_code) of access procedure := (
|
||||||
core.signal_up => move_camera_up'access,
|
signal_up => check_move_camera_up'access,
|
||||||
core.signal_down => move_camera_down'access,
|
signal_down => check_move_camera_down'access,
|
||||||
core.signal_left => move_camera_left'access,
|
signal_left => check_move_camera_left'access,
|
||||||
core.signal_right => move_camera_right'access,
|
signal_right => check_move_camera_right'access,
|
||||||
core.signal_v => ui_main_style'access,
|
signal_v => ui_main_style'access,
|
||||||
core.signal_kp_add => zoom_in'access,
|
signal_kp_add => zoom_in'access,
|
||||||
core.signal_kp_subtract => zoom_out'access,
|
signal_kp_subtract => zoom_out'access,
|
||||||
others => core.idle'access
|
others => idle'access
|
||||||
);
|
);
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------
|
||||||
@ -113,11 +115,11 @@ procedure main is
|
|||||||
if not view_list (status_preview_panel) then
|
if not view_list (status_preview_panel) then
|
||||||
side_panel := 0;
|
side_panel := 0;
|
||||||
else
|
else
|
||||||
side_panel := core.window_width / 4;
|
side_panel := window_width / 4;
|
||||||
end if;
|
end if;
|
||||||
--
|
--
|
||||||
preview_width := core.window_width - side_panel;
|
preview_width := window_width - side_panel;
|
||||||
preview_height := core.window_height - text_box_height;
|
preview_height := window_height - text_box_height;
|
||||||
text_box_height := 32;
|
text_box_height := 32;
|
||||||
--
|
--
|
||||||
world.draw;
|
world.draw;
|
||||||
@ -132,17 +134,17 @@ procedure main is
|
|||||||
end if;
|
end if;
|
||||||
--
|
--
|
||||||
if view_list (text_box_panel) then
|
if view_list (text_box_panel) then
|
||||||
ui.draw_help_box (0, core.window_height - text_box_height, core.window_width - core.icon * (view'pos (view'last) + 1), text_box_height);
|
ui.draw_help_box (0, window_height - text_box_height, window_width - icon * (view'pos (view'last) + 1), text_box_height);
|
||||||
end if;
|
end if;
|
||||||
--
|
--
|
||||||
for index in view loop
|
for index in view loop
|
||||||
ui.draw_icon (view_icon (index), view_text (index),
|
ui.draw_icon (view_icon (index), view_text (index),
|
||||||
core.window_width - core.icon * (view'pos (view'last) + 1) + core.icon * view'pos (index),
|
window_width - icon * (view'pos (view'last) + 1) + icon * view'pos (index),
|
||||||
core.window_height - text_box_height,
|
window_height - text_box_height,
|
||||||
view_show (index));
|
view_show (index));
|
||||||
end loop;
|
end loop;
|
||||||
--
|
--
|
||||||
signal_list (core.signal_mode).all;
|
signal_list (signal_mode).all;
|
||||||
--
|
--
|
||||||
--~magic.menu (0, 0, true);
|
--~magic.menu (0, 0, true);
|
||||||
--~might.menu (0, 0, true);
|
--~might.menu (0, 0, true);
|
||||||
@ -156,18 +158,18 @@ procedure main is
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
core.dash;
|
dash;
|
||||||
core.echo (core.comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic");
|
echo (comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic");
|
||||||
core.echo (core.comment, "Version -- 1.0.0");
|
echo (comment, "Version -- 1.0.0");
|
||||||
core.echo (core.comment, "License -- GNU/GPLv3+");
|
echo (comment, "License -- GNU/GPLv3+");
|
||||||
core.echo (core.comment, "Xhads is free software, you can redistribute it and modify it under the terms of the GNU General Public License by Free Software Foundation.");
|
echo (comment, "Xhads is free software, you can redistribute it and modify it under the terms of the GNU General Public License by Free Software Foundation.");
|
||||||
core.dash;
|
dash;
|
||||||
|
|
||||||
core.initialize;
|
initialize;
|
||||||
|
|
||||||
ui.configure;
|
ui.configure;
|
||||||
|
|
||||||
core.play (core.import_song (core.c_string ("./song/main_menu.ogg")).index);
|
play (import_song (c_string ("./song/main_menu.ogg")).index);
|
||||||
|
|
||||||
attribute.configure;
|
attribute.configure;
|
||||||
skill.configure;
|
skill.configure;
|
||||||
@ -183,40 +185,40 @@ begin
|
|||||||
|
|
||||||
world.make (world.swamp, 120, 60);
|
world.make (world.swamp, 120, 60);
|
||||||
|
|
||||||
core.dash;
|
dash;
|
||||||
core.echo (core.success, "Successfully initialized game data, entering main gameplay loop.");
|
echo (success, "Successfully initialized game data, entering main gameplay loop.");
|
||||||
core.dash;
|
dash;
|
||||||
|
|
||||||
for index in view loop
|
for index in view loop
|
||||||
view_icon (index) := core.import_sprite ("./sprite/ui/icon/" & core.lowercase (view'image (index)) & ".png", 1, 1);
|
view_icon (index) := import_sprite ("./sprite/ui/icon/" & lowercase (view'image (index)) & ".png", 1, 1);
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
ui.active := ui.imp;
|
ui.active := ui.imp;
|
||||||
|
|
||||||
core.camera := (1, 1);
|
camera := (1, 1);
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
introduction_loop: loop
|
introduction_loop: loop
|
||||||
core.synchronize;
|
synchronize;
|
||||||
--
|
--
|
||||||
exit when core.signal_code'pos (core.signal_mode) = core.signal_code'pos (core.signal_space);
|
exit when signal_mode = signal_space;
|
||||||
--
|
--
|
||||||
introduction;
|
introduction;
|
||||||
end loop introduction_loop;
|
end loop introduction_loop;
|
||||||
|
|
||||||
gameplay_loop: loop
|
gameplay_loop: loop
|
||||||
core.synchronize;
|
synchronize;
|
||||||
--
|
--
|
||||||
exit when core.engine_active = false;
|
exit when engine_active = false;
|
||||||
--
|
--
|
||||||
gameplay;
|
gameplay;
|
||||||
end loop gameplay_loop;
|
end loop gameplay_loop;
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
core.deinitialize;
|
deinitialize;
|
||||||
|
|
||||||
core.dash;
|
dash;
|
||||||
|
|
||||||
end main;
|
end main;
|
||||||
|
@ -227,10 +227,11 @@ package body ui is
|
|||||||
------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
procedure synchronize is
|
procedure synchronize is
|
||||||
|
use core;
|
||||||
begin
|
begin
|
||||||
for index in 0 .. structure_count - 1 loop
|
for index in 0 .. structure_count - 1 loop
|
||||||
if core.signal_code'pos (core.signal_mode) = core.signal_code'pos (structure_array (index).toggle) then
|
if signal_mode = structure_array (index).toggle then
|
||||||
structure_array (index).show := (if structure_array (index).show then false else true);
|
structure_array (index).show := not structure_array (index).show;
|
||||||
end if;
|
end if;
|
||||||
--
|
--
|
||||||
if structure_array (index).show then
|
if structure_array (index).show then
|
||||||
|
Loading…
Reference in New Issue
Block a user