The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on January 09, 2010, 10:07:11 PM

Title: Deity Notebook VX
Post by: modern algebra on January 09, 2010, 10:07:11 PM
Notebook VX
Version: 1.0
Author: Deity
Date: January 9, 2010

Description


This script permits the game player to have a notebook to jot down reminders of a quest or draw special symbols or any number of cool things. It allows complete user input on a canvas, in addition to shoosing a larger size for the pencil or a different colour. Can make for a great tool for the player to take notes to remind him/herself of their objectives or as simply a way to pass the time!

It also supports mouse input in addition to key input

Features


Screenshots

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg192.imageshack.us%2Fimg192%2F8027%2Fdeitynotebook.png&hash=b669af97dc8d219753e6bc3d57faac6668b7619f)

Instructions

Please see the header of the script

Script


Code: [Select]
#????????????????????????????????????????????????????????????????#
# Script:  Notebook VX                                           #
#  by Deity [translated to English by modern algebra (rmrk.net)] #
# Mouse module by Near Fantastica                                #
#????????????????????????????????????????????????????????????????#
# Description:                                                 #
#  This script permits the game player to have a notebook to jot #
# down reminders of a quest or draw special symbols or any       #
# number of cool things. It allows complete user input on a      #
# canvas, in addition to shoosing a larger size for the pencil   #
# or a different colour. Can make for a great tool for the       #
# player to take notes to remind him/herself of their objectives #
# or as simply a way to pass the time!                           #
#  It also supports mouse input in addition to key input         #
#????????????????????????????????????????????????????????????????#
# Instructions:                                                  #
# Choose the settings for the appearance that you want below the #
#  Settings headed. Once that is done, all you need to do is use #
#  the following code in a call script:                          #
#                                                                #
#     $scene = Scene_Notebook.new()                              #
#????????????????????????? Settings ?????????????????????????????#
#                   true = yes / false = no                      #
module Notebook
  USE_MOUSE = false # Use the mouse to draw with?
  KEY_TO_DRAW = Input::Z # Unused buttons: X(A),Y(S),Z(D),L(Q),
                         # R(Q). If you use Z, it is the D key
  BGM = [
  "Town2", # Filename of BGM to play
  100,     # Volume
  100,     # Pitch
  ] # <= Do not delete!
  # Select the drawing colours for the note book. These are of
  # the (Red, Green, Blue, Alpha) form. All numbers must be
  # between 0 and 255.
  COLORS = [
  Color.new(0,0,0,255),       # Black
  Color.new(255,255,255,255), # White
  Color.new(255,0,0,255),     # Red
  Color.new(0,255,0,255),     # Green
  Color.new(0,0,255,255),     # Blue
  Color.new(255,255,0,255),   # Yellow
  ] # <= Do not delete!
  # Select the names for the commands of the selection window
  COMMANDS = [
  "Draw",      # Draw
  "Color",     # The color to draw in
  "Size",      # Size of Pencil
  "Erase", # Erase All
  ] # <= Do not delete!
  # Comment for the lower help window
  HELP_TEXT = "[D: Draw] [B: Back] [Shift: Accelerate]"
  # Colour of background
  BACKGROUND_START_COLOR = Color.new(255,255,255,255)
  # Starting settings for the cursor
  CURSOR_START_VALUES = [
  80, # X-coordinate of cursor start position
  80, # Y-coordinate of cursor start position
  Color.new(0,0,0,255), # Color of cursor on startup
  4, # Size of cursor on startup
  ] # <= Do not delete!
