show and hide conditional buttons (artwork, hints, versions) based on per-game options store

This commit is contained in:
4am 2018-04-01 12:21:48 -04:00
parent 9e386162bd
commit ba9b0605e5
8 changed files with 228 additions and 122 deletions

View File

@ -6,8 +6,14 @@
; Public functions
; - LoadGameInfo
;
; Public variables
; - gHasSavedGames 0=false, 1=true
;
; Public constants (keys in gOptionsStore)
; - kHasArtwork
; - kHasHints
; - kHasVersions
!zone {
kTextRootDirectory
!byte 5
!raw "TEXT/"
@ -16,6 +22,17 @@ gVersionsStore
!word $FDFD ; set in LoadGlobalPreferences
gOptionsStore
!word $FDFD ; set in LoadGameInfo
gHasSavedGames
!byte 0
kHasArtwork
!byte 7
!raw "ARTWORK"
kHasHints
!byte 5
!raw "CLUES"
kHasVersions
!byte 8
!raw "VERSIONS"
sectionPointers ; array of pointers to start of each section
addrEOF
@ -41,6 +58,7 @@ addrInfo
; $00..$05 clobbered
; $0800..$1FFF clobbered
;------------------------------------------------------------------------------
!zone {
LoadGameInfo
jsr ResetPath
+LDADDR kTextRootDirectory
@ -131,7 +149,6 @@ LoadGameInfo
lda (SRC)
dec
dec ; chop off filename suffix ('Z3' or similar)
tay
phy
- lda (SRC),y
@ -139,19 +156,38 @@ LoadGameInfo
dey
bpl -
ply
lda #'S' ; add new suffix ('SAV')
lda #$53 ; add new suffix ('SAV')
sta gVal,y
iny
lda #'A'
lda #$41
sta gVal,y
iny
lda #'V'
lda #$56
sta gVal,y
inc gVal ; fix string length
jsr ResetPath
+LDADDR kGameRootDirectory
jsr AddToPath
jsr okvs_get
!word gGlobalPrefsStore
!word kLastPlayed
jsr AddToPath
+LDADDR kPathSeparator
jsr AddToPath
+LDADDR gVal
jsr AddToPath
jsr GetFileInfo
!word gPathname
bcs .no ; no file -> no saved games
lda blocks+1
bne .yes ; file exists and is quite large -> assume saved games
lda blocks
cmp #$06 ; file exists but is small -> no saved games (.Z4/.Z5 files have a 5 block 'empty' .sav file)
bcc .no
.yes lda #1
!byte $2C
.no lda #0
sta gHasSavedGames
rts
}

View File

@ -8,6 +8,12 @@
; - AddToPath
; - SetStartupPath
;
; Public constants
; - kPathSeparator
kPathSeparator
!byte 1
!raw "/"
;------------------------------------------------------------------------------
; ResetPath

View File

@ -56,7 +56,7 @@ Start
MainScreen
ldx #$FF
txs
ldx #WGReset ; reset WeeGUI views
ldx #WGReset
jsr WeeGUI
jsr CreateViews ; create all WeeGUI views (UI elements)
ldx #WGClearScreen ; clear screen
@ -64,6 +64,7 @@ MainScreen
jsr PaintAllViews ; draw all UI elements
bit $C010 ; clear keyboard strobe
.mainRunLoop
jsr RepaintIfDirty
ldx #WGPendingViewAction
jsr WeeGUI ; handle mouse movement and clicks
lda $c000
@ -75,6 +76,8 @@ MainScreen
ExitWeeGUI
ldx #WGDisableMouse ; disable mouse support before quitting
jsr WeeGUI
ldx #WGClearScreen ; clear screen (HOME)
jsr WeeGUI
ldx #WGExit ; clean up WeeGUI
jmp WeeGUI

View File

@ -432,7 +432,7 @@ _setprefix
;-------------------------------
_getfileinfo
lda #CMD_GETFILEINFO ; MLI command
ldy #CMD_GETFILEINFO ; number of parameters for 'getfileinfo' command
ldy #PC_GETFILEINFO ; number of parameters for 'getfileinfo' command
jmp mli
;-------------------------------

View File

@ -7,18 +7,9 @@
; - CreateRadio
; - CreateCheckbox
; - CreateButton
; - CreateTitleView
; - PaintTitleView
; - PaintTitleBar
;
; ROM routines
INVERSE = $FE80
NORMAL = $FE84
; View IDs (application-specific, acceptable range 0..15, no duplicates)
ID_TITLE = 0
!zone {
;------------------------------------------------------------------------------
; CreateRadio/CreateCheckbox/CreateButton
; creates a WeeGUI UI control with the 'raw title' option set
@ -28,6 +19,7 @@ ID_TITLE = 0
; out: $00/$01 clobbered
; all registers clobbered
;------------------------------------------------------------------------------
!zone {
CreateRadio
ldx #WGCreateRadio
!byte $2C ; hide next 2 bytes
@ -41,10 +33,10 @@ CreateButton
+PARAMS_ON_STACK 2
ldy #$01
lda ($00),y
lda (PARAM),y
sta PARAM0
iny
lda ($00),y
lda (PARAM),y
sta PARAM1
.type=*+1
ldx #$FD ; SMC
@ -53,49 +45,87 @@ CreateButton
lda #1
sta PARAM0
jmp WeeGUI
}
!zone {
CreateConditionalButton
+PARAMS_ON_STACK 5
ldy #1
lda (PARAM),y
sta .viewID
ldy #3
lda (PARAM),y
pha
dey
lda (PARAM),y
ply
+STAY .viewConfigurationRecord
ldy #5
lda (PARAM),y
pha
dey
lda (PARAM),y
ply
+STAY .optionsStoreKey
jsr okvs_get
!word gOptionsStore
.optionsStoreKey
!word $FDFD ; SMC
.viewID=*+1
ldx #$FD ; SMC (X = WeeGUI view ID)
jsr okvs_as_boolean
beq .no
lda gViewInUse,x
bne .done
lda #1
sta gViewInUse,x
jsr CreateButton
.viewConfigurationRecord
!word $FDFD ; SMC
bra .done
.no lda gViewInUse,x
beq .done
lda #0
sta gViewInUse,x
txa ; A = WeeGUI view ID
ldx #WGSelectView
jsr WeeGUI
ldx #WGDeleteView
jsr WeeGUI
.done rts
}
;------------------------------------------------------------------------------
; CreateTitleView
; creates the standard title bar on top row of screen
;
; in: none
; out: A,X clobbered
; title view selected
;------------------------------------------------------------------------------
CreateTitleView
ldx #WGCreateView ; create title bar on top line
+LDADDR viewTitle
+STAY PARAM0
jmp WeeGUI
;------------------------------------------------------------------------------
; PaintTitleView
; PaintTitleBar
; paints the title bar
;
; in: none
; out: all registers clobbered
; title view selected
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
PaintTitleView
ldx #WGSelectView
lda #ID_TITLE
!zone {
PaintTitleBar
ldy #79
- sty PARAM0
stz PARAM1
ldx #WGSetGlobalCursor
jsr WeeGUI
jsr INVERSE
ldx #WGPrint
+LDADDR .stringTitle
+STAY PARAM0
ldx #WGPlot
lda .stringTitle,y
jsr WeeGUI
jmp NORMAL
dey
bpl -
ldx #WGSyncGlobalCursor
jmp WeeGUI
viewTitle
!byte ID_TITLE ; view ID
!byte 0 ; style
!byte 0 ; left
!byte 0 ; top
!byte 80 ; visible width
!byte 1 ; visible height
!byte 80 ; width
!byte 1 ; height
.stringTitle
!raw " Pitch Dark ",0
!raw " "
!byte 16
!raw "itch "
!byte 4
!raw "ark ",0
}

View File

@ -12,17 +12,21 @@
MAGICRTS = $FF58 ; used to set overflow bit
; View IDs (application-specific, acceptable range 0..15, no duplicates)
; ID_TITLE is defined in ui.common.a
ID_PREVIOUS = 1
ID_OPTIONS = 2
ID_NEXT = 3
ID_HR = 4
ID_PLAY = 5
ID_VERSIONS = 6
ID_BOXART = 7
ID_CLUES = 8
ID_INFO = 9
ID_DESCRIPTION = 13
ID_PLAY = 4
ID_BOXART = 5
ID_HINTS = 6
ID_VERSIONS = 7
ID_INFO = 8
ID_DESCRIPTION = 9
gViewInUse
gShowingArtworkButton=*+ID_BOXART
gShowingHintsButton=*+ID_HINTS
gShowingVersionButton=*+ID_VERSIONS
!byte 0,1,1,1,1,0,0,0,1,1,0,0,0,0,0
!zone {
@ -34,27 +38,37 @@ ID_DESCRIPTION = 13
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
CreateViews
jsr CreateTitleView
ldx #WGCreateView ; create horizontal rule
+LDADDR .viewHR
+STAY PARAM0
jsr WeeGUI
jsr CreateButton ; create various buttons
!word .viewPrevious
jsr CreateButton
!word .viewOptions
jsr CreateButton
!word .viewNext
lda gHasSavedGames
beq .wantPlayButton
jsr CreateButton
!word .viewResume
bra .donePlayOrResume
.wantPlayButton
jsr CreateButton
!word .viewPlay
jsr CreateButton
!word .viewVersions
jsr CreateButton
.donePlayOrResume
jsr CreateConditionalButton
!byte ID_BOXART
!word .viewBoxArt
jsr CreateButton
!word .viewClues
jsr CreateButton
!word .viewOptions
!word kHasArtwork
jsr CreateConditionalButton
!byte ID_HINTS
!word .viewHints
!word kHasHints
jsr CreateConditionalButton
!byte ID_VERSIONS
!word .viewVersions
!word kHasVersions
ldx #WGCreateView ; create borderless frame for game title and info
+LDADDR .viewInfo
@ -86,13 +100,13 @@ CreateViews
PaintAllViews
ldx #WGViewPaintAll ; repaint all views that can be painted automatically
jsr WeeGUI
jsr PaintTitleView
jsr paintHRView
jsr PaintTitleBar
jsr paintHR
jsr paintInfoView
jmp paintDescriptionView
;------------------------------------------------------------------------------
; RepaintSomeViews
; RepaintIfDirty
; call WeeGUI to repaint UI elements after changing the current game
;
; in: WeeGUI loaded and initialized
@ -100,28 +114,36 @@ PaintAllViews
; LoadGameInfo has been called to load new game description text
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
RepaintSomeViews
RepaintIfDirty
lda gMainScreenPaintDirty
beq +
jsr CreateViews
ldx #WGViewPaintAll
jsr WeeGUI
jsr paintInfoView
jsr resetDescriptionViewScrolling
jmp paintDescriptionView
jsr paintDescriptionView
stz gMainScreenPaintDirty
+ rts
gMainScreenPaintDirty
!byte 0
;------------------------------------------------------------------------------
; internal functions
paintHRView
ldx #WGSelectView
lda #ID_HR
jsr WeeGUI
lda #1
sta PARAM0
lda #5
paintHR
lda #4
sta PARAM1
lda #78
sta PARAM2
lda #0
sta PARAM3
ldy #83
ldx #WGFillRect
ldy #78
lda #83
- sty PARAM0
ldx #WGSetGlobalCursor
jsr WeeGUI
ldx #WGPlot
jsr WeeGUI
dey
bne -
ldx #WGSyncGlobalCursor
jmp WeeGUI
paintDescriptionView
@ -215,13 +237,13 @@ resetDescriptionViewScrolling
!byte ID_PREVIOUS ; view ID
!byte 1 ; left
!byte 2 ; top
!byte 17 ; width
!byte 13 ; width
!word callback_previous ; callback
!word .stringPrevious ; caption
.stringPrevious
!text "< "
!byte $10 ; 'P' inverse
!text "revious game",0
!text "revious",0
.viewNext
!byte ID_NEXT ; view ID
@ -245,16 +267,6 @@ resetDescriptionViewScrolling
!byte $13 ; 'S' inverse
!text "ettings",0
.viewHR
!byte ID_HR ; view ID
!byte 0 ; style
!byte 1 ; left
!byte 4 ; top
!byte 78 ; visible width
!byte 1 ; visible height
!byte 78 ; width
!byte 1 ; height
.viewPlay
!byte ID_PLAY ; view ID
!byte 66 ; left
@ -268,6 +280,19 @@ resetDescriptionViewScrolling
!byte $67 ; 'g' inverse
!text "ame",0
.viewResume
!byte ID_PLAY ; view ID
!byte 66 ; left
!byte 6 ; top
!byte 13 ; width
!word callback_resume ; callback
!word .stringResume ; caption
.stringResume
!byte 146
!text "esume "
!byte $67 ; 'g' inverse
!text "ame",0
.viewBoxArt
!byte ID_BOXART ; view ID
!byte 66 ; left
@ -279,14 +304,14 @@ resetDescriptionViewScrolling
!byte $01 ; 'A' inverse
!text "rtwork",0
.viewClues
!byte ID_CLUES ; view ID
.viewHints
!byte ID_HINTS ; view ID
!byte 66 ; left
!byte 10 ; top
!byte 13 ; width
!word callback_clues ; callback
!word .stringClues ; caption
.stringClues
!word .stringHints ; caption
.stringHints
!byte $08 ; 'H' inverse
!text "ints",0

View File

@ -33,8 +33,8 @@ ID_Z = $85
!byte $C7,ID_PLAY ; G
!byte $E7,ID_PLAY ; g
!byte $8D,ID_PLAY ; Return
!byte $C8,ID_CLUES ; H
!byte $E8,ID_CLUES ; h
!byte $C8,ID_HINTS ; H
!byte $E8,ID_HINTS ; h
!byte $C1,ID_BOXART ; A
!byte $E1,ID_BOXART ; a
!byte $D3,ID_OPTIONS ; S
@ -69,6 +69,7 @@ HandleKey
dex
dex
bpl -
.notFound
jmp SoftBell ; unknown key, beep softly
.foundKey
lda .keys+1,x ; get ID associated with this key
@ -95,6 +96,9 @@ HandleKey
jsr WeeGUI
bra .focusAndDoAction
.activateView
tax
ldy gViewInUse,x
beq .notFound
ldx #WGSelectView
jsr WeeGUI
.focusAndDoAction
@ -138,8 +142,6 @@ HandleKey
.xyzzy
!byte $00
.xyzzyGo
ldx #WGClearScreen
jsr WeeGUI
jsr SaveGlobalPreferences
jsr ResetPath
+LDADDR kArtworkRootDirectory
@ -208,8 +210,8 @@ callback_next
+ !word $FDFD ; SMC
lda #1
sta gNeedToSavePrefs
jsr LoadGameInfo
jmp RepaintSomeViews
sta gMainScreenPaintDirty
jmp LoadGameInfo
}
callback_versions
@ -217,6 +219,12 @@ callback_versions
!zone {
callback_boxart
jsr okvs_get
!word gOptionsStore
!word kHasArtwork
jsr okvs_as_boolean
beq .boxartError
lda #0 ; set Z flag always
!cpu 65816
rep #2 ; clear Z flag on 65816 only
@ -270,3 +278,4 @@ callback_boxart
callback_options = OptionsDialog
callback_clues = LaunchInterpreterWithHints
callback_play = LaunchInterpreterWithGame
callback_resume = LaunchInterpreterWithGame

View File

@ -9,7 +9,6 @@
!zone {
; View IDs (application-specific, acceptable range 0..15, no duplicates)
; ID_TITLE is defined in paintcommon.a
ID_OPTIONS_FRAME = 1
ID_OPTIONS_FORCE40 = 2
ID_OPTIONS_FORCEUPPER = 3
@ -50,8 +49,6 @@ OptionsDialog
ldx #WGReset ; reset WeeGUI
jsr WeeGUI
jsr CreateTitleView ; create title bar (defined in paintcommon.a)
ldx #WGCreateView ; create frame
+LDADDR .viewFrame
+STAY PARAM0
@ -93,7 +90,7 @@ OptionsDialog
ldx #WGViewPaintAll ; paint UI controls (window frame, buttons, checkboxes, radio buttons)
jsr WeeGUI
jsr PaintTitleView ; paint top title bar
jsr PaintTitleBar ; paint top title bar
ldx #WGSelectView
lda #ID_OPTIONS_FRAME