finish definer callback, add cps to buy buttons, add new buttons, rename clicker cps field

This commit is contained in:
kiefac 2024-05-04 11:14:06 -04:00
parent f351611db5
commit 36c9f2a7f7

View file

@ -54,7 +54,7 @@
[label "Owned: 0"] [label "Owned: 0"]
[auto-resize #t])]) [auto-resize #t])])
(new button% [parent button-panel] (new button% [parent button-panel]
[label (~a "Buy " (clicker-name cl) " (" (clicker-price cl) "¢)")] [label (~a "Buy " (clicker-name cl) " (" (clicker-price cl) "¢, " (clicker-cps cl) "CPS)")]
[callback (λ (b e) [callback (λ (b e)
(when (>= clicks (clicker-price cl)) (when (>= clicks (clicker-price cl))
(set-clicker-count! cl (add1 (clicker-count cl))) (set-clicker-count! cl (add1 (clicker-count cl)))
@ -66,16 +66,20 @@
(new-inc-button left-side "Clicket?" clicks) (new-inc-button left-side "Clicket?" clicks)
; clicks on a timer ; clicks on a timer
(struct clicker (name price multiplier (count #:mutable))) (struct clicker (name price cps (count #:mutable)))
(define all-clickers (list (define all-clickers (list
(clicker "mouse" 10 1 0) (clicker "mouse" 10 1 0)
(clicker "coder" 150 5 0) (clicker "coder" 250 15 0)
(clicker "paren farm" 1000 10 0))) (clicker "paren farm" 1000 40 0)
(clicker "define mine" 2500 75 0)
(clicker "git portal" 9999 200 0)))
(for ([cl all-clickers]) (new-buy-button builtins cl)) (for ([cl all-clickers]) (new-buy-button builtins cl))
; prevent tab panel from resizing to a panel with arrows ; prevent tab panel from resizing to a panel with arrows
(send right-side min-width (send right-side get-width)) (send right-side min-width (send right-side get-width))
; define your own clickers ; define your own clickers
(define init-multiplier 50) ;desired CPS * init-multiplier = cost to define clicker
(define price-multiplier 25) ;desired CPS * price-multiplier = cost to buy clicker
(define definer-panel (new group-box-panel% (define definer-panel (new group-box-panel%
[parent left-side] [parent left-side]
[label "Define custom clicker"])) [label "Define custom clicker"]))
@ -84,9 +88,19 @@
[label "Name"] [label "Name"]
[style '(single vertical-label)])) [style '(single vertical-label)]))
(define clicks-field (new text-field% (define clicks-field (new text-field%
[parent definer-panel] [parent definer-panel]
[label "Clicks per second"] [label "Clicks per second"]
[style '(single vertical-label)])) [style '(single vertical-label)]
[callback (λ (f e)
(define (v) (send f get-value))
(define (v-num) (string->number (v)))
(unless (v-num)
(send f set-value (regexp-replace* #rx"[^0-9]+" (v) "")))
(send init-price set-label "Init price: 0")
(send cl-price set-label "Clicker price: 0")
(when (v-num)
(send init-price set-label (~a "Init price: " (* (v-num) init-multiplier)))
(send cl-price set-label (~a "Clicker price: " (* (v-num) price-multiplier)))))]))
(define price-panel (new group-box-panel% (define price-panel (new group-box-panel%
[parent definer-panel] [parent definer-panel]
[label "Prices"])) [label "Prices"]))
@ -95,12 +109,29 @@
[label "Init price: 0"] [label "Init price: 0"]
[auto-resize #t])) [auto-resize #t]))
(define cl-price (new message% (define cl-price (new message%
[parent price-panel] [parent price-panel]
[label "Clicker price: 0"] [label "Clicker price: 0"]
[auto-resize #t])) [auto-resize #t]))
(new button% [parent definer-panel] (new button% [parent definer-panel]
[label "Define"]) [label "Define"]
; TODO implement callback [callback (λ (b e)
(define name (send name-field get-value))
(define cps-str (send clicks-field get-value))
(define cps (string->number cps-str))
(define price (* cps price-multiplier))
(define cost (* cps init-multiplier))
(when (and name cps-str (>= clicks cost))
(set! clicks (- clicks cost))
(define cl (clicker name price cps 1))
(set! all-clickers (append all-clickers (list cl)))
(new-buy-button definitions cl)
(unless selected-tab
(switch-tab right-side #f)
(send right-side set-selection 1))
(send name-field set-value "")
(send clicks-field set-value "")
(send init-price set-label "Init price: 0")
(send cl-price set-label "Clicker price: 0")))])
; setup timer ; setup timer
@ -111,8 +142,8 @@
(set! cps 0) (set! cps 0)
(for ([cl all-clickers]) (for ([cl all-clickers])
(when (= 0 (modulo timer-ctr 10)) (when (= 0 (modulo timer-ctr 10))
(set! clicks (+ clicks (* (clicker-multiplier cl) (clicker-count cl))))) (set! clicks (+ clicks (* (clicker-cps cl) (clicker-count cl)))))
(set! cps (+ cps (* (clicker-multiplier cl) (clicker-count cl))))) (set! cps (+ cps (* (clicker-cps cl) (clicker-count cl)))))
(send click-msg set-label (click-str)) (send click-msg set-label (click-str))
(send cps-msg set-label (cps-str)) (send cps-msg set-label (cps-str))
(set! timer-ctr (add1 timer-ctr)))])) (set! timer-ctr (add1 timer-ctr)))]))