end
#  You should edit nothing beyond this point unless you are a   #
# scripter and know what you're doing                           #
#???????????????????????????????????????????????????????????????#
include Notebook
# Author of the Mouse module
# Near Fantastica (special thanks)
module Mouse
  GetAsyncKeyState=Win32API.new("user32","GetAsyncKeyState",'i','i')
  GetKeyState=Win32API.new("user32","GetKeyState",'i','i')
  SetCursorPos=Win32API.new('user32','SetCursorPos','nn','n')
  GetCursorPo=Win32API.new('user32','GetCursorPos','p','i')
  ScreenToClient=Win32API.new('user32','ScreenToClient','lp','i')
  GetPrivateProfileStringA=Win32API.new('kernel32','GetPrivateProfileStringA','pppplp','l')
  FindWindowA=Win32API.new('user32','FindWindowA','pp','l')
  GetClientRect=Win32API.new('user32','GetClientRect','lp','i')
  GetWindowRect=Win32API.new('user32','GetWindowRect','lp','i')
  game_name="\0"*256
  GetPrivateProfileStringA.call('Game','Title','',game_name,255,".\\Game.ini")
  game_name.delete!("\0")
  @handle=FindWindowA.call('RGSS Player',game_name)
  module_function
  def click?(button)
    return true if @keys.include?(button)
    return false
  end  
  def press?(button)
    return true if @press.include?(button)
    return false
  end
  def set_pos(x_pos=0,y_pos=0)
    width,height=client_size
    if (x_pos.between?(0,width)&&y_pos.between?(0,height))
      SetCursorPos.call(client_pos[0]+x_pos,client_pos[1]+y_pos)
    end
  end
  def update
    @pos=Mouse.pos
    @keys,@press=[],[]
    @keys.push(1)if GetAsyncKeyState.call(1)&0x01==1
    @keys.push(2)if GetAsyncKeyState.call(2)&0x01==1
    @keys.push(3)if GetAsyncKeyState.call(4)&0x01==1
    @press.push(1)if pressed?(1)
    @press.push(2)if pressed?(2)
    @press.push(3)if pressed?(4)
  end  
  def pressed?(key)
    return true unless GetKeyState.call(key).between?(0,1)
    return false
  end
  def global_pos
    pos=[0,0].pack('ll')
    GetCursorPo.call(pos)!=0 ? (return pos.unpack('ll')):(return nil)
  end
  def pos
    x,y=screen_to_client(*global_pos)
    width,height=client_size
    begin
      x=0 if x<=0;y=0 if y<=0
      x=width if x>=width;y=height if y>=height
      return x,y
    end
  end
  def screen_to_client(x,y)
    return nil unless x&&y
    pos=[x,y].pack('ll')
    ScreenToClient.call(@handle,pos)!=0?(return pos.unpack('ll')):(return nil)
  end
  def client_size
    rect=[0,0,0,0].pack('l4')
    GetClientRect.call(@handle,rect)
    right,bottom=rect.unpack('l4')[2..3]
    return right,bottom
  end
  def client_pos
    rect=[0,0,0,0].pack('l4')
    GetWindowRect.call(@handle,rect)
    left,upper=rect.unpack('l4')[0..1]
    return left+4,upper+30
  end  
  def grid
    return nil if @pos.nil?
    return [(@pos[0]+$game_map.display_x/8)/32,(@pos[1]+$game_map.display_y/8)/32]
  end
end
class Window_ChooseColor < Window_Selectable
  def initialize(width, commands, column_max = 1, row_max = 0, spacing = 32)
    if row_max == 0
      row_max = (commands.size + column_max - 1) / column_max
    end
    super(0, 0, width, row_max * WLH + 32, spacing)
    @commands = commands
    @item_max = commands.size
    @column_max = column_max
    refresh
    self.index = 0
    self.visible = false
    self.active = false
  end
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i)
    end
  end
  def item_rect(index)
    rect = Rect.new(0, 0, 0, 0)
    rect.width = (contents.width + @spacing) / @column_max - @spacing
    rect.height = WLH + 8
    rect.x = index % @column_max * (rect.width + @spacing) + 13
    rect.width = 32
    rect.y = (index / @column_max * WLH)  - 4
    return rect
  end
  def item_rect2(index)
    rect = Rect.new(0, 0, 0, 0)
    rect.width = (contents.width + @spacing) / @column_max - @spacing
    rect.height = WLH
    rect.x = index % @column_max * (rect.width + @spacing)
    rect.y = index / @column_max * WLH
    return rect
  end
  def draw_item(i, enabled = true)
    rect = item_rect2(i)
    rect.x += 4
    rect.width -= 8
    self.contents.clear_rect(rect)
    self.contents.font.color = COLORS[i]
    self.contents.draw_text(rect.x+13,rect.y,24,24,@commands[i].to_s)
    self.contents.fill_rect(rect.x+13,rect.y,24,24,COLORS[i])
  end
