pitch-dark/src/ui.options.a

287 lines
8.7 KiB
Plaintext

;license:MIT
;(c) 2018 by 4am
;
; User interface - views and paint routines for options screen
;
; Public functions
; - OptionsDialog
;
; View IDs (application-specific, acceptable range 0..15, no duplicates)
ID_OPTIONS_FRAME = 1
ID_OPTIONS_FORCE40 = 2
ID_OPTIONS_FORCEUPPER = 3
ID_OPTIONS_SCRIPTTOFILE = 4
ID_OPTIONS_AUTOSCRIPT = 5
ID_OPTIONS_OK = 6
ID_OPTIONS_CANCEL = 7
; action keys for options screen
kOptionsKeys
!byte $CF,ID_OPTIONS_OK ; O
!byte $EF,ID_OPTIONS_OK ; o
!byte $8D,ID_OPTIONS_OK ; Return
!byte $C3,ID_OPTIONS_CANCEL ; C
!byte $E3,ID_OPTIONS_CANCEL ; c
!byte $9B,ID_OPTIONS_CANCEL ; Esc
!byte $B4,ID_OPTIONS_FORCE40 ; 4
!byte $D5,ID_OPTIONS_FORCEUPPER ; U
!byte $F5,ID_OPTIONS_FORCEUPPER ; u
!byte $C6,ID_OPTIONS_SCRIPTTOFILE ; F
!byte $E6,ID_OPTIONS_SCRIPTTOFILE ; f
!byte $D3,ID_OPTIONS_AUTOSCRIPT ; S
!byte $F3,ID_OPTIONS_AUTOSCRIPT ; s
_endOptionsKeys
;------------------------------------------------------------------------------
; OptionsDialog
; call WeeGUI to create and paint option screen, and run to completion
;
; in: WeeGUI initialized
; out: exits via MainScreen
; all registers and flags clobbered
;------------------------------------------------------------------------------
OptionsDialog
ldx #$FF
txs
jsr HardResetWeeGUI
jsr CreateDialog ; create decorated frame
!word kViewOptionsFrame
!word kStringOptionsFrame
jsr CreateButton ; create OK button
!word kViewOptionsOK
jsr CreateButton ; create Cancel button
!word kViewOptionsCancel
jsr CreateCheckbox ; create other UI controls
!word kViewForce40
jsr CreateCheckbox
!word kViewForceUpper
jsr CreateCheckbox
!word kViewScriptToFile
jsr CreateCheckbox
!word kViewAutoScript
jsr SetCheckboxByPref ; set initial state of checkboxes based on preferences
!byte ID_OPTIONS_FORCE40
!word kForce40
jsr SetCheckboxByPref
!byte ID_OPTIONS_FORCEUPPER
!word kForceUpper
jsr SetCheckboxByPref
!byte ID_OPTIONS_SCRIPTTOFILE
!word kScriptToFile
jsr SetCheckboxByPref
!byte ID_OPTIONS_AUTOSCRIPT
!word kAutoScript
ldx #WGDesktop ; paint background
jsr WeeGUI
jsr PaintTitleBar ; paint top title bar
ldx #WGViewPaintAll ; paint UI controls (window frame, buttons, checkboxes, radio buttons)
jsr WeeGUI
ldx #WGSelectView ; select frame (required for print routines that follow)
lda #ID_OPTIONS_FRAME
jsr WeeGUI
jsr PrintAt ; paint static text labels
!byte 6,3
!word kStringForce40Description
jsr PrintAt
!byte 6,8
!word kStringForceUpperDescription
jsr PrintAt
!byte 6,13
!word kStringScriptToFileDescription
jsr PrintAt
!byte 6,18
!word kStringAutoScriptDescription
jsr ClearPendingInput
- ldx #WGPendingViewAction
jsr WeeGUI ; handle mouse movement and clicks
lda $C000
bpl -
jsr ClearPendingInput
jsr HandleOptionsKey ; handle keypresses
bra -
;------------------------------------------------------------------------------
; internal functions
;------------------------------------------------------------------------------
; HandleOptions
;
; in: A = key pressed
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
HandleOptionsKey
ldx #(_endOptionsKeys-kOptionsKeys)-2
- cmp kOptionsKeys,x
beq @found
dex
dex
bpl -
jmp SoftBell
@found lda kOptionsKeys+1,x
ldx #WGSelectView
jsr WeeGUI
jmp SimulateClick
callback_options_ok
jsr SetPrefByCheckbox
!byte ID_OPTIONS_FORCE40
!word kForce40
jsr SetPrefByCheckbox
!byte ID_OPTIONS_FORCEUPPER
!word kForceUpper
jsr SetPrefByCheckbox
!byte ID_OPTIONS_SCRIPTTOFILE
!word kScriptToFile
jsr SetPrefByCheckbox
!byte ID_OPTIONS_AUTOSCRIPT
!word kAutoScript
lda #1
sta gGlobalPrefsDirty ; must set, otherwise SaveGlobalPreferences does nothing
jsr SaveGlobalPreferences ; immediately write new preferences to disk
; execution falls through here
callback_options_cancel
jmp MainScreen
SetCheckboxByPref
+PARAMS_ON_STACK 3
ldy #1
lda (PARAM),y
sta @view
+LDPARAM 2
+STAY @key
jsr okvs_get
!word gGlobalPrefsStore
@key !word $FDFD ; SMC
bcs @exit
jsr okvs_as_boolean
beq @exit
ldx #WGSelectView
@view=*+1
lda #$FD ; SMC
jsr WeeGUI
ldx #WGSetState
lda #1
sta PARAM0
jsr WeeGUI
@exit rts
SetPrefByCheckbox
+PARAMS_ON_STACK 3
+LDPARAM 2
+STAY @key
ldy #1
lda (PARAM),y
ldx #WGSelectView
jsr WeeGUI
ldx #WGGetState
jsr WeeGUI
lda PARAM0
and #1
sta @valueb
jsr okvs_update
!word gGlobalPrefsStore
@key !word $FDFD ; SMC
!word @value
rts
@value !byte 1
@valueb !byte $FD ; SMC
;------------------------------------------------------------------------------
; WeeGUI view configuration records
kViewOptionsFrame
!byte ID_OPTIONS_FRAME ; view ID
!byte 2 ; style (decorated frame)
!byte 12 ; left
!byte 3 ; top
!byte 56 ; visible width
!byte 19 ; visible height
!byte 56 ; width
!byte 19 ; height
kViewOptionsOK
!byte ID_OPTIONS_OK ; view ID
!byte 56 ; left
!byte 4 ; top
!byte 10 ; width
!word callback_options_ok ; callback
!word kStringOK ; caption
kViewOptionsCancel
!byte ID_OPTIONS_CANCEL ; view ID
!byte 56 ; left
!byte 6 ; top
!byte 10 ; width
!word callback_options_cancel ; callback
!word kStringCancel ; caption
kViewForce40
!byte ID_OPTIONS_FORCE40 ; view ID
!byte 14 ; left
!byte 4 ; top
!word kStringForce40 ; caption
kViewForceUpper
!byte ID_OPTIONS_FORCEUPPER ; view ID
!byte 14 ; left
!byte 9 ; top
!word kStringForceUpper ; caption
kViewScriptToFile
!byte ID_OPTIONS_SCRIPTTOFILE ; view ID
!byte 14 ; left
!byte 14 ; top
!word kStringScriptToFile ; caption
kViewAutoScript
!byte ID_OPTIONS_AUTOSCRIPT ; view ID
!byte 14 ; left
!byte 19 ; top
!word kStringAutoScript ; caption
kStringOptionsFrame
!text "Settings",0
kStringForce40
!text "Force "
!byte $34 ; '4' inverse
!text "0 column",0
kStringForce40Description
!text "Some games may be glitchy",0
kStringForceUpper
!text "Force "
!byte $75 ; 'u' inverse
!text "ppercase",0
kStringForceUpperDescription
!text "A MATTER OF PREFERENCE, I SUPPOSE",0
kStringScriptToFile
!text "SCRIPT to "
!byte $66 ; 'f' inverse
!text "ile",0
kStringScriptToFileDescription
!text "Save transcripts to a file instead of printer",0
kStringAutoScript
!text "Always "
!byte $13 ; 'S' inverse
!text "CRIPT",0
kStringAutoScriptDescription
!text "Turn on SCRIPT mode automatically",0