Skip to content

Commit

Permalink
Implemented ability to override text box properties via message headers
Browse files Browse the repository at this point in the history
  • Loading branch information
RPGHacker committed Jan 15, 2024
1 parent 9792ebf commit db970b0
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 18 deletions.
79 changes: 74 additions & 5 deletions docs/vwf/manual/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
<li><a href="#header-settings-vwf_width"><code>vwf_width()</code></a></li>
<li><a href="#header-settings-vwf_height"><code>vwf_height()</code></a></li>

<li><a href="#header-settings-vwf_text_box_bg_pattern"><code>vwf_text_box_bg_pattern()</code></a></li>
<li><a href="#header-settings-vwf_text_box_bg_color"><code>vwf_text_box_bg_color()</code></a></li>
<li><a href="#header-settings-vwf_text_box_frame"><code>vwf_text_box_frame()</code></a></li>

<li><a href="#header-settings-vwf_box_animation"><code>vwf_box_animation()</code></a></li>
</ul></details>

Expand Down Expand Up @@ -451,8 +455,8 @@
<ul>
<li>Each 8×8 tile represents one BG pattern. The tile is simply repeated horizontally and vertically to fill up the entire background of a text box.</li>
<li>The file size of <code>vwfbgpatterns.bin</code> must be divisible by 16. That's exactly the size of one 8x8 tiles in 2BPP GB graphics format in YY-CHR.</li>
<li>The default background color is defined via <code>!vwf_default_text_box_bg_color</code> in <code>data/vwfconfig.cfg</code>. Currently, to switch to a different BG color at run-time, custom code is needed.</li>
<li>The default background pattern is defined via <code>!vwf_default_text_box_bg_pattern</code> in <code>data/vwfconfig.cfg</code>. A value of <code>$00</code> represents the first tile in <code>vwfbgpatterns.bin</code>, a value of <code>$01</code> the second tile and so forth. Currently, to switch to a different BG pattern at run-time, custom code is needed.</li>
<li>The default background color is defined via <code>!vwf_default_text_box_bg_color</code> in <code>data/vwfconfig.cfg</code>. 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.</li>
<li>The default background pattern is defined via <code>!vwf_default_text_box_bg_pattern</code> in <code>data/vwfconfig.cfg</code>. A value of <code>$00</code> represents the first tile in <code>vwfbgpatterns.bin</code>, a value of <code>$01</code> the second tile 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.</li>
<li>You should only every use color <code>$01</code> of a palette for BG patterns (that is "the second color from left" in a typical 2BPP four-color palette).
The reason for this is that colors <code>$02</code> and <code>$03</code> are reserved for fonts.</li>
</ul>
Expand All @@ -474,7 +478,7 @@
<img class="d-block m-1 my-2 ir-crisp" src="screenshots/frames-1.png" alt="Screenshot" width="588" height="355"/>
</li>
<li>The file size of <code>vwfframes.bin</code> must be divisible by 144. That's exactly the size of nine 8x8 tile in 2BPP GB graphics format in YY-CHR.</li>
<li>The default text box frame is defined via <code>!vwf_default_text_box_frame</code> in <code>data/vwfconfig.cfg</code>. A value of <code>$00</code> represents the first nine tiles in <code>vwfframes.bin</code>, a value of <code>$01</code> the second nine tiles and so forth. Currently, to switch to a different text box frame at run-time, custom code is needed.</li>
<li>The default text box frame is defined via <code>!vwf_default_text_box_frame</code> in <code>data/vwfconfig.cfg</code>. A value of <code>$00</code> represents the first nine tiles in <code>vwfframes.bin</code>, a value of <code>$01</code> 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.</li>
<li>The define <code>!vwf_frame_palette</code> in <code>data/vwfconfig.cfg</code> 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 <code>$00</code> to <code>$07</code>. This image illustrates how these values map onto the palette from Lunar Magic:
<img class="d-block m-1 my-2 ir-crisp" src="screenshots/lm-palette-1.png" alt="Screenshot" width="530" height="329"/>
</li>
Expand Down Expand Up @@ -721,6 +725,69 @@ incsrc "vwftable_for_my_font.asm"</code></pre>
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.
</p></dd>

<dt id="header-settings-vwf_text_box_bg_pattern"><code>vwf_text_box_bg_pattern()</code></dt>
<dd><p>
<table class="api-documentation">
<tr>
<th>Usage</th>
<td><pre><code class="65c816_asar">vwf_text_box_bg_pattern(pattern_id)</code></pre></td>
</tr>
<tr>
<th>Short Aliases</th>
<td><pre><code class="65c816_asar">text_box_bg_pattern(pattern_id) = vwf_text_box_bg_pattern(pattern_id)</code></pre></td>
</tr>
<tr>
<th>Parameters</th>
<td><ul class="parameter-list">
<li><code>pattern_id: number:</code> The index of the pattern to use. (min: <code>$00</code>, max: <code>[total number of patterns] - 1</code>)</li>
</ul></td>
</tr>
</table>
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.
</p></dd>

