PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Mausscript



SMWma
18.01.2009, 20:13
Es gibt hier zwar eins, aber dies erfüllt das, wass ich will nicht 100%.
Es besitzt nähmlich ein Problem...
Nämlich benutze ich Karten, die größer als 20X15
Und dies ist das Problem:
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW

WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWW
Die vielen W´s ist die Karte.
Der bunte Berreich[Rot, Orange undGelb] ist die Sicht, die man gerade hat. Warum ich die jetzt bunt gemacht habe, weiß ich nicht mehr :eek:
Nun komm aber das besagte Problem.
Die obere und untere Karte ist die selbe.
Aber die Sicht ist jewals um ein W verschoben.
Trozdem haben die grüne und blaue W´s die gleichen Koordianten.
Und daher, wo man die Karte scrollen kann, kann ich dies nicht mit
Variable X => 123
Variable Y =< 185
bestimmen, sonst würde dies ja bei jeder Srollstellung gehen.
Genauer kann ich dies nicht erklären.
Das folgende Script soll so erweitert werden, dass die Koordianten sich nicht auf das Fenster sondern auf die Karte bestimmen:


#==============================================================================
#
# Mouse Script 1.0 created by: cybersam
# edited by: MagicMagor
#
#==============================================================================
#
# (got rid of cybersams explanation here, because it isn't true for this module)
# MagicMagor
#==============================================================================

#==============================================================================
# I have edited cybersams script, to fit my needs and my personal style of
# coding. I have also extended the script and got rid of several bugs.
# If you use this, give credit to cybersam and me.
#------------------------------------------------------------------------------
# MagicMagor
#==============================================================================

module Mouse

MOUSE_LEFT = 0x01 # left mouse button
MOUSE_RIGHT = 0x02 # right mouse button

attr_reader :MOUSE_LEFT, :MOUSE_RIGHT

# Flags

INIT_CURSOR = 0x01
INIT_SAVE = 0x02
INIT_TYPE = 0x03
CURSOR_PIC = 0x01
CURSOR_ROOT = 0x02
CURSOR_BITMAP = 0x03

attr_reader :INIT_CURSOR, :INIT_SAVE, :INIT_TYPE,
:CURSOR_PIC, :CURSOR_ROOT, :CURSOR_BITMAP


@getCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
@getWindowRect = Win32API.new('user32', 'GetWindowRect', ['p', 'p'], 'i')
@scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
@client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
@readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
@findwindow = Win32API.new('user32', 'FindWindow', %w(p p), 'l')
@getKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')

#---------------------------------------------------------------------------
# Initialize the mouse-system, with given arguments. Is automaticly called
# if needed.
#---------------------------------------------------------------------------
def Mouse.initSystem(*args)
@init = true
@handle = self.getHandle()
@cursor = Sprite.new()
if args.length >= 1
flags = args[0]
@showCursor = (flags & INIT_CURSOR)
@saveToGame = (flags & INIT_SAVE)
withType = (flags & INIT_TYPE)
if (@showCursor != 0)
@showCursor = true
else
@showCursor = false
end
if (@saveToGame != 0)
@saveToGame = true
else
@saveToGame = false
end
@cursor.visible = @showCursor
@originX = 0
@originY = 0
if (@saveToGame)
@gameX = args[-2]
@gameY = args[-1]
end
if (@showCursor)
if (withType)
self.setCursor(args[1], args[2])
else
self.setCursor(args[1])
end
end
end
return nil
end

#---------------------------------------------------------------------------
# Checks if key was pressed.
#---------------------------------------------------------------------------
def Mouse.pressed?(key)
return ((@getKeyState.call(key) & 0x01) == 1)
end

#---------------------------------------------------------------------------
# Returns true if saving mouse positions to game-variables is enabled
#---------------------------------------------------------------------------
def Mouse.saveToGame?()
if !(@init)
self.initSystem(nil)
end
return @saveToGame
end

#---------------------------------------------------------------------------
# Enables saving the mouse positions to game-variables
#---------------------------------------------------------------------------
def Mouse.enableSaveToGame(game_x = nil, game_y = nil )
if !(@init)
self.initSystem(nil)
end
@saveToGame = true
if (game_x != nil)
@gameX = game_x
end
if (game_y != nil)
@gameY = game_y
end
return nil
end

