Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

+[Advance Text Reader]+ & Easy Text Decoration Tags!!

Advance Text Reader
Version 1.0
by Woratana
Release Date: 16/02/2008

Introduction
This script will allow you to read text file, and decorate it to make text more interesting!

Features
+[Features in Version 1.0]+

** Start Read Text File by call script:
$scene = Text_Reader.new("filename with file type")

** Custom Folder for Text File
You can change Text File's folder at line:
TEXT_FOLDER = "folder you want"

Screenshot
advtextxp1.jpg


This is text file I used for this screenshot:

C:
<div class="c" id="{CB}" style="font-family: monospace;"><ol>[cen][b]Show Text in Center

 

[/b]No Bold Text here!! *O*

[i]Try italic text...

[b]Italic with bold ^w^

 

This script released on <span style="color: #cc66cc;">16/<span style="color: #cc66cc;">02/<span style="color: #cc66cc;">2008

 

Version [<span style="color: #cc66cc;">1.0]

 

[cen]Advance Text Reader

by

[/i]Woratana

[b][woratana@hotmail.<span style="color: #202020;">com]

 

I will glad to hear any comment and suggestion

about this script!

 

TEST

TEST

TEST

Script
Place it above main.
Code:
#==============================================================================

# [XP] Advance Text Reader by Woratana

#-------------------------------------------------------------------------

# Version: 1.0

# Released on: 16/02/2008

# by Woratana [woratana@hotmail.com] 

#

=begin

==================================

+[Features in Version 1.0]+

 

** Start Read Text File by call script&#058;

$scene = Text_Reader.new("filename with file type")

 

* For example, you want to read file "test.txt", call script&#058;

$scene = Text_Reader.new("text.txt")

 

** Custom Folder for Text File

You can change Text File's folder at line:

TEXT_FOLDER = "folder you want"

 

"" << for no folder, text file should be in your game's folder.

"Files/" << for folder "Your Game Folder > Files"

"Data/Files/" << for folder "Your Game Folder > Data > Files"

 

==================================

+[Decorate Text]+

 

You can decorate your text by following features:

 

[b] << Bold Text

[/b] << Not Bold Text

 

[i] << Italic Text

[/i] << Not Italic Text

 

[cen] << Show Text in Center

 << Show Text in Left side

 << Show Text in Right side

 

[re] << Reset Text to be Not Bold & Not Italic

 

* Note: Don't put features that have opposite effects in same line...

For example, [b] that make text bold, and [/b] that make text not bold

 

* Note2: The decoration effect will be use in the next lines,

Until you use opposite effect features... For example,

 

[b]text1

text2

[/b]text3

 

text1 and text2 will be bold text, and text3 will be thin text.

 

==================================

+[Configuration]+

 

OPEN_SPEED = Speed when Reader Window is Opening/Closing

SCROLL_SPEED = Speed when player Scroll Reader Window up/down

 

TEXT_FOLDER = Folder for Text Files

e.g. "Data/Texts/" for Folder "Your Project Folder > Data > Texts"

 

=end

#===========================================================================

 

class Text_Reader

  

  OPEN_SPEED = 30 # Open/Close Speed of Reader Window (Higher = Faster)

  SCROLL_SPEED = 5 # Scroll Up/Down Speed

  

  TEXT_FOLDER = "Texts/" # Folder for Text Files

  

  BG_Picture = "" # Use background picture from folder "Graphics\Pictures",

  # put BG_Picture = "" to use Map as background

  

  # put BG_Picture = "picture file's name without file type" to use that picture as background

  # e.g. You want to use picture "bg_test.png", put BG_Picture = "bg_test"

  

  Window_OPACITY = 200 # Reader Window's opacity

  Window_WIDTH = 640

  Window_HEIGHT = 480

  Window_X = 0

  Window_Y = 0

  

  def initialize(file_name)

    @filename = file_name

  end

  

  def main

    if BG_Picture != ""

      viewport = Viewport.new(0,0,640,480)

     @bg = Sprite.new(viewport)

     @bg.bitmap = RPG::Cache.picture(BG_Picture)

    else

      @bg = Spriteset_Map.new

    end

    file = File.open(TEXT_FOLDER + @filename)

    @text = []

    for i in file.readlines

      @text.push i.sub(/\n/) {}

    end

    @window = Window_Reader.new(@text)

    Graphics.transition

    loop do

      Graphics.update

      Input.update

      update

      if $scene != self

        break

      end

    end

    Graphics.freeze

    @bg.dispose

  end

  

  def update

    @window.update

    if Input.trigger?(Input::B) or Input.trigger?(Input::C)

      $game_system.se_play($data_system.cancel_se)

      while @window.opacity > 0

        @window.opacity -= OPEN_SPEED

        @window.contents_opacity -= OPEN_SPEED

        Graphics.update

      end

      @window.dispose

      $scene = Scene_Map.new

    end

    if Input.press?(Input::DOWN)

      @window.oy += SCROLL_SPEED if (@window.oy + 320) < @window.contents.height

    end

    if Input.press?(Input::UP)

      @window.oy -= SCROLL_SPEED if @window.oy > 0

    end

  end

  

