Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##########################
- # Kyu TextLog V2.0 #
- ########CONSTANTES########
- PADY = 25 #Margenes en el eje X
- PADX = 25 #Margenes en el eje Y
- INTERPAD = 12 #Margen entre cuadros de texto.
- IMG = nil #Si no se usa imagen: nil. Si se usa: "nombreImagen"
- ##########################
- class Log
- def initialize()
- $PokemonGlobal.log ||= [] if !$PokemonGlobal.log
- @pos = $PokemonGlobal.log.length-1
- @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @viewport.z = 99999
- @sprite = Sprite.new(@viewport)
- #Crea un fondo negro o carga una imagen según el valor de IMG
- if !IMG
- @sprite.bitmap = Bitmap.new(Graphics.width,Graphics.height)
- @sprite.bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0))
- @sprite.opacity = 150
- else
- @sprite.bitmap = Bitmap.new("Graphics/Pictures/"+IMG)
- end
- #Donde se dibujan los textos
- @sprite2 = Sprite.new(@viewport)
- @sprite2.y = PADY
- @sprite2.bitmap = Bitmap.new(Graphics.width,Graphics.height)
- @canvas = @sprite2.bitmap
- pbSetSystemFont(@canvas)
- @totalheight = 0
- @w = 0
- @lines = 0 #Lineas en la página actual. Sirve para conocer el aumento de
- #@pos a la hora de pulsar arriba.
- #Calcula cuantos textos pueden caber en pantalla, los añade en una
- #array y los dibuja.
- aux = []
- while @totalheight <= Graphics.height - 2*PADY and @pos-@w >= 0
- @totalheight+= 32*$PokemonGlobal.log[@pos-@w].length + INTERPAD
- if @totalheight <= Graphics.height - 2*PADY
- aux.push($PokemonGlobal.log[@pos-@w])
- end
- @w+=1
- end
- @totalheight = 0
- for i in 0...aux.length
- for z in 0...aux[aux.length-1-i].length
- chr = getFormattedText(@canvas,PADX,@totalheight+(32*z),
- Graphics.width - 2*PADX, Graphics.height,
- aux[aux.length-1-i][z],32)
- drawFormattedChars(@canvas,chr)
- end
- @totalheight += 32*aux[aux.length-1-i].length + INTERPAD
- end
- @lines = aux.length
- @pos+=1
- aux.clear
- self.update
- end
- def update
- loop do
- if Input.trigger?(Input::DOWN) and @pos < $PokemonGlobal.log.length - 1
- @canvas.clear
- @totalheight = 0
- @w = 0
- #Dibuja cuadros de texto hasta que el siguiente sobrepase el límite.
- while @totalheight <= Graphics.height - 2*PADY and (@pos+@w) <= $PokemonGlobal.log.length - 1
- if @totalheight + 32*$PokemonGlobal.log[@pos + @w].length <= Graphics.height - 2*PADY
- for i in 0...$PokemonGlobal.log[@pos + @w].length
- chr = getFormattedText(@canvas,PADX,@totalheight+(32*i),
- Graphics.width - 2*PADX, Graphics.height,
- $PokemonGlobal.log[@pos + @w][i],32)
- drawFormattedChars(@canvas,chr)
- end
- end
- @totalheight += 32*$PokemonGlobal.log[@pos + @w].length + INTERPAD
- @w += 1
- end
- @pos+= @w-1
- @lines = @w-1
- end
- if Input.trigger?(Input::UP) and @pos - @lines > 0
- @canvas.clear
- @pos-=@lines+1
- @totalheight = 0
- @w = 0
- #Mismo funcionamiento que al iniciar la pantalla.
- aux = []
- while @totalheight <= Graphics.height - 2*PADY and @pos-@w >= 0
- @totalheight+= 32*$PokemonGlobal.log[@pos-@w].length + INTERPAD
- if @totalheight <= Graphics.height - 2*PADY
- aux.push($PokemonGlobal.log[@pos-@w])
- end
- @w+=1
- end
- @totalheight = 0
- for i in 0...aux.length
- for z in 0...aux[aux.length-1-i].length
- chr = getFormattedText(@canvas,PADX,@totalheight+(32*z),
- Graphics.width - 2*PADX,Graphics.height,
- aux[aux.length-1-i][z],32)
- drawFormattedChars(@canvas,chr)
- end
- @totalheight += 32*aux[aux.length-1-i].length + INTERPAD
- end
- @lines = aux.length
- @pos+=1
- aux.clear
- end
- if Input.trigger?(Input::B) #Cerrar
- @canvas.clear
- @canvas.dispose
- @sprite.dispose
- @viewport.dispose
- Input.update
- Graphics.update
- break
- end
- Input.update
- Graphics.update
- end
- end
- end
- class Scene_Map #Añade la acción de Input F en Scene_Map para abrir el log
- alias update_old update
- def update
- if Input.trigger?(Input::F)
- Log.new
- end
- update_old
- end
- end
- class PokemonGlobalMetadata #Añade la variable global log, que guarda todo.
- attr_accessor :log
- alias kyu_initialize initialize
- def initialize
- kyu_initialize
- @log ||= []
- end
- end
- def getLineChunks(value) #Divide un texto en varias líneas en función de PADX
- regex = [/<[cC].*>/,/<\/[cC].*>/,/<[bB]>/,/<\/[bB]>/,/<[iI]>/,/<\/[iI]>/,
- /<[uU]>/,/<\/[uU]>/,/<[sS]>/,/<\/[sS]>/,/<outln>/,/<\/outln>/,/<outln2>/,
- /<\/outln2>/,/<fn=\d+>/,/<\/fn>/,/<fs=\d+>/,/<\/fs>/,/<[oO]=\d*>/,/<\/[oO]>/,
- /<ac>/,/<\/ac>/,/<al>/,/<\/al>/,/<ar>/,/<\/ar>/]
- width = Graphics.width - 2*PADX
- bitmap = Bitmap.new(width,Graphics.height)
- pbSetSystemFont(bitmap)
- totalwidth = 0 #Anchura total de la línea actual
- count = 0 #Línea actual
- #Color, bold, italic, underlined, struck, outline, thickoutline, font,
- #fontsize, opacity, centered, left-centered,righ-centered
- regs=["","","","","","","","","","","","",""]
- ret=[""] #Array con todas las líneas del texto.
- words = value.split
- #Análisis de todas las palabras del texto.
- words.each{|word|
- word+= " " #Añade un espacio entre palabras.
- init = "" #Expresiones de apertura Ej: <fs=X>
- ending = "" #Expresiones de cierre Ej: </fs>
- #Detecta comandos especiales y los activa en regs hasta que encuentra
- #el de cierre.
- regex.each_index{|index|
- aux = word.slice!(regex[index])
- if aux != nil
- if index % 2 != 0 #Comando de cierre
- regs[((index+1)/2)-1]=""
- ending += aux
- if index == 14 #</fn>
- pbSetSystemFont(bitmap)
- end
- else #Comando de apertura
- regs[index/2] = aux
- init += aux
- if index == 14 #<fn=X>
- bitmap.font.name = aux.gsub(/fn=/){""}
- end
- end
- end
- }
- #En word solo queda la palabra neta sin comandos especiales. Se mide
- #cuanto ocupa en bitmap y se añade a totalwidth. En función de ello
- #se realiza un salto de línea o no.
- if word.slice!(/\\n/) != nil
- count += 1
- ret.push("")
- regs.each{|reg|
- ret[count]+=reg
- }
- ret[count]+= word + ending
- totalwidth = 0
- end
- wordwidth = bitmap.text_size(word).width
- totalwidth += wordwidth
- if totalwidth > width
- count += 1
- ret.push("")
- regs.each{|reg|
- ret[count]+=reg
- }
- ret[count]+= word + ending
- totalwidth = wordwidth
- else
- ret[count] += (init + word + ending)
- end
- }
- return ret
- end
Advertisement
Add Comment
Please, Sign In to add comment