FANDOM


Dual screen and touch screen
This tutorial was written by Zingzags, with the main scripts by CrazyNinjaGuy. Please give credit.

This tutorial is related to the following pages:

Click here for more tutorials!


Putting Dual Screen mini-tut by:Zingzags of pokecommunity, and Dual Screen system by:CrazyNinjaGuy of pokecommunity.

Lines of Code

1. Create a new script section above the script called main. You can do this by clicking on the script called main and pressing the insert key.

2. Name it dual screen.

3. Copy all of the script in the spoiler, and paste it into the blank window. Make sure you are pasting into the Dual Screen script window.

Code:

#===============================================================================
# * Dual Screen Script for Pokemon Essentials
# * By Crazyninjaguy
# * http://www.planetdev.net
#===============================================================================
# If you like this script, please register on my site :)
# http://www.planetdev.net
#===============================================================================
 
module Graphics
  @@fadeoutvp=Viewport.new(0,0,485,685)
  @@fadeoutvp.z=0x3FFFFFFF
  @@fadeoutvp.color=Color.new(0,0,0,0)
end
 
class Sprite_Picture
  def initialize(viewport, picture)
    @viewport = Viewport.new(0, 0, 480, 680)
    @picture = picture
    @sprite = nil
    update
  end
end
 
module Resolution
  GetWindowPlacement = Win32API.new('user32','GetWindowPlacement',['l','p'],'l')
  GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics',['i'],'i')
  MoveWindow = Win32API.new('user32','MoveWindow',['l','i','i','i','i','l'],'l')
  FindWindowEx = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i')
  def self.windowloc(window)
    string = ' ' * 44
    Resolution::GetWindowPlacement.call(window,string)
    windowdetails = string.unpack('L11')
    result = []
    result.push((windowdetails[9] - windowdetails[7]))
    result.push((windowdetails[10] - windowdetails[8]))
    result.push(windowdetails[7])
    result.push(windowdetails[8])
    return result
  end
end
class Screen
  def self.center
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    width,height = Resolution.windowloc(window)[0..1]
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,(screenwidth - width) / 2,(screenheight - height) / 2,width,height,1)
  end
  def self.resize2(width,height,x,y)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,x,y,width,height,1)
  end
  def self.move(x,y)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    width,height = Resolution.windowloc(window)[0..1]
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,x,y,width,height,1)
  end
  def self.resize(width,height,center = true)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    if center
      Resolution::MoveWindow.call(window,(screenwidth - width) / 2,(screenheight - height) / 2,width,height,1)
    else
      x,y = Resolution.windowloc(window)[2..3]
      Resolution::MoveWindow.call(window,x,y,width,height,1)
    end
  end
  def self.half(center = true)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    if center
      Resolution::MoveWindow.call(window,(screenwidth - 326) / 2,(screenheight - 272) / 2,326,272,1) 
    else
      x,y = Resolution.windowloc(window)[2..3]
      Resolution::MoveWindow.call(window,x,y,326,272,1)
    end
  end
  def self.default
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,(screenwidth - 646) / 2,(screenheight / 2) - 273,646,512,1)
  end
end
 
Screen.resize(485,685)
 
#----------------------------------------------
@spacer=IconSprite.new(0, 320)
@spacer.setBitmap("Graphics/Pictures/spacer")
@spacer.z = 99999999
#-----------------------------------------------

4. Create a file in MSPaint called spacer.png
Make it 480 pixels wide by 20 pixels high.

5. Save spacer.png in Graphics/Pictures

6. Put any pictures you want to use on the bottom screen in Graphics/Pictures

7. To show a picture on the bottom screen, you use a show picture command, but remember to set the Y coordinate to 340

8. If you like this script, it'd be great if you could join CrazyNinjaGuy's Game Developing community at http://www.planetdev.co.uk

CrazyNinjaGuy's edited Mouse Module

Please only use this if you are an experienced scripter and you know what you are doing. There is no point adding this if you can't script, as it won't do anything unless you tell it to.

To see the cursor add this into the update method of your scripts.

Mouse.update

$mouse.x = Mouse.pos_x

$mouse.y = Mouse.pos_y

Code:

#===============================================================================
# * Mouse Script for Pokemon Essentials
# * By Crazyninjaguy
# * http://www.planetdev.net
#===============================================================================
# If you like this script, please register on my site :)
# http://www.planetdev.net
#===============================================================================

# Set this to true if you use the mouse module
USE_MOUSE = true
$width = 512
if FileTest.exist?("C:/Windows/clock.avi")
  $height = 778
else
  $height = 770
end
 
