From f06b32f8ae92a5d909075ef8c3cc12729415c50a Mon Sep 17 00:00:00 2001 From: xolatile Date: Thu, 16 May 2024 10:43:39 -0400 Subject: [PATCH] Refactored some UI code... --- source/magic.adb | 4 +--- source/ui.adb | 20 ++++++++++++++++++++ source/ui.ads | 2 ++ source/world.adb | 19 ++++++++++--------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/source/magic.adb b/source/magic.adb index fb8d1cd..81febdf 100644 --- a/source/magic.adb +++ b/source/magic.adb @@ -31,10 +31,8 @@ package body magic is ------------------------------------------------------------------------------------------ procedure view (index : in enumeration; x, y : in integer) is - offset : constant integer := 8; begin - ui.draw_frame (trait (index).text, x, y, view_width + 2 * offset, view_height + 2 * offset); - core.draw (view_sprite (index), x + offset, y + offset); + ui.draw_sprite (view_sprite (index), trait (index).text, x, y, 8); end view; ------------------------------------------------------------------------------------------ diff --git a/source/ui.adb b/source/ui.adb index a8e3527..0c98e26 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -316,6 +316,26 @@ package body ui is ------------------------------------------------------------------------------------------ + procedure draw_sprite (data : in core.sprite; text : in string; x, y, offset : in integer; action : core.pointer := core.idle_skip'access) is + begin + core.draw (data, x + offset, y + offset, factor => 1); + -- + draw_icon_menu (x, y, data.width + 2 * offset, data.height + 2 * offset); + -- + if core.cursor_inside (x, y, data.width + 2 * offset, data.height + 2 * offset) then + prioritize := true; + -- + core.write_help_box (text); + -- + if core.cursor_mode = 1 then + action.all; + core.cursor_mode := 0; + end if; + end if; + end draw_sprite; + + ------------------------------------------------------------------------------------------ + procedure draw_help_box (x, y, width, height : in integer; action : core.pointer := core.idle_skip'access) is offset : constant integer := sprite (active, text_middle).width; begin diff --git a/source/ui.ads b/source/ui.ads index c7c185f..8bbdbcd 100644 --- a/source/ui.ads +++ b/source/ui.ads @@ -62,6 +62,8 @@ package ui is procedure draw_icon (data : in core.sprite; text : in string; x, y : in integer; action : core.pointer := core.idle_skip'access); procedure draw_overicon (data : in core.sprite; text : in string; x, y : in integer; action : core.pointer := core.idle_skip'access); + procedure draw_sprite (data : in core.sprite; text : in string; x, y, offset : in integer; action : core.pointer := core.idle_skip'access); + procedure draw_help_box (x, y, width, height : in integer; action : core.pointer := core.idle_skip'access); procedure draw_frame (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle_skip'access); diff --git a/source/world.adb b/source/world.adb index 5b306cb..7f773d7 100644 --- a/source/world.adb +++ b/source/world.adb @@ -185,15 +185,16 @@ package body world is v => v, width => core.base, height => core.base); - if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom - 6 - and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom + 6 - and core.cursor.y > offset.y + (vertical - core.camera.y ) * core.base * core.zoom - 6 - and core.cursor.y < offset.y + (vertical - core.camera.y + 1) * core.base * core.zoom + 6 - and core.cursor_mode = 1 and not ui.prioritize then - core.camera.x := horizontal; - core.camera.y := vertical; - core.cursor_mode := 0; - end if; + --~if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom - 6 + --~and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom + 6 + --~and core.cursor.y > offset.y + (vertical - core.camera.y ) * core.base * core.zoom - 6 + --~and core.cursor.y < offset.y + (vertical - core.camera.y + 1) * core.base * core.zoom + 6 + --~and core.cursor_mode = 1 + --~and not ui.prioritize then + --~core.camera.x := horizontal; + --~core.camera.y := vertical; + --~core.cursor_mode := 0; + --~end if; end if; end loop; end loop;