#---------------------------------------------------------------------------
# Disables saving the mouse positions to game-variables
#---------------------------------------------------------------------------
def Mouse.disableSaveToGame()
if !(@init)
self.initSystem(nil)
end
@saveToGame = false
return nil
end

#---------------------------------------------------------------------------
# Sets the variable-ID in which the X position is saved
#---------------------------------------------------------------------------
def Mouse.setGameX(game_x)
if !(@init)
self.initSystem(nil)
end
@gameX = game_x
return nil
end

#---------------------------------------------------------------------------
# Sets the variable-ID in which the Y position is saved
#---------------------------------------------------------------------------
def Mouse.setGameY(game_y)
if !(@init)
self.initSystem(nil)
end
@gameY = game_y
return nil
end

#---------------------------------------------------------------------------
# Returns the variable-ID in which the X position is saved
#---------------------------------------------------------------------------
def Mouse.gameX
return @gameX
end

#---------------------------------------------------------------------------
# Returns the variable-ID in which the Y position is saved
#---------------------------------------------------------------------------
def Mouse.gameY
return @gameY
end

#---------------------------------------------------------------------------
# Returns X-Value of mouse positions
#---------------------------------------------------------------------------
def Mouse.x()
if !(@init)
self.initSystem(nil)
end
x, y = Mouse.mousePos()
return x
end

#---------------------------------------------------------------------------
# Returns Y-Value of mouse positions
#---------------------------------------------------------------------------
def Mouse.y()
if !(@init)
self.initSystem(nil)
end
x, y = Mouse.mousePos()
return y
end

#---------------------------------------------------------------------------
# Returns TRUE when the mouse-cursor is shown.
#---------------------------------------------------------------------------
def Mouse.shown?()
if !(@init)
self.initSystem(nil)
end
return @showCursor
end

#---------------------------------------------------------------------------
# Enables showing of the mouse-cursor.
#---------------------------------------------------------------------------
def Mouse.enableShow()
if !(@init)
self.initSystem(nil)
end
@showCursor = true
@cursor.visible = true
return nil
end

#---------------------------------------------------------------------------
# Disable showing of the mouse-cursor.
#---------------------------------------------------------------------------
def Mouse.disableShow()
if !(@init)
self.initSystem(nil)
end
@showCursor = false
@cursor.visible = false
return nil
end

#---------------------------------------------------------------------------
# Sets a new bitmap for the cursor.
#---------------------------------------------------------------------------
def Mouse.setCursor(filename, type = CURSOR_PIC, originX = 0, originY = 0)
if !(@init)
self.initSystem(nil)
end
@originX = originX
@originY = originY
case type
when CURSOR_PIC
@cursor.bitmap = RPG::Cache.picture(filename)
@cursor.z = 999
return nil
when CURSOR_ROOT
@cursor.bitmap = Bitmap.new(filename)
@cursor.z = 999
return nil
when CURSOR_BITMAP
@cursor.bitmap = filename
@cursor.z = 999
return nil
end
end

#---------------------------------------------------------------------------
# Sets the x-coordinate of the cursor-picture origin.
#---------------------------------------------------------------------------
def Mouse.setOriginX(originX)
if !(@init)
self.initSystem(nil)
end
@originX = originX
return nil
end

#---------------------------------------------------------------------------
# Sets the y-coordinate of the cursor-picture origin.
#---------------------------------------------------------------------------
def Mouse.setOriginY(originY)
if !(@init)
self.initSystem(nil)
end
@originY = originY
return nil
end

#---------------------------------------------------------------------------
# Updates the position of the mouse-cursor on screen.
#---------------------------------------------------------------------------
def Mouse.update()
if !(@init)
self.initSystem(nil)
end
if (@showCursor)
if Mouse.x() != nil
@cursor.x = Mouse.x() - @originX
end
if Mouse.y() != nil
@cursor.y = Mouse.y() - @originY
end
end
if ((@saveToGame) && (@gameX != nil) && (@gameY != nil))
$game_variables[@gameX] = Mouse.x()
$game_variables[@gameY] = Mouse.y()
end
return nil
end