end

 

 

class Window_Reader < Window_Base

  attr_accessor :firstline, :nowline

  

  def initialize(text)

    super(Text_Reader::Window_X,Text_Reader::Window_Y,Text_Reader::Window_WIDTH,Text_Reader::Window_HEIGHT)

    self.opacity = 0

    self.contents_opacity = 0

    self.active = true

    @text = text

    @align = 0

    draw_text

  end

 

  def update

    if self.opacity < Text_Reader::Window_OPACITY

      self.opacity += Text_Reader::OPEN_SPEED

      self.contents_opacity += Text_Reader::OPEN_SPEED

    end

  end

 

  def draw_text

    self.contents = Bitmap.new(width - 32, @text.size * 24 + 32)

    line_index = 0

    for i in [email=0..@text.size]0..@text.size[/email]

      if !@text[i].nil?

        text = decorate_text(@text[i])

        self.contents.draw_text(0, line_index * 24, width - 32, 24, text, @align)

      end

      line_index += 1

    end

  end

  

  

  def decorate_text(text)

     a = text.scan(/(\[\/b\])/)

     if $1.to_s != ""

       self.contents.font.bold = false

       text.sub!(/\[\/b\]/) {}

     end

     

     a = text.scan(/(\[b\])/)

     if $1.to_s != ""

       self.contents.font.bold = true

       text.sub!(/\[b\]/) {}

     end

     

    a = text.scan(/(\[\/i\])/)

     if $1.to_s != ""

       self.contents.font.italic = false

       text.sub!(/\[\/i\]/) {}

     end

     

     a = text.scan(/(\[i\])/)

     if $1.to_s != ""

       self.contents.font.italic = true

       text.sub!(/\[i\]/) {}

     end

     

     a = text.scan(/(\[cen\])/)

     if $1.to_s != ""

       @align = 1

       text.sub!(/\[cen\]/) {}

     end

     

    a = text.scan(/(\[left\])/)

     if $1.to_s != ""

       @align = 0

       text.sub!(/\[left\]/) {}

     end

     

    a = text.scan(/(\[right\])/)

     if $1.to_s != ""

       @align = 2

       text.sub!(/\[right\]/) {}

     end

     

    a = text.scan(/(\[re\])/)

     if $1.to_s != ""

      self.contents.font.bold = false

      self.contents.font.italic = false

       text.sub!(/\[re\]/) {}

     end

     

     return text

  end

   

end

Instruction

** Start Read Text File by call script:
$scene = Text_Reader.new("filename with file type")

* For example, you want to read file "test.txt", call script:
$scene = Text_Reader.new("text.txt")

** Custom Folder for Text File
You can change Text File's folder at line:
TEXT_FOLDER = "folder you want"

"" Files"
"Data/Files/" Data > Files"


+[Configuration]+

OPEN_SPEED = Speed when Reader Window is Opening/Closing
SCROLL_SPEED = Speed when player Scroll Reader Window up/down

TEXT_FOLDER = Folder for Text Files
e.g. "Data/Texts/" for Folder "Your Project Folder > Data > Texts"


+[Decorate Text]+

You can decorate your text by following features:
Code:
 

[b] << Bold Text

[/b] << Not Bold Text

 

[i] << Italic Text

[/i] << Not Italic Text

 

 << Text with Shadow

 << Text without Shadow

 

[cen] << Show Text in Center

 << Show Text in Left side

 << Show Text in Right side

 

[re] << Reset Text to be Not Bold & Not Italic

Code:
* Note: Don't put features that have opposite effects in same line...

For example, [b] that make text bold, and [/b] that make text not bold

 

* Note2: The decoration effect will be use in the next lines,

Until you use opposite effect features... For example,

 

[b]text1

text2

[/b]text3

 

text1 and text2 will be bold text, and text3 will be thin text.


Author's Notes
Free for use in your non-commercial work if credit included. If your project is commercial, please contact me.

Please do not redistribute this script without permission. If you want to post it on any forum, please link to this topic.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top