minor refactoring of ui.main

This commit is contained in:
4am 2018-04-01 18:26:54 -04:00
parent a7fc951445
commit e914d76c78
6 changed files with 185 additions and 201 deletions

View File

@ -8,7 +8,7 @@
; - SaveGlobalPreferences
;
; Public variables
; - gNeedToSavePrefs byte 0=false, 1=true
; - gGlobalPrefsDirty byte 0=false, 1=true
; set to 1 if prefs have changed. SaveGlobalPreferences won't write to disk if this is 0.
;
; Public constants (all length-prefixed strings)
@ -23,7 +23,7 @@
gGlobalPrefsStore
!word 0
gNeedToSavePrefs
gGlobalPrefsDirty
!byte 0
kForce40
@ -49,7 +49,7 @@ kLastPlayed
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
LoadGlobalPreferences
stz gNeedToSavePrefs
stz gGlobalPrefsDirty
jsr LoadFile ; load prefs file at $2000
!word .globalPrefsFilename
@ -72,7 +72,7 @@ LoadGlobalPreferences
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
SaveGlobalPreferences
lda gNeedToSavePrefs
lda gGlobalPrefsDirty
beq .exit
+LDADDR kGlobalPrefsBuffer
+STAY $FE
@ -138,7 +138,7 @@ SaveGlobalPreferences
.filelen !word $FDFD ; SMC
!word kProDOSFileBuffer
stz gNeedToSavePrefs
stz gGlobalPrefsDirty
rts
addBooleanFromStore

View File

@ -56,18 +56,10 @@ Start
MainScreen
ldx #$FF
txs
ldx #WGReset
jsr WeeGUI
stz gViewInUse+ID_BOXART
stz gViewInUse+ID_HINTS
stz gViewInUse+ID_VERSIONS
jsr CreateViews ; create all WeeGUI views (UI elements)
ldx #WGClearScreen ; clear screen
jsr WeeGUI
jsr PaintAllViews ; draw all UI elements
jsr PaintMain ; create all WeeGUI views (UI elements) and paint them
bit $C010 ; clear keyboard strobe
.mainRunLoop
jsr RepaintIfDirty
jsr RepaintMainIfDirty
ldx #WGPendingViewAction
jsr WeeGUI ; handle mouse movement and clicks
lda $c000

View File

@ -47,59 +47,6 @@ CreateButton
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
}
;------------------------------------------------------------------------------
; PaintTitleBar
; paints the title bar

View File

