pitch-dark/src/ui.main.a

351 lines
10 KiB
Plaintext

;license:MIT
;(c) 2018 by 4am
;
; User interface - views and paint routines for main screen
;
; Public functions
; - CreateViews
; - PaintAllViews
; - RepaintSomeViews
;
MAGICRTS = $FF58 ; used to set overflow bit
; View IDs (application-specific, acceptable range 0..15, no duplicates)
ID_PREVIOUS = 1
ID_OPTIONS = 2
ID_NEXT = 3
ID_PLAY = 4
ID_BOXART = 5
ID_HINTS = 6
ID_VERSIONS = 7
ID_INFO = 8
ID_DESCRIPTION = 9
gViewInUse
!byte 0,1,1,1,1,0,0,0,1,1,0,0,0,0,0
;------------------------------------------------------------------------------
; CreateViews
; call WeeGUI to create all application views
;
; in: WeeGUI loaded and initialized
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
!zone {
CreateViews
jsr CreateButton ; create various buttons
!word kViewPrevious
jsr CreateButton
!word kViewOptions
jsr CreateButton
!word kViewNext
lda gHasSavedGames
beq .wantPlayButton
jsr CreateButton
!word kViewResume
bra .donePlayOrResume
.wantPlayButton
jsr CreateButton
!word kViewPlay
.donePlayOrResume
jsr CreateConditionalButton
!byte ID_BOXART
!word kViewBoxArt
!word kHasArtwork
jsr CreateConditionalButton
!byte ID_HINTS
!word kViewHints
!word kHasHints
jsr CreateConditionalButton
!byte ID_VERSIONS
!word kViewVersions
!word kHasVersions
ldx #WGCreateView ; create borderless frame for game title and info
+LDADDR kViewInfo
+STAY PARAM0
jsr WeeGUI
ldx #WGViewSetAction
+LDADDR paintInfoView
+STAY PARAM0
jsr WeeGUI
ldx #WGCreateView ; create scrollable frame for game description text
+LDADDR kViewDescription
+STAY PARAM0
jsr WeeGUI
ldx #WGViewSetAction
+LDADDR paintDescriptionView
+STAY PARAM0
jmp WeeGUI
}
;------------------------------------------------------------------------------
; PaintAllViews
; call WeeGUI to paint all UI elements
;
; in: WeeGUI loaded and initialized
; CreateViews has been called
; out: all registers and flags clobbered
; $00/$01 clobbered
;------------------------------------------------------------------------------
!zone {
PaintAllViews
ldx #WGViewPaintAll ; repaint all views that can be painted automatically
jsr WeeGUI
jsr PaintTitleBar
jsr paintHR
jsr paintInfoView
jmp paintDescriptionView
}
;------------------------------------------------------------------------------
; RepaintIfDirty
; call WeeGUI to repaint UI elements after changing the current game
;
; in: WeeGUI loaded and initialized
; CreateViews has been called
; LoadGameInfo has been called to load new game description text
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
!zone {
RepaintIfDirty
lda gMainScreenPaintDirty
beq +
jsr CreateViews
ldx #WGViewPaintAll
jsr WeeGUI
jsr paintInfoView
jsr resetDescriptionViewScrolling
jsr paintDescriptionView
stz gMainScreenPaintDirty
+ rts
gMainScreenPaintDirty
!byte 0
}
;------------------------------------------------------------------------------
; internal functions
!zone {
paintHR
lda #4
sta PARAM1
ldy #78
lda #83
- sty PARAM0
ldx #WGSetGlobalCursor
jsr WeeGUI
ldx #WGPlot
jsr WeeGUI
dey
bne -
ldx #WGSyncGlobalCursor
jmp WeeGUI
paintDescriptionView
ldx #WGSelectView
lda #ID_DESCRIPTION
jsr WeeGUI
+LDAY addrDescription
ldx #kDescriptionPaintWidth
jsr multiPrint
lda .vtab+1
cmp #10
bcs +
lda #10
+ ldx #WGSetContentHeight
jmp WeeGUI
paintInfoView
ldx #WGSelectView
lda #ID_INFO
jsr WeeGUI
+LDAY addrInfo
ldx #kInfoPaintWidth
jsr multiPrint
jsr okvs_get ; get shortname of current game
!word gGlobalPrefsStore
!word kLastPlayed
+STAY + ; A/Y contains address
jsr okvs_get ; get selected version of this game
!word gGlobalPrefsStore
+ !word $FDFD ; SMC
+STAY + ; A/Y contains address
jsr okvs_get ; get long description of this version
!word gVersionsStore
+ !word $FDFD ; SMC
; A/Y contains address
ldx #kInfoPaintWidth
jsr CreateNullTerminatedString
+LDADDR kNullTerminatedBuffer
bra multiPrintWhereYouAre
multiPrint
stz .htab+1
stz .vtab+1
multiPrintWhereYouAre
stx .printLineLength+1
+STAY $00
.printLoop
lda ($00)
beq .printDone
ldx #WGSetCursor
.htab lda #$FD ; SMC
sta PARAM0
.vtab lda #$FD ; SMC
sta PARAM1
jsr WeeGUI
ldx #WGPrint
lda $00
sta PARAM0
lda $01
sta PARAM1
bit MAGICRTS ; set overflow bit
jsr WeeGUI
lda $00
clc
.printLineLength
adc #$fd ; SMC
sta $00
bcc +
inc $01
+ inc .vtab+1
bne .printLoop
.printDone
rts
resetDescriptionViewScrolling
ldx #WGSelectView
lda #ID_DESCRIPTION
jsr WeeGUI
ldx #WGScrollX
lda #0
jsr WeeGUI
ldx #WGScrollY
lda #0
jmp WeeGUI
kViewPrevious
!byte ID_PREVIOUS ; view ID
!byte 1 ; left
!byte 2 ; top
!byte 13 ; width
!word callback_previous ; callback
!word kStringPrevious ; caption
kStringPrevious
!text "< "
!byte $10 ; 'P' inverse
!text "revious",0
kViewNext
!byte ID_NEXT ; view ID
!byte 66 ; left
!byte 2 ; top
!byte 13 ; width
!word callback_next ; callback
!word kStringNext ; caption
kStringNext
!byte $0E ; 'N' inverse
!text "ext game >",0
kViewOptions
!byte ID_OPTIONS ; view ID
!byte 34 ; left
!byte 2 ; top
!byte 12 ; width
!word callback_options ; callback
!word kStringOptions
kStringOptions
!byte $13 ; 'S' inverse
!text "ettings",0
kViewPlay
!byte ID_PLAY ; view ID
!byte 66 ; left
!byte 6 ; top
!byte 13 ; width
!word callback_play ; callback
!word kStringPlay ; caption
kStringPlay
!byte 144
!text "lay "
!byte $67 ; 'g' inverse
!text "ame",0
kViewResume
!byte ID_PLAY ; view ID
!byte 66 ; left
!byte 6 ; top
!byte 13 ; width
!word callback_resume ; callback
!word kStringResume ; caption
kStringResume
!byte 146
!text "esume "
!byte $67 ; 'g' inverse
!text "ame",0
kViewBoxArt
!byte ID_BOXART ; view ID
!byte 66 ; left
!byte 8 ; top
!byte 13 ; width
!word callback_boxart ; callback
!word kStringBoxArt ; caption
kStringBoxArt
!byte $01 ; 'A' inverse
!text "rtwork",0
kViewHints
!byte ID_HINTS ; view ID
!byte 66 ; left
!byte 10 ; top
!byte 13 ; width
!word callback_clues ; callback
!word kStringHints ; caption
kStringHints
!byte $08 ; 'H' inverse
!text "ints",0
kViewVersions
!byte ID_VERSIONS ; view ID
!byte 66 ; left
!byte 12 ; top
!byte 13 ; width
!word callback_versions ; callback
!word kStringVersions ; caption
kStringVersions
!byte $12 ; 'R' inverse
!text "evisions",0
kViewInfo
!byte ID_INFO ; view ID
!byte 0 ; style
!byte 0 ; left
!byte 6 ; top
!byte 65 ; visible width
!byte 6 ; visible height
!byte 65 ; width
!byte 6 ; height
kViewDescription
!byte ID_DESCRIPTION ; view ID
!byte 2 ; style
!byte 1 ; left
!byte 15 ; top
!byte 77 ; visible width
!byte 8 ; visible height
!byte 77 ; width
!byte 39 ; height
}