<dt id="header-settings-vwf_text_box_bg_color"><code>vwf_text_box_bg_color()</code></dt>
<dd><p>
<table class="api-documentation">
<tr>
<th>Usage</th>
<td><pre><code class="65c816_asar">vwf_text_box_bg_color(color)</code></pre></td>
</tr>
<tr>
<th>Short Aliases</th>
<td><pre><code class="65c816_asar">text_box_bg_color(color) = vwf_text_box_bg_color(color)</code></pre></td>
</tr>
<tr>
<th>Parameters</th>
<td><ul class="parameter-list">
<li><code>color: rgb15-color:</code> The color to use, in RGB15 format.</li>
</ul></td>
</tr>
</table>
Overrides the setting for the text box background color used by this text box.
</p></dd>

<dt id="header-settings-vwf_text_box_frame"><code>vwf_text_box_frame()</code></dt>
<dd><p>
<table class="api-documentation">
<tr>
<th>Usage</th>
<td><pre><code class="65c816_asar">vwf_text_box_frame(frame_id)</code></pre></td>
</tr>
<tr>
<th>Short Aliases</th>
<td><pre><code class="65c816_asar">text_box_frame(frame_id) = vwf_text_box_frame(frame_id)</code></pre></td>
</tr>
<tr>
<th>Parameters</th>
<td><ul class="parameter-list">
<li><code>frame_id: number:</code> The index of the frame to use. (min: <code>$00</code>, max: <code>[total number of frames] - 1</code>)</li>
</ul></td>
</tr>
</table>
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.
</p></dd>

<dt id="header-settings-vwf_box_animation"><code>vwf_box_animation()</code></dt>
<dd><p>
<table class="api-documentation">
Expand Down Expand Up @@ -769,7 +836,7 @@ BoxAnimation = VWF_BoxAnimation</code></pre></td>
<tr>
<th>Parameters</th>
<td><ul class="parameter-list">
<li><code>font_id: number:</code> The ID of the font to use. (min: <code>0</code>, max: <code>[number of total fonts] - 1</code>)</li>
<li><code>font_id: number:</code> The ID of the font to use. (min: <code>0</code>, max: <code>[total number of fonts] - 1</code>)</li>
</ul></td>
</tr>
</table>
Expand Down Expand Up @@ -1697,7 +1764,8 @@ ControllerButton = VWF_ControllerButton</code></pre></td>
</tr>
<tr>
<th>Short Aliases</th>
<td><pre><code class="65c816_asar">!open_message(message_no, show_close_anim, show_open_anim) = %vwf_display_message(message_no, show_close_anim, show_open_anim)</code></pre></td>
<td><pre><code class="65c816_asar">!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)</code></pre></td>
</tr>
<tr>
<th>Parameters</th>
Expand Down Expand Up @@ -2542,6 +2610,7 @@ endif</code></pre>
<li>Added the <code>%vwf_wait_for_button()</code> and <code>%vwf_wait_for_custom_button()</code> text commands, the <code>VWF_AutoWait.WaitForButton</code> auto-wait mode, as well as the <code>!vwf_default_advance_button_mask</code>, <code>!vwf_select_choice_button_mask</code> and <code>!vwf_skip_message_button_mask</code> settings, which give finer control over which buttons affect the patch. These features replace the <code>%vwf_wait_for_a()</code> text command and the <code>VWF_AutoWait.WaitForA</code> auto-wait mode, which are now deprecated.</li>
<li>The maximum value for the <code>VWF_AutoWait.WaitFrames</code> auto-wait mode has been extended from <code>254</code> to <code>255</code>.</li>
<li>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.</li>
<li>Text box properties (background pattern, background color and frame) can now be overridden by message headers. This functionality is available via the <a href="#header-settings-vwf_text_box_bg_pattern"><code>vwf_text_box_bg_pattern()</code></a>, <a href="#header-settings-vwf_text_box_bg_color"><code>vwf_text_box_bg_color()</code></a> and <a href="#header-settings-vwf_text_box_frame"><code>vwf_text_box_frame()</code></a> header settings.</li>
</ul>
</p></dd>

Expand Down
8 changes: 5 additions & 3 deletions patches/vwf_dialogues/data/smw/data/vwfconfig.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 19 additions & 5 deletions patches/vwf_dialogues/data/testing/data/vwfmessages.asm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ endif
!clear()
!options(TestSelectionPage2,
!str("Wait for Buttons"),
!str("-"),
!str("Text box overrides"),
!str("-"),
!str("-"),
!str("-"),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2071,31 +2073,43 @@ 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()

;-------------------------------------------------------

%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()

;-------------------------------------------------------

%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()

;-------------------------------------------------------

%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()

Expand Down
54 changes: 50 additions & 4 deletions patches/vwf_dialogues/vwf_dialogues.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
48 changes: 47 additions & 1 deletion patches/vwf_dialogues/vwfmacros.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit db970b0

Please sign in to comment.