end
class Scene_Notebook < Scene_Base
  def start
    @color = Window_ChooseColor.new(544,["","","","","",""],6)
    @commands = Window_Command.new(544,COMMANDS,4)
    create_background
    create_cursor
    @size = Window_NumberInput.new
    @size.visible = false
    @size.opacity = 255
    @size.digits_max = 2
    @size.number = @cursor.width
    @help = Window_Help.new
    @help.y = 416 - @help.height
    Audio.bgm_play("Audio/BGM/"+BGM[0],BGM[1],BGM[2])
    @mouse = USE_MOUSE
  end
  def create_background
    @background = Sprite.new
    if $game_system.notebookbitmap.empty?
      @background.bitmap = Bitmap.new(544,416)    
      @background.bitmap.fill_rect(0,0,544,416,BACKGROUND_START_COLOR)
    else
      @background.bitmap = $game_system.gimme_bitmap
    end
  end
  def create_cursor
    @cursor = Sprite.new
    @cursor.x = CURSOR_START_VALUES[0]
    @cursor.y = CURSOR_START_VALUES[1]
    @cursor.bitmap = Bitmap.new(CURSOR_START_VALUES[3],CURSOR_START_VALUES[3])
    @cursor.bitmap.fill_rect(0,0,CURSOR_START_VALUES[0],CURSOR_START_VALUES[1],CURSOR_START_VALUES[2])
  end
  def active_window
    return true if @color.active == false && @commands.active == false && @size.active == false
    return false
  end
  def set_cursor_color(color)
    Sound.play_decision
    @cursor.bitmap.fill_rect(0,0,@cursor.width,@cursor.height,color)
  end
  def set_cursor_size(w)
    if w != 0
      Sound.play_decision
      @cursor.bitmap.dispose
      @cursor.bitmap = Bitmap.new(w,w)
      @cursor.bitmap.fill_rect(0,0,w,w,COLORS[@color.index])
    else
      Sound.play_buzzer
    end
  end
  def close_all
    @color.dispose
    @commands.dispose
    @cursor.dispose
    @background.dispose
    @size.dispose
    @help.dispose
  end
  def update
    Mouse.update
    if @mouse      
      @cursor.x,@cursor.y =Mouse.pos
    end
    if active_window && @mouse == false
      if Input.press?(Input::A)
        speed = 2
      else
        speed = 1
      end
      case Input.dir8
        when 1;  @cursor.y += speed
                       @cursor.x -= speed
        when 2;  @cursor.y += speed
        when 3;  @cursor.y += speed
                       @cursor.x += speed
        when 4;  @cursor.x -= speed
        when 7;  @cursor.y -= speed
                       @cursor.x -= speed
        when 6;  @cursor.x += speed
        when 9;  @cursor.y -= speed
                       @cursor.x += speed
        when 8;  @cursor.y -= speed
      end
      if @cursor.y < 0
        @cursor.y = 0
      end
      if @cursor.y + @cursor.height > 416
        @cursor.y = 416 - @cursor.height
      end
      if @cursor.x < 0
        @cursor.x = 0
      end
      if @cursor.x + @cursor.width > 544
        @cursor.x = 544 - @cursor.width
      end
    end
    if active_window
      @help.visible = false
    else
      @help.visible = true
      @help.set_text(HELP_TEXT,1)
    end
    if Input.press?(KEY_TO_DRAW) && active_window && @mouse == false
      @background.bitmap.fill_rect(@cursor.x,@cursor.y,@cursor.bitmap.width,@cursor.bitmap.height,@cursor.bitmap.get_pixel(0,0))
    end
    if @mouse && Mouse.press?(1) && active_window
      @background.bitmap.fill_rect(@cursor.x,@cursor.y,@cursor.bitmap.width,@cursor.bitmap.height,@cursor.bitmap.get_pixel(0,0))
    end
    @color.update if @color.active == true
    @commands.update if @commands.active == true
    @size.update if @size.active == true
    if Input.trigger?(Input::C)
      if @commands.active == true
        Sound.play_decision
        case @commands.index
        when 0
          @commands.active = false
          @commands.visible = false
        when 1
          @commands.active = false
          @commands.visible = false
          @color.active = true
          @color.visible = true
        when 2
          @commands.active = false
          @commands.visible = false
          @size.active = true
          @size.visible = true
        when 3
          @background.bitmap.fill_rect(0,0,544,416,Notebook::BACKGROUND_START_COLOR)
        end
      elsif @color.active == true
        set_cursor_color(COLORS[@color.index])
      elsif @size.active == true
        set_cursor_size(@size.number)
      end
    end
    if Input.trigger?(Input::B)
      Sound.play_cancel
      if @commands.active == true
        $game_system.dump_bitmap(@background.bitmap)
        close_all
        Audio.bgm_stop
        $game_map.autoplay
        return_scene
      elsif @color.active == true
        @commands.active = true
        @commands.visible = true
        @color.active = false
        @color.visible = false
      elsif @size.active == true
        @commands.active = true
        @commands.visible = true
        @size.active = false
        @size.visible = false
      elsif active_window
        @commands.active = true
        @commands.visible = true
      end
    end
  end
  def return_scene
    $scene = Scene_Map.new
  end
