Raccoon Game RPG รวมพลนักพัฒนา
สคริปต์ +Advance Text Reader+ version 1.0 Rpgvx_1024x768b

Join the forum, it's quick and easy

Raccoon Game RPG รวมพลนักพัฒนา
สคริปต์ +Advance Text Reader+ version 1.0 Rpgvx_1024x768b
Raccoon Game RPG รวมพลนักพัฒนา
Would you like to react to this message? Create an account in a few clicks or log in to continue.

สคริปต์ +Advance Text Reader+ version 1.0

Go down

สคริปต์ +Advance Text Reader+ version 1.0 Empty สคริปต์ +Advance Text Reader+ version 1.0

ตั้งหัวข้อ by boyhit Mon Oct 31, 2011 6:04 am

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


Introduction
สคริปต์นี้ใช้อ่านไฟล์ Text (เช่น .txt ที่ใช้ตอนเขียนใน Notepad)

Features
CODE
+[Features in Version 1.0]+

** เริ่มอ่าน text โดยใช้ Call Script:
$scene = Text_Reader.new("ชื่อไฟล์ textพร้อมนามสกุลไฟล์")

** ตั้งโฟลเดอร์สำหรับไฟล์ Text เองได้ โดยเปลี่ยนที่บรรทัดนี้:
TEXT_FOLDER = "โฟลเดอร์ที่ต้องการ"


Screenshot
สคริปต์ +Advance Text Reader+ version 1.0 Advtext10

อันนี้คือไฟล์ Text ที่ผมใช้ใน Screenshot รูปนี้:
CODE
[cen]Show Text in Center

No Bold Text here!! *O*
[right]Try italic text...
Italic with bold ^w^

[cen]Advance Text Reader
by
Woratana
[b][woratana@hotmail.com]



[b]Script

วางสคริปต์ไว้เหนือ Main

Version 1.0
Code:
#==============================================================================
# [VX] 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:
$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")

* If your text file is save as UTF-8 encoding
(This encoding is for other languages)
You have to call script like this:
$scene = Text_Reader.new("filename with file type",1)

** 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

[s] << Text with Shadow
[/s] << Text without Shadow

[cen] << Show Text in Center
 << Show Text in Left side
[right] << Show Text in Right side

* 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 < Scene_Base
 
  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
 
  def initialize(file_name,mode = 0)
    @filename = file_name
    @mode = mode
  end
 
  def start
    super
    create_menu_background
    file = File.open(TEXT_FOLDER + @filename)
    @text = []
    for i in file.readlines
      @text.push i.sub(/\n/) {}
    end
    if @mode == 1
      @text[0] = @text[0].sub(/^./m) {}
    end
    @window = Window_Reader.new(@text)
  end
 
  def update
    @window.update
    if Input.trigger?(Input::B) or Input.trigger?(Input::C)
      Sound.play_cancel
      while @window.openness > 0
        @window.openness -= OPEN_SPEED
        Graphics.update
      end
      @window.dispose
      $scene = Scene_Map.new
    end
    if Input.press?(Input::DOWN)
      @window.oy += SCROLL_SPEED if (@window.oy + 272) < @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(0,0,544,416)
    self.openness = 0
    self.active = true
    @firstline = @nowline = 0
    @text = text
    @align = 0
    draw_text
  end

  def update
    if self.openness < 255
      self.openness += 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 0..@text.size
      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(/(\[\/s\])/)
    if $1.to_s != ""
      self.contents.font.shadow = false
      text.sub!(/\[\/s\]/) {}
    end
   
    a = text.scan(/(\[s\])/)
    if $1.to_s != ""
      self.contents.font.shadow = true
      text.sub!(/\[s\]/) {}
    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
   
    return text
  end
 
end

Instruction

QUOTE
เริ่มอ่าน text โดยใช้ Call Script:
$scene = Text_Reader.new("ชื่อไฟล์ text พร้อมนามสกุลไฟล์")

