# DarkPlasma_AutoLineBreak for RPG Maker VX Ace
# 버전: 1.0.5 (LINE_MARGIN 상수 참조 수정 + 약간의 안정성 개선)
# 목표: 최대한 간단하게 유지하면서 에러 제거
module DarkPlasma
module AutoLineBreak
PROHIBIT_BEFORE = ',)]}、〕〉》」』】〙〗〟’”⦆»ゝゞーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇷ゚ㇺㇻㇼㇽㇾㇿ々〻‐゠–〜~?!‼⁇⁈⁉・:;/。.'.freeze
PROHIBIT_AFTER = '([{〔〈《「『【〘〖〝‘“⦅«'.freeze
LINE_MARGIN = 4
WORD_BASE = false # true = 영어 단어 단위 시도 (아주 제한적)
IGNORE_CLASS_NAMES = [] # 필요하면 여기에 클래스 이름 추가
end
end
class Window_Base
attr_accessor :ignore_auto_linebreak_temp
def ignore_auto_linebreak?
DarkPlasma::AutoLineBreak::IGNORE_CLASS_NAMES.include?(self.class.name) ||
@ignore_auto_linebreak_temp
end
def start_ignore_auto_linebreak
@ignore_auto_linebreak_temp = true
end
def finish_ignore_auto_linebreak
@ignore_auto_linebreak_temp = false
end
def auto_line_width
contents.width - DarkPlasma::AutoLineBreak::LINE_MARGIN
end
def prohibit_before?(char)
DarkPlasma::AutoLineBreak::PROHIBIT_BEFORE.include?(char)
end
def prohibit_after?(char)
DarkPlasma::AutoLineBreak::PROHIBIT_AFTER.include?(char)
end
# 자동 줄바꿈 필요 여부 판단 (VX Ace 한계로 매우 단순화됨)
def should_auto_break_here?(c, pos)
return false if ignore_auto_linebreak?
return false if c == "\n" || c.nil? || c.empty?
char_width = begin
contents.text_width(c)
rescue
12 # 폰트/문자 문제 시 기본값
end
current_x = pos[:x]
# 1. 기본 폭 초과 → 행두 금지 문자가 아니면 줄바꿈
if current_x + char_width > auto_line_width
return !prohibit_before?(c)
end
# 2. 행미 금지 문자 + 여유 공간 부족 시 강제 줄바꿈 시도
if prohibit_after?(c) && current_x + char_width + DarkPlasma::AutoLineBreak::LINE_MARGIN > auto_line_width
return true
end
# 3. 영어 단어 단위 (매우 제한적 – lookahead 불가)
if DarkPlasma::AutoLineBreak::WORD_BASE &&
pos[:last_char] == ' ' && c != ' ' && c =~ /\w/
if current_x + char_width * 4 > auto_line_width # 임의 예측
return true
end
end
false
end
end
class Window_Base
alias dp_alb_process_character process_character
def process_character(c, text, pos)
if ignore_auto_linebreak?
dp_alb_process_character(c, text, pos)
return
end
# 자동 줄바꿈 필요 시 먼저 줄 바꿈
if should_auto_break_here?(c, pos)
process_new_line(text, pos)
pos[:x] = pos[:new_x] # x 위치 초기화 (중요!)
end
# 마지막 문자 기억 (영어 옵션용)
pos[:last_char] = c if c =~ /[\w\s]/
# 원본 처리
dp_alb_process_character(c, text, pos)
end
# \ALB[START] / \ALB[FINISH] 간단 구현
alias dp_alb_process_escape_character process_escape_character
def process_escape_character(code, text, pos)
if code.upcase == 'ALB'
if text.sub!(/^\[START\]/i, '')
start_ignore_auto_linebreak
return
elsif text.sub!(/^\[FINISH\]/i, '')
finish_ignore_auto_linebreak
return
end
end
dp_alb_process_escape_character(code, text, pos)
end
end
# 레이아웃이 깨지기 쉬운 윈도우는 자동 줄바꿈 끄기
class Window_ChoiceList < Window_Command
def ignore_auto_linebreak?
true
end
end
class Window_BattleLog < Window_Selectable
def ignore_auto_linebreak?
true
end
end
적용된 게임 참조: https://kone.gg/s/somisoft/bC8e92EXqwOp90q_d0MzWb
용머리 게임 텍스트 자동 줄바꿈 스크립트
aHR0cHM6Ly9raW8uYWMvYy9jN251a3lBamxNSzZ6NERfQUZFNTBi
업로드한 파일은 바로 적용 못함
에디터로 스크립트 넣을 수 있는 상태에서 복사 붙여넣기용
▼ シーン ## 자동 줄바꿈.txt
▼ 적용 위치 ## 스크립트명