module Resolution
  GetWindowPlacement = Win32API.new('user32','GetWindowPlacement',['l','p'],'l')
  GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics',['i'],'i')
  MoveWindow = Win32API.new('user32','MoveWindow',['l','i','i','i','i','l'],'l')
  FindWindowEx = Win32API.new('user32','FindWindowEx',['l','l','p','p'],'i')
  def self.windowloc(window)
    string = ' ' * 44
    Resolution::GetWindowPlacement.call(window,string)
    windowdetails = string.unpack('L11')
    result = []
    result.push((windowdetails[9] - windowdetails[7]))
    result.push((windowdetails[10] - windowdetails[8]))
    result.push(windowdetails[7])
    result.push(windowdetails[8])
    return result
  end
end
class Screen
  def self.center
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    width,height = Resolution.windowloc(window)[0..1]
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,(screenwidth - width) / 2,(screenheight - height) / 2,width,height,1)
  end
  def self.resize2(width,height,x,y)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,x,y,width,height,1)
  end
  def self.move(x,y)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    width,height = Resolution.windowloc(window)[0..1]
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,x,y,width,height,1)
  end
  def self.resize(width,height,center = true)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    if center
      Resolution::MoveWindow.call(window,(screenwidth - width) / 2,(screenheight - height) / 2,width,height,1)
    else
      x,y = Resolution.windowloc(window)[2..3]
      Resolution::MoveWindow.call(window,x,y,width,height,1)
    end
  end
  def self.half(center = true)
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    if center
      Resolution::MoveWindow.call(window,(screenwidth - 326) / 2,(screenheight - 272) / 2,326,272,1) 
    else
      x,y = Resolution.windowloc(window)[2..3]
      Resolution::MoveWindow.call(window,x,y,326,272,1)
    end
  end
  def self.default
    window = Resolution::FindWindowEx.call(0,0,"RGSS Player",0)
    screenwidth = Resolution::GetSystemMetrics.call(0)
    screenheight = Resolution::GetSystemMetrics.call(1)
    Resolution::MoveWindow.call(window,(screenwidth - 646) / 2,(screenheight / 2) - 273,646,512,1)
  end
end

class MouseSprite
  def initialize
    @mouse = Sprite.new
    @mouse.bitmap = RPG::Cache.picture("Mouse.png")
    @mouse.z = 9999999
    @mouse.x = 512
    @mouse.zoom_x = 1
    @mouse.zoom_y = 1
  end
  def self.x
    return @mouse.x
  end
  def self.y
    return @mouse.y
  end
  def update
    case $ResizeFactor
    when 0.5
      @mouse.x = Mouse.pos_x * 2
      @mouse.y = Mouse.pos_y * 2
    when 1.0
      @mouse.x = Mouse.pos_x
      @mouse.y = Mouse.pos_y
    end
  end
  def cursor(filename)
    @mouse.bitmap = RPG::Cache.picture(filename)
  end
  def opacity(opacity)
    @mouse.opacity = opacity
  end
  def defaults
    @mouse.bitmap = RPG::Cache.picture("Mouse.png")
    @mouse.opacity = 255
    @mouse.zoom_x = 2
    @mouse.zoom_y = 2
  end
end

