From ff9cf274d07fc098a10adc74661ecdf00fbebaed Mon Sep 17 00:00:00 2001 From: xolatile Date: Thu, 9 May 2024 03:53:38 -0400 Subject: [PATCH] Added cursor movement with range 6 and more tiny fixes... --- source/core.adb | 16 ++++++++++++++-- source/core.ads | 5 +++++ source/main.adb | 2 +- source/ui.adb | 17 +++++++---------- source/ui.ads | 5 +++-- source/world.adb | 26 ++++++++++---------------- sprite/ui/dwarf/title_bar_left.png | Bin 511 -> 539 bytes sprite/ui/dwarf/title_bar_middle.png | Bin 155 -> 155 bytes sprite/ui/dwarf/title_bar_right.png | Bin 403 -> 434 bytes 9 files changed, 40 insertions(+), 31 deletions(-) diff --git a/source/core.adb b/source/core.adb index c535bea..17e7986 100644 --- a/source/core.adb +++ b/source/core.adb @@ -134,6 +134,18 @@ package body core is ------------------------------------------------------------------------------------------ + function center_x (object : in integer) return integer is begin return (window_width - object) / 2; end center_x; + function center_y (object : in integer) return integer is begin return (window_height - object) / 2; end center_y; + + ------------------------------------------------------------------------------------------ + + function cursor_inside (x, y, width, height : in integer) return boolean is + begin + return cursor.x > x and cursor.x < x + width and cursor.y > y and cursor.y < y + height; + end cursor_inside; + + ------------------------------------------------------------------------------------------ + function import_sprite (file_path : in string; frames, states : in integer) return sprite is this : sprite; begin @@ -217,8 +229,8 @@ package body core is ray.draw_text (data => font_array (data.index), text => c_string (text), view => (float (x), float (y)), - scale => float ((if size = 0 then data.scale else size)), - space => float (data.space), + scale => (if size = 0 then float (font_array (data.index).base) else float (size)), + space => float (font_array (data.index).pad), tint => new_tint); end write; diff --git a/source/core.ads b/source/core.ads index ea49379..29090d9 100644 --- a/source/core.ads +++ b/source/core.ads @@ -110,6 +110,11 @@ package core is function window_width return integer; function window_height return integer; + function center_x (object : in integer) return integer; + function center_y (object : in integer) return integer; + + function cursor_inside (x, y, width, height : in integer) return boolean; + function import_sprite (file_path : in string; frames, states : in integer) return sprite; function import_font (file_path : in string; scale, space : in integer) return font; function import_song (file_path : in string) return song; diff --git a/source/main.adb b/source/main.adb index 33b709a..3db62f5 100644 --- a/source/main.adb +++ b/source/main.adb @@ -105,7 +105,7 @@ procedure main is procedure introduction is begin - ui.write ("[-- Please press Spacebar to continue]", 0, 0, 14, (102, 102, 102, 255)); + core.write ("[-- Please press Spacebar to continue]", 0, center_y (24), (102, 102, 102, 255)); end introduction; ------------------------------------------------------------------------------------------ diff --git a/source/ui.adb b/source/ui.adb index 555904f..c4eed13 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -70,13 +70,6 @@ package body ui is ------------------------------------------------------------------------------------------ - function cursor_inside (x, y, width, height : in integer) return boolean is - begin - return core.cursor.x > x and core.cursor.x < x + width and core.cursor.y > y and core.cursor.y < y + height; - end cursor_inside; - - ------------------------------------------------------------------------------------------ - procedure draw (index : in element := none; x : in integer := 0; y : in integer := 0; @@ -229,6 +222,8 @@ package body ui is procedure synchronize is use core; begin + prioritize := false; + -- for index in 0 .. structure_count - 1 loop if signal_mode = structure_array (index).toggle then structure_array (index).show := not structure_array (index).show; @@ -236,13 +231,15 @@ package body ui is -- if structure_array (index).show then draw_structure (structure_array (index)); + -- + prioritize := true; end if; end loop; end synchronize; ------------------------------------------------------------------------------------------ - procedure write (text : in string; x, y : in integer; size : in natural := 0; tint : in core.colour := (others => 255)) is + procedure write (text : in string; x, y : in integer; tint : in core.colour := (others => 255); size : in natural := 0) is begin core.write (text, x, y, tint, font (active).scale, font (active)); end write; @@ -258,7 +255,7 @@ package body ui is core.draw (data, x, y); core.zoom := save_zoom; -- - if cursor_inside (x, y, core.icon, core.icon) then + if core.cursor_inside (x, y, core.icon, core.icon) then draw (icon_selected, x, y); -- core.write_text_box (description); @@ -360,7 +357,7 @@ package body ui is -- draw_horizontally (title_bar_middle, x + sprite (active, title_bar_left).width, y - sprite (active, title_bar_middle).height, middle_width); -- - write (title, x + sprite (active, title_bar_left).width + offset, y - font (active).scale - 4, tint => font_tint (active)); + write (title, x + sprite (active, title_bar_left).width, y - font (active).scale - 4, tint => font_tint (active)); end draw_title_bar; ------------------------------------------------------------------------------------------ diff --git a/source/ui.ads b/source/ui.ads index 6de346e..5ae989e 100644 --- a/source/ui.ads +++ b/source/ui.ads @@ -47,14 +47,15 @@ package ui is ------------------------------------------------------------------------------------------ - active : style := main; + active : style := main; + prioritize : boolean := false; ------------------------------------------------------------------------------------------ procedure configure; procedure synchronize; - procedure write (text : in string; x, y : in integer; size : in natural := 0; tint : in core.colour := (others => 255)); + procedure write (text : in string; x, y : in integer; tint : in core.colour := (others => 255); size : in natural := 0); procedure draw_icon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access); procedure draw_overicon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access); diff --git a/source/world.adb b/source/world.adb index 80d526e..c9468a0 100644 --- a/source/world.adb +++ b/source/world.adb @@ -130,16 +130,15 @@ package body world is v => v, width => core.base, height => core.base); - --~--MOVE PLAYER TO TILE WHERE YOU CLICKED - --~if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom - --~and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom - --~and core.cursor.y > offset.y + (vertical - core.camera.y ) * core.base * core.zoom - --~and core.cursor.y < offset.y + (vertical - core.camera.y + 1) * core.base * core.zoom - --~and core.cursor_mode = 1 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; @@ -174,7 +173,7 @@ package body world is for horizontal in 0 .. map.width - 1 loop exit when offset.x + (horizontal - core.camera.x) * core.base * core.zoom > core.window_width; -- - if (horizontal - core.camera.x) ** 2 + (vertical - core.camera.y) ** 2 > view_reach then + if (horizontal - core.camera.x) ** 2 + (vertical - core.camera.y) ** 2 > view_reach then core.draw (data => dark, x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom, y => offset.y + (vertical - core.camera.y) * core.base * core.zoom); @@ -189,11 +188,6 @@ package body world is offset : core.vector := ((core.window_width - core.base) / 2, (core.window_height - core.base) / 2); begin - --~for x in 0 .. view_reach loop - --~for y in 0 .. view_reach loop - --~map.views ((x + core.camera.x - view_reach / 2) mod map.width, (y + core.camera.y - view_reach / 2) mod map.height) := true; - --~end loop; - --~end loop; for vertical in 0 .. map.height - 1 loop exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height; -- diff --git a/sprite/ui/dwarf/title_bar_left.png b/sprite/ui/dwarf/title_bar_left.png index 55dc9df72084cb96a8f19d70a2ca67b6d09cb33c..96a3bbb906f348661ef059f70d85d2162ce5ab01 100644 GIT binary patch delta 492 zcmV+Jq=eL;&%Zw#D@^F1h40|Emqz+M*xz9i^wLtZDBS?!s<6*+uG*$VD@&(wiFK_$|wGU zusuW@=N$2H|M>4dFfnsnD$zPr@`H$mh1jd7+tU+hAK(IDTyD{{txNG+{c3UkDMSyB z{`}I_CC}9p4S#9j^&%ohMCNE9BILcFE2(e&xd&42%75%YYX~>U55)WDpSQGn;BE8c zWapDeW**-F-}uPMSYJD$=52qK_uVI9fc_6v}MJv7E>V(rP&d?cj$rR$T?A} z1}*}S3ZW%F3qT7Z)!ee*$RZ)4eXB?=R1zY0?!DBb_%my6^qCw!cC5-n_Yy+8+0ql{ iM4u`rv8F@*%k~1g*Jk_iyKWi)00000WbcW1pfn&Ie)Q9L_t(&-tCytk;5PiL`8-M+`_hy7N~_9QbKA_Ewqpp)PhTJ zeqvwZOAfFjkY~;_`3c6e4~Yed=-`jj`Y?d$umAw27~?S`0ALCs95aR1;zdLqz-z92 z3jn7jKBYt=;>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