Simple Word Processing
Version: 1.0a
Author: cozziekuns
Date: June 20, 2011
Version History
- <Version 1.0a> 2011.21.07 - Updated visibility (thanks Pacman).
- <Version 1.0> 2011.20.07 - Original Release
Planned Future Versions
Description
A simple word processer which lets the player create, store and open various pieces of text. Not really practical, as I did this more as a challenge than as a utility, but it could be useful for things like player journals, organizers and the like.
Features
- Mostly plug and play.
- Can store an infinite amount of "files".
- Can allow the player to save, edit and open any piece of text.
- Not much else to say, has less features than Notepad as of now.
- CTRL Button to switch between Ribbon Window and Word Window.
Instructions
See Script.
Script
THIS SCRIPT
REQUIRES WIJFLY'S KEYBOARD INPUT SCRIPT AND MODERN ALGEBRA'S PARAGRAPH FORMATTER.
WIJFLY'S KEYBOARD INPUT SCRIPT: http://pastebin.com/aRCVaGiTMA'S PARAGRAPH FORMATTER: http://rmrk.net/index.php/topic,25129.0.htmlSORRY ABOUT THE ALL CAPS, IT'S THAT IMPORTANT.
#
# THIS SCRIPT REQUIRES WIJFLY'S KEYBOARD INPUT SCRIPT AND MODERN ALGEBRA'S
# PARAGRAPH FORMATTER.
#
# WIJFLY'S KEYBOARD INPUT SCRIPT : http://pastebin.com/aRCVaGiT
# MA'S PARAGRAPH FORMATTER : http://rmrk.net/index.php/topic,25129.0.html
#
#===============================================================================
# Simple Word Processing
#-------------------------------------------------------------------------------
# Version: 1.0a
# Author: cozziekuns (rmrk)
# Last Date Updated: 7/16/2011
#===============================================================================
# Description:
#-------------------------------------------------------------------------------
# A simple word processer which lets the player create, store and open various
# pieces of text. Not really practical, as I did this more as a challenge than
# as a utility, but it could be useful for things like player journals,
# organizers and the like.
#===============================================================================
# Updates
# ------------------------------------------------------------------------------
# o 7/21/2011 - Small update with visibility (Thanks Pacman).
# o 7/20/2011 - Started Script.
#===============================================================================
# To-do List
#-------------------------------------------------------------------------------
# o Nothing. Post some ideas.
#===============================================================================
# Instructions
#-------------------------------------------------------------------------------
# Copy and paste this script above ? Main Process but below ? Materials, and
# edit the modules to your liking. Some difficult modules have links to the
# instructions. To call this scene, make a call script with the command $scene =
# Scene_WordProcess.new
#===============================================================================
# Return Scene
#-------------------------------------------------------------------------------
# For people unexperienced with RGSS2, a list of built in scenes:
#
# Scene_Map.new (Map Screen)
# Scene_Menu.new (Menu Screen)
# Scene_Item.new (Item Screen)
#===============================================================================
module COZZIEKUNS
module SWP
RETURN_SCENE = (Scene_Item.new) # See Line 37
TITLE = "Journal" # Text you want to show in the Top Window
end
end
#==============================================================================
# *** Paragrapher
#==============================================================================
module Paragrapher
#============================================================================
# ** Formatter_Coz
#============================================================================
class Formatter_Coz < Formatter
#--------------------------------------------------------------------------
# * Format
#--------------------------------------------------------------------------
def format (string, specifications)
@string = string
# Checks whether specifications is a bitmap or a number. It then sets
# max_width and f.bitmap accordingly
if specifications.is_a? (Bitmap)
bitmap = specifications
@max_width = specifications.width
elsif specifications.is_a? (Numeric)
@max_width = specifications
bitmap = Bitmap.new (@max_width, 32)
else
# Error Catching: Incorrect Specifications
f = format ('Specifications Error', Bitmap.new (200, 64))
p 'Specifications Error: Please Pass Numeric or Bitmap'
return f
end
# Initializes Formatted_Text object
@format_text = Formatted_Text.new ([], [], bitmap)
@line_break = 0
@last_word = 0
for i in 0...@string.size
format_character (i)
end
fm_text = @string[@line_break, @string.size - @line_break]
fm_text == nil ? fm_text = "" : fm_text = fm_text
# Adds the last line to f.lines
@format_text.lines.push ( fm_text.scan (/./) )
# Since the last line is drawn normally, blank_width should be 0
@format_text.blank_width.push (0)
height = @format_text.lines.size * Window_Base::WLH
@format_text.bitmap = Bitmap.new (@max_width, height) if specifications.is_a? (Numeric)
# Returns the Formatted_Text object
formatted_text = @format_text.dup
@format_text = nil
return formatted_text
end
end
end
#==============================================================================
# ** Game_System
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :journal_text
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias coz_wp_gs_initialize_73481 initialize
def initialize
coz_wp_gs_initialize_73481
@journal_text = []
end
end
#==============================================================================
# ** Window_TextType
#==============================================================================
class Window_TextType < Window_Base
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :text
attr_accessor :cursor_position
#--------------------------------------------------------------------------
# * Object Initialization
# x : window X coordinate
# y : window Y coordinate
#--------------------------------------------------------------------------
def initialize(x, y)
super(x, y, 160, WLH + 32)
@text = ""
@cursor_position = 0
@blink = false
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.draw_text(4, 0, 120, WLH, @text)
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update(allow_typing = true)
happenings = false
if (Graphics.frame_count % 30 == 0)
@blink = !@blink
@clear = true
happenings = true
end
if Input.repeat?(Input::LEFT) and @cursor_position > 0
@text.gsub!(/\¦/) {""}
@blink = true
@clear = true
@cursor_position -= 1
happenings = true
elsif Input.repeat?(Input::RIGHT)
happenings = true
if @blink
if @cursor_position < @text.size - "¦".size
@text.gsub!(/\¦/) {""}
@blink = true
@clear = true
@cursor_position += 1
end
else
if @cursor_position < @text.size
@text.gsub!(/\¦/) {""}
@blink = true
@clear = true
@cursor_position += 1
end
end
elsif Input.typing? and allow_typing
if self.contents.text_size(@text).width > 100
Sound.play_buzzer
return
end
happenings = true
@blink = false
@clear = true
@text.insert(@cursor_position, Input.key_type)
@cursor_position += 1
elsif Input.repeat?(Input::BACK) and @cursor_position > 0
happenings = true
@blink = true
@clear = true
@text.gsub!(/\¦/) {""}
@text[@cursor_position - 1] = ""
@cursor_position -= 1
end
if @clear
@blink ? @text.insert(@cursor_position, "¦") : @text.gsub!(/\¦/) {""}
@clear = false
happenings = true
end
refresh if happenings
end
end
#==============================================================================
# ** Window_Word
#==============================================================================
class Window_Word < Window_Base
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :text
attr_accessor :cursor_position
#--------------------------------------------------------------------------
# * Object Initialization
# x : window X coordinate
# y : window Y coordinate
#--------------------------------------------------------------------------
def initialize
super(160, 56, 384, 360)
@text = ""
@cursor_position = 0
@blink = false
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.paragraph_formatter = Paragrapher::Formatter_Coz
self.contents.draw_paragraph(4, 0, 344, 376, @text)
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update(allow_typing = true)
happenings = false
if (Graphics.frame_count % 30 == 0)
@blink = !@blink
@clear = true
happenings = true
end
if Input.repeat?(Input::LEFT) and @cursor_position > 0
@text.gsub!(/\¦/) {""}
@blink = true
@clear = true
@cursor_position -= 1
happenings = true
elsif Input.repeat?(Input::RIGHT)
happenings = true
if @blink
if @cursor_position < @text.size - "¦".size and @text[@cursor_position + 1] != nil
@text.gsub!(/\¦/) {""}
@blink = true
@clear = true
@cursor_position += 1
end
else
if @cursor_position < @text.size and @text[@cursor_position + 1] != nil
@text.gsub!(/\¦/) {""}
@blink = true
@clear = true
@cursor_position += 1
end
end
elsif Input.typing? and allow_typing
if dupe
Sound.play_buzzer
else
happenings = true
@blink = false
@clear = true
@text.insert(@cursor_position, Input.key_type)
@cursor_position += 1
end
elsif Input.repeat?(Input::BACK) and @cursor_position > 0
happenings = true
@blink = true
@clear = true
@text.gsub!(/\¦/) {""}
@text[@cursor_position - 1] = ""
@cursor_position -= 1
elsif Input.repeat?(Input::ENTER) and allow_typing
if dupe
Sound.play_buzzer
else
happenings = true
@text.insert(@cursor_position, "\n")
@cursor_position += 1
end
end
if @clear
(@blink ? @text.insert(@cursor_position, "¦") : @text.gsub!(/\¦/) {""}) rescue @cursor_position -= 1
@clear = false
happenings = true
end
refresh if happenings
end
#-------------------------------------------------------------------------
# * Dupe
#-------------------------------------------------------------------------
def dupe
dup_text = @text.dup
dup_text.gsub!(/\n/m) {"oooooooooooooooooooooooooooooooooo"}
dup_text.gsub!(/\¦/) {""}
return self.contents.text_size(dup_text).width > 4008
end
end
#==============================================================================
# ** Scene_WordProcess
#==============================================================================
class Scene_WordProcess < Scene_Base
#--------------------------------------------------------------------------
# * Start processing
#--------------------------------------------------------------------------
def start
super
@sloppy_timer = 0
create_menu_background
create_ribbon_window
@word_window = Window_Word.new
@help_window = Window_Help.new
@help_window.set_text(COZZIEKUNS::SWP::TITLE, 1)
@typing_window = Window_TextType.new(192, 180)
@typing_window.visible = false
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@ribbon_window.dispose
@word_window.dispose
@help_window.dispose
@typing_window.dispose
end
#--------------------------------------------------------------------------
# * Create Ribbon Window
#--------------------------------------------------------------------------
def create_ribbon_window
@ribbon_window = Window_Command.new(160, ["New", "Save", "Open", "Quit"])
@ribbon_window.height = 360
@ribbon_window.y = 56
end
#--------------------------------------------------------------------------
# * Create Open Window
#--------------------------------------------------------------------------
def create_open_window
commands = []
for entry in $game_system.journal_text
commands.push(entry[0])
end
@open_window = Window_Command.new(160, commands)
@open_window.height = 360
@open_window.y = 56
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if @sloppy_timer > 0
@sloppy_timer -= 1
sloppy = false
else
sloppy = true
end
update_menu_background
openwin = (@open_window != nil and !@open_window.disposed?)
@word_window.update unless @ribbon_window.active or openwin or @typing_window.visible
@ribbon_window.update
@ribbon_index = @ribbon_window.index
@open_window.update if openwin
@typing_window.update if @typing_window.visible
if Input.trigger?(Input::CTRL) and not openwin and not @typing_window.visible
Sound.play_cursor
@ribbon_window.active = !@ribbon_window.active
end
if @ribbon_window.active and Input.trigger?(Input::C)
case @ribbon_window.index
when 0
Sound.play_decision
@word_window.text = ""
@word_window.cursor_position = 0
@word_window.update(false)
@ribbon_window.active = false
when 1
Sound.play_decision
@ribbon_window.active = false
@typing_window.text = ""
@typing_window.cursor_position = 0
@typing_window.visible = true
@typing_window.update(false)
sloppy = false
@sloppy_timer = 5
when 2
if $game_system.journal_text.empty?
Sound.play_buzzer
else
Sound.play_decision
@ribbon_window.active = false
create_open_window
end
when 3
Sound.play_decision
$scene = COZZIEKUNS::SWP::RETURN_SCENE
end
elsif @typing_window.visible and sloppy
if Input.trigger?(Input::ENTER)
text = @typing_window.text.gsub(/\¦/) {""}
words = @word_window.text.gsub(/\¦/) {""}
value = false
Sound.play_decision
for data in $game_system.journal_text
if text == data[0]
data = [text, words]
value = true
break
end
end
$game_system.journal_text.push([text, words]) unless value
@ribbon_window.active = true
@typing_window.visible = false
end
elsif openwin
@ribbon_window.visible = false
if Input.trigger?(Input::C)
Sound.play_decision
@ribbon_window.visible = true
@word_window.text = ""
@word_window.text = $game_system.journal_text[@open_window.index][1]
@word_window.cursor_position = 0
@word_window.update(false)
@open_window.dispose
elsif Input.trigger?(Input::B)
Sound.play_cancel
@ribbon_window.visible = true
@ribbon_window.active = true
@open_window.dispose
end
end
@help_window.update
super
end
end
Credit
- cozziekuns
- WijFly (OriginalWij and Yanfly) for their Keyboard Input Script.
- Modern Algebra and Zeriab, for their PF2 base code.
Thanks
- WijFly (OriginalWij and Yanfly), for their Keyboard Input script and being amazing scripters in their own right.
- Modern Algebra, for making an easy to edit Paragraph Formatter and generally being an awesome guy.
- Zeriab, for helping Modern Algebra with his Paragraph Formatter and his Guide to REGEXP in RGSS.
- Pacman, for pointing out a visibility issue.
Support
Just post down below.
Known Compatibility Issues
None as of yet.
Author's Notes
I really doubt that this script is very practical, but I'm posting it anyways. Who knows?