summaryrefslogtreecommitdiff
path: root/scripts/prompt.scm
diff options
context:
space:
mode:
authorhenriquelalves <henriquelalves@gmail.com>2025-05-17 23:18:54 +0300
committerhenriquelalves <henriquelalves@gmail.com>2025-05-17 23:18:54 +0300
commitbb605eef824f287f20473b6d110d5e40eb475390 (patch)
tree2c550b10cd22515f8aee8bf9f3534a541c76c612 /scripts/prompt.scm
parent3de3dbb01dae64c747e5371c6243bea79f8723de (diff)
downloadgamejam-slgj-2025-bb605eef824f287f20473b6d110d5e40eb475390.tar.gz
gamejam-slgj-2025-bb605eef824f287f20473b6d110d5e40eb475390.tar.bz2
gamejam-slgj-2025-bb605eef824f287f20473b6d110d5e40eb475390.zip
update scripts
Diffstat (limited to 'scripts/prompt.scm')
-rw-r--r--scripts/prompt.scm45
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/prompt.scm b/scripts/prompt.scm
new file mode 100644
index 0000000..e78e5b3
--- /dev/null
+++ b/scripts/prompt.scm
@@ -0,0 +1,45 @@
+(define prompt-active #f)
+(define prompt-box (make-rect 0 0 800 20))
+(define prompt-text "")
+
+(define (prompt-update)
+ (if (eq? current-pressed-key KEY_F1)
+ (set! prompt-active (not prompt-active))
+ )
+
+ (if prompt-active
+ (begin
+ (let ((key (rl-get-char-pressed)))
+ (cond ((and (>= key 32) (<= key 125))
+ (set! prompt-text
+ (string-append prompt-text (string (integer->char key)))))
+ ))
+
+ (if (rl-is-key-down KEY_ENTER)
+ (begin
+ (eval-string prompt-text)
+ (set! prompt-text "")
+ ))
+
+ (if (eq? current-pressed-key KEY_BACKSPACE)
+ (let ((n (string-length prompt-text)))
+ (cond ((>= n 1)
+ (set! prompt-text (substring prompt-text 0 (- n 1))))
+ )))
+
+ ))
+
+ )
+
+(define (prompt-draw)
+ (if prompt-active
+ (begin
+ (rl-draw-rectangle
+ (rect-x prompt-box)
+ (rect-y prompt-box)
+ (rect-width prompt-box)
+ (rect-height prompt-box)
+ (make-color 190 100 255 255))
+ (rl-draw-text prompt-text 0 0 20 (make-color 0 0 0 255))
+ ))
+ )