#===============================================================================
# * 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
module Input
class << self
alias cng_input_update update
def update
cng_input_update
Mouse.update
end
end
end
Well of course the button is going to appear and disappear as the menu is the script calling the graphic.Ok, thank you very much, Im starting to get somewhere.
Now I can move mouse with no problem, but my button appears only when I press X to open old menu (which I still can use with no problem), but when I click on it, nothing happens. Also it disappears when I close standard menu with X.
Well its still so much better than it was, but I wonder what's wrong now. I used my old PokemonMenu (posted few posts upper) without changing anything.
class PokemonMenu_Scene
def pbShowCommands(commands)
ret=-1
[EMAIL="cmdwindow=@sprites["cmdwindow"]cmdwindow=@sprites["cmdwindow[/EMAIL]"]
cmdwindow.viewport=Viewport.new(0, 0, 480, 320)
cmdwindow.index=$PokemonTemp.menuLastChoice
cmdwindow.resizeToFit(commands)
cmdwindow.commands=commands
cmdwindow.x=480-cmdwindow.width
cmdwindow.y=0
cmdwindow.visible=true
loop do
cmdwindow.update
Graphics.update
Input.update
Mouse.update
$mouse.x = Mouse.pos_x
$mouse.y = Mouse.pos_y
pbUpdateSceneMap
if Input.trigger?(Input::B)
ret=-1
break
end
if Input.trigger?(Input::C) || @abortable || Mouse.click?(1)
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
@sprites["button"]=IconSprite.new(20, 340)
@sprites["button"].setBitmap("Graphics/Pictures/button.png")
@sprites["button1"]=IconSprite.new(20, 390)
@sprites["button1"].setBitmap("Graphics/Pictures/button1.png")
@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
if Mouse.mouse_in_area?(20, 340, 71, 46)
if Mouse.click?(1)
pbFadeOutIn(99999) {
scene=PokemonPokedexScene.new
screen=PokemonPokedex.new(scene)
screen.pbStartScreen
@scene.pbRefresh
}
end
end
if Mouse.mouse_in_area?(20, 390, 71, 46)
if Mouse.click?(1)
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
}
end
end
[EMAIL="[email protected](commands"][email protected](commands[/EMAIL])
# if cmdPokedex>=0 && command==cmdPokedex
# pbFadeOutIn(99999) {
# scene=PokemonPokedexScene.new
# screen=PokemonPokedex.new(scene)
# screen.pbStartScreen
# @scene.pbRefresh
# }
if 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
Ok, thank you for posting your example. First, before modifying my menu i wanted to try will even your in original form work for me. But when i used your (i placed all graphics with your width and height in pictures) I was stil unable to use buttons - when i was clicking on them nothing happened. Also when i choose pokedex in standard menu, it just close the menu.
I guess its no point for me trying to use your script as example if it doesn't work for me even in original form.
I wonder what am i doing wrong. If this script works for you and not for me, it must be fault of my game. But i have only standard essentials scripts and Dual screen.
Is it possible, that this script may just not work on Windows 7 64-bit and will be fine on other PCs?
Thank you. My Essentials generally works different than it should. For example it saves games in C\Users\Mackoo\Saved Games instead of putting it in game folder (first it wasn't saving at all, and when I downloaded Curts region starter kit and used it, and then it finally started) so I got same save file ifor all essentials projects I download. But games made in Essentials, like Pokemon Raptor work normal and save game in its folder...Hmm, it can be that although I couldn't see the problem being caused by Windows 7. It's slightly odd aswell how most of the mouse features work when ever they feel like to. I'll have a look into it for you.
Try PokemonScriptProject DS. Ok, this starter kit is in french but with you can transalte it in english. A lot of scripts have been did.
Enjoy :)
Sorry for my bad english
i was thinking i having problem. is anyone can solve this? my mouse not appear infront of sprite it just behind it.Well I was thinking the dual screen, so when the mouse goes onto it is appears.