设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 4626|回复: 4
打印 上一主题 下一主题

[已经解决] 请问如何把地图以png格式导出

[复制链接]

Lv1.梦旅人

梦石
0
星屑
70
在线时间
12 小时
注册时间
2020-3-19
帖子
2
跳转到指定楼层
1
发表于 2020-3-21 19:13:36 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 人间魔芋爽 于 2020-3-21 19:22 编辑

是不太懂的新人,打算导出地图的png格式直接在sai里加工,但截图和用图块拼接对我来说都有弊端。
听说可以用脚本导出,但脚本方面我完全是个小白,在论坛这边翻了半天也没能找到有类似功能的现成脚本...总而言之有什么办法吗,拜托了!

Lv4.逐梦者 (版主)

职业の水客

梦石
0
星屑
13994
在线时间
7204 小时
注册时间
2010-6-16
帖子
3497

开拓者

来自 5楼
发表于 2023-4-22 12:32:12 | 只看该作者
https://himeworks.com/redirect.p ... name=Map_Screenshot
下面提供的脚本有问题 这里提供原作者的
一个看图的地方
群爆炸重建后状态:论坛老人最多(只剩下了活跃的老人),技术力很强(依旧不变)的编程灌水群:901540785
专门讨论RM相关的Q群:56875149
PS:第一个群不是专门讨论RM的,第二个才是哦。
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
1
星屑
14790
在线时间
2106 小时
注册时间
2017-9-28
帖子
662
2
发表于 2020-3-21 19:31:33 | 只看该作者
按f7


  1. =begin
  2. #===============================================================================
  3. Title: 地图截图
  4. Author: Hime
  5. Date: Sep 25, 2015
  6. --------------------------------------------------------------------------------
  7. ** Change log
  8. Sep 25, 2015
  9.    - fixed placement issue with large sprites
  10. Dec 7, 2014
  11.    - added option to draw certain events
  12. Apr 15, 2013
  13.    - updated script to use GDI+ interface
  14.    - added support for region map overlay and passage map overlay
  15. Apr 6, 2013
  16.    - fixed bug where drawing events crashed the game
  17. Apr 2, 2013
  18.    - map data is now setup by an instance of Game_Map, to account for custom
  19.      map scripts adding to the map
  20. Jul 27
  21.    - Export dirNames are now optional
  22. May 28
  23.    - updated overlay mapping compatibility to draw the overlays
  24.      based on the player's current position
  25.    - fixed issue where import hash was commented out
  26.    - Added support for Yami's overlay mapping
  27. May 24, 2012
  28.    - fixed large characters
  29.    - some optimizations for calculating bounds and dimensions
  30. May 5, 2012
  31.    - fixed waterfall autotile
  32.    - added screenshot feature
  33. May 4, 2012
  34.    - fixed tiles with alpha channel
  35.    - fixed shadows
  36.    - fixed wall autotiles
  37. May 1, 2012
  38.    - fixed wall autotile, although there is still an issue with some tiles
  39. Apr 29, 2012
  40.    - fixed shadow map drawing
  41.    - added region highlighting
  42.    - added damage tile highlighting
  43. Apr 28, 2012
  44.    - Initial Release
  45. ------------------------------------------------------------------------------
  46. ** 介绍

  47. 允许你为游戏中的任何一张地图截取全图像,一张全地图的图像称为"mapshot" (而不是
  48. screenshot).

  49. 本脚本还可以设定地图截图中显示的元素,例如是否显示事件、载具、区域ID或特定的
  50. 图块.

  51. ------------------------------------------------------------------------------
  52. ** 使用方法

  53. 默认地图截图键是 F7. 可以在下面的设定部分里修改.

  54. 为地图截图的方法,首先需要启动游戏,然后按下F7.
  55. 一个文本会显示并告诉你截图成功.图像会保存在游戏目录下的"Mapshots"或"Screenshots"
  56. 文件夹内(默认)。

  57. 此外,你也可以使用脚本来给地图截图.

  58.     Map_Saver.new(地图_id).export
  59.    
  60. 除了输出截图图像,你还可以在游戏里使用已经保存了的地图截图.

  61.    ms = Map_Saver.new(地图_id)
  62.    bmp = ms.map_image
  63.    
  64. 以上方法可以引用一个包含地图截图的位图对象.
  65. --------------------------------------------------------------------------------
  66.   ** Credits

  67.   Cremno
  68.     -GDI+ interface code
  69.   Cidiomar
  70.     -for drawing autotiles and shadows,
  71.     -providing efficient bmp and png exporters
  72.   Moon
  73.     -auto-tile related info
  74.   Mephistox
  75.     -testing and suggestions
  76. ================================================================================
  77. =end
  78. $imported = {} if $imported.nil?
  79. $imported["TH_MapSaver"] = true
  80. #===============================================================================
  81. # ** 设定
  82. #===============================================================================
  83. module TH
  84.   module Map_Saver
  85.    

  86.     Mapshot_Button = Input::F7  # 地图截图键
  87.     Mapshot_Scale = 1           # 缩放比率
  88.    
  89.     Screenshot_Button = Input::F8  # 画面截图键
  90.     Screenshot_Scale = 1           # 缩放比率
  91.    
  92.     Mapshot_Directory = "Mapshots"        # 地图截图文件夹的名称
  93.     Screenshot_Directory = "Screenshots"  # 画面截图文件夹的名称
  94.    
  95.     # 导出的图片格式. 最好只用 png.
  96.     # 可选: [bmp, png]
  97.     Export_Format = "png"
  98.    
  99.     Draw_Events = true      # 是否在截图里显示事件
  100.     Draw_Player = false    # 是否在截图里显示玩家
  101.     Draw_Followers = false # 是否在截图里显示队友
  102.     Draw_Vehicles = false  # 是否在截图里显示载具
  103.    
  104.     #是否显示影子? 影子的颜色?
  105.     Draw_Shadow = false
  106.     Shadow_Color = Color.new(0, 0, 0, 128)
  107.    
  108.     # 是否显示区域? 需要脚本 "Region Overlay Map"
  109.     Draw_Regions = false
  110.    
  111.     # 是否显示地图图块的通行度? 需要脚本 "Passage Overlay Map"
  112.     Draw_Passages = false
  113.    
  114.     #带地形伤害的图块是否高亮显示? 用什么颜色?
  115.     Highlight_Damage = false
  116.     Damage_Color = Color.new(128, 0, 0, 128)
  117.   end
  118. end

  119. #==============================================================================
  120. # ** Module: Map_Tiles
  121. # Contains data and methods useful for working with maps and tiles
  122. #==============================================================================

  123. module Map_Tiles
  124.   AUTOTILE_PARTS = [[18,17,14,13], [ 2,14,17,18], [13, 3,17,18], [ 2, 3,17,18],
  125.                     [13,14,17, 7], [ 2,14,17, 7], [13, 3,17, 7], [ 2, 3,17, 7],
  126.                     [13,14, 6,18], [ 2,14, 6,18], [13, 3, 6,18], [ 2, 3, 6,18],
  127.                     [13,14, 6, 7], [ 2,14, 6, 7], [13, 3, 6, 7], [ 2, 3, 6, 7],
  128.                     [16,17,12,13], [16, 3,12,13], [16,17,12, 7], [12, 3,16, 7],
  129.                     [10, 9,14,13], [10, 9,14, 7], [10, 9, 6,13], [10, 9, 6, 7],
  130.                     [18,19,14,15], [18,19, 6,15], [ 2,19,14,15], [ 2,19, 6,15],
  131.                     [18,17,22,21], [ 2,17,22,21], [18, 3,22,21], [ 2, 3,21,22],
  132.                     [16,19,12,15], [10, 9,22,21], [ 8, 9,12,13], [ 8, 9,12, 7],
  133.                     [10,11,14,15], [10,11, 6,15], [18,19,22,23], [ 2,19,22,23],
  134.                     [16,17,20,21], [16, 3,20,21], [ 8,11,12,15], [ 8, 9,20,21],
  135.                     [16,19,20,23], [10,11,22,23], [ 8,11,20,23], [ 0, 1, 4, 5]]
  136.   WATERFALL_PIECES = [[ 2, 1, 6, 5], [ 0, 1, 4, 5], [ 2, 3, 6, 7], [0, 3, 4, 7]]
  137.   WALL_PIECES =  [[10, 9, 6, 5], [ 8, 9, 4, 5], [ 2, 1, 6, 5], [ 0, 1, 4, 5],
  138.                   [10,11, 6, 7], [ 8,11, 4, 7], [ 2, 3, 6, 7], [ 0, 3, 4, 7],
  139.                   [10, 9,14,13], [ 8, 9,12,13], [ 2, 1,14,13], [ 0, 1,12,13],
  140.                   [10,11,14,15], [8, 11,12,15], [ 2, 3,14,15], [ 0, 3,12,15]]

  141.   A1_TILES = [[0, 0], [0, 96], [192, 0], [192, 96],
  142.                [256, 0], [448, 0], [256, 96], [448, 96],
  143.                [0, 192], [192, 192], [0, 288], [192, 288],
  144.                [256, 192], [448, 192], [256, 288], [448, 288]]
  145.    
  146.   
  147.   #--------------------------------------------------------------------------
  148.   # * Checks if a tile is a wall
  149.   #--------------------------------------------------------------------------
  150.   def is_wall?(data)
  151.     return true if data.between?(2288, 2335)
  152.     return true if data.between?(2384, 2431)
  153.     return true if data.between?(2480, 2527)
  154.     return true if data.between?(2576, 2623)
  155.     return true if data.between?(2672, 2719)
  156.     return true if data.between?(2768, 2815)
  157.     return true if data.between?(4736, 5119)
  158.     return true if data.between?(5504, 5887)
  159.     return true if data.between?(6272, 6655)
  160.     return true if data.between?(7040, 7423)
  161.     return true if data > 7807
  162.     false
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # * Checks if a tile is roof
  166.   #--------------------------------------------------------------------------
  167.   def is_roof?(data)
  168.     return true if data.between?(4352, 4735)
  169.     return true if data.between?(5120, 5503)
  170.     return true if data.between?(5888, 6271)
  171.     return true if data.between?(6656, 7039)
  172.     return true if data.between?(7424, 7807)
  173.     false
  174.   end  
  175.   #--------------------------------------------------------------------------
  176.   # * Checks if a tile is soil
  177.   #--------------------------------------------------------------------------
  178.   def is_soil?(data)
  179.     return true if data.between?(2816, 4351) && !is_table?(data)
  180.     return true if data > 1663 && !is_stair?(data)
  181.     false
  182.   end   
  183.   #--------------------------------------------------------------------------
  184.   # * Checks if a tile is a stair
  185.   #--------------------------------------------------------------------------
  186.   def is_stair?(data)
  187.      return true if data.between?(1541, 1542)
  188.      return true if data.between?(1549, 1550)
  189.      return true if data.between?(1600, 1615)
  190.      false
  191.   end
  192.   #--------------------------------------------------------------------------
  193.   # * Checks if a tile is a table
  194.   #--------------------------------------------------------------------------
  195.   def is_table?(data)
  196.     return true if data.between?(3152, 3199)
  197.     return true if data.between?(3536, 3583)
  198.     return true if data.between?(3920, 3967)
  199.     return true if data.between?(4304, 4351)
  200.     false
  201.   end

  202.   #--------------------------------------------------------------------------
  203.   # * The tileset to be used
  204.   #--------------------------------------------------------------------------
  205.   def tileset
  206.     $data_tilesets[@tileset_id]
  207.   end
  208.   
  209.   #--------------------------------------------------------------------------
  210.   # * Region ID
  211.   #--------------------------------------------------------------------------
  212.   def region_id(x, y)
  213.     valid?(x, y) ? @map.data[x, y, 3] >> 8 : 0
  214.   end
  215.   
  216.   #--------------------------------------------------------------------------
  217.   # * Gets all of the tiles for each layer at position x,y
  218.   #--------------------------------------------------------------------------
  219.   def layered_tiles(x, y)
  220.     [2, 1, 0].collect {|z| @map.data[x, y, z] }
  221.   end
  222.   
  223.   def layered_tiles_flag?(x, y, bit)
  224.     layered_tiles(x, y).any? {|tile_id| tileset.flags[tile_id] & bit != 0 }
  225.   end
  226.    
  227.   def valid?(x, y)
  228.     x >= 0 && x < width && y >= 0 && y < height
  229.   end
  230.   
  231.   def damage_floor?(x, y)
  232.     valid?(x, y) && layered_tiles_flag?(x, y, 0x100)
  233.   end
  234.   
  235.   #--------------------------------------------------------------------------
  236.   # * Specifies which type of autotile is used
  237.   #--------------------------------------------------------------------------
  238.   def auto_tile(id)
  239.     id / 48
  240.   end
  241.   
  242.   #--------------------------------------------------------------------------
  243.   # * Specifies the specific arrangement of autotiles used
  244.   #--------------------------------------------------------------------------
  245.   def auto_index(id)
  246.     id % 48
  247.   end
  248.   
  249.   #--------------------------------------------------------------------------
  250.   # * Put the auto-tile pieces together
  251.   #--------------------------------------------------------------------------
  252.   def make_autotile(rects, sx, sy)
  253.     @tile.clear
  254.     for i in 0...4
  255.       @auto_rect.x = (rects[i] % 4) * 16 + sx
  256.       @auto_rect.y = (rects[i] / 4) * 16 + sy
  257.       @tile.blt((i % 2) * 16,(i / 2) * 16, @tilemap, @auto_rect)
  258.     end
  259.   end
  260.      
  261.   #--------------------------------------------------------------------------
  262.   # * Get auto-tile A1 tiles
  263.   #--------------------------------------------------------------------------
  264.   def autotile_A1(tile_id)
  265.     @tilemap = @bitmaps[0]
  266.     autotile = tile_id / 48
  267.     auto_id = tile_id % 48
  268.     sx, sy = A1_TILES[autotile]
  269.     if is_wall?(tile_id + 2048)
  270.       rects = WATERFALL_PIECES[auto_id]
  271.     else  
  272.       rects = AUTOTILE_PARTS[auto_id]
  273.     end
  274.     make_autotile(rects, sx, sy)
  275.   end
  276.   
  277.   #--------------------------------------------------------------------------
  278.   # * Get auto-tile A2 tiles.
  279.   # 64x96 tiles, 8 per row, 4 rows
  280.   #--------------------------------------------------------------------------
  281.   def autotile_A2(tile_id)
  282.     autotile = tile_id / 48
  283.     auto_id = tile_id % 48
  284.     @tilemap = @bitmaps[1]
  285.     sx = (autotile % 8) * 64
  286.     sy = (autotile / 8 % 4) * 96
  287.     rects = AUTOTILE_PARTS[auto_id]
  288.     make_autotile(rects, sx, sy)
  289.   end
  290.   
  291.   #--------------------------------------------------------------------------
  292.   # * Get auto-tile A3 tiles.
  293.   # 64x64 tiles, 8 per row, 4 rows
  294.   #--------------------------------------------------------------------------
  295.   def autotile_A3(tid)
  296.     @tilemap = @bitmaps[2]
  297.     sx = (auto_tile(tid) % 8) * 64
  298.     sy = (auto_tile(tid) / 8 % 4) * 64
  299.     rects = WALL_PIECES[auto_index(tid)]
  300.     make_autotile(rects, sx, sy)
  301.   end
  302.   
  303.   #--------------------------------------------------------------------------
  304.   # * Get auto-tile A4 tiles (walls)
  305.   #--------------------------------------------------------------------------
  306.   def autotile_A4(tile_id)
  307.     @tilemap = @bitmaps[3]
  308.     autotile = tile_id / 48
  309.     auto_id = tile_id % 48
  310.     sx = (autotile % 8) * 64
  311.     sy = (autotile / 16 * 160) + (autotile / 8 % 2) * 96
  312.     if is_wall?(tile_id + 5888)
  313.       rects = WALL_PIECES[auto_id]
  314.     else
  315.       rects = AUTOTILE_PARTS[auto_id]
  316.     end
  317.     make_autotile(rects, sx, sy)
  318.   end
  319.   
  320.   #--------------------------------------------------------------------------
  321.   # * Get auto-tile A5 tiles (normal)
  322.   #--------------------------------------------------------------------------
  323.   def autotile_A5(tile_id)
  324.     @tilemap = @bitmaps[4]
  325.     sx = (tile_id) % 8 * tilesize
  326.     sy = (tile_id) / 8 * tilesize
  327.     @src_rect.set(sx, sy, tilesize, tilesize)
  328.     @tile.clear
  329.     @tile.blt(0, 0, @tilemap, @src_rect)
  330.   end
  331.   
  332.   #--------------------------------------------------------------------------
  333.   # * Get normal tiles B, C, D, E
  334.   #--------------------------------------------------------------------------
  335.   def normal_tile(tile_id)
  336.     @tilemap = @bitmaps[5 + tile_id / 256]
  337.     sx = (tile_id / 128 % 2 * 8 + tile_id % 8) * tilesize;
  338.     sy = (tile_id % 256 / 8 % 16) * tilesize;
  339.     @src_rect.set(sx, sy, tilesize, tilesize)
  340.     @tile.clear
  341.     @tile.blt(0, 0, @tilemap, @src_rect)
  342.   end
  343.    
  344.   #--------------------------------------------------------------------------
  345.   # * Get bitmap for the specified tile id
  346.   #--------------------------------------------------------------------------
  347.   def get_bitmap(id)
  348.     if id < 1024
  349.       normal_tile(id)
  350.     elsif id < 1664
  351.       autotile_A5(id - 1536)
  352.     elsif id < 2816
  353.       autotile_A1(id - 2048)
  354.     elsif id < 4352
  355.       autotile_A2(id - 2816)
  356.     elsif id < 5888
  357.       autotile_A3(id - 4352)
  358.     else
  359.       autotile_A4(id - 5888)
  360.     end
  361.   end
  362. end

  363. #==============================================================================
  364. # **
  365. #==============================================================================

  366. class Game_Player < Game_Character
  367.   
  368.   alias :th_mapsaver_update :update
  369.   def update
  370.     th_mapsaver_update
  371.     if Input.trigger?(TH::Map_Saver::Mapshot_Button)
  372.       s = Map_Saver.new($game_map.map_id)
  373.       s.set_scale(TH::Map_Saver::Mapshot_Scale)
  374.       s.mapshot
  375.     end
  376.     if Input.trigger?(TH::Map_Saver::Screenshot_Button)
  377.       s = Map_Saver.new($game_map.map_id)
  378.       s.set_scale(TH::Map_Saver::Screenshot_Scale)
  379.       s.screenshot
  380.     end
  381.   end
  382. end

  383. class Game_Vehicle < Game_Character
  384.   attr_reader :map_id
  385. end

  386. class Game_Map
  387.   attr_reader :map
  388. end

  389. #==============================================================================
  390. # **
  391. #==============================================================================

  392. class Map_Saver
  393.   include TH::Map_Saver
  394.   include Map_Tiles
  395.   #--------------------------------------------------------------------------
  396.   # * Constants
  397.   #--------------------------------------------------------------------------

  398.   SHADOW_COLOR = TH::Map_Saver::Shadow_Color
  399.   DAMAGE_COLOR = TH::Map_Saver::Damage_Color

  400.   #--------------------------------------------------------------------------
  401.   # * Public instance variables
  402.   #--------------------------------------------------------------------------
  403.   attr_reader :map_image
  404.   
  405.   def initialize(map_id=$game_map.map_id, x=$game_player.x, y=$game_player.y)
  406.     @scale = 1
  407.     @local_x = x
  408.     @local_y = y
  409.     @screen_local = false
  410.     @shadow_bitmap = Bitmap.new(128, 128)
  411.     @draw_layer0 = true
  412.     @draw_layer1 = true
  413.     @draw_layer2 = true
  414.     @draw_events = Draw_Events
  415.     @draw_vehicles = Draw_Vehicles
  416.     @draw_player = Draw_Player
  417.     @draw_followers = Draw_Followers
  418.     @draw_shadow = Draw_Shadow
  419.     @draw_damage = Highlight_Damage
  420.     @draw_regions = Draw_Regions
  421.     @draw_passages = Draw_Passages
  422.     @tile = Bitmap.new(32, 32) #stores the current tile to be drawn
  423.     @tilemap = nil
  424.     @src_rect = Rect.new
  425.     @auto_rect = Rect.new(0, 0, tilesize / 2, tilesize/ 2) #constant
  426.     @tile_rect = Rect.new(0, 0, tilesize, tilesize)        #constant
  427.   end
  428.   
  429.   def load_tilesets
  430.     bitmaps = []
  431.     tileset.tileset_names.each_with_index do |name, i|
  432.       bitmaps[i] = Cache.tileset(name)
  433.     end
  434.     return bitmaps
  435.   end
  436.   
  437.   #--------------------------------------------------------------------------
  438.   # * Refresh, possibly with a new map
  439.   #--------------------------------------------------------------------------
  440.   def redraw(map_id=$game_map.map_id, x=$game_player.x, y=$game_player.y)
  441.     @map_image.dispose if @map_image
  442.     @map_id = map_id
  443.     @local_x = x
  444.     @local_y = y
  445.     @game_map = Game_Map.new
  446.     @game_map.setup(map_id)
  447.     @map = @game_map.map
  448.     @map_info = $data_mapinfos[map_id]
  449.     @screen = $game_map.screen
  450.     @tileset_id = @game_map.tileset.id
  451.     @bitmaps = load_tilesets
  452.    
  453.     get_bounds
  454.     @map_image = Bitmap.new(@width * tilesize, @height * tilesize)
  455.     draw_map
  456.     scale_map if @scale != 1
  457.   end
  458.   
  459.   #--------------------------------------------------------------------------
  460.   # * Pre-process. These will never change when drawing the map.
  461.   #--------------------------------------------------------------------------
  462.   def get_bounds
  463.     @start_x = start_x
  464.     @start_y = start_y
  465.     @end_x = end_x
  466.     @end_y = end_y
  467.     @width = width
  468.     @height = height
  469.     @tilesize = tilesize
  470.   end
  471.   
  472.   def screen_tile_x
  473.     Graphics.width / 32
  474.   end
  475.   
  476.   def screen_tile_y
  477.     Graphics.height / 32
  478.   end
  479.   
  480.   #--------------------------------------------------------------------------
  481.   # * Sets the scale for the map
  482.   #--------------------------------------------------------------------------
  483.   def set_scale(scale)
  484.     @scale = scale
  485.   end
  486.   
  487.   #--------------------------------------------------------------------------
  488.   # * Size of a tile
  489.   #--------------------------------------------------------------------------
  490.   def tilesize
  491.     32
  492.   end
  493.   
  494.   #--------------------------------------------------------------------------
  495.   # * Width and height of the map, both locally and globally
  496.   #--------------------------------------------------------------------------
  497.   def width
  498.     end_x - @start_x
  499.   end
  500.   
  501.   def height
  502.     end_y - @start_y
  503.   end
  504.   
  505.   #--------------------------------------------------------------------------
  506.   # * Starting and end positions, relative to the screen or map
  507.   #--------------------------------------------------------------------------
  508.   def start_x
  509.     @screen_local ? [[$game_player.x - screen_tile_x / 2, @map.width - screen_tile_x].min, 0].max : 0
  510.   end

  511.   def start_y
  512.     @screen_local ? [[$game_player.y - screen_tile_y / 2, @map.height - screen_tile_y].min, 0].max : 0
  513.   end
  514.   
  515.   def end_x
  516.     @screen_local ? [[screen_tile_x, @local_x + screen_tile_x / 2 + 1].max, @map.width].min : @map.width
  517.   end
  518.   
  519.   def end_y
  520.     @screen_local ? [[screen_tile_y, @local_y + screen_tile_y / 2 + 1].max, @map.height].min : @map.height
  521.   end

  522.   #--------------------------------------------------------------------------
  523.   # * Draw tile onto image. x and y values are absolute coords. They should
  524.   # be re-mapped based on the start_x and start_y values
  525.   #--------------------------------------------------------------------------
  526.   def draw_tile(x, y, tile, rect)
  527.     ox = (x - @start_x) * tilesize
  528.     oy = (y - @start_y) * tilesize
  529.     @map_image.blt(ox, oy, tile, rect)
  530.   end
  531.   
  532.   def draw_character(x, y, width, height, bmp, rect)
  533.     ox = (x - @start_x) * tilesize
  534.     oy = (y - @start_y) * tilesize
  535.    
  536.     ox = ox - width / 4 if width > 32
  537.     oy = oy - height / 2 if height > 32
  538.     @map_image.blt(ox, oy, bmp, rect)
  539.   end
  540.   
  541.   #--------------------------------------------------------------------------
  542.   # * Get bitmap for the specified character
  543.   #--------------------------------------------------------------------------
  544.   def get_character_bitmap(name)
  545.     charmap = Cache.character(name)
  546.     sign = name[/^[\!\$]./]
  547.     if sign && sign.include?(')
  548.       cw = charmap.width / 3
  549.       ch = charmap.height / 4
  550.     else
  551.       cw = charmap.width / 12
  552.       ch = charmap.height / 8
  553.     end
  554.     return charmap, cw, ch
  555.   end
  556.   
  557.   #--------------------------------------------------------------------------
  558.   # * Draw the character onto the tile
  559.   #--------------------------------------------------------------------------
  560.   def set_character_bitmap(character, x, y)
  561.     charmap, cw, ch = get_character_bitmap(character.character_name)
  562.     index = character.character_index
  563.     pattern = character.pattern < 3 ? character.pattern : 1
  564.     sx = (index % 4 * 3 + pattern) * cw
  565.     sy = (index / 4 * 4 + (character.direction - 2) / 2) * ch
  566.     @src_rect.set(sx, sy, cw, ch)
  567.     draw_character(x, y, cw, ch, charmap, @src_rect)
  568.   end
  569.   
  570.   #--------------------------------------------------------------------------
  571.   # * create the shadow map
  572.   #--------------------------------------------------------------------------
  573.   def make_shadow_map
  574.     for s in 0 ... 16
  575.       x = s % 4
  576.       y = s / 4
  577.       if s & 0b1000 == 0b1000
  578.         @shadow_bitmap.fill_rect(x*tilesize+16, y*@tilesize+16, 16, 16, SHADOW_COLOR)
  579.       end
  580.       if s & 0b0100 == 0b0100
  581.         @shadow_bitmap.fill_rect(x*tilesize, y*@tilesize+16, 16, 16, SHADOW_COLOR)
  582.       end
  583.       if s & 0b0010 == 0b0010
  584.         @shadow_bitmap.fill_rect(x*tilesize+16, y*@tilesize, 16, 16, SHADOW_COLOR)
  585.       end
  586.       if s & 0b0001 == 0b0001
  587.         @shadow_bitmap.fill_rect(x*tilesize, y*@tilesize, 16, 16, SHADOW_COLOR)
  588.       end
  589.     end
  590.   end
  591.   
  592.   def draw_parallax
  593.     image = Cache.parallax(@map.parallax_name)
  594.     @src_rect.set(0, 0, image.width, image.height)
  595.     @map_image.blt(0, 0, image, @src_rect)
  596.   end
  597.   
  598.   #--------------------------------------------------------------------------
  599.   # * Draw the shadow map
  600.   #--------------------------------------------------------------------------
  601.   def draw_shadow_map
  602.     for x in @start_x ... @end_x
  603.       for y in @start_y ... @end_y
  604.       _x, _y = x*@tilesize, y*@tilesize
  605.         s = @map.data[x, y, 3]  & 0b1111
  606.         if s != 0
  607.           x_ = (s % 4) * @tilesize
  608.           y_ = (s / 4) * @tilesize
  609.           @src_rect.set(x_, y_, @tilesize, @tilesize)
  610.           draw_tile(x, y, @shadow_bitmap, @src_rect)
  611.         end
  612.       end
  613.     end
  614.   end
  615.   
  616.   #--------------------------------------------------------------------------
  617.   # * Draw the specified layer
  618.   #--------------------------------------------------------------------------
  619.   def draw_layer(layer)
  620.     for x in @start_x ... @end_x
  621.       for y in @start_y ... @end_y
  622.         _x, _y = x*@tilesize, y*@tilesize
  623.         tile_id = @map.data[x, y, layer]
  624.         next if tile_id == 0
  625.         get_bitmap(tile_id)
  626.         draw_tile(x, y, @tile, @tile_rect)
  627.       end
  628.     end
  629.   end
  630.   
  631.   #-----------------------------------------------------------------------------
  632.   # Draw game regions
  633.   #-----------------------------------------------------------------------------
  634.   def draw_regions
  635.     if $imported["TH_RegionOverlay"]
  636.       image = SceneManager.scene.instance_variable_get(:@spriteset).instance_variable_get(:@region_map).bitmap
  637.       @src_rect.set(@start_x * tilesize, @start_y * tilesize, image.width, image.height)
  638.       @map_image.blt(0, 0, image, @src_rect, 255)
  639.     end
  640.   end
  641.   
  642.   def draw_passages
  643.     if $imported["TH_OverlayPassageMap"]
  644.       image = SceneManager.scene.instance_variable_get(:@spriteset).instance_variable_get(:@passage_map).bitmap
  645.       @src_rect.set(@start_x * tilesize, @start_y * tilesize, image.width, image.height)
  646.       @map_image.blt(0, 0, image, @src_rect, 255)
  647.     end
  648.   end

  649.   #--------------------------------------------------------------------------
  650.   # * Draw the game player
  651.   #--------------------------------------------------------------------------
  652.   def draw_player
  653.     set_character_bitmap($game_player, $game_player.x, $game_player.y) if @map_id == $game_map.map_id
  654.   end
  655.   
  656.   def draw_followers
  657.   end
  658.   
  659.   #--------------------------------------------------------------------------
  660.   # * Draw map events
  661.   #--------------------------------------------------------------------------
  662.   def draw_events
  663.     @map.events.values.each do |event|
  664.       canDraw = event.pages[0].list.any? do |cmd|
  665.         cmd.code == 108 && cmd.parameters[0] =~ /<screenshot:\s*tile\s*>/i
  666.       end
  667.       next unless @draw_events || canDraw
  668.       id = event.pages[0].graphic.tile_id
  669.       char_name = event.pages[0].graphic.character_name
  670.       if id > 0
  671.         normal_tile(id)
  672.         draw_tile(event.x, event.y, @tilemap, @src_rect)
  673.       elsif char_name != ""
  674.         set_character_bitmap(event.pages[0].graphic, event.x, event.y)
  675.       end
  676.     end
  677.   end
  678.   
  679.   #--------------------------------------------------------------------------
  680.   # * Draw map vehicles
  681.   #--------------------------------------------------------------------------
  682.   def draw_vehicles
  683.     $game_map.vehicles.each do |vehicle|
  684.       set_character_bitmap(vehicle, vehicle.x, vehicle.y) if @map_id == vehicle.map_id
  685.     end
  686.   end
  687.   
  688.   #--------------------------------------------------------------------------
  689.   # * Draw map sprites
  690.   #--------------------------------------------------------------------------
  691.   def draw_sprites
  692.     draw_events
  693.     draw_vehicles if @draw_vehicles
  694.     draw_player if @draw_player
  695.     draw_followers if @draw_followers
  696.   end
  697.   
  698.   #--------------------------------------------------------------------------
  699.   # * Highlight damage tiles
  700.   #--------------------------------------------------------------------------
  701.   def draw_damage
  702.     @tile.clear
  703.     @tile.fill_rect(0, 0, @tilesize, @tilesize, DAMAGE_COLOR)
  704.     @src_rect.set(0, 0, @tilesize, @tilesize)
  705.     for x in @start_x ... @end_x
  706.       for y in @start_y ... @end_y
  707.         _x, _y = x*@tilesize, y*@tilesize
  708.         if damage_floor?(x, y)
  709.           draw_tile(x, y, @tile, @src_rect)
  710.         end
  711.       end
  712.     end
  713.   end
  714.   
  715.   def draw_screen_effects
  716.   end
  717.   #--------------------------------------------------------------------------
  718.   # * Draw the map
  719.   #--------------------------------------------------------------------------
  720.   def draw_map
  721.     make_shadow_map if @draw_shadow
  722.     draw_parallax
  723.     draw_layer(0)
  724.     draw_layer(1)
  725.     draw_shadow_map
  726.     draw_layer(2)
  727.     draw_damage if @draw_damage
  728.     draw_regions if @draw_regions
  729.     draw_passages if @draw_passages
  730.     draw_sprites
  731.     draw_screen_effects
  732.   end
  733.   
  734.   #--------------------------------------------------------------------------
  735.   # * Scale the map
  736.   #--------------------------------------------------------------------------
  737.   def scale_map
  738.     nw = @width * @scale
  739.     nh = @height * @scale
  740.     @src_rect.set(0, 0, @width, @height)
  741.     scaled_map = Bitmap.new(nw, nh)
  742.     scaled_rect = Rect.new(0, 0, nw, nh)
  743.     scaled_map.stretch_blt(scaled_rect, @map_image, @src_rect)
  744.     @map_image = scaled_map
  745.   end
  746.   
  747.   #--------------------------------------------------------------------------
  748.   # * Take a mapshot of the map
  749.   #--------------------------------------------------------------------------
  750.   def mapshot
  751.     @screen_local = false
  752.     redraw
  753.     export(TH::Map_Saver::Mapshot_Directory)
  754.     $game_message.add("截图成功")
  755.   end
  756.    
  757.   #--------------------------------------------------------------------------
  758.   # * Take a screenshot of the map
  759.   #--------------------------------------------------------------------------
  760.   def screenshot
  761.     @screen_local = true
  762.     redraw
  763.     export(TH::Map_Saver::Screenshot_Directory)
  764.     $game_message.add("截图成功")
  765.   end
  766.   
  767.   #--------------------------------------------------------------------------
  768.   # * Get the format to export to
  769.   #--------------------------------------------------------------------------
  770.   def get_format
  771.     TH::Map_Saver::Export_Format
  772.   end
  773.   
  774.   #--------------------------------------------------------------------------
  775.   # * Export the map to a file
  776.   #--------------------------------------------------------------------------
  777.   def export(dirName="")
  778.     format = get_format
  779.     #name = @map.display_name != "" ? @map.display_name : @map_info.name
  780.     name = sprintf("Map%03d" %[@map_id])
  781.     Dir.mkdir(dirName) unless File.directory?(dirName)
  782.     name =
  783.     filename = "%s\\%s.%s" %[dirName, name, format]
  784.     t1 = Time.now
  785.     @map_image.save(filename)
  786.     t2 = Time.now
  787.     $game_message.add("截图已导出,用时: %f 秒" %[t2 - t1])
  788.   end
  789. end

  790. class Bitmap

  791.   def save(filename, options = {})
  792.     options.merge!(format: File.extname(filename)[1..-1].to_sym)
  793.     retval = false
  794.     #bitmap = Gdiplus::Bitmap.new(:hbitmap, hbitmap)
  795.     #bitmap = Gdiplus::Bitmap.new(:gdidib, *gdidib)
  796.     # this seems to be the fastest one (RGSS 3.0.1, Windows 8 64-bit)
  797.     bitmap = Gdiplus::Bitmap.new(:scan0, width, height, scan0)
  798.     if bitmap
  799.       retval = bitmap.save(:file, filename, options[:format])
  800.       bitmap.dispose
  801.     end
  802.     retval
  803.   end

  804. private

  805.   def _data_struct(offset = 0)
  806.     @_data_struct ||= (DL::CPtr.new((object_id << 1) + 16).ptr + 8).ptr
  807.     (@_data_struct + offset).ptr.to_i
  808.   end

  809.   def gdidib
  810.      [_data_struct(8), _data_struct(16)]
  811.   end

  812.   def hbitmap
  813.     _data_struct(44)
  814.   end

  815.   def scan0
  816.     _data_struct(12)
  817.   end

  818. end

  819. # ★ GDI+ interface
  820. # ★★★★★★★★★★★★
  821. #
  822. # Author : Cremno
  823. #

  824. module Gdiplus
  825.   DLL = 'gdiplus.dll'

  826.   def self.get_function name, import, export = 'L'
  827.     Win32API.new DLL, name, import, export
  828.   end

  829.   FUNCTIONS = {
  830.     GdiplusStartup: get_function('GdiplusStartup', 'PPP'),
  831.     GdiplusShutdown: get_function('GdiplusShutdown', 'P', 'V'),
  832.     GdipDisposeImage: get_function('GdipDisposeImage', 'P'),
  833.     GdipSaveImageToFile: get_function('GdipSaveImageToFile', 'PPPP'),
  834.     GdipCreateBitmapFromGdiDib: get_function('GdipCreateBitmapFromGdiDib', 'LLP'),
  835.     GdipCreateBitmapFromHBITMAP: get_function('GdipCreateBitmapFromHBITMAP', 'LLP'),
  836.     GdipCreateBitmapFromScan0: get_function('GdipCreateBitmapFromScan0', 'LLLLPP')
  837.   }

  838.   @@token = [0].pack('I')
  839.   def self.token
  840.     @@token
  841.   end

  842.   @@clsids = {}
  843.   def self.clsids
  844.     @@clsids
  845.   end

  846.   def self.gen_clsids
  847.     return unless @@clsids.empty?
  848.     func = Win32API.new('rpcrt4.dll', 'UuidFromString', 'PP', 'L')
  849.     {
  850.       bmp:  '557cf400-1a04-11d3-9a73-0000f81ef32e',
  851.       jpeg: '557cf401-1a04-11d3-9a73-0000f81ef32e',
  852.       gif:  '557cf402-1a04-11d3-9a73-0000f81ef32e',
  853.       tiff: '557cf405-1a04-11d3-9a73-0000f81ef32e',
  854.       png:  '557cf406-1a04-11d3-9a73-0000f81ef32e'
  855.     }.each_pair do |k, v|
  856.       clsid = [0].pack('I')
  857.       func.call(v, clsid)
  858.       @@clsids[k] = clsid
  859.     end
  860.     @@clsids[:jpg] = @@clsids[:jpeg]
  861.     @@clsids[:tif] = @@clsids[:tiff]
  862.   end

  863.   # TODO: prepend prefix (Gdip or Gdiplus) automatically
  864.   def self.call(*args)
  865.     name = args.shift
  866.     func = FUNCTIONS[name]
  867.     v = func.call(*args)
  868.     if v && v != 0
  869.       msgbox "GDI+ error: #{v}\n\nFunction: #{name}\nArguments: #{args.inspect}"
  870.       false
  871.     else
  872.       true
  873.     end
  874.   end

  875.   def self.startup
  876.     call :GdiplusStartup, @@token, [1, 0, 0, 0].pack('L4'), 0
  877.   end

  878.   def self.shutdown
  879.     call :GdiplusShutdown, @@token
  880.   end

  881.   class Image

  882.     attr_reader :instance
  883.     def initialize
  884.       @instance = 0
  885.       true
  886.     end

  887.     def save(destination, *args)
  888.       case destination
  889.       when :file
  890.         filename = args.shift << "\0"
  891.         filename.encode!('UTF-16LE')
  892.         argv = [:GdipSaveImageToFile, filename, Gdiplus.clsids[args.shift], 0]
  893.       else
  894.         raise ArgumentError, "unknown GDI+ image destination: #{source}"
  895.       end
  896.       argv.insert(1, @instance)
  897.       Gdiplus.call *argv
  898.     end

  899.     def dispose
  900.       Gdiplus.call :GdipDisposeImage, @instance
  901.     end
  902.   end

  903.   class Bitmap < Image

  904.     def initialize source, *args
  905.       case source
  906.       when :gdidib
  907.         argv = [:GdipCreateBitmapFromGdiDib, args.shift, args.shift]
  908.       when :hbitmap
  909.         argv = [:GdipCreateBitmapFromHBITMAP, args.shift, 0]
  910.       when :scan0
  911.         w = args.shift
  912.         h = args.shift
  913.         argv = [:GdipCreateBitmapFromScan0, w, h, w * -4, 0x26200a, args.shift]
  914.       else
  915.         raise ArgumentError, "unknown GDI+ bitmap source: #{source}"
  916.       end
  917.       argv.push([0].pack('I'))
  918.       retval = Gdiplus.call *argv
  919.       @instance = retval ? argv.last.unpack('I').first : 0
  920.       retval
  921.     end
  922.   end
  923. end

  924. if Gdiplus.startup
  925.   Gdiplus.gen_clsids
  926.   class << SceneManager
  927.     alias_method :run_wo_gdip_shutdown, :run
  928.     def run
  929.       run_wo_gdip_shutdown
  930.       Gdiplus.shutdown
  931.     end
  932.   end
  933. end

  934. #==============================================================================
  935. # * Compatibility add-ons
  936. #==============================================================================
  937. #Yami overlays
  938. if $imported["YSE-OverlayMapping"]
  939.   class Map_Saver
  940.     def draw_overlay_map_ground
  941.       filename = YSA::OVERLAY::GROUND
  942.       filename += $game_map.map_id.to_s
  943.       filename += "-" + $game_variables[YSA::OVERLAY::GROUND_VARIABLE].to_s
  944.       p filename
  945.       image = Cache.overlay(filename)
  946.       @src_rect.set(@start_x*tilesize, @start_y*tilesize, image.width, image.height)
  947.       @map_image.blt(0, 0, image, @src_rect)
  948.     end
  949.    
  950.     def draw_overlay_map_parallax
  951.       filename = YSA::OVERLAY::PARALLAX
  952.       filename += $game_map.map_id.to_s
  953.       filename += "-" + $game_variables[YSA::OVERLAY::PARALLAX_VARIABLE].to_s
  954.       image = Cache.overlay(filename)
  955.       @src_rect.set(@start_x*tilesize, @start_y*tilesize, image.width, image.height)
  956.       @map_image.blt(0, 0, image, @src_rect)
  957.     end
  958.    
  959.     def draw_overlay_map_light
  960.       filename = YSA::OVERLAY::LIGHT
  961.       filename += $game_map.map_id.to_s
  962.       filename += "-" + $game_variables[YSA::OVERLAY::LIGHT_VARIABLE].to_s
  963.       image = Cache.overlay(filename)
  964.       @src_rect.set(@start_x*tilesize, @start_y*tilesize, image.width, image.height)
  965.       @map_image.blt(0, 0, image, @src_rect, 10)
  966.     end
  967.    
  968.     def draw_overlay_map_shadow
  969.       filename = YSA::OVERLAY::SHADOW
  970.       filename += $game_map.map_id.to_s
  971.       filename += "-" + $game_variables[YSA::OVERLAY::SHADOW_VARIABLE].to_s
  972.       image = Cache.overlay(filename)
  973.       @src_rect.set(@start_x*tilesize, @start_y*tilesize, image.width, image.height)
  974.       @map_image.blt(0, 0, image, @src_rect, 10)
  975.     end
  976.   
  977.     alias :th_map_overlay_draw_map :draw_map
  978.     def draw_map
  979.       th_map_overlay_draw_map
  980.       draw_overlay_map_ground if $game_switches[YSA::OVERLAY::GROUND_SWITCH]
  981.       draw_overlay_map_parallax if $game_switches[YSA::OVERLAY::PARALLAX_SWITCH]
  982.       draw_overlay_map_shadow if $game_switches[YSA::OVERLAY::SHADOW_SWITCH]
  983.       draw_overlay_map_light if $game_switches[YSA::OVERLAY::LIGHT_SWITCH]
  984.     end
  985.   end
  986. end

  987. if $imported["TH_AreaOverlay"]
  988.   class Map_Saver
  989.     def draw_overlay_area_map
  990.       image = SceneManager.scene.instance_variable_get(:@spriteset).instance_variable_get(:@area_map).bitmap
  991.       @src_rect.set(@start_x * tilesize, @start_y * tilesize, image.width, image.height)
  992.       @map_image.blt(0, 0, image, @src_rect, 255)
  993.     end
  994.    
  995.     alias :th_area_overlay_draw_map :draw_map
  996.     def draw_map
  997.       th_area_overlay_draw_map
  998.       draw_overlay_area_map
  999.     end
  1000.   end
  1001. end
复制代码

评分

参与人数 1星屑 +30 收起 理由
alexncf125 + 30 塞糖

查看全部评分

VA外站脚本汉化群:226308173   |    部分远古文件备份:https://wwzv.lanzoue.com/b02rac5pc  密码:acgm
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
70
在线时间
12 小时
注册时间
2020-3-19
帖子
2
3
 楼主| 发表于 2020-3-21 20:05:07 | 只看该作者



非常感谢!不过游戏测试显示出错无法运行...能再请问一下这是什么问题吗
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
55
在线时间
7 小时
注册时间
2022-2-14
帖子
1
4
发表于 2022-4-7 17:59:09 | 只看该作者
人间魔芋爽 发表于 2020-3-21 20:05
**** 作者被禁止或删除 内容自动屏蔽 ****

我也有这个问题,请问你是否得到解决了呢?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-22 03:37

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表