end
class Game_System
  attr_reader  :notebookbitmap
  alias initialize_notebook initialize
  def initialize
    initialize_notebook
    @notebookbitmap = []
  end
  # Convert Bitmap in Array (Colors)
  def dump_bitmap(bitmap)
    @notebookbitmap.clear
    for i in 0...bitmap.height
      n = []
      for o in 0...bitmap.width
        n.push(bitmap.get_pixel(o,i))
      end
      @notebookbitmap.push(n)
    end
  end
  # Convert Array (Colors) in Bitmap
  def gimme_bitmap
    bit = Bitmap.new(@notebookbitmap[0].size,@notebookbitmap.size)
      for i in 0...@notebookbitmap.size
        for o in 0...@notebookbitmap[i].size
          bit.set_pixel(o,i,@notebookbitmap[i][o])
        end
      end
    return bit
  end
end

Credit



Thanks


Support


Please post in this topic at rmrk.net for support and I will either try to answer it myself or forward it to Deity.

Known Compatibility Issues

None known.

Demo


No demo should be necessary.

Translator's Notes


Again, all credit goes to Deity, with Thanks to Near Fantastica for the mouse module Deity uses in this script

Title: Re: Deity Notebook VX
Post by: Countdown on January 09, 2010, 10:30:51 PM
Is there any way to save the notes, for later?  For example.  You're character is told to remember a certain number, so he writes it down in the notebook.  How would he save that note so that he can look at it later when he needs that number?
Title: Re: Deity Notebook VX
Post by: modern algebra on January 09, 2010, 10:37:16 PM
Mmn, I mentioned that to Deity after I translated, but he hasn't gotten back to me.

Currently, he would just have to be sure to not erase over it. Everytime you open the notebook, it saves what has already been drawn. It's not very much, which is why I mentioned he should make multiple pages. For now that's all there is though :)
Title: Re: Deity Notebook VX
Post by: Countdown on January 09, 2010, 10:49:40 PM
Hmm, thanks.  I never noticed it saved that little bit.  If he does get back to you, do you want to let me know?  That would be greatly appreciated.
Title: Re: Deity Notebook VX
Post by: SuperMega on January 10, 2010, 05:39:53 AM
Wow, these Deity scripts are amazing!  Are there anymore to come?
Title: Re: Deity Notebook VX
Post by: modern algebra on January 10, 2010, 05:41:16 AM
Yeah, there are at least two others already written that I haven't translated yet, and I know of at least one more that he's working on that sounds very cool.
Title: Re: Deity Notebook VX
Post by: Deity on January 10, 2010, 06:10:12 PM
Hi @ all
Now when I read the replys I have to register and say
Thanks. :D