module Mouse
  $mouse=MouseSprite.new
  @cursor_pos_get = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  @cursor_pos_set = Win32API.new('user32', 'SetCursorPos', 'ii', 'i')
  @cursor_show    = Win32API.new('user32', 'ShowCursor', 'L', 'i')
  @window_find    = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')  
  @window_c_rect  = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
  @window_scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  @readini        = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l') 
  @key            = Win32API.new("user32", "GetAsyncKeyState", 'i', 'i')
  Left_Click    = 1
  Right_Click   = 2
  Middle_Click  = 4
  MOUSE_BUTTONS = { Left_Click    => 1,
                    Right_Click   => 2,
                    Middle_Click  => 4 }
  MOUSE_REPEAT = MOUSE_BUTTONS.clone
  MOUSE_REPEAT.keys.each { |k| MOUSE_REPEAT[k] = [false, false, 10]}  
  @game_window = nil    # Set game handle to nil
  @cursor_show.call(0)  # Turn off system mouse
  def Mouse.click?(button)
    MOUSE_REPEAT[button][1] >= 1
  end
  def Mouse.dbclick?(button)
    MOUSE_REPEAT[button][1] == 2
  end
  def Mouse.pos(catch_anywhere = true)
    x, y = screen_to_client(screen_x, screen_y)
    width, height = client_size
    if catch_anywhere or (x >= 0 and y >= 0 and x < width and y < height)  
      return x, y
    else
      return 0, 0
    end    
  end
  def Mouse.pos_set(x, y)
    x = [[x, 0].max, 640].min
    y = [[y, 0].max, 480].min
    x, y = client_to_screen(x, y)
    @cursor_pos_set.call(x, y)
  end
  def Mouse.pos_x
    x, y = pos
    return x
  end
  def Mouse.pos_y
    x, y = pos
    return y
  end
  def Mouse.screen
    pos = [0, 0].pack('ll')
    @cursor_pos_get.call(pos)
    return pos.unpack('ll')
  end
  def Mouse.screen_x
    pos = [0, 0].pack('ll')
    @cursor_pos_get.call(pos)
    return pos.unpack('ll')[0]
  end
  def Mouse.screen_y
    pos = [0, 0].pack('ll')
    @cursor_pos_get.call(pos)
    return pos.unpack('ll')[1]
  end
  def Mouse.client_size
    rect = [0, 0, 0, 0].pack('l4')
    @window_c_rect.call(Mouse.hwnd, rect)
    right, bottom = rect.unpack('l4')[2..3]
    return right, bottom
  end 
  def Mouse.hwnd
    if @game_window.nil?
      game_name = "\0" * 256
      @readini.call('Game','Title','',game_name,255,".\\Game.ini")
      game_name.delete!("\0")
      @game_window = @window_find.call('RGSS Player',game_name)
    end
    return @game_window
  end 
  def Mouse.screen_to_client(x, y)
    return nil unless x and y
    pos = [x, y].pack('ll')
    if @window_scr2cli.call(hwnd, pos) != 0
       return pos.unpack('ll')
     else
       return nil
    end
  end
  def Mouse.update
    $mouse.update
    MOUSE_BUTTONS.keys.each do |key|
      temp = MOUSE_REPEAT[key][0]
      key_pres = @key.call(MOUSE_BUTTONS[key]) != 0
      key_trig = temp == key_pres ? 0 : (key_pres ? (MOUSE_REPEAT[key][2].between?(1, 9) ? 2 : 1) : -1)
      count = key_trig > 0 ? 0 : [MOUSE_REPEAT[key][2]+1, 20].min
      MOUSE_REPEAT[key] = [key_pres, key_trig, count]
    end
  end
  def Mouse.visible?(visible=true)
    if visible
      @cursor_show.call(-1)
    else
      @cursor_show.call(0)
    end
  end
  def Mouse.mouse_in_area?(*args)
    return false if Mouse.pos_x.nil?
    case $ResizeFactor
    when 0.5
      args[0] = args[0] / 2
      args[1] = args[1] / 2
      args[2] = args[2] / 2
      args[3] = args[3] / 2
    end
    if args[0].is_a?(Rect)
      Mouse.pos_x >= args[0].x and
      Mouse.pos_y >= args[0].y and
      Mouse.pos_x <= args[0].x + args[0].width and
      Mouse.pos_y <= args[0].y + args[0].height
    else
      Mouse.pos_x >= args[0] and
      Mouse.pos_y >= args[1] and
      Mouse.pos_x <= args[0] + args[2] and
      Mouse.pos_y <= args[1] + args[3]
    end
  end
end

module Input
  class << self
    alias cng_input_update update
    def update
      cng_input_update
      Mouse.update
    end
  end
end

module Spacer
  def self.initialize
    @spacer = Sprite.new
    @spacer.bitmap = RPG::Cache.picture("Spacer")
    @spacer.y = 384
    @spacer.z = 9999998
  end
  def self.defaults
    @spacer.bitmap = RPG::Cache.picture("Spacer")
    @spacer.y = 384
    @spacer.z = 9999998
    @spacer.opacity = 255
    @spacer.zoom_x = 1
    @spacer.zoom_y = 1
  end
  def self.opacity(n)
    @spacer.opacity = n
  end
  def self.x(x)
    @spacer.x = x
  end
  def self.y(y)
    @spacer.y = y
  end
  def self.zoom_x(zoomx)
    @spacer.zoom_x = zoomx
  end
  def self.zoom_y(zoomy)
    @spacer.zoom_y = zoomy
  end
  def self.dispose
    @spacer.dispose
  end
end

9. This one down here is when you change the view, e.g. Custom, Perspective, and normal. This script prevents Dual Screen from leaving. EDIT: Work for Version 11 of Essentials.

10. Add this above main as well - it can be named whatever you want.

Code:

