;license:MIT ;(c) 2018 by 4am ; ; User interface - views and paint routines for options screen ; ; Public functions ; - OptionsDialog ; !zone { ; 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 .keys !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 .endkeys ;------------------------------------------------------------------------------ ; OptionsDialog ; call WeeGUI to create and paint option screen, and run to completion ; ; in: WeeGUI loaded and initialized ; out: exits via MainScreen ; all registers clobbered ; all flags clobbered ;------------------------------------------------------------------------------ OptionsDialog ldx #$FF txs ldx #WGReset ; reset WeeGUI jsr WeeGUI ldx #WGCreateView ; create frame +LDADDR kViewFrame +STAY PARAM0 jsr WeeGUI ldx #WGViewSetTitle +LDADDR kStringFrame +STAY PARAM0 jsr WeeGUI jsr CreateButton ; create UI controls !word kViewOK jsr CreateButton !word kViewCancel jsr CreateCheckbox !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 ldx #WGViewPaintAll ; paint UI controls (window frame, buttons, checkboxes, radio buttons) jsr WeeGUI jsr PaintTitleBar ; paint top title bar ldx #WGSelectView lda #ID_OPTIONS_FRAME jsr WeeGUI ldx #WGSetCursor ; paint static text labels lda #6 sta PARAM0 lda #3 sta PARAM1 jsr WeeGUI ldx #WGPrint +LDADDR kStringForce40Description +STAY PARAM0 jsr WeeGUI ldx #WGSetCursor lda #6 sta PARAM0 lda #8 sta PARAM1 jsr WeeGUI ldx #WGPrint +LDADDR kStringForceUpperDescription +STAY PARAM0 jsr WeeGUI ldx #WGSetCursor lda #6 sta PARAM0 lda #13 sta PARAM1 jsr WeeGUI ldx #WGPrint +LDADDR kStringScriptToFileDescription +STAY PARAM0 jsr WeeGUI ldx #WGSetCursor lda #6 sta PARAM0 lda #18 sta PARAM1 jsr WeeGUI ldx #WGPrint +LDADDR kStringAutoScriptDescription +STAY PARAM0 jsr WeeGUI .runLoop ldx #WGPendingViewAction jsr WeeGUI lda $C000 bpl .runLoop bit $C010 jsr HandleOptionsKey bra .runLoop ;------------------------------------------------------------------------------ ; internal functions HandleOptionsKey ldx #.endkeys-.keys - cmp .keys,x beq .foundKey dex dex bpl - jmp SoftBell .foundKey lda .keys+1,x ldx #WGSelectView jsr WeeGUI ldx #WGViewFocus jsr WeeGUI ldx #WGViewFocusAction jsr WeeGUI ldx #WGViewUnfocus jmp WeeGUI 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 !zone { SetCheckboxByPref +PARAMS_ON_STACK 3 ldy #1 lda (PARAM),y sta .id iny lda (PARAM),y sta .key iny lda (PARAM),y sta .key+1 jsr okvs_get !word gGlobalPrefsStore .key !word $FDFD ; SMC bcs .exit jsr okvs_as_boolean beq .exit ldx #WGSelectView .id=*+1 lda #$FD ; SMC jsr WeeGUI ldx #WGSetState lda #1 sta PARAM0 jsr WeeGUI .exit rts } !zone { SetPrefByCheckbox +PARAMS_ON_STACK 3 ldy #1 lda (PARAM),y sta .id iny lda (PARAM),y sta .key iny lda (PARAM),y sta .key+1 ldx #WGSelectView .id=*+1 lda #$FD ; SMC jsr WeeGUI ldx #WGGetState jsr WeeGUI lda PARAM0 and #1 sta .value+1 jsr okvs_update !word gGlobalPrefsStore .key !word $FDFD ; SMC !word .value rts .value !byte 1 !byte $FD ; SMC } kViewFrame !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 kStringFrame !text "Settings",0 kViewOK !byte ID_OPTIONS_OK ; view ID !byte 56 ; left !byte 4 ; top !byte 10 ; width !word callback_options_ok ; callback !word kStringOK ; caption kStringOK !byte $0F ; 'P' inverse !byte 139,0 kViewCancel !byte ID_OPTIONS_CANCEL ; view ID !byte 56 ; left !byte 6 ; top !byte 10 ; width !word callback_options_cancel ; callback !word kStringCancel ; caption kStringCancel !byte $03 ; 'C' inverse !text "ancel",0 kViewForce40 !byte ID_OPTIONS_FORCE40 ; view ID !byte 14 ; left !byte 4 ; top !word kStringForce40 ; caption kStringForce40 !text "Force " !byte $34 ; '4' inverse !text "0 column",0 kStringForce40Description !text "Some games may be glitchy",0 kViewForceUpper !byte ID_OPTIONS_FORCEUPPER ; view ID !byte 14 ; left !byte 9 ; top !word kStringForceUpper ; caption kStringForceUpper !text "Force " !byte $75 ; 'u' inverse !text "ppercase",0 kStringForceUpperDescription !text "A MATTER OF PREFERENCE, I SUPPOSE",0 kViewScriptToFile !byte ID_OPTIONS_SCRIPTTOFILE ; view ID !byte 14 ; left !byte 14 ; top !word kStringScriptToFile ; caption kStringScriptToFile !text "SCRIPT to " !byte $66 ; 'f' inverse !text "ile",0 kStringScriptToFileDescription !text "Save transcripts to a file instead of printer",0 kViewAutoScript !byte ID_OPTIONS_AUTOSCRIPT ; view ID !byte 14 ; left !byte 19 ; top !word kStringAutoScript ; caption kStringAutoScript !text "Always " !byte $13 ; 'S' inverse !text "CRIPT",0 kStringAutoScriptDescription !text "Turn on SCRIPT mode automatically",0 }