Greets
Deity
Title: Re: Deity Notebook VX
Post by: Eternal on January 11, 2010, 06:24:18 PM
You're an amazing scripter, Deity; this looks really cool!


Btw can you change the background to a picture (of fx. a piece of paper) instead of just plain white?
Title: Re: Deity Notebook VX
Post by: Deity on January 11, 2010, 07:50:07 PM
Well thanks a lot!
Yes in the update you willl be able to write and draw. You're also able to choose a pictrue as a background.
I hope it will be finished in the near future. :D

Greets
Deity
Title: Re: Deity Notebook VX
Post by: Countdown on January 11, 2010, 10:52:25 PM
Hey, Deity, you should make it so that you can save notes with this thing.  That would be awesome!
Title: Re: Deity Notebook VX
Post by: Deity on January 12, 2010, 04:42:20 PM
What do you mean? The Bitmap saves if you close the Notebook and next time if you use the Notebook you can continue draw on the last picture.
Maybe I just understand something wrong.

Greets
Deity
Title: Re: Deity Notebook VX
Post by: Countdown on January 12, 2010, 06:45:31 PM
No that's fine.  I didn't really explain it well. What I'm trying to get at is to make it so that it will save a picture so that you can save the picture, erase it, and exit the notebook.  When you enter the notebook again you have the option to load it to see and edit it again so that you don't end up with this page loaded full of pictures and stuff, you could save one, make a new one, save it, load the first one, etc. So that it would look neater.  And example is the Pictograph on The Legend of Zelda Wind Waker (except it is a camera, not a notebook).
Title: Re: Deity Notebook VX
Post by: Deity on January 14, 2010, 07:59:25 PM
I send the update to modern algebra.
So if he have the time and want to have some extra work, maybe he will translate it.
The update took so long becuase I have to translate the Input module a bit to the english and to the german keyboard.

In the update was an error so it have to be fixxed, but I don't have time jet so it takes a bit. :(

Greets
Deity
Title: Re: Deity Notebook VX
Post by: Eternal on January 17, 2010, 01:00:12 PM
I can't wait xD
Title: Re: Deity Notebook VX
Post by: Countdown on June 14, 2010, 07:16:47 PM
Can I get rid of the BGM that plays in the Notebook so that the map's music plays instead?
Title: Re: Deity Notebook VX
Post by: Linkx7 on September 16, 2010, 04:51:40 PM
GOOD notebook :)
Title: Re: Deity Notebook VX
Post by: Linkx7 on September 17, 2010, 08:47:54 AM
<a href="http://www.youtube.com/watch?v=cCpMyCrdNyA" target="_blank">http://www.youtube.com/watch?v=cCpMyCrdNyA</a>
Very Good and Here we are the video on youtube
:yourmom: :headtoss: :kashii:
Title: Re: Deity Notebook VX
Post by: zerothedarklord on March 03, 2015, 05:06:55 PM
Not that I'm one to necropost, because that would be kind of a dick move, but after 20 years since the last post, I must say I agree and second the motion to allow for saving and loading capabilities.
Title: Re: Deity Notebook VX
Post by: &&&&&&&&&&&&& on March 12, 2015, 02:12:16 PM
2008 was 10 years ago
where does time go? :(
Title: Re: Deity Notebook VX
Post by: &&&&&&&&&&&&& on March 12, 2015, 02:12:34 PM
also 1973 was 50 years ago
Title: Re: Deity Notebook VX
Post by: &&&&&&&&&&&&& on March 12, 2015, 02:13:02 PM
the world is going to end soon, it's ending in 2012
that's only 2 years away D:
Title: Re: Deity Notebook VX
Post by: Deity on April 13, 2015, 12:41:37 PM
Not that I'm one to necropost, because that would be kind of a dick move, but after 20 years since the last post, I must say I agree and second the motion to allow for saving and loading capabilities.
2008 was 10 years ago
where does time go? :(
also 1973 was 50 years ago
the world is going to end soon, it's ending in 2012
that's only 2 years away D:


Maybe English has to be my native language to undertsand that or its an insider but I really don't know what you're talking about! :D

Greets