Added more information to terrain tag editor

This commit is contained in:
Maruno17
2021-02-21 20:24:30 +00:00
parent 611d0a74eb
commit bcab462ef0
2 changed files with 166 additions and 147 deletions

View File

@@ -2,6 +2,7 @@
# Terrain tags
#===============================================================================
module PBTerrain
None = 0
Ledge = 1
Grass = 2
Sand = 3
@@ -19,75 +20,61 @@ module PBTerrain
Bridge = 15
Puddle = 16
def self.isSurfable?(tag)
return PBTerrain.isWater?(tag)
module_function
def isSurfable?(tag)
return isWater?(tag)
end
def self.isWater?(tag)
return tag==PBTerrain::Water ||
tag==PBTerrain::StillWater ||
tag==PBTerrain::DeepWater ||
tag==PBTerrain::WaterfallCrest ||
tag==PBTerrain::Waterfall
def isWater?(tag)
return [Water, StillWater, DeepWater, WaterfallCrest, Waterfall].include?(tag)
end
def self.isPassableWater?(tag)
return tag==PBTerrain::Water ||
tag==PBTerrain::StillWater ||
tag==PBTerrain::DeepWater ||
tag==PBTerrain::WaterfallCrest
def isPassableWater?(tag)
return [Water, StillWater, DeepWater, WaterfallCrest].include?(tag)
end
def self.isJustWater?(tag)
return tag==PBTerrain::Water ||
tag==PBTerrain::StillWater ||
tag==PBTerrain::DeepWater
def isJustWater?(tag)
return [Water, StillWater, DeepWater].include?(tag)
end
def self.isDeepWater?(tag)
return tag==PBTerrain::DeepWater
def isDeepWater?(tag)
return tag == DeepWater
end
def self.isWaterfall?(tag)
return tag==PBTerrain::WaterfallCrest ||
tag==PBTerrain::Waterfall
def isWaterfall?(tag)
return [WaterfallCrest, Waterfall].include?(tag)
end
def self.isGrass?(tag)
return tag==PBTerrain::Grass ||
tag==PBTerrain::TallGrass ||
tag==PBTerrain::UnderwaterGrass ||
tag==PBTerrain::SootGrass
def isGrass?(tag)
return [Grass, TallGrass, UnderwaterGrass, SootGrass].include?(tag)
end
def self.isJustGrass?(tag) # The Poké Radar only works in these tiles
return tag==PBTerrain::Grass ||
tag==PBTerrain::SootGrass
def isJustGrass?(tag) # The Poké Radar only works in these tiles
return [Grass, SootGrass].include?(tag)
end
def self.isLedge?(tag)
return tag==PBTerrain::Ledge
def isLedge?(tag)
return tag == Ledge
end
def self.isIce?(tag)
return tag==PBTerrain::Ice
def isIce?(tag)
return tag == Ice
end
def self.isBridge?(tag)
return tag==PBTerrain::Bridge
def isBridge?(tag)
return tag == Bridge
end
def self.hasReflections?(tag)
return tag==PBTerrain::StillWater ||
tag==PBTerrain::Puddle
def hasReflections?(tag)
return [StillWater, Puddle].include?(tag)
end
def self.onlyWalk?(tag)
return tag==PBTerrain::TallGrass ||
tag==PBTerrain::Ice
def onlyWalk?(tag)
return [TallGrass, Ice].include?(tag)
end
def self.isDoubleWildBattle?(tag)
return tag==PBTerrain::TallGrass
def isDoubleWildBattle?(tag)
return tag == TallGrass
end
end

View File