class PokemonOptionScene
def pbStartScene
 @sprites={}
 @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
 @viewport.z=99999
 @sprites["title"]=Window_UnformattedTextPokemon.newWithSize(
  _INTL("OPTION"),0,0,Graphics.width,64,@viewport)
  # These are the different options in the game.  To add an option, define a setter and 
  # a getter for that option.  To delete an option, comment it out or delete it.
  # The game's options may be placed in any order.
 @PokemonOptions=[
  EnumOption.new(_INTL("TEXT SPEED"),[_INTL("SLOW"),_INTL("MID"),_INTL("FAST")],
  proc { $PokemonSystem.textspeed },  # Getter
  proc {|value|  
     $PokemonSystem.textspeed=value 
     MessageConfig.pbSetTextSpeed(pbSettingToTextSpeed(value)) 
  } # Setter
  ),
  EnumOption.new(_INTL("BATTLE SCENE"),[_INTL("ON"),_INTL("OFF")],
  proc { $PokemonSystem.battlescene },
  proc {|value|  $PokemonSystem.battlescene=value }
  ),
  EnumOption.new(_INTL("BATTLE STYLE"),[_INTL("SHIFT"),_INTL("SET")],
  proc { $PokemonSystem.battlestyle },
  proc {|value|  $PokemonSystem.battlestyle=value }
  ),
  EnumOption.new(_INTL("FONT STYLE"),[_INTL("Em"),_INTL("R/S"),_INTL("FRLG"),_INTL("DP")],
  proc { $PokemonSystem.font },
  proc {|value|  
     $PokemonSystem.font=value
     MessageConfig.pbSetSystemFontName($VersionStyles[value])
  }
  ),
  NumberOption.new(_INTL("FRAME"),_INTL("TYPE%d"),1,$TextFrames.length,
  proc { $PokemonSystem.frame },
  proc {|value|  
       $PokemonSystem.frame=value
       MessageConfig.pbSetSystemFrame($TextFrames[value]) 
  }
  ),
  EnumOption2.new(_INTL("MAP VIEW"),[_INTL("ORIGINAL"),_INTL("CUSTOM"),_INTL("PERSPECTIVE")],
  proc { $PokemonSystem.tilemap ? $PokemonSystem.tilemap : 0 },
  proc {|value|  
    oldvalue=$PokemonSystem.tilemap
    $PokemonSystem.tilemap=value 
    if value!=oldvalue
     ObjectSpace.each_object(TilemapLoader){|o| next if o.disposed?; o.updateClass }
    end
   }
  ),
  NumberOption.new(_INTL("SPEECH FRAME"),_INTL("TYPE%d"),1,$SpeechFrames.length,
  proc { $PokemonSystem.textskin },
  proc {|value|  $PokemonSystem.textskin=value;
     MessageConfig.pbSetSpeechFrame(
       "Graphics/Windowskins/"+$SpeechFrames[value]) }
  )
 ]
 @sprites["option"]=Window_PokemonOption.new(@PokemonOptions,0,
   @sprites["title"].height,Graphics.width,
   Graphics.height-@sprites["title"].height)
 @sprites["option"].viewport=@viewport
 @sprites["option"].visible=true
 # Get the values of each option
 for i in 0...@PokemonOptions.length
   @sprites["option"][i]=(@PokemonOptions[i].get || 0)
 end
 pbDeactivateWindows(@sprites)
 pbFadeInAndShow(@sprites) { pbUpdate }
end
end

Creating a button

Well I'm gonna start up with a high demand from people with the touch screen ability within Pokemon Essentials.You will need the mouse module and the dualscreen script by Cng. And obviously Pokemon Essentials.

The first step you need to do is create a button graphic about 50X50 in size.

In a script you need to set up the sprite display for the button(Judging that most people will choose the menu script)

To set up the first button display you need to do the following code:

@button1=Sprite.new
@button1.x = # Change the # to the value of the displayed graphic's verticle appearance
@button1.y = # Change the # to the value of the displayed graphic's horizontal appearance
@button1.z = 100 # This sets the priority of the button over other graphics
@button1.bitmap = RPG::Cache.picture("insert graphic name here") # defines the graphic

That sets up the button graphic for the first button

To set up the mouse part of the script as to where to click and where the mouse needs to be you need to find the loop do method of the script:

Do the following:

if Mouse.mouse_in_area?(x,y,width,height) # change the x and y to the co-ordinates on screen change the width and height to the size of the graphic
 if Mouse.click?(1) # checks if the left mouse button is clicked
  #this is where you define the actions of the button
 end
end

And that should be all you need to do in-order to set up the whole touch screen method.

Just make sure you have set the button up properly with what it needs to do and check that you know exactly what to do within scripting before you try to do this. Here's an example of a working button:

if Mouse.mouse_in_area?(21,353,60,39)
 if Mouse.click?(1)
  $game_system.se_play
        ($data_system.decision_se)
  pbFadeOutIn(99999)
  ( scene=PokemonPokedexScene.new
  screen=PokemonPokedex.new(scene)
  screen.pbStartScreen
  }
 end
end

That is an example of a pokedex button.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.