* ตัวอย่างเช่น คุณต้องการอ่านไฟล์ text ชื่อ "test.txt", ก็ Call Script แบบนี้:
$scene = Text_Reader.new("text.txt")

* ถ้าต้องการใช้กับภาษาไทย
ใน Notepad ให้เลือก encoding ตอนเซฟเป็น UTF-8
สคริปต์ +Advance Text Reader+ version 1.0 Utf8
และให้ Call Script แบบนี้แทน:
$scene = Text_Reader.new("ชื่อไฟล์ text พร้อมนามสกุลไฟล์",1)

** ตั้งโฟลเดอร์สำหรับไฟล์ Text เองได้ โดยเปลี่ยนที่บรรทัดนี้:
TEXT_FOLDER = "โฟลเดอร์ที่ต้องการ"

ตัวอย่างการตั้ง "โฟลเดอร์ที่ต้องการ"
"" << ไม่มีโฟลเดอร์ หมายถึงว่าไฟล์ text ต้องอยู่ในโฟลเดอร์นอกสุดของเกม (โฟลเดอร์เดียวกับที่เก็บ Game.exe)
"Files/" << หมายถึง ไฟล์ text อยู่ในโฟลเดอร์ "โฟลเดอร์เกม > Files"
"Data/Files/" << หมายถึง ไฟล์ text อยู่ในโฟลเดอร์ "โฟลเดอร์เกม > Data > Files"


CODE
+[การตั้งค่าต่าง ๆ]+

OPEN_SPEED = ความเร็วในการเปิด/ปิดหน้าต่างอ่านไฟล์ text
SCROLL_SPEED = ความเร็วการเลื่อนขึ้น/ลงเพื่ออ่านไฟล์ text ใช้เมื่อไฟล์ text ยาวเกินหน้าจอเกม


CODE
+[การตกแต่งตัวอักษร]+

คุณสามารถตกแต่งตัวอักษรด้วยการพิมพ์ tag ต่าง ๆ ดังนี้:

<< ทำตัวหนา
<< ทำให้ไม่หนา

<< ทำตัวเอียง
<< ทำให้ไม่เอียง

[s] << ใส่เงาตัวอักษร
[/s] << ไม่ใส่เงาตัวอักษร

[cen] << แสดงตัวอักษรกลางจอ
<< แสดงตัวอักษรชิดขอบด้านซ้าย
[right] << แสดงตัวอักษรชิดขอบด้านขวา

* Note: ไม่ควรใส่ tag ที่ให้ผลตรงข้ามกันในบรรทัดเดียวกัน เพราะมันจะทำงานผิดปกติ~
เช่น ที่ทำให้ตัวอักษรหนา กับ ที่ทำให้ตัวอักษรไม่หนา

* Note2: tag ที่ตกแต่งจะถูกใช้ในบรรทัดถัด ๆ ไปด้วย
ถ้าจะยกเลิกการตกแต่งนั้น ก็ใช้ tag ที่ให้ผลตรงข้ามกัน เช่น...

text1
text2
text3

text1 กับ text2 จะเป็นตัวหนา ( ของบรรทัดแรกแสดงผลในบรรทัดต่อไปด้วย)
ส่วน text3 จะเป็นตัวไม่หนา เพราะมีการใช้
ยกเลิกตัวหนาอยู่



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.

เครดิต วอราม่อน
boyhit
boyhit
Admin
Admin

ชื่อเล่น : เเอล
ความฝัน : ศิลปิน
จำนวนข้อความ : 1130
เครดิต : 3356
วันที่สมัคร : 09/10/2011
คะเเนนน้ำใจ : 11
เพศ : Male อายุ : 24
เหรียญรางวัล : สคริปต์ +Advance Text Reader+ version 1.0 Medalhead2

https://raccoongame-rpg.thai-forum.net

ขึ้นไปข้างบน Go down

ขึ้นไปข้างบน

- Similar topics

 
Permissions in this forum:
คุณไม่สามารถพิมพ์ตอบ