@@ -16,66 +16,17 @@ end
# Edits the terrain tags of tiles in tilesets.
#===============================================================================
class PokemonTilesetScene
TILESET_WIDTH = 256
TILE_SIZE = 32
TILE_SIZE = 32 # in pixels
TILES_PER_ROW = 8
TILESET_WIDTH = TILES_PER_ROW * TILE_SIZE
TILES_PER_AUTOTILE = 48
TILESET_START_ID = TILES_PER_ROW * TILES_PER_AUTOTILE
CURSOR_COLOR = Color.new(255, 0, 0)
TEXT_COLOR = Color.new(80, 80, 80)
TEXT_SHADOW_COLOR = Color.new(192, 192, 192)
def pbUpdateTileset
@sprites["overlay"].bitmap.clear
textpos = []
@sprites["tileset"].src_rect = Rect.new(0,@topy,TILESET_WIDTH,Graphics.height)
tilesize = @tileset.terrain_tags.xsize
for yy in 0...Graphics.height/TILE_SIZE
ypos = (yy+(@topy/TILE_SIZE))*8+384
next if ypos>=tilesize
for xx in 0...8
terr = ypos<384 ? @tileset.terrain_tags[xx*48] : @tileset.terrain_tags[ypos+xx]
if ypos<384
@tilehelper.bltTile(@sprites["overlay"].bitmap,xx*TILE_SIZE,yy*TILE_SIZE,xx*48)
end
textpos.push(["#{terr}",xx*TILE_SIZE+TILE_SIZE/2,yy*TILE_SIZE,2,Color.new(80,80,80),Color.new(192,192,192)])
end
end
@sprites["overlay"].bitmap.fill_rect(@x,@y-@topy,TILE_SIZE,4,Color.new(255,0,0))
@sprites["overlay"].bitmap.fill_rect(@x,@y-@topy,4,TILE_SIZE,Color.new(255,0,0))
@sprites["overlay"].bitmap.fill_rect(@x,@y-@topy+28,TILE_SIZE,4,Color.new(255,0,0))
@sprites["overlay"].bitmap.fill_rect(@x+28,@y-@topy,4,TILE_SIZE,Color.new(255,0,0))
pbDrawTextPositions(@sprites["overlay"].bitmap,textpos)
end
def pbGetSelected(x,y)
return (y<0) ? 48*(x/TILE_SIZE) : (y/TILE_SIZE)*8+384+(x/TILE_SIZE)
end
def pbSetSelected(i,value)
if i<384
for j in 0...48
@tileset.terrain_tags[i+j] = value
end
else
@tileset.terrain_tags[i] = value
end
end
def pbChooseTileset
commands = []
for i in 1...@tilesetwrapper.data.length
commands.push(sprintf("%03d %s",i,@tilesetwrapper.data[i].name))
end
ret = pbShowCommands(nil,commands,-1)
if ret>=0
@tileset = @tilesetwrapper.data[ret+1]
@tilehelper.dispose
@tilehelper = TileDrawingHelper.fromTileset(@tileset)
@sprites["tileset"].setBitmap("Graphics/Tilesets/#{@tileset.tileset_name}")
@x = 0
@y = -TILE_SIZE
@topy = -TILE_SIZE
pbUpdateTileset
end
end
def pbStartScene
@viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
def initialize
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@viewport.z = 99999
@tilesetwrapper = pbTilesetWrapper
@tileset = @tilesetwrapper.data[1]
@@ -83,10 +34,10 @@ class PokemonTilesetScene
@sprites = {}
@sprites["title"] = Window_UnformattedTextPokemon.newWithSize(_INTL("Tileset Editor\r\nPgUp/PgDn: SCROLL\r\nZ: MENU"),
TILESET_WIDTH, 0, Graphics.width - TILESET_WIDTH, 128, @viewport)
@sprites["tileset"] = IconSprite.new(0,0,@viewport)
@sprites["tileset"] = IconSprite.new(0, 0, @viewport)
@sprites["tileset"].setBitmap("Graphics/Tilesets/#{@tileset.tileset_name}")
@sprites["tileset"].src_rect = Rect.new(0,0,TILESET_WIDTH,Graphics.height)
@sprites["overlay"] = BitmapSprite.new(TILESET_WIDTH,Graphics.height,@viewport)
@sprites["tileset"].src_rect = Rect.new(0, 0, TILESET_WIDTH, Graphics.height)
@sprites["overlay"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
@sprites["overlay"].x = 0
@sprites["overlay"].y = 0
pbSetSystemFont(@sprites["overlay"].bitmap)
@@ -96,47 +47,131 @@ class PokemonTilesetScene
@x = 0
@y = -TILE_SIZE
@topy = -TILE_SIZE
height = @sprites["tileset"].bitmap.height
@height = @sprites["tileset"].bitmap.height
pbUpdateTileset
end
def pbUpdateTileset
@sprites["overlay"].bitmap.clear
@sprites["tileset"].src_rect = Rect.new(0, @topy, TILESET_WIDTH, Graphics.height)
# Draw all text over tiles, along with their coordinates (and graphics for autotiles)
textpos = []
tilesize = @tileset.terrain_tags.xsize
for yy in 0...Graphics.height / TILE_SIZE
ypos = (yy + (@topy / TILE_SIZE)) * TILES_PER_ROW + TILESET_START_ID
next if ypos >= tilesize
for xx in 0...TILES_PER_ROW
if ypos < TILESET_START_ID
@tilehelper.bltTile(@sprites["overlay"].bitmap, xx * TILE_SIZE, yy * TILE_SIZE, xx * TILES_PER_AUTOTILE)
end
terr = (ypos < TILESET_START_ID) ? @tileset.terrain_tags[xx * TILES_PER_AUTOTILE] : @tileset.terrain_tags[ypos + xx]
textpos.push(["#{terr}", xx * TILE_SIZE + TILE_SIZE / 2, yy * TILE_SIZE, 2, TEXT_COLOR, TEXT_SHADOW_COLOR])
end
end
pbDrawTextPositions(@sprites["overlay"].bitmap, textpos)
# Draw cursor
@sprites["overlay"].bitmap.fill_rect(@x, @y - @topy, TILE_SIZE, 4, CURSOR_COLOR)
@sprites["overlay"].bitmap.fill_rect(@x, @y - @topy, 4, TILE_SIZE, CURSOR_COLOR)
@sprites["overlay"].bitmap.fill_rect(@x, @y - @topy + TILE_SIZE - 4, TILE_SIZE, 4, CURSOR_COLOR)
@sprites["overlay"].bitmap.fill_rect(@x + TILE_SIZE - 4, @y - @topy, 4, TILE_SIZE, CURSOR_COLOR)
pbUpdateTileInformation
end
def pbUpdateTileInformation
overlay = @sprites["overlay"].bitmap
tile_x = Graphics.width * 3 / 4 - TILE_SIZE
tile_y = Graphics.height / 2 - TILE_SIZE
tile_id = pbGetSelected(@x, @y) || 0
# Draw tile (at 200% size)
@tilehelper.bltSmallTile(overlay, tile_x, tile_y, TILE_SIZE * 2, TILE_SIZE * 2, tile_id)
# Draw box around tile image
overlay.fill_rect(tile_x - 1, tile_y - 1, TILE_SIZE * 2 + 2, 1, Color.new(255, 255, 255))
overlay.fill_rect(tile_x - 1, tile_y - 1, 1, TILE_SIZE * 2 + 2, Color.new(255, 255, 255))
overlay.fill_rect(tile_x - 1, tile_y + TILE_SIZE * 2, TILE_SIZE * 2 + 2, 1, Color.new(255, 255, 255))
overlay.fill_rect(tile_x + TILE_SIZE * 2, tile_y - 1, 1, TILE_SIZE * 2 + 2, Color.new(255, 255, 255))
# Write terrain tag info about selected tile
terrain_tag = @tileset.terrain_tags[tile_id] || 0
terrain_tag_name = getConstantNameOrValue(PBTerrain, terrain_tag)
if terrain_tag_name == terrain_tag.to_s
terrain_tag_name = terrain_tag.to_s
else
terrain_tag_name = sprintf("%d: %s", terrain_tag, terrain_tag_name)
end
textpos = [
[_INTL("Terrain Tag:"), tile_x + TILE_SIZE, tile_y + TILE_SIZE * 2 + 16, 2, Color.new(248, 248, 248), Color.new(40, 40, 40)],
[terrain_tag_name, tile_x + TILE_SIZE, tile_y + TILE_SIZE * 2 + 48, 2, Color.new(248, 248, 248), Color.new(40, 40, 40)]
]
# Draw all text
pbDrawTextPositions(overlay, textpos)
end
def pbChooseTileset
commands = []
for i in 1...@tilesetwrapper.data.length
commands.push(sprintf("%03d %s", i, @tilesetwrapper.data[i].name))
end
ret = pbShowCommands(nil, commands, -1)
if ret >= 0
@tileset = @tilesetwrapper.data[ret + 1]
@tilehelper.dispose
@tilehelper = TileDrawingHelper.fromTileset(@tileset)
@sprites["tileset"].setBitmap("Graphics/Tilesets/#{@tileset.tileset_name}")
@x = 0
@y = -TILE_SIZE
@topy = -TILE_SIZE
pbUpdateTileset
@height = @sprites["tileset"].bitmap.height
end
end
def pbGetSelected(x, y)
return TILES_PER_AUTOTILE * (x / TILE_SIZE) if y < 0 # Autotile
return TILESET_START_ID + (y / TILE_SIZE) * TILES_PER_ROW + (x / TILE_SIZE)
end
def pbSetSelected(i,value)
if i < TILESET_START_ID
for j in 0...TILES_PER_AUTOTILE
@tileset.terrain_tags[i + j] = value
end
else
@tileset.terrain_tags[i] = value
end
end
def update_cursor_position(x_offset, y_offset)
old_x = @x
old_y = @y
if x_offset != 0
@x += x_offset * TILE_SIZE
@x = @x.clamp(0, TILESET_WIDTH - TILE_SIZE)
end
if y_offset != 0
@y += y_offset * TILE_SIZE
@y = @y.clamp(-TILE_SIZE, @height - TILE_SIZE)
@topy = @y if @y < @topy
@topy = @y - Graphics.height + TILE_SIZE if @y >= @topy + Graphics.height
end
pbUpdateTileset if @x != old_x || @y != old_y
end
def pbStartScene
pbFadeInAndShow(@sprites)
########
loop do
Graphics.update
Input.update
if Input.repeat?(Input::UP)
@y -= TILE_SIZE
@y = -TILE_SIZE if @y<-TILE_SIZE
@topy = @y if @y<@topy
pbUpdateTileset
update_cursor_position(0, -1)
elsif Input.repeat?(Input::DOWN)
@y += TILE_SIZE
@y = height-TILE_SIZE if @y>=height-TILE_SIZE
@topy = @y-Graphics.height+TILE_SIZE if @y-@topy>=Graphics.height
pbUpdateTileset
update_cursor_position(0, 1)
elsif Input.repeat?(Input::LEFT)
@x -= TILE_SIZE
@x = 0 if @x<0
pbUpdateTileset
update_cursor_position(-1, 0)
elsif Input.repeat?(Input::RIGHT)
@x += TILE_SIZE
@x = TILESET_WIDTH-TILE_SIZE if @x>=TILESET_WIDTH-TILE_SIZE
pbUpdateTileset
update_cursor_position(1, 0)
elsif Input.repeat?(Input::L)
@y -= (Graphics.height/TILE_SIZE)*TILE_SIZE
@topy -= (Graphics.height/TILE_SIZE)*TILE_SIZE
@y = -TILE_SIZE if @y<-TILE_SIZE
@topy = @y if @y<@topy
@topy = -TILE_SIZE if @topy<-TILE_SIZE
pbUpdateTileset
update_cursor_position(0, -Graphics.height / TILE_SIZE)
elsif Input.repeat?(Input::R)
@y += (Graphics.height/TILE_SIZE)*TILE_SIZE
@topy += (Graphics.height/TILE_SIZE)*TILE_SIZE
@y = height-TILE_SIZE if @y>=height-TILE_SIZE
@topy = @y-Graphics.height+TILE_SIZE if @y-@topy>=Graphics.height
if @topy>=height-Graphics.height
@topy = height-Graphics.height
end
pbUpdateTileset
update_cursor_position(0, Graphics.height / TILE_SIZE)
elsif Input.trigger?(Input::A)
commands = [
_INTL("Go to bottom"),
@@ -144,19 +179,17 @@ class PokemonTilesetScene
_INTL("Change tileset"),
_INTL("Cancel")
]
ret = pbShowCommands(nil,commands,-1)
case ret
case pbShowCommands(nil,commands,-1)
when 0
@y = height-TILE_SIZE
@topy = @y-Graphics.height+TILE_SIZE if @y-@topy>=Graphics.height
@y = @height - TILE_SIZE
@topy = @y - Graphics.height + TILE_SIZE if @y - @topy >= Graphics.height
pbUpdateTileset
when 1
@y = -TILE_SIZE
@topy = @y if @y<@topy
@topy = @y if @y < @topy
pbUpdateTileset
when 2
pbChooseTileset
height = @sprites["tileset"].bitmap.height
end
elsif Input.trigger?(Input::B)
if pbConfirmMessage(_INTL("Save changes?"))
@@ -164,7 +197,7 @@ class PokemonTilesetScene
$data_tilesets = @tilesetwrapper.data
if $game_map && $MapFactory
$MapFactory.setup($game_map.map_id)
$game_player.center($game_player.x,$game_player.y)
$game_player.center($game_player.x, $game_player.y)
if $scene.is_a?(Scene_Map)
$scene.disposeSpritesets
$scene.createSpritesets
@@ -174,15 +207,14 @@ class PokemonTilesetScene
end
break if pbConfirmMessage(_INTL("Exit from the editor?"))
elsif Input.trigger?(Input::C)
selected = pbGetSelected(@x,@y)
selected = pbGetSelected(@x, @y)
params = ChooseNumberParams.new
params.setRange(0,99)
params.setRange(0, 99)
params.setDefaultValue(@tileset.terrain_tags[selected])
pbSetSelected(selected,pbMessageChooseNumber(_INTL("Set the terrain tag."),params))
pbSetSelected(selected,pbMessageChooseNumber(_INTL("Set the terrain tag."), params))
pbUpdateTileset
end
end
########
pbFadeOutAndHide(@sprites)
pbDisposeSpriteHash(@sprites)
@viewport.dispose