@ -4,9 +4,8 @@
; User interface - views and paint routines for main screen
;
; Public functions
; - CreateViews
; - PaintAllViews
; - RepaintSomeViews
; - PaintMain
; - RepaintMainIfDirty
;
MAGICRTS = $FF58 ; used to set overflow bit
@ -22,26 +21,49 @@ 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
gMainScreenPaintDirty
!byte 0 ; 0=false, 1=true
gViewHasActiveHotkey
!byte 0,1,1,1,1,0,0,0,0,0,0,0,0,0,0
;------------------------------------------------------------------------------
; CreateViews
; call WeeGUI to create all application views
; PaintMain/RepaintMainIfDirty
; call WeeGUI to create all application views and paint them
; PaintMain entry point will clear the screen and unconditionally paint everything
; RepaintMainIfDirty will only repaint certain views that vary between games,
; and only if gMainScreenPaintDirty=1
;
; in: WeeGUI loaded and initialized
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
!zone {
CreateViews
jsr CreateButton ; create various buttons
PaintMain
ldx #WGReset
jsr WeeGUI
stz gViewHasActiveHotkey+ID_BOXART
stz gViewHasActiveHotkey+ID_HINTS
stz gViewHasActiveHotkey+ID_VERSIONS
ldx #1 ; flag - clear screen before painting
stx gMainScreenPaintDirty
!byte $2C
RepaintMainIfDirty
ldx #0 ; flag - do not clear screen before painting
lda gMainScreenPaintDirty
bne +
rts
+ stz gMainScreenPaintDirty ; clear dirty flag
phx ; push 'clear screen' flag (will pop at end of procedure)
jsr CreateButton ; create 'previous' button
!word kViewPrevious
jsr CreateButton
jsr CreateButton ; create 'settings' button
!word kViewOptions
jsr CreateButton
jsr CreateButton ; create 'next game' button
!word kViewNext
lda gHasSavedGames
lda gHasSavedGames ; create 'play game' or 'resume game' button
beq .wantPlayButton
jsr CreateButton
!word kViewResume
@ -51,17 +73,17 @@ CreateViews
!word kViewPlay
.donePlayOrResume
jsr CreateConditionalButton
jsr CreateConditionalButton ; create or destroy 'artwork' button
!byte ID_BOXART
!word kViewBoxArt
!word kHasArtwork
jsr CreateConditionalButton
jsr CreateConditionalButton ; create or destroy 'hints' button
!byte ID_HINTS
!word kViewHints
!word kHasHints
jsr CreateConditionalButton
jsr CreateConditionalButton ; create or destroy 'revisions' button
!byte ID_VERSIONS
!word kViewVersions
!word kHasVersions
@ -70,71 +92,23 @@ CreateViews
+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
ldx #WGViewSetAction ; set view action (called automatically after scrolling)
+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
pla ; clear screen before repainting?
beq .nohome ; no -> repaint over existing screen, YOLO
ldx #WGClearScreen ; clear screen
jsr WeeGUI
jsr paintInfoView
jsr resetDescriptionViewScrolling
jsr paintDescriptionView
stz gMainScreenPaintDirty
+ rts
gMainScreenPaintDirty
!byte 0
}
jsr PaintTitleBar ; paint top bar
;------------------------------------------------------------------------------
; internal functions
!zone {
paintHR
lda #4
lda #4 ; paint horizontal separator bar
sta PARAM1
ldy #78
lda #83
@ -146,15 +120,97 @@ paintHR
dey
bne -
ldx #WGSyncGlobalCursor
jmp WeeGUI
jsr WeeGUI
paintDescriptionView
.nohome ldx #WGViewPaintAll
jsr WeeGUI ; tell everything that can paint itself, to paint itself
jsr PaintInfoView ; paint info box manually
ldx #WGSelectView ; reset scrolling of description box
lda #ID_DESCRIPTION
jsr WeeGUI
ldx #WGScrollX
lda #0
jsr WeeGUI
ldx #WGScrollY
lda #0
jsr WeeGUI
jmp PaintDescriptionView ; paint description box manually
}
;------------------------------------------------------------------------------
; CreateConditionalButton
; conditionally create a WeeGUI Button, based on per-game options
;
; in: WeeGUI loaded and initialized
; gOptionsStore populated
; stack contains 5 bytes of parameters:
; +1 [byte] WeeGUI view ID
; +2 [word] address of WeeGUI view configuration record
; +4 [word] address of length-prefixed key into gOptionsStore
; out: all registers and flags clobbered
;------------------------------------------------------------------------------
!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 gViewHasActiveHotkey,x
bne .done
lda #1
sta gViewHasActiveHotkey,x
jsr CreateButton
.viewConfigurationRecord
!word $FDFD ; SMC
bra .done
.no lda gViewHasActiveHotkey,x
beq .done
lda #0
sta gViewHasActiveHotkey,x
txa ; A = WeeGUI view ID
ldx #WGSelectView
jsr WeeGUI
ldx #WGDeleteView
jsr WeeGUI
.done rts
}
!zone {
PaintDescriptionView
ldx #WGSelectView
lda #ID_DESCRIPTION
jsr WeeGUI
+LDAY addrDescription
ldx #kDescriptionPaintWidth
jsr multiPrint
jsr MultiPrint
lda .vtab+1
cmp #10
bcs +
@ -162,13 +218,13 @@ paintDescriptionView
+ ldx #WGSetContentHeight
jmp WeeGUI
paintInfoView
PaintInfoView
ldx #WGSelectView
lda #ID_INFO
jsr WeeGUI
+LDAY addrInfo
ldx #kInfoPaintWidth
jsr multiPrint
jsr MultiPrint
jsr okvs_get ; get shortname of current game
!word gGlobalPrefsStore
@ -188,12 +244,12 @@ paintInfoView
jsr CreateNullTerminatedString
+LDADDR kNullTerminatedBuffer
bra multiPrintWhereYouAre
bra MultiPrintWhereYouAre
multiPrint
MultiPrint
stz .htab+1
stz .vtab+1
multiPrintWhereYouAre
MultiPrintWhereYouAre
stx .printLineLength+1
+STAY $00
.printLoop
@ -224,17 +280,6 @@ multiPrintWhereYouAre
.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

View File

@ -97,7 +97,7 @@ HandleKey
bra .focusAndDoAction
.activateView
tax
ldy gViewInUse,x
ldy gViewHasActiveHotkey,x
beq .notFound
ldx #WGSelectView
jsr WeeGUI
@ -209,9 +209,9 @@ callback_next
!word kLastPlayed
+ !word $FDFD ; SMC
lda #1
sta gNeedToSavePrefs
sta gMainScreenPaintDirty
jmp LoadGameInfo
sta gGlobalPrefsDirty ; will trigger a file write later
sta gMainScreenPaintDirty ; will trigger a repaint later, in main run loop
jmp LoadGameInfo ; load new game info first
}
callback_versions

View File

