Advertisement
biud436

Untitled

Feb 22nd, 2018
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 65.86 KB | None | 0 0
  1. #==============================================================================
  2. # ** Hangul Message System 1.5.5 (RPG Maker VX Ace)
  3. #==============================================================================
  4. # Name       : Hangul Message System
  5. # Author     : biud436
  6. # Version    : 1.5.5
  7. # Link       : http://biud436.blog.me/220251747366
  8. #==============================================================================
  9. # ** 업데이트 로그
  10. #==============================================================================
  11. # 2017.06.20 :
  12. # - 말풍선 모드에서도 얼굴 이미지 사용 가능
  13. # - 멈춤 표시 이미지 표시
  14. # - 말풍선 위치 화면 내로 자동 조절
  15. # 2016.05.07 - 정규표현식 및 텍스트 매칭 코드 수정, 자동 개행 기능 추가
  16. # 2015.10.12 - 이름 윈도우 텍스트 크기 설정
  17. # 2015.09.06 - 화면 영역 내 메시지 표시 기능
  18. # 2015.08.22 - 버그 수정(명령어 처리 순서 변경)
  19. # 2015.08.11 - RGB 모듈 코드 정리
  20. # 2015.08.08 - 이름 윈도우 폭을 텍스트 길이에 맞춤
  21. # 2015.08.06 - 말풍선 크기 계산 방법 수정 (폭과 높이를 동적으로 계산)
  22. # 2015.08.02 - 이름 윈도우 좌표 버그 수정, 페이스칩 클래스 추가
  23. # 2015.07.29 - 말풍선 그래픽이 없을 때 말풍선 모드에서 이름 윈도우 위치 수정
  24. # 2015.06.19 - 그림 삽입 기능 추가
  25. # 2015.06.18 - 변수, 주인공, 파티원, 골드 등 새로운 명령어 추가
  26. # 2015.06.15 - 정규표현식을 UTF_8(16진수)에서 한글로 변경, 상수를 해시로 정리
  27. # 2015.06.11 - 페이스칩 좌표 및 정렬 기능 수정, 페이스칩 투명 처리 변경
  28. # 2015.06.10 - 색상 불러오기 기능 추가
  29. # 2015.06.08 - 최대 라인 수 변경 기능 업데이트
  30. # 2015.06.03 - 사용자 정의 그래픽, 최대 라인 수 변경 기능 추가
  31. # 2015.06.02 - 선택지 Z좌표 수정
  32. # 2015.05.13 - 기울임꼴 문제 수정
  33. # 2015.05.11 - 기본 폰트 사이즈를 변경할 때 생기는 말풍선 좌표 오차 수정
  34. # 2015.04.15 - 페이스칩 반전 기능 사용 여부 스크립트 사용자 선택에 맡김
  35. # 2015.03.21 - 코드 정리
  36. # 2015.03.20 - 말풍선 스프라이트 추가, 말풍선으로 시작 시 창열림효과 제거, 투명도 조절
  37. # 2015.02.20 - 저장 버그 수정
  38. # 2015.02.16 - 말풍선 모드 추가, 효과음 재생 기능 추가, 이름 윈도우 거리 조절 기능
  39. # 2015.02.14 - 굵게, 기울임꼴, 테두리색 추가, 버그 픽스
  40. # 2015.02.13 - 한글 명령어 추가, 큰 페이스칩 이름 수정, 이름 윈도우 정렬 위치 수정
  41. # 2015.02.12 - 이름 윈도우 정렬 오류 수정
  42. # 2015.02.11 - 이름 윈도우 좌표 수정
  43. # 2015.02.05 - 메시지 시스템 + 색상 변환 스크립트 통합
  44. # 2015.01.26 - 버그 픽스
  45. # 2015.01.25 - 스크립트 통합
  46. #==============================================================================
  47. # ** 사용법
  48. #==============================================================================
  49. # \이름<이벤트명>
  50. # \말풍선[이벤트의 ID]
  51. # \말풍선[0]
  52. # \말풍선[-1]
  53. # \변수[인덱스]
  54. # \골드
  55. # \주인공[인덱스]
  56. # \파티원[인덱스]
  57. # \색[색상명]
  58. # \효과음![효과음명]
  59. # \테두리색![색상명]
  60. # \#색상코드!
  61. # \굵게!
  62. # \이탤릭!
  63. # \속도![텍스트의 속도]
  64. # \그림![그림파일명]
  65. # \자동개행!
  66. #==============================================================================
  67. # ** Terms of Use
  68. #==============================================================================
  69. # Free for commercial and non-commercial use
  70. #==============================================================================
  71. # ** RS
  72. #------------------------------------------------------------------------------
  73. # 기본 설정값입니다.
  74. #==============================================================================
  75. module RS
  76.  
  77.   LIST = CODE = {}
  78.  
  79.   # 기본 설정
  80.   LIST["폰트명"] = Font.default_name
  81.   LIST["폰트크기"] = Font.default_size
  82.   LIST["X"] = -186
  83.   LIST["Y"] = 0
  84.   LIST["높이"] = Graphics.height - LIST["Y"]
  85.   LIST["라인"] = 4
  86.   LIST["효과음"] = "Attack3"
  87.   LIST["반전"] = true
  88.   LIST["바탕화면"] = nil
  89.   LIST["왼쪽"] = 190
  90.   LIST["오른쪽"] = 534
  91.   LIST["투명도"] = 250
  92.   LIST["이름윈도우X1"] = 10
  93.   LIST["이름윈도우X2"] = 210
  94.   LIST["이름윈도우Y"] = 36
  95.   LIST["텍스트시작X"] = LIST["왼쪽"] + 12
  96.   LIST["텍스트속도-최소"] = 0
  97.   LIST["텍스트속도-최대"] = 8
  98.   LIST["화면영역내표시"] = true
  99.  
  100.   # 정규 표현식
  101.   CODE["16진수"] = /#([a-zA-Z^\d]*)/i
  102.   CODE["색상추출"] = /^\p{hangul}+|c_[a-zA-z]+$/
  103.   CODE["명령어"] = /^[\$\.\|\^!><\{\}\\]|^[A-Z]|^[-]+[!]*/i
  104.   CODE["이름색상코드"] = /\[(\p{hangul}+[\d]*|c_[\p{Latin}]+)\]/
  105.   CODE["웹색상"] = /([\p{Latin}\d]+)!/
  106.   CODE["추출"] = /^(\p{hangul}+)/
  107.   CODE["큰페이스칩"] = /^큰\_+/
  108.   CODE["효과음"] = /^\[(.+?)\]/i
  109.   CODE["처리!"] = /^(\p{hangul}+)!/
  110.   CODE["이름"] = /\e이름\<(.+?)\>/
  111.   CODE["말풍선"] = /\e말풍선\[(\d+|-\d+)\]/i
  112.   CODE["이름추출"] = /\[(.*)\]/
  113.   CODE["이름색상변경1"] = /\eC\[(.+)\]/
  114.   CODE["이름색상변경2"] = /\e색\[(.+)\]/
  115.  
  116.   extend self
  117.   #--------------------------------------------------------------------------
  118.   # 색상을 불러옵니다(토큰 추출)
  119.   #--------------------------------------------------------------------------
  120.   def import_color(string)
  121.     begin
  122.       data = INI.read_string("색상목록",string,'색상테이블.ini')
  123.       parser = RubyVM::InstructionSequence.compile(data)
  124.       token = parser.to_a[13][2][0]
  125.       case token
  126.       when :duparray then return Color.new(*parser.eval())
  127.       else
  128.         return Color.new(255,255,255,255)
  129.       end
  130.     rescue
  131.       Color.new(255,255,255,255)
  132.     end
  133.   end
  134.  
  135. end
  136.  
  137. #==============================================================================
  138. # ** RS::BALLOON
  139. #------------------------------------------------------------------------------
  140. # 말풍선 대화창을 위한 상수들이 정의되어있습니다
  141. #==============================================================================
  142. module RS::BALLOON
  143.  
  144.   # 폰트 사이즈(폰트 사이즈를 바꾸는 상수가 아니라 기본 폭과 높이에 영향을 주는 상수입니다)
  145.   FONT_SIZE = 24
  146.  
  147.   # 간격
  148.   STD_PADDING = 24
  149.  
  150.   # 최소 폭
  151.   WIDTH = (FONT_SIZE * 6) + STD_PADDING
  152.  
  153.   # 최소 높이
  154.   HEIGHT = FONT_SIZE + (STD_PADDING / 2)
  155.  
  156.   #--------------------------------------------------------------------------
  157.   # * 말풍선 스프라이트가 있는가?
  158.   #--------------------------------------------------------------------------
  159.   def balloon_sprite?
  160.     return false
  161.   end
  162. end
  163.  
  164. #==============================================================================
  165. # ** RS::BNSprite
  166. #------------------------------------------------------------------------------
  167. # 말풍선 스프라이트 생성을 위한 메소드들이 정의되어있습니다
  168. #==============================================================================
  169. module RS::BNSprite
  170.   #--------------------------------------------------------------------------
  171.   # * 말풍선 스프라이트 생성
  172.   #--------------------------------------------------------------------------
  173.   def create_balloon_sprite
  174.     @b_cursor = Sprite.new
  175.     @b_cursor.visible = false
  176.     @b_cursor.bitmap = Cache.system("Window")
  177.     @b_cursor.src_rect.set(96, 80, 16, 16)
  178.     @b_cursor.z = 290
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # * 말풍선 스프라이트 해방
  182.   #--------------------------------------------------------------------------
  183.   def update_balloon_sprite
  184.     if @b_cursor and @b_cursor.bitmap
  185.       dx = 16 * ((Time.now.to_i % 2) + 1)
  186.       @b_cursor.src_rect.set(96 + dx, 80,16, 16)
  187.     end
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   # * 말풍선 스프라이트 해방
  191.   #--------------------------------------------------------------------------
  192.   def dispose_balloon_sprite
  193.     if @b_cursor
  194.       @b_cursor.bitmap.dispose
  195.       @b_cursor.dispose
  196.     end
  197.   end
  198. end
  199.  
  200. #==============================================================================
  201. # ** RS::LoadFace
  202. #------------------------------------------------------------------------------
  203. # 큰 페이스칩 설정을 위한 메소드들이 정의되어있습니다
  204. #==============================================================================
  205. module RS::LoadFace
  206.   #--------------------------------------------------------------------------
  207.   # * 비트맵 생성
  208.   #--------------------------------------------------------------------------
  209.   def create_face_bitmap
  210.     @face_sprite = Sprite.new
  211.     @face_bitmap = Bitmap.new(544, 416)
  212.   end
  213.   #--------------------------------------------------------------------------
  214.   # * 스프라이트 생성
  215.   #--------------------------------------------------------------------------
  216.   def create_face_sprite(align=false)
  217.     @face_sprite.visible = true
  218.     @face_sprite.bitmap = @face_bitmap
  219.     @face_sprite.opacity = 255
  220.     @face_sprite.x = RS::LIST["X"] + RS::LIST[align ? "오른쪽" : "왼쪽"]
  221.     @face_sprite.mirror = RS::LIST["반전"] ? align : false
  222.     @face_sprite.y = RS::LIST["높이"] - @face_bitmap.height
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # * 스프라이트 설정
  226.   #--------------------------------------------------------------------------
  227.   def set_sprite(align)
  228.     @face_sprite.visible = true
  229.     @face_sprite.bitmap = @face_bitmap
  230.     @face_sprite.x = RS::LIST["X"] + RS::LIST[align ? "오른쪽" : "왼쪽"]
  231.     @face_sprite.mirror = RS::LIST["반전"] ? align : false
  232.     @face_sprite.y = RS::LIST["높이"] - @face_bitmap.height
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # * 페이스칩 인덱스 체크
  236.   #--------------------------------------------------------------------------
  237.   def bigface_right_alignment?
  238.     $game_message.face_index != 0
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # * 큰 페이스칩 체크
  242.   #--------------------------------------------------------------------------
  243.   def bigface_valid?
  244.     return false if $game_message.face_name == ""
  245.     return true if $game_message.face_name[RS::CODE["큰페이스칩"]] == "큰_"
  246.     return false
  247.   end
  248.   #--------------------------------------------------------------------------
  249.   # * 일반 페이스칩 체크
  250.   #--------------------------------------------------------------------------
  251.   def normal_face?
  252.     return true if bigface_valid? == false && $game_message.face_name.size > 0
  253.     return false
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * 비트맵 제거
  257.   #--------------------------------------------------------------------------
  258.   def iface_clear
  259.     @face_bitmap = nil
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   # * 비트맵 업데이트
  263.   #--------------------------------------------------------------------------
  264.   def face_update
  265.     @face_sprite.visible = if $game_message.visible
  266.     @face_sprite.update; true else; false end
  267.   end
  268. end
  269.  
  270. #==============================================================================
  271. # ** RS::Face
  272. #------------------------------------------------------------------------------
  273. # 큰 페이스칩과 관련된 클래스입니다.
  274. #==============================================================================
  275. class RS::Face
  276.   include RS::LoadFace
  277.   #--------------------------------------------------------------------------
  278.   # * 초기화
  279.   #--------------------------------------------------------------------------
  280.   def initialize(message_window)
  281.     create_face_bitmap
  282.     create_face_sprite
  283.     init_params
  284.     @face_sprite.z = message_window.z - 1
  285.   end
  286.   #--------------------------------------------------------------------------
  287.   # * 인스턴스 초기화
  288.   #--------------------------------------------------------------------------
  289.   def init_params
  290.     @face_set_x = 0
  291.     @face_index = 0
  292.     @face_name = ""
  293.   end
  294.   #--------------------------------------------------------------------------
  295.   # * 이름 초기화
  296.   #--------------------------------------------------------------------------
  297.   def reset_face_name
  298.     @face_name = ""
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # * 투명도 초기화
  302.   #--------------------------------------------------------------------------
  303.   def reset_opacity
  304.     @face_sprite.opacity = 0
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # * 인덱스가 유효한가?
  308.   #--------------------------------------------------------------------------
  309.   def face_index_invalid?
  310.     @face_index != $game_message.face_index
  311.   end
  312.   #--------------------------------------------------------------------------
  313.   # * 이름이 유효한가?
  314.   #--------------------------------------------------------------------------
  315.   def face_name_invalid?
  316.     @face_name != $game_message.face_name
  317.   end
  318.   #--------------------------------------------------------------------------
  319.   # * 다시 그려야 하는가?
  320.   #--------------------------------------------------------------------------
  321.   def check_redraw?
  322.     face_index_invalid? || face_name_invalid?
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # * 해방
  326.   #--------------------------------------------------------------------------
  327.   def dispose
  328.     @face_bitmap.dispose
  329.     @face_sprite.dispose
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # * 큰 페이스칩 그리기
  333.   #--------------------------------------------------------------------------
  334.   def draw_bigface(align)
  335.     set_sprite(align)
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # * 투명도 조절
  339.   #--------------------------------------------------------------------------
  340.   def opacity=(n)
  341.     @face_sprite.opacity = n
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # * 큰 페이스칩 다시 그리기
  345.   #--------------------------------------------------------------------------
  346.   def redraw_bigface
  347.     @face_bitmap = Cache.face($game_message.face_name)
  348.     @face_index = $game_message.face_index
  349.     @face_name = $game_message.face_name
  350.     draw_bigface(align)
  351.   end
  352.   #--------------------------------------------------------------------------
  353.   # * 정렬 위치
  354.   #--------------------------------------------------------------------------
  355.   def align
  356.     bigface_right_alignment?
  357.   end
  358.   #--------------------------------------------------------------------------
  359.   # * Set Visible
  360.   #--------------------------------------------------------------------------
  361.   def visible=(toggle)
  362.     @face_sprite.visible = toggle
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # * 오른쪽 정렬인가?
  366.   #--------------------------------------------------------------------------
  367.   def right_alignment_check?
  368.     @face_sprite.visible && align == false && $game_message.balloon == -2
  369.   end
  370.   #--------------------------------------------------------------------------
  371.   # * 큰 페이스칩이 설정된 상태인가?
  372.   #--------------------------------------------------------------------------
  373.   def visible?
  374.     @face_Sprite.visible == true
  375.   end
  376. end
  377.  
  378. #==============================================================================
  379. # ** RS::Color
  380. #------------------------------------------------------------------------------
  381. # 색상테이블 파일을 만듭니다
  382. #==============================================================================
  383. module RS::Color
  384.   #--------------------------------------------------------------------------
  385.   # * 색상을 초기화합니다
  386.   #--------------------------------------------------------------------------
  387.   def init_color_table
  388.     # 기본 색상을 추가합니다
  389.     color_table = {}
  390.     color_range = (0..31)
  391.     color_range.each_with_index do |color,index|
  392.       color_table["기본색#{index}"] = text_color(color).to_a
  393.     end
  394.     # 추가로 정의된 색상을 추가합니다
  395.     extend_color {|k,v| color_table[k] = v }
  396.     # INI 파일을 생성합니다
  397.     color_table.to_ini("색상테이블.ini","색상목록")
  398.   end
  399.   #--------------------------------------------------------------------------
  400.   # * 색상을 추가합니다
  401.   #--------------------------------------------------------------------------
  402.   def extend_color
  403.     yield "하늘색",[153, 217, 234, 255]
  404.     yield "연보라색",[200,191,231,255]
  405.   end
  406. end
  407.  
  408. #==============================================================================
  409. # ** Unicode
  410. #==============================================================================
  411. module Unicode
  412.   MultiByteToWideChar = Win32API.new('Kernel32','MultiByteToWideChar','llpipi','i')
  413.   WideCharToMultiByte = Win32API.new('Kernel32','WideCharToMultiByte','llpipipp','i')
  414.   # 코드 페이지
  415.   UTF_8 = 65001
  416.   #--------------------------------------------------------------------------
  417.   # * MBCS(멀티바이트) -> WBCS(유니코드)
  418.   #--------------------------------------------------------------------------
  419.   def unicode!
  420.     buf = "\0" * (self.size * 2 + 1)
  421.     MultiByteToWideChar.call(UTF_8, 0, self, -1, buf, buf.size)
  422.     buf
  423.   end
  424.   #--------------------------------------------------------------------------
  425.   # * WBCS(유니코드) -> MBCS(멀티바이트)
  426.   #--------------------------------------------------------------------------
  427.   def unicode_s
  428.     buf = "\0" * (self.size * 2 + 1)
  429.     WideCharToMultiByte.call(UTF_8, 0, self, -1, buf, buf.size, nil, nil)
  430.     buf.delete("\0")
  431.   end
  432. end
  433.  
  434. #==============================================================================
  435. # ** String 확장
  436. #==============================================================================
  437. class String
  438.   include Unicode
  439. end
  440.  
  441. #==============================================================================
  442. # ** INI
  443. #------------------------------------------------------------------------------
  444. # INI 파일을 만들거나 읽을 수 있는 모듈입니다
  445. #==============================================================================
  446. module INI
  447.   WritePrivateProfileStringW = Win32API.new('Kernel32','WritePrivateProfileStringW','pppp','s')
  448.   GetPrivateProfileStringW = Win32API.new('Kernel32','GetPrivateProfileStringW','ppppip','s')
  449.   extend self
  450.   #--------------------------------------------------------------------------
  451.   # * INI 파일의 내용을 작성합니다
  452.   #--------------------------------------------------------------------------
  453.   def write_string(app,key,str,file_name)
  454.     path = ".\\" + file_name
  455.     (param = [app,key.to_s,str.to_s,path]).collect! {|i| i.unicode!}
  456.     success = WritePrivateProfileStringW.call(*param)
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # * INI 파일의 내용을 읽어옵니다
  460.   #--------------------------------------------------------------------------
  461.   def read_string(app_name,key_name,file_name)
  462.     buf = "\0" * 256
  463.     path = ".\\" + file_name
  464.     (param = [app_name,key_name,path]).collect! {|x| x.unicode!}
  465.     GetPrivateProfileStringW.call(*param[0..1],0,buf,256,param[2])
  466.     buf.unicode_s.unpack('U*').pack('U*')
  467.   end
  468. end
  469.  
  470. #==============================================================================
  471. # ** Hash
  472. #------------------------------------------------------------------------------
  473. # Hash의 원소(Key, Value)를 바탕으로 INI 파일을 만듭니다
  474. #==============================================================================
  475. class Hash
  476.   def to_ini(file_name="Default.ini",app_name="Default")
  477.     self.each { |k, v| INI.write_string(app_name,k.to_s.dup,v.to_s.dup,file_name) }
  478.   end
  479. end
  480.  
  481. #==============================================================================
  482. # ** RGB
  483. #==============================================================================
  484. module RGB
  485.   extend self
  486.   #--------------------------------------------------------------------------
  487.   # * 색상 코드 처리(정수형)
  488.   #--------------------------------------------------------------------------
  489.   def int_to_rgb(rgb)
  490.     [rgb, rgb>>8, rgb>>16].map {|i| i & 0xFF }
  491.   end
  492.   #--------------------------------------------------------------------------
  493.   # * 색상 코드 처리(16진수)
  494.   #--------------------------------------------------------------------------
  495.   def hex_to_rgb(hex)
  496.     return unless hex.is_a?(String)
  497.     hex = hex.delete('#').to_i(16)
  498.     return int_to_rgb(hex).reverse
  499.   end
  500. end
  501.  
  502. #==============================================================================
  503. # ** Colour
  504. #==============================================================================
  505. module Colour
  506.   include RGB
  507.   # 색상을 추출합니다
  508.   GET_COLOR = ->(cint){color = Color.new(*int_to_rgb(cint),get_alpha); color}
  509.   extend self
  510.  
  511.   @@c_alpha = 255
  512.   @@c_base = Color.new(255,255,255,255)
  513.   #--------------------------------------------------------------------------
  514.   # * 색상 코드 처리
  515.   #--------------------------------------------------------------------------
  516.   def gm_color(string)
  517.     case string
  518.     when "청록",'청록색','c_aqua' then GET_COLOR.(16776960)
  519.     when "검은색","검정",'c_black' then GET_COLOR.(0)
  520.     when "파란색","파랑",'c_blue' then GET_COLOR.(16711680)
  521.     when "짙은회색",'c_dkgray' then GET_COLOR.(4210752)
  522.     when "자홍색","자홍",'c_fuchsia' then GET_COLOR.(16711935)
  523.     when "회색",'c_gray' then GET_COLOR.(8421504)
  524.     when "녹색",'c_green' then GET_COLOR.(32768)
  525.     when "밝은녹색","라임",'c_lime' then GET_COLOR.(65280)
  526.     when "밝은회색",'c_ltgray' then GET_COLOR.(12632256)
  527.     when "밤색","마룬",'c_maroon' then GET_COLOR.(128)
  528.     when "감청색","네이비",'c_navy'  then GET_COLOR.(8388608)
  529.     when "황록색","올리브",'c_olive' then GET_COLOR.(32896)
  530.     when "주황색","주황","오렌지",'c_orange' then GET_COLOR.(4235519)
  531.     when "보라색","보라",'c_purple' then GET_COLOR.(8388736)
  532.     when "빨간색","빨강",'c_red' then GET_COLOR.(255)
  533.     when "은색","은",'c_silver' then GET_COLOR.(12632256)
  534.     when "민트색",'c_teal'   then GET_COLOR.(8421376)
  535.     when "흰색","흰",'c_white'  then GET_COLOR.(16777215)
  536.     when "노란색","노랑",'c_yellow' then GET_COLOR.(65535)
  537.     when "기본","기본색",'c_normal' then get_base_color
  538.     else
  539.       RS.import_color(string)
  540.     end
  541.   end
  542.   #--------------------------------------------------------------------------
  543.   # * 투명도 조절
  544.   #--------------------------------------------------------------------------
  545.   def draw_set_alpha(value)
  546.     @@c_alpha = if value.between?(0,255)
  547.       value
  548.     else
  549.       255
  550.     end
  551.   end
  552.   #--------------------------------------------------------------------------
  553.   # * 기본색 획득
  554.   #--------------------------------------------------------------------------
  555.   def get_base_color
  556.     @@c_base
  557.   end
  558.   #--------------------------------------------------------------------------
  559.   # * 기본색 설정
  560.   #--------------------------------------------------------------------------
  561.   def set_base_color=(color)
  562.     @@c_base = color
  563.   end
  564.   #--------------------------------------------------------------------------
  565.   # * 투명색 획득
  566.   #--------------------------------------------------------------------------
  567.   def get_alpha
  568.     @@c_alpha
  569.   end
  570. end
  571.  
  572. #==============================================================================
  573. # ** Color
  574. #==============================================================================
  575. class Color
  576.   extend Colour
  577.   #--------------------------------------------------------------------------
  578.   # * 정수로 변환
  579.   #--------------------------------------------------------------------------
  580.   def to_int(r=red.round,g=green.round,b=blue.round)
  581.     (r) | (g << 8) | (b << 16)
  582.   end
  583.   #--------------------------------------------------------------------------
  584.   # * 16진수로 웹 색상 코드로 변환
  585.   #--------------------------------------------------------------------------
  586.   def to_hex(r=red.round,g=green.round,b=blue.round)
  587.     "#" + ([r,g,b].collect {|i| sprintf("%#02x", i)}.join)[2..-1].upcase
  588.   end
  589.   #--------------------------------------------------------------------------
  590.   # * 배열로 변환
  591.   #--------------------------------------------------------------------------
  592.   def to_a
  593.     [red.round,green.round,blue.round,alpha.round]
  594.   end
  595. end
  596.  
  597. #==============================================================================
  598. # ** String
  599. #==============================================================================
  600. class String
  601.   #--------------------------------------------------------------------------
  602.   # * 색상 코드 처리
  603.   #--------------------------------------------------------------------------
  604.   def c
  605.     Color.gm_color(self) if (self =~ RS::CODE["색상추출"])
  606.   end
  607.   #--------------------------------------------------------------------------
  608.   # * 웹 색상 코드 처리
  609.   #--------------------------------------------------------------------------
  610.   def hex_to_color
  611.     Color.new *Color.hex_to_rgb(self),255
  612.   end
  613. end
  614.  
  615. #==============================================================================
  616. # ** Window_Base
  617. #==============================================================================
  618. class Window_Base
  619.   #--------------------------------------------------------------------------
  620.   # * 기본색 처리
  621.   #--------------------------------------------------------------------------
  622.   alias get_base_text_color_initialize initialize
  623.   def initialize(x, y, width, height)
  624.     get_base_text_color_initialize(x, y, width, height)
  625.     Color.set_base_color = text_color(0)
  626.   end
  627.   #--------------------------------------------------------------------------
  628.   # * 문자 처리
  629.   #--------------------------------------------------------------------------
  630.   def obtain_escape_code(text)
  631.     text.slice!(RS::CODE["명령어"])
  632.   end
  633.   #--------------------------------------------------------------------------
  634.   # * 색상 코드 처리
  635.   #--------------------------------------------------------------------------
  636.   def obtain_name_color(text)
  637.     text.slice!(RS::CODE["이름색상코드"])[$1]
  638.   end
  639.   #--------------------------------------------------------------------------
  640.   # * 웹 색상 코드 처리
  641.   #--------------------------------------------------------------------------
  642.   def to_hex(text)
  643.     text.slice!(RS::CODE["웹색상"])[$1] rescue "#FFFFFF"
  644.   end
  645.   #--------------------------------------------------------------------------
  646.   # * 명령 문자 처리
  647.   #--------------------------------------------------------------------------
  648.   alias color_process_escape_character process_escape_character
  649.   def process_escape_character(code, text, pos)
  650.     case code.upcase
  651.     when '색'
  652.       color = Color.gm_color(obtain_name_color(text))
  653.       change_color(color)
  654.     when '#'
  655.       color = "##{to_hex(text)}".hex_to_color
  656.       change_color(color)
  657.     else
  658.       color_process_escape_character(code, text, pos)
  659.     end
  660.   end
  661.   #--------------------------------------------------------------------------
  662.   # * 기본 폰트 설정
  663.   #--------------------------------------------------------------------------
  664.   def reset_font_settings
  665.     change_color(normal_color)
  666.     contents.font.size = RS::LIST["폰트크기"]
  667.     contents.font.bold = Font.default_bold
  668.     contents.font.italic = Font.default_italic
  669.     contents.font.outline = Font.default_outline
  670.     contents.font.out_color = Font.default_out_color
  671.   end
  672.   #--------------------------------------------------------------------------
  673.   # * 테두리 색상 처리
  674.   #--------------------------------------------------------------------------
  675.   def change_out_color(color, enabled = true)
  676.     contents.font.out_color.set(color)
  677.     contents.font.out_color.alpha = translucent_alpha unless enabled
  678.   end
  679.   #--------------------------------------------------------------------------
  680.   # * 아이템 이름
  681.   #--------------------------------------------------------------------------
  682.   def draw_item_name(item, x, y, enabled = true, width = 172)
  683.     return unless item
  684.     draw_icon(item.icon_index, x, y, enabled)
  685.     change_color(normal_color, enabled)
  686.     draw_text_ex(x + 24, y, item.name)
  687.   end
  688. end
  689.  
  690. #==============================================================================
  691. # ** Window_Message
  692. #------------------------------------------------------------------------------
  693. # 메시지 시스템이 구현되어있는 클래스입니다
  694. #==============================================================================
  695. class Window_Message
  696.   include RS::BNSprite
  697.   include RS::Color
  698.   include RS::BALLOON
  699.   #--------------------------------------------------------------------------
  700.   # * 재정의
  701.   #--------------------------------------------------------------------------
  702.   alias load_face_initialize initialize
  703.   alias load_face_update update
  704.   alias load_face_dispose dispose
  705.   #--------------------------------------------------------------------------
  706.   # * 초기화
  707.   #--------------------------------------------------------------------------
  708.   def initialize
  709.     load_face_initialize
  710.     init_color_table
  711.     @util = RS::Face.new(self)
  712.     create_balloon_sprite
  713.     set_font(RS::LIST["폰트명"],RS::LIST["폰트크기"])
  714.   end
  715.   #--------------------------------------------------------------------------
  716.   # * 폰트 설정
  717.   #--------------------------------------------------------------------------
  718.   def set_font(name, size = Font.default_size )
  719.     self.contents.font.name = name
  720.     self.contents.font.size = size
  721.   end
  722.   #--------------------------------------------------------------------------
  723.   # * 인스턴스 초기화
  724.   #--------------------------------------------------------------------------
  725.   alias load_face_clear_instance_variables clear_instance_variables
  726.   def clear_instance_variables
  727.     load_face_clear_instance_variables
  728.     @util.reset_face_name if @util
  729.   end
  730.   #--------------------------------------------------------------------------
  731.   # * 피버 메인
  732.   #--------------------------------------------------------------------------
  733.   def fiber_main
  734.     $game_message.visible = true
  735.     update_background
  736.     update_balloon_position
  737.     @util.face_update
  738.     loop do
  739.       process_all_text if $game_message.has_text?
  740.       process_input
  741.       $game_message.clear
  742.       @name_window.close
  743.       @gold_window.close
  744.       Fiber.yield
  745.       break unless text_continue?
  746.     end
  747.     close_and_wait
  748.     $game_message.visible = false
  749.     @util.reset_opacity
  750.     @util.face_update
  751.     resize_message_system
  752.     @util.reset_face_name
  753.     @fiber = nil
  754.   end
  755.   #--------------------------------------------------------------------------
  756.   # * 업데이트
  757.   #--------------------------------------------------------------------------
  758.   def update
  759.     load_face_update
  760.     update_balloon_sprite
  761.     @util.face_update if @fiber
  762.   end
  763.   #--------------------------------------------------------------------------
  764.   # * 해방
  765.   #--------------------------------------------------------------------------
  766.   def dispose
  767.     load_face_dispose
  768.     @util.dispose
  769.     dispose_balloon_sprite
  770.   end
  771.   #--------------------------------------------------------------------------
  772.   # * 새로운 페이지
  773.   #--------------------------------------------------------------------------
  774.   def new_page(text, pos)
  775.     contents.clear
  776.     @util.bigface_valid? ? draw_bigface_entity(text,pos) : draw_normalface_entity(text,pos)
  777.   end
  778.   #--------------------------------------------------------------------------
  779.   # * 큰 페이스칩 그리기
  780.   #--------------------------------------------------------------------------
  781.   def draw_bigface_entity(text,pos)
  782.     @util.create_face_sprite( @util.align )
  783.     if @util.check_redraw?
  784.       @util.redraw_bigface
  785.     else
  786.       @util.visible = true
  787.     end
  788.     normal_set_page(pos,@util.align ? 0 : RS::LIST["텍스트시작X"],text)
  789.   end
  790.   #--------------------------------------------------------------------------
  791.   # * 일반 페이스칩 그리기
  792.   #--------------------------------------------------------------------------
  793.   def draw_normalface_entity(text,pos)
  794.     @util.opacity = 0 if @util.check_redraw?
  795.     draw_face($game_message.face_name,$game_message.face_index, 0, 0)
  796.     normal_set_page(pos,new_line_x,text)
  797.   end
  798.   #--------------------------------------------------------------------------
  799.   # * 새로운 페이지
  800.   #--------------------------------------------------------------------------
  801.   def normal_set_page(pos,*args)
  802.     reset_font_settings
  803.     pos[:x] = args[0]
  804.     pos[:y] = 0
  805.     pos[:new_x] = args[0]
  806.     pos[:height] = calc_line_height(args[1])
  807.     clear_flags
  808.   end
  809.   #--------------------------------------------------------------------------
  810.   # * 효과음 추출
  811.   #--------------------------------------------------------------------------
  812.   def obtain_escape_sound(text)
  813.     text.slice!(RS::CODE["효과음"])[$1] rescue RS::LIST["효과음"]
  814.   end
  815.   #--------------------------------------------------------------------------
  816.   # * Preconvert Control Characters
  817.   #    As a rule, replace only what will be changed into text strings before
  818.   #    starting actual drawing. The character "\" is replaced with the escape
  819.   #    character (\e).
  820.   #--------------------------------------------------------------------------
  821.   def convert_escape_characters(text)
  822.     result = text.to_s.clone
  823.     result.gsub!(/\\/)            { "\e" }
  824.     result.gsub!(/\e\e/)          { "\\" }
  825.     result.gsub!(/(?:\eV|\e변수)\[(\d+)\]/i) { $game_variables[$1.to_i] }
  826.     result.gsub!(/(?:\eV|\e변수)\[(\d+)\]/i) { $game_variables[$1.to_i] }
  827.     result.gsub!(/(?:\eN|\e주인공)\[(\d+)\]/i) { actor_name($1.to_i) }
  828.     result.gsub!(/(?:\eP|\e파티원)\[(\d+)\]/i) { party_member_name($1.to_i) }
  829.     result.gsub!(/(?:\eG|\e골드)/i)          { Vocab::currency_unit }
  830.     result
  831.   end
  832.   #--------------------------------------------------------------------------
  833.   # * 명령어 처리 (대화가 시작된 후에 처리됩니다)
  834.   #--------------------------------------------------------------------------
  835.   alias msg_speed_process_escape_character process_escape_character
  836.   def process_escape_character(code, text, pos)
  837.       case code
  838.       when '속도!'
  839.         set_text_speed(obtain_escape_param(text).to_i)
  840.       when '크기!'
  841.         t = obtain_escape_param(text).to_i
  842.         contents.font.size = t
  843.         pos[:height] = [t,pos[:height]].max
  844.       when '굵게!'
  845.         contents.font.bold = !contents.font.bold
  846.       when '이탤릭!'
  847.         contents.font.italic = !contents.font.italic
  848.       when '테두리!'
  849.         contents.font.outline = !contents.font.outline
  850.       when '테두리색!'
  851.         color = Color.gm_color(obtain_name_color(text))
  852.         change_out_color(color)
  853.       when '그림!'
  854.         process_draw_picture(obtain_escape_sound(text).to_s,pos)
  855.       when '효과음!'
  856.         $game_map.se_play = obtain_escape_sound(text).to_s
  857.       when '자동개행!'
  858.         $game_message.word_wrap_enabled = true
  859.       else
  860.         msg_speed_process_escape_character(code, text, pos)
  861.       end
  862.   end
  863.   #--------------------------------------------------------------------------
  864.   # * 그림의 처리
  865.   #--------------------------------------------------------------------------
  866.   def process_draw_picture(picture_name, pos)
  867.     draw_picture(pos ,picture_name)
  868.     wait_for_one_character
  869.   end
  870.   #--------------------------------------------------------------------------
  871.   # * 그림 그리기
  872.   #--------------------------------------------------------------------------
  873.   def draw_picture(pos, picture_name, enabled = true)
  874.     bitmap = Cache.picture(picture_name)
  875.     rect = Rect.new(0, 0, bitmap.width, bitmap.height)
  876.  
  877.     pic_opacity = enabled ? 255 : translucent_alpha
  878.  
  879.     # 원본 복제
  880.     contents_temp = Bitmap.new(contents_width,contents_height + bitmap.height)
  881.     temp_rect = Rect.new(0,0,self.width,self.height + bitmap.height)
  882.     contents_temp.blt(0,0,contents,temp_rect,pic_opacity)
  883.  
  884.     # 콘텐츠 높이 계산
  885.     if rect.height <= (self.height - STD_PADDING)
  886.       self.height += rect.height
  887.     else
  888.       value = rect.height - (self.height - STD_PADDING)
  889.       self.height += value + line_height if value > 0
  890.     end
  891.  
  892.     # 새로운 비트맵
  893.     self.contents = contents_temp
  894.  
  895.     # 위치 업데이트
  896.     update_placement
  897.  
  898.     # 묘화
  899.     contents.blt(pos[:x],pos[:y] , bitmap, rect,pic_opacity)
  900.     pos[:x] += bitmap.width
  901.     pos[:y] += bitmap.height
  902.   end
  903.   #--------------------------------------------------------------------------
  904.   # * 새로운 페이지가 필요한 지 여부를 결정합니다
  905.   #--------------------------------------------------------------------------
  906.   def need_new_page?(text, pos)
  907.     pos[:y] + pos[:height] > (self.height - STD_PADDING) && !text.empty?
  908.   end
  909.   #--------------------------------------------------------------------------
  910.   # * 텍스트 속도 조절
  911.   #--------------------------------------------------------------------------
  912.   def set_text_speed(text_speed)
  913.     $game_message.message_speed = case text_speed
  914.     when (RS::LIST["텍스트속도-최소"]..RS::LIST["텍스트속도-최대"])
  915.       text_speed
  916.     else
  917.       RS::LIST["텍스트속도-최소"]
  918.     end
  919.   end
  920.   #--------------------------------------------------------------------------
  921.   # * 명렁어 처리(대화가 시작되기 전에 처리됩니다)
  922.   #--------------------------------------------------------------------------
  923.   alias rs_extend_msg_convert_escape_characters convert_escape_characters
  924.   def convert_escape_characters(text)
  925.     f = rs_extend_msg_convert_escape_characters(text)
  926.     f.gsub!(RS::CODE["이름"]) { name_window_open($1.to_s); "" }
  927.     f.gsub!(RS::CODE["말풍선"]) { $game_message.balloon = $1.to_i; "" }
  928.     f
  929.   end
  930.   #--------------------------------------------------------------------------
  931.   # * 문자 출력 속도
  932.   #--------------------------------------------------------------------------
  933.   def wait_for_one_character
  934.     update_show_fast
  935.     wait($game_message.message_speed) unless @show_fast || @line_show_fast
  936.   end
  937.   #--------------------------------------------------------------------------
  938.   # * 이름 뽑아내기
  939.   #--------------------------------------------------------------------------
  940.   def obtain_name_text(text)
  941.     text.slice!(RS::CODE["이름추출"])[$1]
  942.   end
  943.   #--------------------------------------------------------------------------
  944.   # * 이름 윈도우 띄우기
  945.   #--------------------------------------------------------------------------
  946.   def name_window_open(text)
  947.     @name_window.draw_name(text)
  948.   end
  949.   #--------------------------------------------------------------------------
  950.   # * 이름 윈도우 생성
  951.   #--------------------------------------------------------------------------
  952.   alias namewindow_create_all_windows create_all_windows
  953.   def create_all_windows
  954.     namewindow_create_all_windows
  955.     @name_window = RS::Window_Name.new
  956.     @name_window.x = self.x + RS::LIST["이름윈도우X1"]
  957.     @name_window.y = self.y - RS::LIST["이름윈도우Y"]
  958.     @name_window.openness = 0
  959.   end
  960.   #--------------------------------------------------------------------------
  961.   # * 윈도우 업데이트
  962.   #--------------------------------------------------------------------------
  963.   alias namewindow_update_all_windows update_all_windows
  964.   def update_all_windows
  965.     update_name_windows
  966.     namewindow_update_all_windows
  967.   end
  968.   #--------------------------------------------------------------------------
  969.   # * 이름 윈도우의 X좌표
  970.   #--------------------------------------------------------------------------
  971.   def namewindow_get_x
  972.     if @util.normal_face?
  973.       return self.x + 112 + RS::LIST["이름윈도우X1"]
  974.     else
  975.       if @util.bigface_valid?
  976.         if @util.bigface_right_alignment?
  977.           return self.x + RS::LIST["이름윈도우X1"]
  978.         else
  979.           return self.x + RS::LIST["이름윈도우X2"]
  980.         end
  981.       end
  982.     end
  983.     return self.x + RS::LIST["이름윈도우X1"]
  984.   end
  985.   #--------------------------------------------------------------------------
  986.   # * 이름 윈도우 업데이트
  987.   #--------------------------------------------------------------------------
  988.   def update_name_windows
  989.     @name_window.x = namewindow_get_x
  990.     @name_window.y = self.y - RS::LIST["이름윈도우Y"]
  991.     @name_window.update
  992.   end
  993.   #--------------------------------------------------------------------------
  994.   # * 이름 윈도우 제거
  995.   #--------------------------------------------------------------------------
  996.   alias namewindow_dispose_all_windows dispose_all_windows
  997.   def dispose_all_windows
  998.     @name_window.dispose
  999.     namewindow_dispose_all_windows
  1000.   end
  1001.   #--------------------------------------------------------------------------
  1002.   # * 이름 윈도우의 Y값 조절
  1003.   #--------------------------------------------------------------------------
  1004.   alias namewindow_update_placement update_placement
  1005.   def update_placement
  1006.     update_name_windows
  1007.     if @name_window.open?
  1008.       @position = $game_message.position
  1009.       case @position
  1010.       when 0 then self.y = 25
  1011.       else; self.y = @position * (Graphics.height - height) / 2
  1012.       end
  1013.       @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height
  1014.     else
  1015.       self.ox = $game_message.ox
  1016.       namewindow_update_placement
  1017.     end
  1018.   end
  1019. end
  1020.  
  1021. #==============================================================================
  1022. # ** RS::Window_Name
  1023. #------------------------------------------------------------------------------
  1024. # 이름 윈도우가 구현되어있는 클래스입니다
  1025. #==============================================================================
  1026. class RS::Window_Name < Window_Base
  1027.   #--------------------------------------------------------------------------
  1028.   # * 초기화
  1029.   #--------------------------------------------------------------------------
  1030.   def initialize
  1031.     @in_pos = 0
  1032.     @text = ""
  1033.     super(0, 0, window_width, fitting_height(1))
  1034.     create_back_bitmap
  1035.     create_back_sprite
  1036.     self.z = 206
  1037.     refresh
  1038.   end
  1039.   #--------------------------------------------------------------------------
  1040.   # * 이름 윈도우의 크기
  1041.   #--------------------------------------------------------------------------
  1042.   def window_width
  1043.     return 140
  1044.   end
  1045.   #--------------------------------------------------------------------------
  1046.   # * 배경 비트맵 생성
  1047.   #--------------------------------------------------------------------------
  1048.   def create_back_bitmap
  1049.     @back_bitmap = Bitmap.new(width, height)
  1050.     back_color2 =  Color.new(12, 24, 13, 0)
  1051.     back_color1 =  Color.new(0, 13, 24, 160)
  1052.     rect1 = Rect.new(standard_padding, 0, width, 12)
  1053.     rect2 = Rect.new(standard_padding, 12, width, height - 24)
  1054.     rect3 = Rect.new(standard_padding, height - 12, width, 12)
  1055.     @back_bitmap.gradient_fill_rect(rect1, back_color2, back_color1, true)
  1056.     @back_bitmap.fill_rect(rect2, back_color1)
  1057.     @back_bitmap.gradient_fill_rect(rect3, back_color1, back_color2, true)
  1058.   end
  1059.   #--------------------------------------------------------------------------
  1060.   # * 배경 스프라이트 생성
  1061.   #--------------------------------------------------------------------------
  1062.   def create_back_sprite
  1063.     @back_sprite = Sprite.new
  1064.     @back_sprite.bitmap = @back_bitmap
  1065.     @back_sprite.visible = false
  1066.     @back_sprite.z = z + 2
  1067.   end
  1068.   #--------------------------------------------------------------------------
  1069.   # * 배경 스프라이트의 업데이트
  1070.   #--------------------------------------------------------------------------
  1071.   def update_back_sprite
  1072.     @back_sprite.visible = (@background == 1)
  1073.     @back_sprite.x = x
  1074.     @back_sprite.y = y
  1075.     @back_sprite.opacity = openness
  1076.     @back_sprite.wave_amp = 3
  1077.     @back_sprite.update
  1078.   end
  1079.   #--------------------------------------------------------------------------
  1080.   # * 배경 스프라이트의 해방
  1081.   #--------------------------------------------------------------------------
  1082.   def dispose
  1083.     super
  1084.     @back_bitmap.dispose
  1085.     @back_sprite.dispose
  1086.   end
  1087.   #--------------------------------------------------------------------------
  1088.   # * 업데이트
  1089.   #--------------------------------------------------------------------------
  1090.   def update
  1091.     super
  1092.     update_back_sprite
  1093.   end
  1094.   #--------------------------------------------------------------------------
  1095.   # * 말풍선 영역 계산
  1096.   #--------------------------------------------------------------------------
  1097.   def get_balloon_text_rect(text)
  1098.     begin
  1099.       tmp_text = text_processing(text)
  1100.       tmp_text = tmp_text.split("\n")
  1101.       tmp_text.sort! {|a,b| b.size - a.size }
  1102.       _rect = contents.text_size(tmp_text[0])
  1103.       @_width = (_rect.width) + RS::BALLOON::STD_PADDING
  1104.     rescue
  1105.       @_width = window_width
  1106.     end
  1107.   end
  1108.   #--------------------------------------------------------------------------
  1109.   # * 텍스트 매칭 (모든 명령어 제거)
  1110.   #--------------------------------------------------------------------------
  1111.   def text_processing(text)
  1112.     f = text.dup
  1113.     f.gsub!("\\") { "\e" }
  1114.     f.gsub!("\e\e") { "\\" }
  1115.     f.gsub!(/\e[\$\.\|\!\>\<\^]/) { "" }
  1116.     f.gsub!(/(?:\eV|\e변수)\[(\d+)\]/i) { $game_variables[$1.to_i] }
  1117.     f.gsub!(/(?:\eV|\e변수)\[(\d+)\]/i) { $game_variables[$1.to_i] }
  1118.     f.gsub!(/(?:\eN|\e주인공)\[(\d+)\]/i) { actor_name($1.to_i) }
  1119.     f.gsub!(/(?:\eP|\e파티원)\[(\d+)\]/i) { party_member_name($1.to_i) }
  1120.     f.gsub!(/(?:\eG|\e골드)/i)          { Vocab::currency_unit }
  1121.     f.gsub!(/(?:\eC)\[(\d+)\]/i) { "" }
  1122.     f.gsub!(/\e색\[(.+?)\]/) { "" }
  1123.     f.gsub!(/\e테두리색!\[(.+)\]/) { "" }
  1124.     f.gsub!(/\e#([\p{Latin}\d]+)!/) { "" }
  1125.     f.gsub!(RS::CODE["이름"]) { "" }
  1126.     f.gsub!(RS::CODE["말풍선"]) { "" }
  1127.     f.gsub!(/\e효과음!\[(.+?)\]/i) { "" }
  1128.     f.gsub!(/\e속도!\[\d+\]/) { "" }
  1129.     f.gsub!(/\e크기!\[\d+\]/) { "" }
  1130.     f.gsub!(/\e굵게!/) { "" }
  1131.     f.gsub!(/\e이탤릭!/) { "" }
  1132.     f.gsub!(/\e테두리!/) { "" }
  1133.     f.gsub!(/\e그림!\[(.+?)\]/) { "" }
  1134.     f
  1135.   end
  1136.   #--------------------------------------------------------------------------
  1137.   # * 명령어 처리 (대화가 시작되기 전에 처리됩니다)
  1138.   #--------------------------------------------------------------------------
  1139.   alias rs_extend_name_convert_escape_characters convert_escape_characters
  1140.   def convert_escape_characters(text)
  1141.     f = rs_extend_name_convert_escape_characters(text)
  1142.     f.gsub!(RS::CODE["이름색상변경1"]) { change_color(text_color($1.to_i)) }
  1143.     f.gsub!(RS::CODE["이름색상변경2"]) do
  1144.       color = Color.gm_color($1)
  1145.       change_color(color)
  1146.     end
  1147.     f
  1148.   end
  1149.   #--------------------------------------------------------------------------
  1150.   # * 리프레쉬
  1151.   #--------------------------------------------------------------------------
  1152.   def refresh
  1153.     contents.clear
  1154.     @background = $game_message.background
  1155.     self.opacity = @background == 0 ? RS::LIST["투명도"] : 0
  1156.     update_back_sprite
  1157.     rect = text_size(@text)
  1158.     self.arrows_visible = false
  1159.     self.width = @_width || window_width
  1160.     text = convert_escape_characters(@text)
  1161.     self.contents.font.size = RS::LIST["폰트크기"]
  1162.     draw_text(0,0,contents_width,calc_line_height(text),text.to_s,1)
  1163.   end
  1164.   #--------------------------------------------------------------------------
  1165.   # * 이름 출력
  1166.   #--------------------------------------------------------------------------
  1167.   def draw_name(text)
  1168.     @text = text
  1169.     @_width = window_width
  1170.     get_balloon_text_rect(text.dup) if $game_message.background != 1
  1171.     open
  1172.   end
  1173.   #--------------------------------------------------------------------------
  1174.   # * 기본색 처리
  1175.   #--------------------------------------------------------------------------
  1176.   def set_base_color
  1177.     change_color("기본색".c)
  1178.   end
  1179.   #--------------------------------------------------------------------------
  1180.   # * 창을 닫고 비활성화합니다
  1181.   #--------------------------------------------------------------------------
  1182.   def close
  1183.     set_base_color
  1184.     super
  1185.   end
  1186.   #--------------------------------------------------------------------------
  1187.   # * 이름 윈도우를 활성화합니다
  1188.   #--------------------------------------------------------------------------
  1189.   def open
  1190.     @back_sprite.ox = 0
  1191.     refresh
  1192.     super
  1193.   end
  1194. end
  1195.  
  1196. #==============================================================================
  1197. # ** Game_Message
  1198. #------------------------------------------------------------------------------
  1199. # 메시지 시스템에 사용되는 인스턴스 변수들이 선언되어있는 클래스입니다
  1200. #==============================================================================
  1201. class Game_Message
  1202.   attr_accessor :message_speed
  1203.   attr_accessor :line
  1204.   attr_accessor :balloon
  1205.   attr_accessor :texts
  1206.   attr_accessor :ox
  1207.   attr_accessor :word_wrap_enabled
  1208.   #--------------------------------------------------------------------------
  1209.   # * 초기화
  1210.   #--------------------------------------------------------------------------
  1211.   alias multi_line_initialize initialize
  1212.   def initialize
  1213.     multi_line_initialize
  1214.     @line = RS::LIST["라인"]
  1215.   end
  1216.   #--------------------------------------------------------------------------
  1217.   # * 클리어
  1218.   #--------------------------------------------------------------------------
  1219.   alias msg_speed_clear clear
  1220.   def clear
  1221.     msg_speed_clear
  1222.     @message_speed = 1
  1223.     @balloon = -2
  1224.     @ox = 0
  1225.     @word_wrap_enabled = false
  1226.   end
  1227. end
  1228.  
  1229. #==============================================================================
  1230. # ** Game_Map
  1231. #==============================================================================
  1232. class Game_Map
  1233.   attr_accessor :msg_owner
  1234.   attr_accessor :msg_event
  1235.   alias game_map_balloon_initialize initialize
  1236.   #--------------------------------------------------------------------------
  1237.   # * 말풍선 대화창의 소유자를 설정합니다
  1238.   #--------------------------------------------------------------------------
  1239.   def initialize
  1240.     game_map_balloon_initialize
  1241.     @msg_owner = $game_player
  1242.     @msg_event = 0
  1243.   end
  1244.   #--------------------------------------------------------------------------
  1245.   # * 효과음을 재생합니다
  1246.   #--------------------------------------------------------------------------
  1247.   def se_play=(name)
  1248.     msg_se = RPG::SE.new
  1249.     msg_se.name = name
  1250.     msg_se.play
  1251.   end
  1252. end
  1253.  
  1254. #==============================================================================
  1255. # ** Window_Message
  1256. #------------------------------------------------------------------------------
  1257. # 말풍선 시스템과 관련되어있습니다.
  1258. #==============================================================================
  1259. class Window_Message < Window_Base
  1260.   include RS::BALLOON
  1261.   #--------------------------------------------------------------------------
  1262.   # * 새로운 페이지 설정
  1263.   #--------------------------------------------------------------------------
  1264.   alias balloon_new_page new_page
  1265.   def new_page(text, pos)
  1266.     open_balloon
  1267.     balloon_new_page(text,pos)
  1268.     wait(1)
  1269.   end
  1270.   #--------------------------------------------------------------------------
  1271.   # * 말풍선 설정
  1272.   #--------------------------------------------------------------------------
  1273.   def open_balloon(sign=$game_message.balloon)
  1274.     # return nil if $game_message.face_name.size > 0
  1275.     if sign == -2
  1276.       resize_message_system
  1277.       return nil
  1278.     end
  1279.     setup_owner(sign.to_i)
  1280.     update_balloon_position
  1281.     $game_message.word_wrap_enabled = false
  1282.   end
  1283.   #--------------------------------------------------------------------------
  1284.   # * 텍스트 처리
  1285.   #--------------------------------------------------------------------------
  1286.   def process_all_text
  1287.     open_and_wait
  1288.     get_balloon_text_rect($game_message.all_text.dup)
  1289.     text = convert_escape_characters($game_message.all_text)
  1290.     pos = {}
  1291.     new_page(text, pos)
  1292.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  1293.   end
  1294.   #--------------------------------------------------------------------------
  1295.   # * 말풍선 영역 계산
  1296.   #--------------------------------------------------------------------------
  1297.   def get_balloon_text_rect(text)
  1298.     tmp_text = text_processing(text)
  1299.     tmp_text = tmp_text.split("\n")
  1300.     tmp_text.sort! {|a,b| b.size - a.size }
  1301.     _rect = contents.text_size(tmp_text[0])
  1302.     @_width = (_rect.width) + standard_padding * 2
  1303.     @_height = tmp_text.size * FONT_SIZE + standard_padding * 2
  1304.     if $game_message.face_name.size > 0
  1305.       @_width += new_line_x
  1306.       @_height = [@_height, fitting_height(4)].max
  1307.     end
  1308.   end
  1309.   #--------------------------------------------------------------------------
  1310.   # * 텍스트 매칭 (모든 명령어 제거)
  1311.   #--------------------------------------------------------------------------
  1312.   def text_processing(text)
  1313.     f = text.dup
  1314.     f.gsub!("\\") { "\e" }
  1315.     f.gsub!("\e\e") { "\\" }
  1316.     f.gsub!(/\e[\$\.\|\!\>\<\^]/) { "" }
  1317.     f.gsub!(/(?:\eV|\e변수)\[(\d+)\]/i) { $game_variables[$1.to_i] }
  1318.     f.gsub!(/(?:\eV|\e변수)\[(\d+)\]/i) { $game_variables[$1.to_i] }
  1319.     f.gsub!(/(?:\eN|\e주인공)\[(\d+)\]/i) { actor_name($1.to_i) }
  1320.     f.gsub!(/(?:\eP|\e파티원)\[(\d+)\]/i) { party_member_name($1.to_i) }
  1321.     f.gsub!(/(?:\eG|\e골드)/i)          { Vocab::currency_unit }
  1322.     f.gsub!(/(?:\eC)\[(\d+)\]/i) { "" }
  1323.     f.gsub!(/\e색\[(.+?)\]/) { "" }
  1324.     f.gsub!(/\e테두리색!\[(.+)\]/) { "" }
  1325.     f.gsub!(/\e#([\p{Latin}\d]+)!/) { "" }
  1326.     f.gsub!(RS::CODE["이름"]) { "" }
  1327.     f.gsub!(RS::CODE["말풍선"]) { "" }
  1328.     f.gsub!(/\e효과음!\[(.+?)\]/i) { "" }
  1329.     f.gsub!(/\e속도!\[\d+\]/) { "" }
  1330.     f.gsub!(/\e크기!\[\d+\]/) { "" }
  1331.     f.gsub!(/\e굵게!/) { "" }
  1332.     f.gsub!(/\e이탤릭!/) { "" }
  1333.     f.gsub!(/\e테두리!/) { "" }
  1334.     f.gsub!(/\e그림!\[(.+?)\]/) { "" }
  1335.     f
  1336.   end
  1337.   #--------------------------------------------------------------------------
  1338.   # * 메시지 윈도우의 X좌표를 구합니다
  1339.   #--------------------------------------------------------------------------
  1340.   def get_x(n)
  1341.     return n unless RS::LIST["화면영역내표시"]
  1342.     case
  1343.     when n < 0 then return 0
  1344.     when n > Graphics.width - @_width
  1345.       Graphics.width - @_width
  1346.     else
  1347.       return n
  1348.     end
  1349.   end
  1350.   #--------------------------------------------------------------------------
  1351.   # * 메시지 윈도우의 Y좌표를 구합니다
  1352.   #--------------------------------------------------------------------------
  1353.   def get_y(n)
  1354.     return n unless RS::LIST["화면영역내표시"]
  1355.     case
  1356.     when n < 0 then return 0 + @name_window.height - @name_window.x
  1357.     when n > Graphics.height - @_height + @_height
  1358.       Graphics.height - @_height
  1359.     else
  1360.       return n
  1361.     end
  1362.   end
  1363.   #--------------------------------------------------------------------------
  1364.   # * 말풍선 위치 업데이트
  1365.   #--------------------------------------------------------------------------
  1366.   def update_balloon_position
  1367.     return update_placement if $game_message.balloon == -2
  1368.  
  1369.     # 말풍선 소유자의 화면 좌표
  1370.     mx = $game_map.msg_owner.screen_x rescue 0
  1371.     my = $game_map.msg_owner.screen_y rescue 0
  1372.     tx = @_width / 2
  1373.     ty = @_height
  1374.     scale_y = 1
  1375.     tile_height = 32
  1376.     dx = mx - @_width / 2
  1377.     dy = my - @_height - tile_height
  1378.     ny = self.y - @name_window.height - RS::LIST["이름윈도우Y"]
  1379.  
  1380.     # 화면 좌측
  1381.     if (mx - @_width / 2) < 0
  1382.       dx = 0
  1383.       tx = mx
  1384.     end
  1385.  
  1386.     # 화면 우측
  1387.     if (mx - @_width / 2) > (Graphics.width - @_width)
  1388.       dx = Graphics.width - @_width
  1389.       tx = mx - dx
  1390.     end
  1391.  
  1392.     # 화면 상단
  1393.     if (my - @_height - tile_height / 2) < 0
  1394.       dy = my + tile_height / 2
  1395.       scale_y = -1
  1396.       ty = (@_height * scale_y) + @_height
  1397.       ny = (self.y + @_height) + RS::LIST["이름윈도우Y"]
  1398.     end
  1399.  
  1400.     # 화면 하단
  1401.     if (my - @_height) > Graphics.height - @_height
  1402.       dy = Graphics.width - @_height
  1403.       ty = dy - @_height
  1404.     end
  1405.  
  1406.     # 말풍선 위치 및 크기 설정
  1407.     self.x = dx
  1408.     self.y = dy
  1409.     self.width = @_width
  1410.     self.height = @_height
  1411.  
  1412.     # pause 커서의 좌표
  1413.     @b_cursor.x = dx + tx
  1414.     @b_cursor.y = dy + ty
  1415.     @b_cursor.mirror = (scale_y == -1) ? true : false
  1416.  
  1417.     # 이름 윈도우 좌표 수정
  1418.     @name_window.y = ny
  1419.  
  1420.     # 투명도 설정
  1421.     self.opacity = balloon_sprite? ? 0 : RS::LIST["투명도"]
  1422.     @balloon_pause = false
  1423.     self.arrows_visible = false
  1424.     @b_cursor.visible = true
  1425.     show
  1426.   end
  1427.   #--------------------------------------------------------------------------
  1428.   # * 소유자를 설정합니다
  1429.   #--------------------------------------------------------------------------
  1430.   def setup_owner(sign)
  1431.     $game_map.msg_owner = case sign
  1432.     when -1
  1433.       $game_player
  1434.     when 0
  1435.       $game_map.msg_event
  1436.     else
  1437.       $game_map.events[sign]
  1438.     end
  1439.   end
  1440.   #--------------------------------------------------------------------------
  1441.   # * 크기 재설정
  1442.   #--------------------------------------------------------------------------
  1443.   def resize_message_system
  1444.  
  1445.     # 대화창의 소유자 설정
  1446.     $game_map.msg_owner = $game_player
  1447.  
  1448.     @balloon_pause = true
  1449.     self.arrows_visible = true
  1450.     @b_cursor.visible = false
  1451.  
  1452.     # 대화창의 위치
  1453.     @position = $game_message.position
  1454.  
  1455.     # 대화창의 Y좌표
  1456.     y = @position * (Graphics.height - window_height) / 2
  1457.  
  1458.     # 위치 및 크기 설정
  1459.     self.move(0, y, window_width, fitting_height($game_message.line || RS::LIST["라인"]) )
  1460.  
  1461.   end
  1462.   #--------------------------------------------------------------------------
  1463.   # * Input Pause Processing (말풍선 모드)
  1464.   #--------------------------------------------------------------------------
  1465.   def input_pause
  1466.     self.pause = @balloon_pause
  1467.     wait(10)
  1468.     Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C)
  1469.     Input.update
  1470.     self.pause = false
  1471.   end
  1472.   #--------------------------------------------------------------------------
  1473.   # * 말풍선 체크
  1474.   #--------------------------------------------------------------------------
  1475.   def open_and_wait
  1476.     hide if $game_message.all_text.include?("\\말풍선")
  1477.     open
  1478.     Fiber.yield until open?
  1479.   end
  1480.   #--------------------------------------------------------------------------
  1481.   # * 배경 업데이트
  1482.   #--------------------------------------------------------------------------
  1483.   def update_background
  1484.     update_balloon_sprite
  1485.     @background = $game_message.background
  1486.     self.opacity = @background == 0 ? RS::LIST["투명도"] : 0
  1487.   end
  1488. end
  1489.  
  1490. #==============================================================================
  1491. # ** 게임 인터프리터
  1492. #==============================================================================
  1493. class Game_Interpreter
  1494.   #--------------------------------------------------------------------------
  1495.   # * 문장의 표시(오버라이딩)
  1496.   #--------------------------------------------------------------------------
  1497.   def command_101
  1498.     wait_for_message
  1499.     $game_map.msg_event = get_character(@event_id > 0? 0 : -1)
  1500.     $game_message.face_name = @params[0]
  1501.     $game_message.face_index = @params[1]
  1502.     $game_message.background = @params[2]
  1503.     $game_message.position = @params[3]
  1504.  
  1505.     # 라인 확장 여부 체크
  1506.     multi_line_flag? ? multi_line_add_message : default_add_message
  1507.  
  1508.     case next_event_code
  1509.     when 102  # Show Choices
  1510.       @index += 1
  1511.       setup_choices(@list[@index].parameters)
  1512.     when 103  # Input Number
  1513.       @index += 1
  1514.       setup_num_input(@list[@index].parameters)
  1515.     when 104  # Select Item
  1516.       @index += 1
  1517.       setup_item_choice(@list[@index].parameters)
  1518.     end
  1519.     wait_for_message
  1520.   end
  1521.   #--------------------------------------------------------------------------
  1522.   # * 기본형 메시지 추가
  1523.   #--------------------------------------------------------------------------
  1524.   def default_add_message
  1525.     while next_event_code == 401       # Text data
  1526.       @index += 1
  1527.       $game_message.add(@list[@index].parameters[0])
  1528.     end
  1529.   end
  1530.   #--------------------------------------------------------------------------
  1531.   # * 확장형 대화창 추가
  1532.   #--------------------------------------------------------------------------
  1533.   def multi_line_add_message
  1534.     init_line_height # 라인 초기화
  1535.     until @line_height >= $game_message.line # 라인 읽기
  1536.       while next_event_code == 401       # 텍스트 데이터
  1537.         @index += 1
  1538.         $game_message.add(@list[@index].parameters[0])
  1539.         add_line_height # 라인 추가
  1540.       end
  1541.         # 다음 이벤트가 대화창이 아니면 루프 탈출
  1542.         break if next_event_code != 101
  1543.     end
  1544.   end
  1545.   #--------------------------------------------------------------------------
  1546.   # * 라인 초기화
  1547.   #--------------------------------------------------------------------------
  1548.   def init_line_height
  1549.     @line_height = 0
  1550.   end
  1551.   #--------------------------------------------------------------------------
  1552.   # * 라인 확장 설정 확인
  1553.   #--------------------------------------------------------------------------
  1554.   def multi_line_flag?
  1555.     $game_message.line > 4
  1556.   end
  1557.   #--------------------------------------------------------------------------
  1558.   # * 라인 추가
  1559.   #--------------------------------------------------------------------------
  1560.   def add_line_height
  1561.     @line_height += 1
  1562.     @index += 1 if next_event_code == 101
  1563.   end
  1564. end
  1565.  
  1566. #==============================================================================
  1567. # ** Window_ChoiceList (선택지 Z좌표)
  1568. #==============================================================================
  1569. class Window_ChoiceList < Window_Command
  1570.   alias choicelist_initialize initialize
  1571.   #--------------------------------------------------------------------------
  1572.   # * 선택지 윈도우의 Z좌표를 설정합니다
  1573.   #--------------------------------------------------------------------------
  1574.   def initialize(message_window)
  1575.     choicelist_initialize(message_window)
  1576.     self.z = @message_window.z + 5
  1577.   end
  1578. end
  1579.  
  1580. #==============================================================================
  1581. # ** Game_Temp(Call Refer)
  1582. #==============================================================================
  1583. class Game_Temp
  1584.   attr_accessor :set_max_line
  1585.   #--------------------------------------------------------------------------
  1586.   # * 최대 라인 수를 결정합니다
  1587.   #--------------------------------------------------------------------------
  1588.   def max_line=(n)
  1589.     return if @set_max_line.nil?
  1590.     @set_max_line.call(n)
  1591.   end
  1592. end
  1593.  
  1594. #==============================================================================
  1595. # ** Window_Message
  1596. #==============================================================================
  1597. class Window_Message
  1598.   alias xxxheight_initialize initialize
  1599.   #--------------------------------------------------------------------------
  1600.   # * 라인 수를 설정합니다
  1601.   #--------------------------------------------------------------------------
  1602.   def initialize
  1603.     xxxheight_initialize
  1604.     $game_temp.set_max_line = method(:set_height)
  1605.     set_height(RS::LIST["라인"])
  1606.   end
  1607.   #--------------------------------------------------------------------------
  1608.   # * 메시지 윈도우의 높이를 변경합니다
  1609.   #--------------------------------------------------------------------------
  1610.   def set_height(n)
  1611.     contents.clear
  1612.     $game_message.line = n
  1613.     self.height = fitting_height(n)
  1614.     create_contents
  1615.     update_placement
  1616.   end
  1617.   #--------------------------------------------------------------------------
  1618.   # * 윈도우의 배경 화면을 사용자 정의 그래픽으로 설정합니다
  1619.   #--------------------------------------------------------------------------
  1620.   if RS::LIST["바탕화면"]
  1621.     def create_back_bitmap
  1622.       @back_bitmap = Cache.picture(RS::LIST["바탕화면"])
  1623.     end
  1624.   end
  1625.   #--------------------------------------------------------------------------
  1626.   # * 보여질 라인의 갯수
  1627.   #--------------------------------------------------------------------------
  1628.   def visible_line_number
  1629.     $game_message.line || RS::LIST["라인"]
  1630.   end
  1631.   #--------------------------------------------------------------------------
  1632.   # * Character Processing
  1633.   #     c    : Characters
  1634.   #     text : A character string buffer in drawing processing (destructive)
  1635.   #     pos  : Draw position {:x, :y, :new_x, :height}
  1636.   #--------------------------------------------------------------------------
  1637.   def process_character(c, text, pos)
  1638.     case c
  1639.     when "\n"   # New line
  1640.       process_new_line(text, pos)
  1641.     when "\f"   # New page
  1642.       process_new_page(text, pos)
  1643.     when "\e"   # Control character
  1644.       process_escape_character(obtain_escape_code(text), text, pos)
  1645.     else        # Normal character
  1646.       process_normal_character(c, pos, text)
  1647.     end
  1648.   end
  1649.   #--------------------------------------------------------------------------
  1650.   # * 텍스트 자동 개행
  1651.   #--------------------------------------------------------------------------
  1652.   alias process_word_wrap_character process_normal_character
  1653.   def process_normal_character(c, pos, text)
  1654.  
  1655.     # 자동 개행 여부 판단
  1656.     if $game_message.word_wrap_enabled
  1657.       tw = text_size(c).width
  1658.       if pos[:x] + (tw * 2) > contents_width
  1659.         process_new_line(text, pos)
  1660.       end
  1661.     end
  1662.     process_word_wrap_character(c, pos)
  1663.   end
  1664. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement