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

Project1

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

[有事请教] 地图如何导出截图

[复制链接]

Lv1.梦旅人

梦石
0
星屑
32
在线时间
2 小时
注册时间
2025-2-22
帖子
2
跳转到指定楼层
1
发表于 2025-2-22 16:18:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
求助,之前看空猫大佬的那个教程,里面网盘网址过期了
想知道如何才能把地图截图导出,导入ps中修改

Lv4.逐梦者

梦石
0
星屑
5875
在线时间
793 小时
注册时间
2019-1-20
帖子
217
2
发表于 2025-2-23 15:22:19 | 只看该作者
论坛左上角有 搜索 功能,
你可以找一个相对应版本的,比较符合自己实际情况的用。

提高解决问题的方法:
查看对应版本的帮助文件或者默认脚本中可能相似的部分 看有没有思路能照搬(不是)
改变问题为更有可能的,常见的,系统性的 如:天气自动变化成下雨→天气系统 要多想几种可能
使用论坛的搜索功能查找相关问题 咦?这跟我想的不一样啊!讨厌啦~\(≧□≦)/~啦啦啦
清楚说明实际上你想解决的问题  想看坛友的女装,想看!  
脚本自己有改过的地方要尽量标明  提高除BUG效率 ... ...
脚本有问题但不是默认脚本的要全部贴出来 大胆点,尽情发,我说的是女装照!
三包原则:包有BUG,包甩锅,包咕咕 长期下线,急事换人!难事换人!啥事都换人!换人换人换人!!!
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
1
星屑
14282
在线时间
2107 小时
注册时间
2017-9-28
帖子
663
3
发表于 昨天 22:30 | 只看该作者
  1. =begin
  2. #===============================================================================
  3. Title: Map Screenshot 地图截图
  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. 默认的截取地图截图按键是F7。可以在配置部分更改此设置。

  48. 要截取地图截图,请先启动游戏,然后按F7。
  49. 将出现一条消息,通知您已成功截取地图截图。

  50. 或者,您可以使用脚本调用来截取地图截图。

  51.     Map_Saver.new(map_id).export

  52. 除了导出图像外,您还可以使用地图保存器捕获的图像。

  53.    ms = Map_Saver.new(map_id)
  54.    bmp = ms.map_image

  55. 这将为您提供一个Bitmap对象的引用,该对象包含您地图的图像。
  56. --------------------------------------------------------------------------------
  57.   ** 致谢

  58.   Cremno
  59.     -GDI+接口代码
  60.   Cidiomar
  61.     -用于绘制自动图块和阴影
  62.     -提供高效的bmp和png导出器
  63.   Moon
  64.     -自动图块相关信息
  65.   Mephistox
  66.     -测试和建议
  67. ================================================================================
  68. =end
  69. $imported = {} if $imported.nil?
  70. $imported["TH_MapSaver"] = true
  71. #===============================================================================
  72. # ** 配置
  73. #===============================================================================
  74. module TH
  75.   module Map_Saver
  76.    
  77.     #地图截图选项。这会截取整个地图的图像
  78.     Mapshot_Button = Input::F7
  79.     Mapshot_Scale = 1
  80.    
  81.     #屏幕截图选项。这会截取可见地图的图像
  82.     Screenshot_Button = Input::F6
  83.     Screenshot_Scale = 1
  84.    
  85.     #地图导出到的文件夹
  86.     Mapshot_Directory = "Mapshots"
  87.     Screenshot_Directory = "Screenshots"
  88.    
  89.     # 要导出的格式。您应该坚持使用png。
  90.     # 选项: [bmp, png]
  91.     Export_Format = "png"
  92.    
  93.     # 精灵绘制选项
  94.     Draw_Events = false
  95.     Draw_Player = false
  96.     Draw_Followers = false
  97.     Draw_Vehicles = false
  98.    
  99.     #是否绘制阴影?什么颜色?
  100.     Draw_Shadow = false
  101.     Shadow_Color = Color.new(0, 0, 0, 128)
  102.    
  103.     # 是否绘制区域?需要"Region Overlay Map"脚本
  104.     Draw_Regions = false
  105.    
  106.     # 是否绘制通行设置?需要"Passage Overlay Map"脚本
  107.     Draw_Passages = false
  108.    
  109.     #是否高亮显示伤害图块?什么颜色?
  110.     Highlight_Damage = false
  111.     Damage_Color = Color.new(128, 0, 0, 128)
  112.   end
  113. end

  114. #==============================================================================
  115. # ** Module: Map_Tiles
  116. # Contains data and methods useful for working with maps and tiles
  117. #==============================================================================

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

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

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

  358. #==============================================================================
  359. # **
  360. #==============================================================================

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

  378. class Game_Vehicle < Game_Character
  379.   attr_reader :map_id
  380. end

  381. class Game_Map
  382.   attr_reader :map
  383. end

  384. #==============================================================================
  385. # **
  386. #==============================================================================

  387. class Map_Saver
  388.   include TH::Map_Saver
  389.   include Map_Tiles
  390.   #--------------------------------------------------------------------------
  391.   # * Constants
  392.   #--------------------------------------------------------------------------

  393.   SHADOW_COLOR = TH::Map_Saver::Shadow_Color
  394.   DAMAGE_COLOR = TH::Map_Saver::Damage_Color

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

  506.   def start_y
  507.     @screen_local ? [[$game_player.y - screen_tile_y / 2, @map.height - screen_tile_y].min, 0].max : 0
  508.   end
  509.   
  510.   def end_x
  511.     @screen_local ? [[screen_tile_x, @local_x + screen_tile_x / 2 + 1].max, @map.width].min : @map.width
  512.   end
  513.   
  514.   def end_y
  515.     @screen_local ? [[screen_tile_y, @local_y + screen_tile_y / 2 + 1].max, @map.height].min : @map.height
  516.   end

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

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

  785. class Bitmap

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

  799. private

  800.   def _data_struct(offset = 0)
  801.     @_data_struct ||= (DL::CPtr.new((object_id << 1) + 16).ptr + 8).ptr
  802.     (@_data_struct + offset).ptr.to_i
  803.   end

  804.   def gdidib
  805.      [_data_struct(8), _data_struct(16)]
  806.   end

  807.   def hbitmap
  808.     _data_struct(44)
  809.   end

  810.   def scan0
  811.     _data_struct(12)
  812.   end

  813. end

  814. # ★ GDI+ interface
  815. # ★★★★★★★★★★★★
  816. #
  817. # Author : Cremno
  818. #

  819. module Gdiplus
  820.   DLL = 'gdiplus.dll'

  821.   def self.get_function name, import, export = 'L'
  822.     Win32API.new DLL, name, import, export
  823.   end

  824.   FUNCTIONS = {
  825.     GdiplusStartup: get_function('GdiplusStartup', 'PPP'),
  826.     GdiplusShutdown: get_function('GdiplusShutdown', 'P', 'V'),
  827.     GdipDisposeImage: get_function('GdipDisposeImage', 'P'),
  828.     GdipSaveImageToFile: get_function('GdipSaveImageToFile', 'PPPP'),
  829.     GdipCreateBitmapFromGdiDib: get_function('GdipCreateBitmapFromGdiDib', 'LLP'),
  830.     GdipCreateBitmapFromHBITMAP: get_function('GdipCreateBitmapFromHBITMAP', 'LLP'),
  831.     GdipCreateBitmapFromScan0: get_function('GdipCreateBitmapFromScan0', 'LLLLPP')
  832.   }

  833.   @@token = [0].pack('I')
  834.   def self.token
  835.     @@token
  836.   end

  837.   @@clsids = {}
  838.   def self.clsids
  839.     @@clsids
  840.   end

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

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

  870.   def self.startup
  871.     call :GdiplusStartup, @@token, [1, 0, 0, 0].pack('L4'), 0
  872.   end

  873.   def self.shutdown
  874.     call :GdiplusShutdown, @@token
  875.   end

  876.   class Image

  877.     attr_reader :instance
  878.     def initialize
  879.       @instance = 0
  880.       true
  881.     end

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

  894.     def dispose
  895.       Gdiplus.call :GdipDisposeImage, @instance
  896.     end
  897.   end

  898.   class Bitmap < Image

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

  919. if Gdiplus.startup
  920.   Gdiplus.gen_clsids
  921.   class << SceneManager
  922.     alias_method :run_wo_gdip_shutdown, :run
  923.     def run
  924.       run_wo_gdip_shutdown
  925.       Gdiplus.shutdown
  926.     end
  927.   end
  928. end

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

  982. if $imported["TH_AreaOverlay"]
  983.   class Map_Saver
  984.     def draw_overlay_area_map
  985.       image = SceneManager.scene.instance_variable_get(:@spriteset).instance_variable_get(:@area_map).bitmap
  986.       @src_rect.set(@start_x * tilesize, @start_y * tilesize, image.width, image.height)
  987.       @map_image.blt(0, 0, image, @src_rect, 255)
  988.     end
  989.    
  990.     alias :th_area_overlay_draw_map :draw_map
  991.     def draw_map
  992.       th_area_overlay_draw_map
  993.       draw_overlay_area_map
  994.     end
  995.   end
  996. end
复制代码
VA外站脚本汉化群:226308173   |    部分远古文件备份:https://wwzv.lanzoue.com/b02rac5pc  密码:acgm
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-10-4 08:27

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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