@ -50,26 +50,26 @@ OptionsDialog
jsr WeeGUI
ldx #WGCreateView ; create frame
+LDADDR .viewFrame
+LDADDR kViewFrame
+STAY PARAM0
jsr WeeGUI
ldx #WGViewSetTitle
+LDADDR .stringFrame
+LDADDR kStringFrame
+STAY PARAM0
jsr WeeGUI
jsr CreateButton ; create UI controls
!word .viewOK
!word kViewOK
jsr CreateButton
!word .viewCancel
!word kViewCancel
jsr CreateCheckbox
!word .viewForce40
!word kViewForce40
jsr CreateCheckbox
!word .viewForceUpper
!word kViewForceUpper
jsr CreateCheckbox
!word .viewScriptToFile
!word kViewScriptToFile
jsr CreateCheckbox
!word .viewAutoScript
!word kViewAutoScript
jsr SetCheckboxByPref ; set initial state of checkboxes based on preferences
!byte ID_OPTIONS_FORCE40
@ -103,7 +103,7 @@ OptionsDialog
sta PARAM1
jsr WeeGUI
ldx #WGPrint
+LDADDR .stringForce40Description
+LDADDR kStringForce40Description
+STAY PARAM0
jsr WeeGUI
@ -114,7 +114,7 @@ OptionsDialog
sta PARAM1
jsr WeeGUI
ldx #WGPrint
+LDADDR .stringForceUpperDescription
+LDADDR kStringForceUpperDescription
+STAY PARAM0
jsr WeeGUI
@ -125,7 +125,7 @@ OptionsDialog
sta PARAM1
jsr WeeGUI
ldx #WGPrint
+LDADDR .stringScriptToFileDescription
+LDADDR kStringScriptToFileDescription
+STAY PARAM0
jsr WeeGUI
@ -136,16 +136,16 @@ OptionsDialog
sta PARAM1
jsr WeeGUI
ldx #WGPrint
+LDADDR .stringAutoScriptDescription
+LDADDR kStringAutoScriptDescription
+STAY PARAM0
jsr WeeGUI
.runLoop
ldx #WGPendingViewAction
jsr WeeGUI
lda $c000
lda $C000
bpl .runLoop
bit $c010
bit $C010
jsr HandleOptionsKey
bra .runLoop
@ -185,8 +185,8 @@ callback_options_ok
!byte ID_OPTIONS_AUTOSCRIPT
!word kAutoScript
lda #1
sta gNeedToSavePrefs
jsr SaveGlobalPreferences
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
@ -258,7 +258,7 @@ SetPrefByCheckbox
!byte $FD ; SMC
}
.viewFrame
kViewFrame
!byte ID_OPTIONS_FRAME ; view ID
!byte 2 ; style (decorated frame)
!byte 12 ; left
@ -267,76 +267,76 @@ SetPrefByCheckbox
!byte 19 ; visible height
!byte 56 ; width
!byte 19 ; height
.stringFrame
kStringFrame
!text "Settings",0
.viewOK
kViewOK
!byte ID_OPTIONS_OK ; view ID
!byte 56 ; left
!byte 4 ; top
!byte 10 ; width
!word callback_options_ok ; callback
!word .stringOK ; caption
.stringOK
!word kStringOK ; caption
kStringOK
!byte $0F ; 'P' inverse
!byte 139,0
.viewCancel
kViewCancel
!byte ID_OPTIONS_CANCEL ; view ID
!byte 56 ; left
!byte 6 ; top
!byte 10 ; width
!word callback_options_cancel ; callback
!word .stringCancel ; caption
.stringCancel
!word kStringCancel ; caption
kStringCancel
!byte $03 ; 'C' inverse
!text "ancel",0
.viewForce40
kViewForce40
!byte ID_OPTIONS_FORCE40 ; view ID
!byte 14 ; left
!byte 4 ; top
!word .stringForce40 ; caption
.stringForce40
!word kStringForce40 ; caption
kStringForce40
!text "Force "
!byte $34 ; '4' inverse
!text "0 column",0
.stringForce40Description
kStringForce40Description
!text "Some games may be glitchy",0
.viewForceUpper
kViewForceUpper
!byte ID_OPTIONS_FORCEUPPER ; view ID
!byte 14 ; left
!byte 9 ; top
!word .stringForceUpper ; caption
.stringForceUpper
!word kStringForceUpper ; caption
kStringForceUpper
!text "Force "
!byte $75 ; 'u' inverse
!text "ppercase",0
.stringForceUpperDescription
kStringForceUpperDescription
!text "A MATTER OF PREFERENCE, I SUPPOSE",0
.viewScriptToFile
kViewScriptToFile
!byte ID_OPTIONS_SCRIPTTOFILE ; view ID
!byte 14 ; left
!byte 14 ; top
!word .stringScriptToFile ; caption
.stringScriptToFile
!word kStringScriptToFile ; caption
kStringScriptToFile
!text "SCRIPT to "
!byte $66 ; 'f' inverse
!text "ile",0
.stringScriptToFileDescription
kStringScriptToFileDescription
!text "Save transcripts to a file instead of printer",0
.viewAutoScript
kViewAutoScript
!byte ID_OPTIONS_AUTOSCRIPT ; view ID
!byte 14 ; left
!byte 19 ; top
!word .stringAutoScript ; caption
.stringAutoScript
!word kStringAutoScript ; caption
kStringAutoScript
!text "Always "
!byte $13 ; 'S' inverse
!text "CRIPT",0
.stringAutoScriptDescription
kStringAutoScriptDescription
!text "Turn on SCRIPT mode automatically",0
}