#===============================================================================
# Private methods start here
# Do not call them directly.
# Edit them only if you know what you are doing.
#===============================================================================

#---------------------------------------------------------------------------
# Calculates mouse position inside the programms window.
#---------------------------------------------------------------------------
def Mouse.mousePos(catch_anywhere = false)
x, y = Mouse.screenToClient(*Mouse.getPos)
width, height = Mouse.clientSize()
if ((x == nil) || (y == nil))
return nil
end
if ((catch_anywhere) || ((x >= 0) && (y >= 0) && (x < width) && (y < height)))
return x, y
else
return nil
end
end

#---------------------------------------------------------------------------
# Gets mouse position from OS.
#---------------------------------------------------------------------------
def Mouse.getPos()
if !(@init)
Mouse.initSystem(nil)
end
pos = [0, 0].pack('ll')
if @getCursorPos.call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end

#---------------------------------------------------------------------------
# Transforms screen-coordinates in client-coordinates.
#---------------------------------------------------------------------------
def Mouse.screenToClient(x, y)
if !(@init)
self.initSystem(nil)
end
return nil unless x and y
pos = [x, y].pack('ll')
if @scr2cli.call(@handle, pos) != 0
return pos.unpack('ll')
else
return nil
end
end


#---------------------------------------------------------------------------
# Gets the client size from OS.
#---------------------------------------------------------------------------
def Mouse.clientSize()
if !(@init)
self.initSystem(nil)
end
rect = [0, 0, 0, 0].pack('l4')
@client_rect.call(@handle, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end

#---------------------------------------------------------------------------
# Gets the windows handle from OS.
#---------------------------------------------------------------------------
def Mouse.getHandle()
if !(@init)
self.initSystem(nil)
end
gameName = "\0" * 256
@readini.call('Game', 'Title', '', gameName, 255, ".\\Game.ini")
gameName.delete!("\0")
if ($DEBUG)
# Only one RGSS Player should be open
result = @findwindow.call('RGSS Player', 0)
else
result = @findwindow.call('RGSS Player', gameName)
end
return result
end


end
Ich will es einfach mit Copy + Paste durch das alte ersetzen wollen und nicht das halbe Spiel umprogranmmieren müssen.

Belohnung:
Held im Spiel >Noch geheim<*
Creditseintrag

Der Held wird als besonderer Einheit - wie in Stracraft Jim Raynor - gewertet.

MagicMagor
19.01.2009, 12:08
Ich habe damals mit Absicht das Mausscript nur die Screen-Koordinaten ausgeben lassen, denn mit diesen lässt sich prinzipiell am meisten anfangen. Eine Umrechnung in Maker-Koordinaten wäre möglich, umgekehrt geht das schon nicht mehr.

Ich werde mich heute nachmittag mal dransetzen und die Makerkoordinaten (ich denke du meinst damit die X- und Y-Position des Tiles, über dem sich gerade der Mauszeiger befindet, oder?) als zusätzliche Ausgabe einbauen.

SMWma
19.01.2009, 21:14
achso.
Danke im Vorraus.
Dann wird wohl nur die Heldenrolle vergeben^^

SMWma
23.01.2009, 17:36
alsoooooo....
Was ist jetzt mit der Zúsatzfunktion?

SMWma
24.01.2009, 16:22
also, was ist jetzt mit der Erweiterung?
Schon lange aber vergebens
warte ich auf deine .... ähhh.... erweiterung

Ohne diese werde ich nicht arbeiten können weiter,
ohne dich werde grauenhaft ich scheiter^^

<>Okaj, die Deutsche Sprache kann ich besser^^<>

MagicMagor
27.01.2009, 12:46
Entschuldigung, daß es etwas länger gedauert hat.

Hier ist das neue Mouse-Script mit der Erweiterung:

#==============================================================================
#
# Mouse Script 1.0.1 created by: cybersam
# edited by: MagicMagor
#
#==============================================================================
#
# (got rid of cybersams explanation here, because it isn't true for this module)
# MagicMagor
#==============================================================================

#==============================================================================
# I have edited cybersams script, to fit my needs and my personal style of
# coding. I have also extended the script and got rid of several bugs.
# If you use this, give credit to cybersam and me.
#------------------------------------------------------------------------------
# MagicMagor
#==============================================================================

module Mouse

MOUSE_LEFT = 0x01 # left mouse button
MOUSE_RIGHT = 0x02 # right mouse button

attr_reader :MOUSE_LEFT, :MOUSE_RIGHT

GAME_PIXEL = 0
GAME_TILE = 1

TILE_WIDTH = 32
TILE_HEIGHT = 32

attr_reader :GAME_PIXEL, :GAME_TILE, :TILE_WIDTH, :TILE_HEIGHT

# Flags

INIT_CURSOR = 0x01
INIT_SAVE = 0x02
INIT_TYPE = 0x03
CURSOR_PIC = 0x01
CURSOR_ROOT = 0x02
CURSOR_BITMAP = 0x03

attr_reader :INIT_CURSOR, :INIT_SAVE, :INIT_TYPE,
:CURSOR_PIC, :CURSOR_ROOT, :CURSOR_BITMAP


@getCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
@getWindowRect = Win32API.new('user32', 'GetWindowRect', ['p', 'p'], 'i')
@scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
@client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
@readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
@findwindow = Win32API.new('user32', 'FindWindow', %w(p p), 'l')
@getKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')

#---------------------------------------------------------------------------
# Initialize the mouse-system, with given arguments. Is automaticly called
# if needed.
#---------------------------------------------------------------------------
def Mouse.initSystem(*args)
@init = true
@handle = self.getHandle()
@cursor = Sprite.new()
if args.length >= 1
flags = args[0]
@showCursor = (flags & INIT_CURSOR)
@saveToGame = (flags & INIT_SAVE)
withType = (flags & INIT_TYPE)
if (@showCursor != 0)
@showCursor = true
else
@showCursor = false
end
if (@saveToGame != 0)
@saveToGame = true
else
@saveToGame = false
end
@cursor.visible = @showCursor
@originX = 0
@originY = 0
if (@saveToGame)
@gameX = args[-2]
@gameY = args[-1]
end
if (@showCursor)
if (withType)
self.setCursor(args[1], args[2])
else
self.setCursor(args[1])
end
end
end
if $scene.is_a?(Scene_Map)
@tilemap = $scene.spriteset.tilemap
else
@tilemap = nil
end
@gameType = GAME_PIXEL

return nil
end

#---------------------------------------------------------------------------
# Checks if key was pressed.
#---------------------------------------------------------------------------
def Mouse.pressed?(key)
return ((@getKeyState.call(key) & 0x01) == 1)
end

#---------------------------------------------------------------------------
# Returns true if saving mouse positions to game-variables is enabled
#---------------------------------------------------------------------------
def Mouse.saveToGame?()
if !(@init)
self.initSystem(nil)
end
return @saveToGame
end

#---------------------------------------------------------------------------
# Enables saving the mouse positions to game-variables
#---------------------------------------------------------------------------
def Mouse.enableSaveToGame(game_x = nil, game_y = nil )
if !(@init)
self.initSystem(nil)
end
@saveToGame = true
if (game_x != nil)
@gameX = game_x
end
if (game_y != nil)
@gameY = game_y
end
return nil
end

#---------------------------------------------------------------------------
# Disables saving the mouse positions to game-variables
#---------------------------------------------------------------------------
def Mouse.disableSaveToGame()
if !(@init)
self.initSystem(nil)
end
@saveToGame = false
return nil
end

#---------------------------------------------------------------------------
# Sets the variable-ID in which the X position is saved
#---------------------------------------------------------------------------
def Mouse.setGameX(game_x)
if !(@init)
self.initSystem(nil)
end
@gameX = game_x
return nil
end

#---------------------------------------------------------------------------
# Sets the variable-ID in which the Y position is saved
#---------------------------------------------------------------------------
def Mouse.setGameY(game_y)
if !(@init)
self.initSystem(nil)
end
@gameY = game_y
return nil
end

#---------------------------------------------------------------------------
# Returns the variable-ID in which the X position is saved
#---------------------------------------------------------------------------
def Mouse.gameX
return @gameX
end

#---------------------------------------------------------------------------
# Returns the variable-ID in which the Y position is saved
#---------------------------------------------------------------------------
def Mouse.gameY
return @gameY
end

#---------------------------------------------------------------------------
# Returns X-Value of mouse positions
#---------------------------------------------------------------------------
def Mouse.x()
if !(@init)
self.initSystem(nil)
end
x, y = Mouse.mousePos()
return x
end

#---------------------------------------------------------------------------
# Returns Y-Value of mouse positions
#---------------------------------------------------------------------------
def Mouse.y()
if !(@init)
self.initSystem(nil)
end
x, y = Mouse.mousePos()
return y
end

#---------------------------------------------------------------------------
# Returns TRUE when the tilemap is avaible
#---------------------------------------------------------------------------
def Mouse.tilemap?()
if !(@init)
self.initSystem(nil)
end
return !(@tilemap.nil?)
end

#---------------------------------------------------------------------------
# Returns the x-coordinate of the tile, the cursor is over.
#---------------------------------------------------------------------------
def Mouse.tileX()
if !(@init)
self.initSystem(nil)
end
return ((Mouse.x+Mouse.tileOX) / Mouse::TILE_WIDTH).floor
end

#---------------------------------------------------------------------------
# Returns the y-coordinate of the tile, the cursor is over.
#---------------------------------------------------------------------------
def Mouse.tileY()
if !(@init)
self.initSystem(nil)
end
return ((Mouse.x+Mouse.tileOY) / Mouse::TILE_HEIGHT).floor
end

#---------------------------------------------------------------------------
# Returns the ox-value of the current tilemap (0 if no tilemap is avaible)
#---------------------------------------------------------------------------
def Mouse.tileOX()
if !(@init)
self.initSystem(nil)
end
if !(@tilemap.nil?)
return @tilemap.ox
else
return 0
end
end

#---------------------------------------------------------------------------
# Returns the ox-value of the current tilemap (0 if no tilemap is avaible)
#---------------------------------------------------------------------------
def Mouse.tileOY()
if !(@init)
self.initSystem(nil)
end
if !(@tilemap.nil?)
return @tilemap.oy
else
return 0
end
end

#---------------------------------------------------------------------------
# Returns the current coordinate-type that is stored in game variables
#---------------------------------------------------------------------------
def Mouse.gameType?()
return @gameType
end

#---------------------------------------------------------------------------
# Sets the type of the coordinates, which are stored in game variables
#---------------------------------------------------------------------------
def setGameType(value)
@gameType = value
end

#---------------------------------------------------------------------------
# Returns TRUE when the mouse-cursor is shown.
#---------------------------------------------------------------------------
def Mouse.shown?()
if !(@init)
self.initSystem(nil)
end
return @showCursor
end

#---------------------------------------------------------------------------
# Enables showing of the mouse-cursor.
#---------------------------------------------------------------------------
def Mouse.enableShow()
if !(@init)
self.initSystem(nil)
end
@showCursor = true
@cursor.visible = true
return nil
end

#---------------------------------------------------------------------------
# Disable showing of the mouse-cursor.
#---------------------------------------------------------------------------
def Mouse.disableShow()
if !(@init)
self.initSystem(nil)
end
@showCursor = false
@cursor.visible = false
return nil
end

#---------------------------------------------------------------------------
# Sets a new bitmap for the cursor.
#---------------------------------------------------------------------------
def Mouse.setCursor(filename, type = CURSOR_PIC, originX = 0, originY = 0)
if !(@init)
self.initSystem(nil)
end
@originX = originX
@originY = originY
case type
when CURSOR_PIC
@cursor.bitmap = RPG::Cache.picture(filename)
@cursor.z = 999
return nil
when CURSOR_ROOT
@cursor.bitmap = Bitmap.new(filename)
@cursor.z = 999
return nil
when CURSOR_BITMAP
@cursor.bitmap = filename
@cursor.z = 999
return nil
end
end

#---------------------------------------------------------------------------
# Sets the x-coordinate of the cursor-picture origin.
#---------------------------------------------------------------------------
def Mouse.setOriginX(originX)
if !(@init)
self.initSystem(nil)
end
@originX = originX
return nil
end

#---------------------------------------------------------------------------
# Sets the y-coordinate of the cursor-picture origin.
#---------------------------------------------------------------------------
def Mouse.setOriginY(originY)
if !(@init)
self.initSystem(nil)
end
@originY = originY
return nil
end

#---------------------------------------------------------------------------
# Updates the position of the mouse-cursor on screen.
#---------------------------------------------------------------------------
def Mouse.update()
if !(@init)
self.initSystem(nil)
end
Mouse.updateTilemap()
if (@showCursor)
if Mouse.x() != nil
@cursor.x = Mouse.x() - @originX
end
if Mouse.y() != nil
@cursor.y = Mouse.y() - @originY
end
end
if ((@saveToGame) && (@gameX != nil) && (@gameY != nil))
if @gameType == GAME_PIXEL
$game_variables[@gameX] = Mouse.x()
$game_variables[@gameY] = Mouse.y()
end
if @gameType == GAME_TILE
$game_variables[@gameX] = Mouse.tileX()
$game_variables[@gameY] = Mouse.tileY()
end
end
return nil
end

#---------------------------------------------------------------------------
# Updates the tilemap
#---------------------------------------------------------------------------
def Mouse.updateTilemap()
if $scene.is_a?(Scene_Map)
@tilemap = $scene.spriteset.tilemap
else
@tilemap = nil
end
end

#===============================================================================
# Private methods start here
# Do not call them directly.
# Edit them only if you know what you are doing.
#===============================================================================

#---------------------------------------------------------------------------
# Calculates mouse position inside the programms window.
#---------------------------------------------------------------------------
def Mouse.mousePos(catch_anywhere = false)
x, y = Mouse.screenToClient(*Mouse.getPos)
width, height = Mouse.clientSize()
if ((x == nil) || (y == nil))
return nil
end
if ((catch_anywhere) || ((x >= 0) && (y >= 0) && (x < width) && (y < height)))
return x, y
else
return nil
end
end

#---------------------------------------------------------------------------
# Gets mouse position from OS.
#---------------------------------------------------------------------------
def Mouse.getPos()
if !(@init)
Mouse.initSystem(nil)
end
pos = [0, 0].pack('ll')
if @getCursorPos.call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end

#---------------------------------------------------------------------------
# Transforms screen-coordinates in client-coordinates.
#---------------------------------------------------------------------------
def Mouse.screenToClient(x, y)
if !(@init)
self.initSystem(nil)
end
return nil unless x and y
pos = [x, y].pack('ll')
if @scr2cli.call(@handle, pos) != 0
return pos.unpack('ll')
else
return nil
end
end


#---------------------------------------------------------------------------
# Gets the client size from OS.
#---------------------------------------------------------------------------
def Mouse.clientSize()
if !(@init)
self.initSystem(nil)
end
rect = [0, 0, 0, 0].pack('l4')
@client_rect.call(@handle, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end

#---------------------------------------------------------------------------
# Gets the windows handle from OS.
#---------------------------------------------------------------------------
def Mouse.getHandle()
if !(@init)
self.initSystem(nil)
end
gameName = "\0" * 256
@readini.call('Game', 'Title', '', gameName, 255, ".\\Game.ini")
gameName.delete!("\0")
if ($DEBUG)
# Only one RGSS Player should be open
result = @findwindow.call('RGSS Player', 0)
else
result = @findwindow.call('RGSS Player', gameName)
end
return result
end

#---------------------------------------------------------------------------
# Used for various testing tasks
#---------------------------------------------------------------------------
def Mouse.test()
p(@tilemap.ox)
end

end

class Scene_Map
attr_reader :spriteset
end

class Spriteset_Map
attr_reader :tilemap
end
Es gibt jetzt zwei Möglichkeiten wie du an die Tile-Koordinaten unter dem Cursor kommst.
Die erste ist es, die Koordinaten direkt abzufragen:


Mouse.tileX()
Mouse.tileY()

Diese beiden Funktionen geben jeweils die X- bzw. die Y-Koordinate der Kachel zurück, über der sich momentan der Cursor befindet.
Die zweite Möglichkeit ist diese Koordinaten anstatt der Pixelkoordinaten in Game-Variablen abzulegen.
Dafür muss der "GameTyp" einmal umgestellt werden.

Mouse.setGameType(value)
Mögliche Werte für "value" sind 0 (Pixelkoordinaten) und 1 (Kachel-Koordinaten). Es gibt auch zwei Konstanten namens GAME_PIXEL und GAME_TILE die dafür verwendet werden können.
Es ist nur möglich die Pixel-koordinaten oder die Tile-Koordinaten in Game-variablen abzuspeichern, beides zugleich geht nicht. Der aktuelle Typ kann mit
Mouse.gameType?() abgefragt werden.
Logischerweise muss Mouse.update weiterhin regelmässig ausgeführt werden um die Koordinaten korrekt wiederzugeben. Insbesondere nach einem Mapwechsel sollte Sorge dafür getragen werden, daß Mouse.update einmal ausgeführt wird, bevor auf Mouse.tileX oder Mouse.tileY zugegriffen wird. (Solltest du die Koordinaten aber über Game-Variablen ansprechen, sorgt das Script schon selbst dafür)

Die Berechnung der Kachel-Koordinaten sollte auch in Scenes funktionieren die keine Map sind. In diesem Fall wird so verfahren wie auf einer 20x15 Map, zumindest theoretisch.

Es waren zwei minimale Änderungen an anderen Klassen notwendig. Namentlich Scene_Map und Spriteset_Map um die nötigen Informationen auslesen zu können. Die Änderungen sind in obigem Script schon enthalten, aufgrund dessen könnten aber Änderungen an diesen Klassen theoretisch zu Problemen führen. (Allerdings unwahrscheinlich) Da das kein Stil ist, den ich persönlich mag, ist diese Änderung von mir nicht "offiziell" und es gibt auch keine Garantie für Support sollten Konflikte mit anderen Scripten auftreten.
Sollte das Script aber sonst buggy sein (zB in manchen Fällen falsche Werte zurückgeben) darfst du dich aber gerne melden.

SMWma
27.01.2009, 21:07
kann man jetzt immer noch die normale Option verwenden?
Wenn ja, welche Variablen benutzt die neue Option?

MagicMagor
27.01.2009, 21:16
Es ist nur möglich die Pixel-koordinaten oder die Tile-Koordinaten in Game-variablen abzuspeichern, beides zugleich geht nicht.
Du kannst nur eine der beiden Arten von Koordinaten in Game-Variablen ablegen, in beiden Fällen werden dieselben Variablen benutzt.

Ansonsten kannst du die Tile-Koordinaten über Callscript auch selber in Game-Variablen abspeichern:


$game_variables[10]=Mouse.tileX
$game_variables[11]=Mouse.tileY

tidloc
30.01.2009, 21:15
Leute, Frage:

Ich habs mir grad in einem Testspiel importiert und prompt nachdem ich die Maus initialisiert habe mit

Mouse.initSystem(0x03)
Mouse.setCursor("Maus.png")
Mouse.enableShow()
Mouse.enableSaveToGame(49,50)
Mouse.setOriginX(0)
Mouse.setOriginY(0)
kommt beim aufrufen von

if Mouse.pressed?(MOUSE_LEFT)
die Fehlermeldung:
"Syntax Error occured while running the script"

Nebei erwähnt, ich kann es auf diese if-Bedingung beschränken, da ich jedwegen anderslautenden Code darunte entfernt habe und alles darüber wird mit einer Textbox getrennt und erst danach der Fehler... :(

Bitte um Hilfe!

Edit: Bevor die Frage kommt: das 'end' hab ich natürlich nicht entfernt ;)

LG Tidloc

MagicMagor
31.01.2009, 19:00
Der Fehler kommt dadurch, daß der Maker den Inhalt von "Call Script" zeilenweise von Ruby interpretieren lässt und dann ifs ohne ends natürlich Probleme verursachen.
Kurz gesagt, innerhalb der Call Script Box verwendet man generell keine If oder Schleifen.

Wenn du überprüfen willst ob die linke Maustaste gedrückt ist benutze einen Conditional Branch. Dort kannst du auf der 4. Seite eine Script-Bedingung setzen, in dem Fall dann einfach den Funktionsaufruf ohne das extra if.

tidloc
01.02.2009, 15:11
Aja, jetzt gehts!

super, danke für die Info!