Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #BigFace by Core
- #1.0
- #big faceset should be 8 times longer in width than usual
- module BigFace
- def self.load_face(face_name)
- bitmap = ''
- begin
- begin
- bitmap = Cache.face(face_name)
- rescue Exception => e
- raise
- end
- rescue
- return
- end
- return bitmap
- end
- def self.convert_data(data)
- data['width'] = data['width'].to_i
- data['height'] = data['height'].to_i
- data['textX'] = data['textX'].to_i
- data['z'] = data['z'].to_i
- data['frames'] = data['frames'].to_i
- data['frameSpeed'] = data['frameSpeed'].to_i
- data['align'] = data['align'].delete!("\n")
- if data['alwaysTalk'] == "true" then
- data['alwaysTalk'] = true
- else
- data['alwaysTalk'] = false
- end
- data['height'] = data['height'] / data['frames']
- return data
- end
- def self.face_data(bitmap, face_name)
- data = {
- "width" => bitmap.width / 8,
- "height" => bitmap.height,
- "textX" => 0,
- "frames" => 1,
- "frameSpeed" => 3,
- "z" => 201,
- "align" => "bottom",
- "alwaysTalk" => false,
- }
- face_name = "Graphics/Faces/" + face_name + ".txt"
- if not File.exists?(face_name)
- return data
- end
- File.foreach(face_name) { |line|
- array = line.split('=')
- data[array[0]] = array[1]
- }
- return convert_data(data)
- end
- def self.draw_face(window, face_name, face_index, x, y, enabled = true)
- face_name = face_name + "-big"
- faceBitmap = load_face(face_name)
- if not faceBitmap then return true end
- data = face_data(faceBitmap, face_name)
- width = data['width']
- height = data['height']
- rect = Rect.new(face_index * width, 0, width, height)
- bitmap = Bitmap.new(width, height)
- bitmap.blt(0, 0, faceBitmap, rect, enabled ? 255 : translucent_alpha)
- face = window.face
- window.faceData = data
- window.faceBitmap = faceBitmap
- window.faceIndex = face_index
- face.bitmap = bitmap
- face.z = data['z']
- if data['align'] == 'bottom' or not data['align']
- face.y = face.y + (window.height - height) - window.padding
- elsif data['align'] == 'top'
- face.y = window.y - height
- end
- return false
- end
- def self.update_face(window)
- face = window.face
- data = window.faceData
- if data.empty?() then return end
- faceBitmap = window.faceBitmap
- width = data['width']
- height = data['height']
- frame = ((window.talkFrame * data['frameSpeed']) % data['frames']).floor()
- rect = Rect.new(window.faceIndex * width, height * frame, width, height)
- bitmap = Bitmap.new(width, height)
- bitmap.blt(0, 0, faceBitmap, rect)
- face.bitmap = bitmap
- end
- end
- #Modifying draw_face function
- class Window_Base < Window
- alias old_draw_face draw_face
- alias old_initialize initialize
- alias old_close close
- attr_accessor :faceData, :faceBitmap, :faceIndex, :face, :talkFrame
- def close
- dispose_face
- old_close
- end
- def dispose_face
- if @face.bitmap then @face.bitmap.dispose end
- if @faceBitmap then @faceBitmap.dispose end
- @face.dispose
- end
- def clear_face
- if @face
- dispose_face
- end
- @talkFrame = 0.0
- @faceData = {}
- @face = Sprite.new
- @face.x = self.x + self.padding
- @face.y = self.y
- end
- def initialize(x, y, width, height)
- old_initialize(x, y, width, height)
- clear_face
- end
- def draw_face(face_name, face_index, x, y, enabled = true)
- clear_face
- drawOld = BigFace::draw_face(self, face_name, face_index, x, y, enabled)
- if drawOld
- old_draw_face(face_name, face_index, x, y, enabled)
- end
- #~ bitmap = Cache.face(face_name)
- #~ rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
- #~ contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
- #~ bitmap.dispose
- end
- end
- #for talk frames
- class Window_Message < Window_Base
- alias old_process_character process_character
- alias old_wait wait
- alias old_process_all_text process_all_text
- alias old_new_line_x new_line_x
- def new_line_x
- if @faceData.empty?()
- old_new_line_x
- else
- @faceData['width'] + @faceData['textX']
- end
- end
- def update_face_talk
- BigFace::update_face(self)
- end
- def can_talk
- if not @faceData['alwaysTalk'] then @talkFrame = 0.0 end
- end
- def process_character(c, text, pos)
- @talkFrame = @talkFrame + 0.1
- if c == "\e"
- can_talk
- end
- update_face_talk
- old_process_character(c, text, pos)
- end
- def process_all_text
- old_process_all_text
- can_talk
- update_face_talk
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement