From db970b014956f51fc3681c6e22eb71c47d5df9dc Mon Sep 17 00:00:00 2001 From: RPG Hacker Date: Mon, 15 Jan 2024 15:01:26 +0100 Subject: [PATCH] Implemented ability to override text box properties via message headers --- docs/vwf/manual/index.xhtml | 79 +++++++++++++++++-- .../vwf_dialogues/data/smw/data/vwfconfig.cfg | 8 +- .../data/testing/data/vwfmessages.asm | 24 ++++-- patches/vwf_dialogues/vwf_dialogues.asm | 54 ++++++++++++- patches/vwf_dialogues/vwfmacros.asm | 48 ++++++++++- 5 files changed, 195 insertions(+), 18 deletions(-) diff --git a/docs/vwf/manual/index.xhtml b/docs/vwf/manual/index.xhtml index 4dca465..26f55bf 100644 --- a/docs/vwf/manual/index.xhtml +++ b/docs/vwf/manual/index.xhtml @@ -120,6 +120,10 @@
  • vwf_width()
  • vwf_height()
  • +
  • vwf_text_box_bg_pattern()
  • +
  • vwf_text_box_bg_color()
  • +
  • vwf_text_box_frame()
  • +
  • vwf_box_animation()
  • @@ -451,8 +455,8 @@ @@ -474,7 +478,7 @@ Screenshot
  • The file size of vwfframes.bin must be divisible by 144. That's exactly the size of nine 8x8 tile in 2BPP GB graphics format in YY-CHR.
  • -
  • The default text box frame is defined via !vwf_default_text_box_frame in data/vwfconfig.cfg. A value of $00 represents the first nine tiles in vwfframes.bin, a value of $01 the second nine tiles and so forth. Currently, to switch to a different text box frame at run-time, custom code is needed.
  • +
  • The default text box frame is defined via !vwf_default_text_box_frame in data/vwfconfig.cfg. A value of $00 represents the first nine tiles in vwfframes.bin, a value of $01 the second nine tiles and so forth. In theory, players can override this default setting in-game, but the patch doesn't provide any built-in menu for doing so. Additionally, the setting can be overridden by a message header.
  • The define !vwf_frame_palette in data/vwfconfig.cfg dictates which section of CGRAM text box frames use for their palette. To give you a better idea of what this means: This define controls which parts of the Lunar Magic palette get overwritten by the text box frame palette while a VWF text box is on screen. Usable values are $00 to $07. This image illustrates how these values map onto the palette from Lunar Magic: Screenshot
  • @@ -721,6 +725,69 @@ incsrc "vwftable_for_my_font.asm" Specifies the height of the inside area (aka the text area) of the text box in 16x16 tile increments. A value of 1 means one 16x16 tile (=16 pixels), a value of 2 two 16x16 tiles etc. To get the total height of the entire text box, add two 8x8 tiles for the text box frame to this.

    +
    vwf_text_box_bg_pattern()
    +

    + + + + + + + + + + + + + +
    Usage
    vwf_text_box_bg_pattern(pattern_id)
    Short Aliases
    text_box_bg_pattern(pattern_id) = vwf_text_box_bg_pattern(pattern_id)
    Parameters
      +
    • pattern_id: number: The index of the pattern to use. (min: $00, max: [total number of patterns] - 1)
    • +
    + Overrides the setting for the text box background pattern used by this text box. NOTE: For technical reasons, the patch can't properly bound-check this setting for the maximum value. Going beyond the maximum will produce glitched text box backgrounds. +

    + +
    vwf_text_box_bg_color()
    +

    + + + + + + + + + + + + + +
    Usage
    vwf_text_box_bg_color(color)
    Short Aliases
    text_box_bg_color(color) = vwf_text_box_bg_color(color)
    Parameters
      +
    • color: rgb15-color: The color to use, in RGB15 format.
    • +
    + Overrides the setting for the text box background color used by this text box. +

    + +
    vwf_text_box_frame()
    +

    + + + + + + + + + + + + + +
    Usage
    vwf_text_box_frame(frame_id)
    Short Aliases
    text_box_frame(frame_id) = vwf_text_box_frame(frame_id)
    Parameters
      +
    • frame_id: number: The index of the frame to use. (min: $00, max: [total number of frames] - 1)
    • +
    + Overrides the setting for the text box frame used by this text box. NOTE: For technical reasons, the patch can't properly bound-check this setting for the maximum value. Going beyond the maximum will produce glitched text box frames. +

    +
    vwf_box_animation()

    @@ -769,7 +836,7 @@ BoxAnimation = VWF_BoxAnimation
    Parameters
      -
    • font_id: number: The ID of the font to use. (min: 0, max: [number of total fonts] - 1)
    • +
    • font_id: number: The ID of the font to use. (min: 0, max: [total number of fonts] - 1)
    @@ -1697,7 +1764,8 @@ ControllerButton = VWF_ControllerButton Short Aliases -

    !open_message(message_no, show_close_anim, show_open_anim) = %vwf_display_message(message_no, show_close_anim, show_open_anim)
    +
    !open_message(message_no, show_close_anim, show_open_anim) = %vwf_display_message(message_no, show_close_anim, show_open_anim)
    +!display_message(message_no, show_close_anim, show_open_anim) = %vwf_display_message(message_no, show_close_anim, show_open_anim)
    Parameters @@ -2542,6 +2610,7 @@ endif
  • Added the %vwf_wait_for_button() and %vwf_wait_for_custom_button() text commands, the VWF_AutoWait.WaitForButton auto-wait mode, as well as the !vwf_default_advance_button_mask, !vwf_select_choice_button_mask and !vwf_skip_message_button_mask settings, which give finer control over which buttons affect the patch. These features replace the %vwf_wait_for_a() text command and the VWF_AutoWait.WaitForA auto-wait mode, which are now deprecated.
  • The maximum value for the VWF_AutoWait.WaitFrames auto-wait mode has been extended from 254 to 255.
  • Simplified many multiplications in the patch. For most of them, this slightly boosts performance. More importantly, this removes any dependency on the mode 7 registers for multiplication, which avoids a potential rare bug that could be caused by HDMA.
  • +
  • Text box properties (background pattern, background color and frame) can now be overridden by message headers. This functionality is available via the vwf_text_box_bg_pattern(), vwf_text_box_bg_color() and vwf_text_box_frame() header settings.
  • diff --git a/patches/vwf_dialogues/data/smw/data/vwfconfig.cfg b/patches/vwf_dialogues/data/smw/data/vwfconfig.cfg index 6ad0746..7a90f27 100644 --- a/patches/vwf_dialogues/data/smw/data/vwfconfig.cfg +++ b/patches/vwf_dialogues/data/smw/data/vwfconfig.cfg @@ -93,9 +93,11 @@ ; These values define the default properties of the text box design. They are used -; when not modified in-game. Note that this patch currently doesn't include a built-in -; method to customize your text box design in-game, so custom code is needed if you -; want to make use of that. +; when the properties were not overridden by a message box header and a player has not +; modified them in-game. Note that this patch currently doesn't include any built-in +; functionality for players to customize their text box, which means unless you implement +; some code for that yourself, message box headers are really the only thing that can override +; these settings. !vwf_default_text_box_bg_pattern ?= $08 !vwf_default_text_box_bg_color ?= rgb_15(4, 6, 17) !vwf_default_text_box_frame ?= $07 diff --git a/patches/vwf_dialogues/data/testing/data/vwfmessages.asm b/patches/vwf_dialogues/data/testing/data/vwfmessages.asm index ee465cb..eaf43a9 100644 --- a/patches/vwf_dialogues/data/testing/data/vwfmessages.asm +++ b/patches/vwf_dialogues/data/testing/data/vwfmessages.asm @@ -105,7 +105,7 @@ endif !clear() !options(TestSelectionPage2, !str("Wait for Buttons"), - !str("-"), + !str("Text box overrides"), !str("-"), !str("-"), !str("-"), @@ -338,6 +338,8 @@ endif !jump(.Page2Start) !opt_loc(TestSelectionPage2, 1) + !display_message(0062, false, false) + !opt_loc(TestSelectionPage2, 2) !opt_loc(TestSelectionPage2, 3) !opt_loc(TestSelectionPage2, 4) @@ -2071,7 +2073,10 @@ BufferOverflowTest: %vwf_message_start(0062) ; Message 10D-1 - ; Message header & text go here + %vwf_header(text_box_bg_pattern($07)) + + !str("This text box overrides the text box background.") : !press_button + !display_message(0063) %vwf_message_end() @@ -2079,7 +2084,10 @@ BufferOverflowTest: %vwf_message_start(0063) ; Message 10D-2 - ; Message header & text go here + %vwf_header(text_box_bg_color(rgb_15(15, 0, 0))) + + !str("This text box overrides the text box color.") : !press_button + !display_message(0064) %vwf_message_end() @@ -2087,7 +2095,10 @@ BufferOverflowTest: %vwf_message_start(0064) ; Message 10E-1 - ; Message header & text go here + %vwf_header(text_box_frame($01)) + + !str("This text box overrides the text box frame.") : !press_button + !display_message(0065) %vwf_message_end() @@ -2095,7 +2106,10 @@ BufferOverflowTest: %vwf_message_start(0065) ; Message 10E-2 - ; Message header & text go here + %vwf_header(text_box_bg_pattern($05), text_box_bg_color(rgb_15(0, 15, 0)), text_box_frame($02)) + + !str("This text box overrides all three text box properties.") : !press_button + !display_message(0050) %vwf_message_end() diff --git a/patches/vwf_dialogues/vwf_dialogues.asm b/patches/vwf_dialogues/vwf_dialogues.asm index ca7980a..4255878 100644 --- a/patches/vwf_dialogues/vwf_dialogues.asm +++ b/patches/vwf_dialogues/vwf_dialogues.asm @@ -601,14 +601,14 @@ InitDefaults: sta !vwf_message sta !vwf_message+1 - lda #!vwf_default_text_box_bg_pattern ; Set default values + lda #!vwf_default_text_box_bg_pattern_internal ; Set default values sta !vwf_chosen_box_bg - lda #!vwf_default_text_box_frame + lda #!vwf_default_text_box_frame_internal sta !vwf_chosen_box_frame - lda.b #!vwf_default_text_box_bg_color + lda.b #!vwf_default_text_box_bg_color_internal sta !vwf_chosen_box_color - lda.b #!vwf_default_text_box_bg_color>>8 + lda.b #!vwf_default_text_box_bg_color_internal>>8 sta !vwf_chosen_box_color+1 rts @@ -1181,6 +1181,45 @@ endif sta !vwf_current_box_color lda !vwf_chosen_box_color+1 sta !vwf_current_box_color+1 + + lda [$00],y ; Text box property override settings + iny + pha + + bit.b #%00000100 + beq .DontOverrideBg + + lda [$00],y ; Text box BG pattern override + sta !vwf_current_box_bg + iny + + pla + pha +.DontOverrideBg + + bit.b #%00000010 + beq .DontOverrideColor + + lda [$00],y ; Text box BG color override + sta !vwf_current_box_color + iny + lda [$00],y + sta !vwf_current_box_color+1 + iny + + pla + pha +.DontOverrideColor + + bit.b #%00000001 + beq .DontOverrideFrame + + lda [$00],y ; Text box frame override + sta !vwf_current_box_frame + iny + +.DontOverrideFrame + pla tya sta $03 @@ -1191,6 +1230,13 @@ endif sta !vwf_text_source sep #$20 + ; Now that the header can override text box properties, we are forced + ; to re-run these steps every time we load a header. I guess we COULD + ; optimize this to detect a changed property and only then call these + ; routines, but I really don't think this optimization is worth it. + jsr BufferGraphics_Start + jsr LoadBoxPalette + .ValidationChecks lda !vwf_width ; Validate all inputs diff --git a/patches/vwf_dialogues/vwfmacros.asm b/patches/vwf_dialogues/vwfmacros.asm index 517edaa..54215a2 100644 --- a/patches/vwf_dialogues/vwfmacros.asm +++ b/patches/vwf_dialogues/vwfmacros.asm @@ -704,6 +704,19 @@ endmacro %vwf_define_header_setter_generic("enable_message_asm", false, false, true) +; These three are special, as they don't directly map onto the settings from vwfconfig.cfg. +; We'll use a bit of trickery here to handle everything while also remaning backwards-compatible. +!vwf_default_text_box_bg_pattern_internal := !vwf_default_text_box_bg_pattern +!vwf_default_text_box_bg_color_internal := !vwf_default_text_box_bg_color +!vwf_default_text_box_frame_internal := !vwf_default_text_box_frame + +!vwf_default_text_box_bg_pattern = $100 +!vwf_default_text_box_bg_color = $10000 +!vwf_default_text_box_frame = $100 + +%vwf_define_header_setter_generic("text_box_bg_pattern", true, $00, $100) +%vwf_define_header_setter_generic("text_box_bg_color", true, $0000, $10000) +%vwf_define_header_setter_generic("text_box_frame", true, $00, $100) macro vwf_header(...) if !vwf_current_message_id == $10000 @@ -827,6 +840,38 @@ macro vwf_header(...) if !vwf_header_argument_enable_message_asm_value dl !vwf_current_message_asm_name endif + + ; db %-----abc + ; %a: BG pattern override enabled + ; %b: BG color override enabled + ; %c: Frame override enabled + !temp_has_bg_pattern #= not(equal(!vwf_header_argument_text_box_bg_pattern_value, $100)) + !temp_has_bg_color #= not(equal(!vwf_header_argument_text_box_bg_color_value, $10000)) + !temp_has_frame #= not(equal(!vwf_header_argument_text_box_frame_value, $100)) + + db (!temp_has_bg_pattern<<2)|(!temp_has_bg_color<<1)|(!temp_has_frame) + + ; db $aa (skip if BG pattern override disabled) + ; $aa: BG pattern override + if !temp_has_bg_pattern + db !vwf_header_argument_text_box_bg_pattern_value + endif + + ; dw $aaaa (skip if BG color override disabled) + ; $aaaa: BG color override + if !temp_has_bg_color + dw !vwf_header_argument_text_box_bg_color_value + endif + + ; db $aa (skip if frame override disabled) + ; $aa: Frame override + if !temp_has_frame + db !vwf_header_argument_text_box_frame_value + endif + + undef "temp_has_bg_pattern" + undef "temp_has_bg_color" + undef "temp_has_frame" endif endmacro @@ -1350,8 +1395,9 @@ if !vwf_enable_short_aliases != false !freeze = %vwf_freeze() !halt = %vwf_freeze() - !jump = %vwf_set_text_pointer + !jump = %vwf_set_text_pointer !open_message = %vwf_display_message + !display_message = %vwf_display_message !font = %vwf_set_font !edit_pal = %vwf_change_colors