- 33
- Posts
- 17
- Years
- Seen Sep 24, 2013
hello i want to make a touch screen menu but i have problems with it can somebody please help me!!
i use this mouse input module from crazyninjaguy (CNG):
and this is my menu script:
please help me making this touchable menu script!!!
sorry for my bad gammer :P
i use this mouse input module from crazyninjaguy (CNG):
Spoiler:
#===============================================================================
# * Mouse Input Module by Dervvulfman
# * Mouse.mouse_in_area? added by Crazyninjaguy
#===============================================================================
$mouse=IconSprite.new
$mouse.setBitmap("Graphics/Pictures/Mouse")
$mouse.z = 999999999
# Left-Clicking Control---
# 0 = single click action
# 1 = double-click action
MOUSE_LEFT_ACTION = 0
# Right-Clicking Control--
# 0 = Menu / 'B' pressed
# 1 = Stop Movement
MOUSE_RIGHT_ACTION = 0
module Mouse
@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.x = Mouse.pos_x
$mouse.y = Mouse.pos_y
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?
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
# * Mouse Input Module by Dervvulfman
# * Mouse.mouse_in_area? added by Crazyninjaguy
#===============================================================================
$mouse=IconSprite.new
$mouse.setBitmap("Graphics/Pictures/Mouse")
$mouse.z = 999999999
# Left-Clicking Control---
# 0 = single click action
# 1 = double-click action
MOUSE_LEFT_ACTION = 0
# Right-Clicking Control--
# 0 = Menu / 'B' pressed
# 1 = Stop Movement
MOUSE_RIGHT_ACTION = 0
module Mouse
@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.x = Mouse.pos_x
$mouse.y = Mouse.pos_y
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?
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
and this is my menu script:
Spoiler:
class PokemonMenu_Scene
def pbShowCommands(commands)
ret=-1
cmdwindow=@sprites["cmdwindow"]
cmdwindow.viewport=@viewport
cmdwindow.index=$PokemonTemp.menuLastChoice
cmdwindow.resizeToFit(commands)
cmdwindow.commands=commands
cmdwindow.x=Graphics.width-cmdwindow.width
cmdwindow.y=0
cmdwindow.visible=true
loop do
cmdwindow.update
Graphics.update
Input.update
pbUpdateSceneMap
if Input.trigger?(Input::B)
ret=-1
break
end
if Input.trigger?(Input::C)
ret=cmdwindow.index
$PokemonTemp.menuLastChoice=ret
break
end
end
return ret
end
def pbShowInfo(text)
@sprites["infowindow"].resizeToFit(text,Graphics.height)
@sprites["infowindow"].text=text
@sprites["infowindow"].visible=true
@infostate=true
end
def pbShowHelp(text)
@sprites["helpwindow"].resizeToFit(text,Graphics.height)
@sprites["helpwindow"].text=text
@sprites["helpwindow"].visible=true
@helpstate=true
pbBottomLeft(@sprites["helpwindow"])
end
def pbStartScene
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
@sprites={}
@sprites["cmdwindow"]=Window_CommandPokemon.new([])
@sprites["infowindow"]=Window_UnformattedTextPokemon.newWithSize("",0,0,32,32,@viewport)
@sprites["infowindow"].visible=false
@sprites["helpwindow"]=Window_UnformattedTextPokemon.newWithSize("",0,0,32,32,@viewport)
@sprites["helpwindow"].visible=false
@sprites["cmdwindow"].visible=false
@infostate=false
@helpstate=false
pbSEPlay("menu")
end
def pbHideMenu
@sprites["cmdwindow"].visible=false
@sprites["infowindow"].visible=false
@sprites["helpwindow"].visible=false
end
def pbShowMenu
@sprites["cmdwindow"].visible=true
@sprites["infowindow"].visible=@infostate
@sprites["helpwindow"].visible=@helpstate
end
def pbEndScene
pbDisposeSpriteHash(@sprites)
@viewport.dispose
end
def pbRefresh
end
end
class PokemonMenu
def initialize(scene)
@scene=scene
end
def pbShowMenu
@scene.pbRefresh
@scene.pbShowMenu
end
def pbStartPokemonMenu
@scene.pbStartScene
endscene=true
commands=[]
cmdPokedex=-1
cmdPokemon=-1
cmdBag=-1
cmdTrainer=-1
cmdSave=-1
cmdOption=-1
cmdPokegear=-1
cmdDebug=-1
cmdQuit=-1
if !$Trainer
if $DEBUG
Kernel.pbMessage(_INTL("The player trainer was not defined, so the menu can't be displayed."))
Kernel.pbMessage(_INTL("Please see the documentation to learn how to set up the trainer player."))
end
return
end
commands[cmdPokedex=commands.length]=_INTL("POKéDEX") if $Trainer.pokedex
commands[cmdPokemon=commands.length]=_INTL("POKéMON") if $Trainer.party.length>0
commands[cmdBag=commands.length]=_INTL("BAG") if !pbInBugContest?
commands[cmdPokegear=commands.length]=_INTL("POKéGEAR") if $Trainer.pokegear
commands[cmdTrainer=commands.length]=$Trainer.name
if pbInSafari?
@scene.pbShowInfo(_INTL("STEPS: {1}/600\nBALLS: {2}",pbSafariState.steps,pbSafariState.ballcount))
commands[cmdQuit=commands.length]=_INTL("QUIT")
elsif pbInBugContest?
if pbBugContestState.lastPokemon
@scene.pbShowInfo(_INTL("CAUGHT: {1}\nLEVEL: {2}\nBALLS: {3}",
PBSpecies.getName(pbBugContestState.lastPokemon.species),
pbBugContestState.lastPokemon.level,
pbBugContestState.ballcount))
else
@scene.pbShowInfo(_INTL("CAUGHT: None\nBALLS: {1}",pbBugContestState.ballcount))
end
commands[cmdQuit=commands.length]=_INTL("QUIT")
else
commands[cmdSave=commands.length]=_INTL("SAVE") if !$game_system || !$game_system.save_disabled
end
commands[cmdOption=commands.length]=_INTL("OPTION")
commands[cmdDebug=commands.length]=_INTL("DEBUG") if $DEBUG
commands[commands.length]=_INTL("EXIT")
loop do
[email protected](commands)
if cmdPokedex>=0 && command==cmdPokedex
pbFadeOutIn(99999) {
scene=PokemonPokedexScene.new
screen=PokemonPokedex.new(scene)
screen.pbStartScreen
@scene.pbRefresh
}
elsif cmdPokegear>=0 && command==cmdPokegear
pbLoadRpgxpScene(Scene_Pokegear.new)
elsif cmdPokemon>=0 && command==cmdPokemon
sscene=PokemonScreen_Scene.new
sscreen=PokemonScreen.new(sscene,$Trainer.party)
hiddenmove=nil
pbFadeOutIn(99999) {
hiddenmove=sscreen.pbPokemonScreen
if hiddenmove
@scene.pbEndScene
else
@scene.pbRefresh
end
}
if hiddenmove
Kernel.pbUseHiddenMove(hiddenmove[0],hiddenmove[1])
return
end
elsif cmdBag>=0 && command==cmdBag
item=0
scene=PokemonBag_Scene.new
screen=PokemonBagScreen.new(scene,$PokemonBag)
pbFadeOutIn(99999) {
item=screen.pbStartScreen
if item>0
@scene.pbEndScene
else
@scene.pbRefresh
end
}
if item>0
Kernel.pbUseKeyItemInField(item)
return
end
elsif cmdTrainer>=0 && command==cmdTrainer
PBDebug.logonerr {
scene=PokemonTrainerCardScene.new
screen=PokemonTrainerCard.new(scene)
pbFadeOutIn(99999) {
screen.pbStartScreen
@scene.pbRefresh
}
}
elsif cmdQuit>=0 && command==cmdQuit
@scene.pbHideMenu
if pbInSafari?
if Kernel.pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?"))
@scene.pbEndScene
pbSafariState.decision=1
pbSafariState.pbGoToStart
return
else
pbShowMenu
end
else
if Kernel.pbConfirmMessage(_INTL("Would you like to end the Contest now?"))
@scene.pbEndScene
pbBugContestState.pbStartJudging
return
else
pbShowMenu
end
end
elsif cmdSave>=0 && command==cmdSave
@scene.pbHideMenu
scene=PokemonSaveScene.new
screen=PokemonSave.new(scene)
if screen.pbSaveScreen
@scene.pbEndScene
endscene=false
break
else
pbShowMenu
end
elsif cmdDebug>=0 && command==cmdDebug
pbFadeOutIn(99999) {
pbDebugMenu
@scene.pbRefresh
}
elsif cmdOption>=0 && command==cmdOption
scene=PokemonOptionScene.new
screen=PokemonOption.new(scene)
pbFadeOutIn(99999) {
screen.pbStartScreen
pbUpdateSceneMap
@scene.pbRefresh
}
else
break
end
end
@scene.pbEndScene if endscene
end
end
def pbShowCommands(commands)
ret=-1
cmdwindow=@sprites["cmdwindow"]
cmdwindow.viewport=@viewport
cmdwindow.index=$PokemonTemp.menuLastChoice
cmdwindow.resizeToFit(commands)
cmdwindow.commands=commands
cmdwindow.x=Graphics.width-cmdwindow.width
cmdwindow.y=0
cmdwindow.visible=true
loop do
cmdwindow.update
Graphics.update
Input.update
pbUpdateSceneMap
if Input.trigger?(Input::B)
ret=-1
break
end
if Input.trigger?(Input::C)
ret=cmdwindow.index
$PokemonTemp.menuLastChoice=ret
break
end
end
return ret
end
def pbShowInfo(text)
@sprites["infowindow"].resizeToFit(text,Graphics.height)
@sprites["infowindow"].text=text
@sprites["infowindow"].visible=true
@infostate=true
end
def pbShowHelp(text)
@sprites["helpwindow"].resizeToFit(text,Graphics.height)
@sprites["helpwindow"].text=text
@sprites["helpwindow"].visible=true
@helpstate=true
pbBottomLeft(@sprites["helpwindow"])
end
def pbStartScene
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
@sprites={}
@sprites["cmdwindow"]=Window_CommandPokemon.new([])
@sprites["infowindow"]=Window_UnformattedTextPokemon.newWithSize("",0,0,32,32,@viewport)
@sprites["infowindow"].visible=false
@sprites["helpwindow"]=Window_UnformattedTextPokemon.newWithSize("",0,0,32,32,@viewport)
@sprites["helpwindow"].visible=false
@sprites["cmdwindow"].visible=false
@infostate=false
@helpstate=false
pbSEPlay("menu")
end
def pbHideMenu
@sprites["cmdwindow"].visible=false
@sprites["infowindow"].visible=false
@sprites["helpwindow"].visible=false
end
def pbShowMenu
@sprites["cmdwindow"].visible=true
@sprites["infowindow"].visible=@infostate
@sprites["helpwindow"].visible=@helpstate
end
def pbEndScene
pbDisposeSpriteHash(@sprites)
@viewport.dispose
end
def pbRefresh
end
end
class PokemonMenu
def initialize(scene)
@scene=scene
end
def pbShowMenu
@scene.pbRefresh
@scene.pbShowMenu
end
def pbStartPokemonMenu
@scene.pbStartScene
endscene=true
commands=[]
cmdPokedex=-1
cmdPokemon=-1
cmdBag=-1
cmdTrainer=-1
cmdSave=-1
cmdOption=-1
cmdPokegear=-1
cmdDebug=-1
cmdQuit=-1
if !$Trainer
if $DEBUG
Kernel.pbMessage(_INTL("The player trainer was not defined, so the menu can't be displayed."))
Kernel.pbMessage(_INTL("Please see the documentation to learn how to set up the trainer player."))
end
return
end
commands[cmdPokedex=commands.length]=_INTL("POKéDEX") if $Trainer.pokedex
commands[cmdPokemon=commands.length]=_INTL("POKéMON") if $Trainer.party.length>0
commands[cmdBag=commands.length]=_INTL("BAG") if !pbInBugContest?
commands[cmdPokegear=commands.length]=_INTL("POKéGEAR") if $Trainer.pokegear
commands[cmdTrainer=commands.length]=$Trainer.name
if pbInSafari?
@scene.pbShowInfo(_INTL("STEPS: {1}/600\nBALLS: {2}",pbSafariState.steps,pbSafariState.ballcount))
commands[cmdQuit=commands.length]=_INTL("QUIT")
elsif pbInBugContest?
if pbBugContestState.lastPokemon
@scene.pbShowInfo(_INTL("CAUGHT: {1}\nLEVEL: {2}\nBALLS: {3}",
PBSpecies.getName(pbBugContestState.lastPokemon.species),
pbBugContestState.lastPokemon.level,
pbBugContestState.ballcount))
else
@scene.pbShowInfo(_INTL("CAUGHT: None\nBALLS: {1}",pbBugContestState.ballcount))
end
commands[cmdQuit=commands.length]=_INTL("QUIT")
else
commands[cmdSave=commands.length]=_INTL("SAVE") if !$game_system || !$game_system.save_disabled
end
commands[cmdOption=commands.length]=_INTL("OPTION")
commands[cmdDebug=commands.length]=_INTL("DEBUG") if $DEBUG
commands[commands.length]=_INTL("EXIT")
loop do
[email protected](commands)
if cmdPokedex>=0 && command==cmdPokedex
pbFadeOutIn(99999) {
scene=PokemonPokedexScene.new
screen=PokemonPokedex.new(scene)
screen.pbStartScreen
@scene.pbRefresh
}
elsif cmdPokegear>=0 && command==cmdPokegear
pbLoadRpgxpScene(Scene_Pokegear.new)
elsif cmdPokemon>=0 && command==cmdPokemon
sscene=PokemonScreen_Scene.new
sscreen=PokemonScreen.new(sscene,$Trainer.party)
hiddenmove=nil
pbFadeOutIn(99999) {
hiddenmove=sscreen.pbPokemonScreen
if hiddenmove
@scene.pbEndScene
else
@scene.pbRefresh
end
}
if hiddenmove
Kernel.pbUseHiddenMove(hiddenmove[0],hiddenmove[1])
return
end
elsif cmdBag>=0 && command==cmdBag
item=0
scene=PokemonBag_Scene.new
screen=PokemonBagScreen.new(scene,$PokemonBag)
pbFadeOutIn(99999) {
item=screen.pbStartScreen
if item>0
@scene.pbEndScene
else
@scene.pbRefresh
end
}
if item>0
Kernel.pbUseKeyItemInField(item)
return
end
elsif cmdTrainer>=0 && command==cmdTrainer
PBDebug.logonerr {
scene=PokemonTrainerCardScene.new
screen=PokemonTrainerCard.new(scene)
pbFadeOutIn(99999) {
screen.pbStartScreen
@scene.pbRefresh
}
}
elsif cmdQuit>=0 && command==cmdQuit
@scene.pbHideMenu
if pbInSafari?
if Kernel.pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?"))
@scene.pbEndScene
pbSafariState.decision=1
pbSafariState.pbGoToStart
return
else
pbShowMenu
end
else
if Kernel.pbConfirmMessage(_INTL("Would you like to end the Contest now?"))
@scene.pbEndScene
pbBugContestState.pbStartJudging
return
else
pbShowMenu
end
end
elsif cmdSave>=0 && command==cmdSave
@scene.pbHideMenu
scene=PokemonSaveScene.new
screen=PokemonSave.new(scene)
if screen.pbSaveScreen
@scene.pbEndScene
endscene=false
break
else
pbShowMenu
end
elsif cmdDebug>=0 && command==cmdDebug
pbFadeOutIn(99999) {
pbDebugMenu
@scene.pbRefresh
}
elsif cmdOption>=0 && command==cmdOption
scene=PokemonOptionScene.new
screen=PokemonOption.new(scene)
pbFadeOutIn(99999) {
screen.pbStartScreen
pbUpdateSceneMap
@scene.pbRefresh
}
else
break
end
end
@scene.pbEndScene if endscene
end
end
please help me making this touchable menu script!!!
sorry for my bad gammer :P