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

Project1

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

[已经解决] 我想问一下怎样把整张大地图截图给截下来?

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3642
在线时间
912 小时
注册时间
2017-1-19
帖子
269
跳转到指定楼层
1
发表于 2019-9-30 15:10:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
地图太大整张截不下来,有什么办法!

Lv4.逐梦者

梦石
8
星屑
4801
在线时间
1567 小时
注册时间
2014-1-9
帖子
402

开拓者

2
发表于 2019-9-30 16:23:57 | 只看该作者
搜索 航拍
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3642
在线时间
912 小时
注册时间
2017-1-19
帖子
269
3
 楼主| 发表于 2019-9-30 16:46:49 | 只看该作者

航拍是xp的
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9330
在线时间
1257 小时
注册时间
2017-9-27
帖子
149
4
发表于 2019-9-30 17:22:35 | 只看该作者
RUBY 代码复制
  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.  ** Description
  47.  
  48.  This script allows you to take a full image of any of your game's maps
  49.  and export. An image of the map is referred to as a "mapshot" (as opposed to
  50.  screenshot).
  51.  
  52.  The script provides various configuration options to control what kinds of
  53.  things you want to see on your map, such as events, vehicles, region ID's, or
  54.  specific tile properties.
  55.  
  56. ------------------------------------------------------------------------------
  57.  ** Usage
  58.  
  59.  The default key for taking a mapshot is F7. This can be changed in the
  60.  configuration section.
  61.  
  62.  To take a mapshot, first start the game, and then hit F7.
  63.  A message will appear informing you that a mapshot was successfully taken.
  64.  
  65.  Alternatively, you can use script calls to take mapshots.
  66.  
  67.     Map_Saver.new(map_id).export
  68.     
  69.  Aside from exporting images, you are able to use the image that the
  70.  map saver captures.
  71.  
  72.    ms = Map_Saver.new(map_id)
  73.    bmp = ms.map_image
  74.    
  75.  This gives you a reference to a Bitmap object that contains an image of
  76.  your map.
  77. --------------------------------------------------------------------------------
  78.   ** Credits
  79.  
  80.   Cremno
  81.     -GDI+ interface code
  82.   Cidiomar
  83.     -for drawing autotiles and shadows,
  84.     -providing efficient bmp and png exporters
  85.   Moon
  86.     -auto-tile related info
  87.   Mephistox
  88.     -testing and suggestions
  89. ================================================================================
  90. =end
  91. $imported = {} if $imported.nil?
  92. $imported["TH_MapSaver"] = true
  93. #===============================================================================
  94. # ** Configuration
  95. #===============================================================================
  96. module TH
  97.   module Map_Saver
  98.  
  99.     #Mapshot options. This takes an image of the entire map
  100.     Mapshot_Button = Input::F7
  101.     Mapshot_Scale = 1
  102.  
  103.     #Screenshot options. This takes an image of the visible map
  104.     Screenshot_Button = Input::F6
  105.     Screenshot_Scale = 1
  106.  
  107.     #Folder that the map will be exported to
  108.     Mapshot_Directory = "Mapshots"
  109.     Screenshot_Directory = "Screenshots"
  110.  
  111.     # format you want to export to. You should stick with png.
  112.     # Options: [bmp, png]
  113.     Export_Format = "png"
  114.  
  115.     # Sprite draw options
  116.     Draw_Events = true
  117.     Draw_Player = true
  118.     Draw_Followers = true
  119.     Draw_Vehicles = true
  120.  
  121.     #Should shadows be drawn? What color?
  122.     Draw_Shadow = true
  123.     Shadow_Color = Color.new(0, 0, 0, 128)
  124.  
  125.     # Should regions be drawn? Requires "Region Overlay Map" script
  126.     Draw_Regions = false
  127.  
  128.     # Should passage settings be drawn? Requires "Passage Overlay Map" script
  129.     Draw_Passages = false
  130.  
  131.     #Should damage tiles be highlighted? What color?
  132.     Highlight_Damage = true
  133.     Damage_Color = Color.new(128, 0, 0, 128)
  134.   end
  135. end
  136.  
  137. #==============================================================================
  138. # ** Module: Map_Tiles
  139. # Contains data and methods useful for working with maps and tiles
  140. #==============================================================================
  141.  
  142. module Map_Tiles
  143.   AUTOTILE_PARTS = [[18,17,14,13], [ 2,14,17,18], [13, 3,17,18], [ 2, 3,17,18],
  144.                     [13,14,17, 7], [ 2,14,17, 7], [13, 3,17, 7], [ 2, 3,17, 7],
  145.                     [13,14, 6,18], [ 2,14, 6,18], [13, 3, 6,18], [ 2, 3, 6,18],
  146.                     [13,14, 6, 7], [ 2,14, 6, 7], [13, 3, 6, 7], [ 2, 3, 6, 7],
  147.                     [16,17,12,13], [16, 3,12,13], [16,17,12, 7], [12, 3,16, 7],
  148.                     [10, 9,14,13], [10, 9,14, 7], [10, 9, 6,13], [10, 9, 6, 7],
  149.                     [18,19,14,15], [18,19, 6,15], [ 2,19,14,15], [ 2,19, 6,15],
  150.                     [18,17,22,21], [ 2,17,22,21], [18, 3,22,21], [ 2, 3,21,22],
  151.                     [16,19,12,15], [10, 9,22,21], [ 8, 9,12,13], [ 8, 9,12, 7],
  152.                     [10,11,14,15], [10,11, 6,15], [18,19,22,23], [ 2,19,22,23],
  153.                     [16,17,20,21], [16, 3,20,21], [ 8,11,12,15], [ 8, 9,20,21],
  154.                     [16,19,20,23], [10,11,22,23], [ 8,11,20,23], [ 0, 1, 4, 5]]
  155.   WATERFALL_PIECES = [[ 2, 1, 6, 5], [ 0, 1, 4, 5], [ 2, 3, 6, 7], [0, 3, 4, 7]]
  156.   WALL_PIECES =  [[10, 9, 6, 5], [ 8, 9, 4, 5], [ 2, 1, 6, 5], [ 0, 1, 4, 5],
  157.                   [10,11, 6, 7], [ 8,11, 4, 7], [ 2, 3, 6, 7], [ 0, 3, 4, 7],
  158.                   [10, 9,14,13], [ 8, 9,12,13], [ 2, 1,14,13], [ 0, 1,12,13],
  159.                   [10,11,14,15], [8, 11,12,15], [ 2, 3,14,15], [ 0, 3,12,15]]
  160.  
  161.   A1_TILES = [[0, 0], [0, 96], [192, 0], [192, 96],
  162.                [256, 0], [448, 0], [256, 96], [448, 96],
  163.                [0, 192], [192, 192], [0, 288], [192, 288],
  164.                [256, 192], [448, 192], [256, 288], [448, 288]]
  165.  
  166.  
  167.   #--------------------------------------------------------------------------
  168.   # * Checks if a tile is a wall
  169.   #--------------------------------------------------------------------------
  170.   def is_wall?(data)
  171.     return true if data.between?(2288, 2335)
  172.     return true if data.between?(2384, 2431)
  173.     return true if data.between?(2480, 2527)
  174.     return true if data.between?(2576, 2623)
  175.     return true if data.between?(2672, 2719)
  176.     return true if data.between?(2768, 2815)
  177.     return true if data.between?(4736, 5119)
  178.     return true if data.between?(5504, 5887)
  179.     return true if data.between?(6272, 6655)
  180.     return true if data.between?(7040, 7423)
  181.     return true if data > 7807
  182.     false
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # * Checks if a tile is roof
  186.   #--------------------------------------------------------------------------
  187.   def is_roof?(data)
  188.     return true if data.between?(4352, 4735)
  189.     return true if data.between?(5120, 5503)
  190.     return true if data.between?(5888, 6271)
  191.     return true if data.between?(6656, 7039)
  192.     return true if data.between?(7424, 7807)
  193.     false
  194.   end  
  195.   #--------------------------------------------------------------------------
  196.   # * Checks if a tile is soil
  197.   #--------------------------------------------------------------------------
  198.   def is_soil?(data)
  199.     return true if data.between?(2816, 4351) && !is_table?(data)
  200.     return true if data > 1663 && !is_stair?(data)
  201.     false
  202.   end   
  203.   #--------------------------------------------------------------------------
  204.   # * Checks if a tile is a stair
  205.   #--------------------------------------------------------------------------
  206.   def is_stair?(data)
  207.      return true if data.between?(1541, 1542)
  208.      return true if data.between?(1549, 1550)
  209.      return true if data.between?(1600, 1615)
  210.      false
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # * Checks if a tile is a table
  214.   #--------------------------------------------------------------------------
  215.   def is_table?(data)
  216.     return true if data.between?(3152, 3199)
  217.     return true if data.between?(3536, 3583)
  218.     return true if data.between?(3920, 3967)
  219.     return true if data.between?(4304, 4351)
  220.     false
  221.   end
  222.  
  223.   #--------------------------------------------------------------------------
  224.   # * The tileset to be used
  225.   #--------------------------------------------------------------------------
  226.   def tileset
  227.     $data_tilesets[@tileset_id]
  228.   end
  229.  
  230.   #--------------------------------------------------------------------------
  231.   # * Region ID
  232.   #--------------------------------------------------------------------------
  233.   def region_id(x, y)
  234.     valid?(x, y) ? @map.data[x, y, 3] >> 8 : 0
  235.   end
  236.  
  237.   #--------------------------------------------------------------------------
  238.   # * Gets all of the tiles for each layer at position x,y
  239.   #--------------------------------------------------------------------------
  240.   def layered_tiles(x, y)
  241.     [2, 1, 0].collect {|z| @map.data[x, y, z] }
  242.   end
  243.  
  244.   def layered_tiles_flag?(x, y, bit)
  245.     layered_tiles(x, y).any? {|tile_id| tileset.flags[tile_id] & bit != 0 }
  246.   end
  247.  
  248.   def valid?(x, y)
  249.     x >= 0 && x < width && y >= 0 && y < height
  250.   end
  251.  
  252.   def damage_floor?(x, y)
  253.     valid?(x, y) && layered_tiles_flag?(x, y, 0x100)
  254.   end
  255.  
  256.   #--------------------------------------------------------------------------
  257.   # * Specifies which type of autotile is used
  258.   #--------------------------------------------------------------------------
  259.   def auto_tile(id)
  260.     id / 48
  261.   end
  262.  
  263.   #--------------------------------------------------------------------------
  264.   # * Specifies the specific arrangement of autotiles used
  265.   #--------------------------------------------------------------------------
  266.   def auto_index(id)
  267.     id % 48
  268.   end
  269.  
  270.   #--------------------------------------------------------------------------
  271.   # * Put the auto-tile pieces together
  272.   #--------------------------------------------------------------------------
  273.   def make_autotile(rects, sx, sy)
  274.     @tile.clear
  275.     for i in 0...4
  276.       @auto_rect.x = (rects[i] % 4) * 16 + sx
  277.       @auto_rect.y = (rects[i] / 4) * 16 + sy
  278.       @tile.blt((i % 2) * 16,(i / 2) * 16, @tilemap, @auto_rect)
  279.     end
  280.   end
  281.  
  282.   #--------------------------------------------------------------------------
  283.   # * Get auto-tile A1 tiles
  284.   #--------------------------------------------------------------------------
  285.   def autotile_A1(tile_id)
  286.     @tilemap = @bitmaps[0]
  287.     autotile = tile_id / 48
  288.     auto_id = tile_id % 48
  289.     sx, sy = A1_TILES[autotile]
  290.     if is_wall?(tile_id + 2048)
  291.       rects = WATERFALL_PIECES[auto_id]
  292.     else  
  293.       rects = AUTOTILE_PARTS[auto_id]
  294.     end
  295.     make_autotile(rects, sx, sy)
  296.   end
  297.  
  298.   #--------------------------------------------------------------------------
  299.   # * Get auto-tile A2 tiles.
  300.   # 64x96 tiles, 8 per row, 4 rows
  301.   #--------------------------------------------------------------------------
  302.   def autotile_A2(tile_id)
  303.     autotile = tile_id / 48
  304.     auto_id = tile_id % 48
  305.     @tilemap = @bitmaps[1]
  306.     sx = (autotile % 8) * 64
  307.     sy = (autotile / 8 % 4) * 96
  308.     rects = AUTOTILE_PARTS[auto_id]
  309.     make_autotile(rects, sx, sy)
  310.   end
  311.  
  312.   #--------------------------------------------------------------------------
  313.   # * Get auto-tile A3 tiles.
  314.   # 64x64 tiles, 8 per row, 4 rows
  315.   #--------------------------------------------------------------------------
  316.   def autotile_A3(tid)
  317.     @tilemap = @bitmaps[2]
  318.     sx = (auto_tile(tid) % 8) * 64
  319.     sy = (auto_tile(tid) / 8 % 4) * 64
  320.     rects = WALL_PIECES[auto_index(tid)]
  321.     make_autotile(rects, sx, sy)
  322.   end
  323.  
  324.   #--------------------------------------------------------------------------
  325.   # * Get auto-tile A4 tiles (walls)
  326.   #--------------------------------------------------------------------------
  327.   def autotile_A4(tile_id)
  328.     @tilemap = @bitmaps[3]
  329.     autotile = tile_id / 48
  330.     auto_id = tile_id % 48
  331.     sx = (autotile % 8) * 64
  332.     sy = (autotile / 16 * 160) + (autotile / 8 % 2) * 96
  333.     if is_wall?(tile_id + 5888)
  334.       rects = WALL_PIECES[auto_id]
  335.     else
  336.       rects = AUTOTILE_PARTS[auto_id]
  337.     end
  338.     make_autotile(rects, sx, sy)
  339.   end
  340.  
  341.   #--------------------------------------------------------------------------
  342.   # * Get auto-tile A5 tiles (normal)
  343.   #--------------------------------------------------------------------------
  344.   def autotile_A5(tile_id)
  345.     @tilemap = @bitmaps[4]
  346.     sx = (tile_id) % 8 * tilesize
  347.     sy = (tile_id) / 8 * tilesize
  348.     @src_rect.set(sx, sy, tilesize, tilesize)
  349.     @tile.clear
  350.     @tile.blt(0, 0, @tilemap, @src_rect)
  351.   end
  352.  
  353.   #--------------------------------------------------------------------------
  354.   # * Get normal tiles B, C, D, E
  355.   #--------------------------------------------------------------------------
  356.   def normal_tile(tile_id)
  357.     @tilemap = @bitmaps[5 + tile_id / 256]
  358.     sx = (tile_id / 128 % 2 * 8 + tile_id % 8) * tilesize;
  359.     sy = (tile_id % 256 / 8 % 16) * tilesize;
  360.     @src_rect.set(sx, sy, tilesize, tilesize)
  361.     @tile.clear
  362.     @tile.blt(0, 0, @tilemap, @src_rect)
  363.   end
  364.  
  365.   #--------------------------------------------------------------------------
  366.   # * Get bitmap for the specified tile id
  367.   #--------------------------------------------------------------------------
  368.   def get_bitmap(id)
  369.     if id < 1024
  370.       normal_tile(id)
  371.     elsif id < 1664
  372.       autotile_A5(id - 1536)
  373.     elsif id < 2816
  374.       autotile_A1(id - 2048)
  375.     elsif id < 4352
  376.       autotile_A2(id - 2816)
  377.     elsif id < 5888
  378.       autotile_A3(id - 4352)
  379.     else
  380.       autotile_A4(id - 5888)
  381.     end
  382.   end
  383. end
  384.  
  385. #==============================================================================
  386. # **
  387. #==============================================================================
  388.  
  389. class Game_Player < Game_Character
  390.  
  391.   alias :th_mapsaver_update :update
  392.   def update
  393.     th_mapsaver_update
  394.     if Input.trigger?(TH::Map_Saver::Mapshot_Button)
  395.       s = Map_Saver.new($game_map.map_id)
  396.       s.set_scale(TH::Map_Saver::Mapshot_Scale)
  397.       s.mapshot
  398.     end
  399.     if Input.trigger?(TH::Map_Saver::Screenshot_Button)
  400.       s = Map_Saver.new($game_map.map_id)
  401.       s.set_scale(TH::Map_Saver::Screenshot_Scale)
  402.       s.screenshot
  403.     end
  404.   end
  405. end
  406.  
  407. class Game_Vehicle < Game_Character
  408.   attr_reader :map_id
  409. end
  410.  
  411. class Game_Map
  412.   attr_reader :map
  413. end
  414.  
  415. #==============================================================================
  416. # **
  417. #==============================================================================
  418.  
  419. class Map_Saver
  420.   include TH::Map_Saver
  421.   include Map_Tiles
  422.   #--------------------------------------------------------------------------
  423.   # * Constants
  424.   #--------------------------------------------------------------------------
  425.  
  426.   SHADOW_COLOR = TH::Map_Saver::Shadow_Color
  427.   DAMAGE_COLOR = TH::Map_Saver::Damage_Color
  428.  
  429.   #--------------------------------------------------------------------------
  430.   # * Public instance variables
  431.   #--------------------------------------------------------------------------
  432.   attr_reader :map_image
  433.  
  434.   def initialize(map_id=$game_map.map_id, x=$game_player.x, y=$game_player.y)
  435.     @scale = 1
  436.     @local_x = x
  437.     @local_y = y
  438.     @screen_local = false
  439.     @shadow_bitmap = Bitmap.new(128, 128)
  440.     @draw_layer0 = true
  441.     @draw_layer1 = true
  442.     @draw_layer2 = true
  443.     @draw_events = Draw_Events
  444.     @draw_vehicles = Draw_Vehicles
  445.     @draw_player = Draw_Player
  446.     @draw_followers = Draw_Followers
  447.     @draw_shadow = Draw_Shadow
  448.     @draw_damage = Highlight_Damage
  449.     @draw_regions = Draw_Regions
  450.     @draw_passages = Draw_Passages
  451.     @tile = Bitmap.new(32, 32) #stores the current tile to be drawn
  452.     @tilemap = nil
  453.     @src_rect = Rect.new
  454.     @auto_rect = Rect.new(0, 0, tilesize / 2, tilesize/ 2) #constant
  455.     @tile_rect = Rect.new(0, 0, tilesize, tilesize)        #constant
  456.   end
  457.  
  458.   def load_tilesets
  459.     bitmaps = []
  460.     tileset.tileset_names.each_with_index do |name, i|
  461.       bitmaps[i] = Cache.tileset(name)
  462.     end
  463.     return bitmaps
  464.   end
  465.  
  466.   #--------------------------------------------------------------------------
  467.   # * Refresh, possibly with a new map
  468.   #--------------------------------------------------------------------------
  469.   def redraw(map_id=$game_map.map_id, x=$game_player.x, y=$game_player.y)
  470.     @map_image.dispose if @map_image
  471.     @map_id = map_id
  472.     @local_x = x
  473.     @local_y = y
  474.     @game_map = Game_Map.new
  475.     @game_map.setup(map_id)
  476.     @map = @game_map.map
  477.     @map_info = $data_mapinfos[map_id]
  478.     @screen = $game_map.screen
  479.     @tileset_id = @game_map.tileset.id
  480.     @bitmaps = load_tilesets
  481.  
  482.     get_bounds
  483.     @map_image = Bitmap.new(@width * tilesize, @height * tilesize)
  484.     draw_map
  485.     scale_map if @scale != 1
  486.   end
  487.  
  488.   #--------------------------------------------------------------------------
  489.   # * Pre-process. These will never change when drawing the map.
  490.   #--------------------------------------------------------------------------
  491.   def get_bounds
  492.     @start_x = start_x
  493.     @start_y = start_y
  494.     @end_x = end_x
  495.     @end_y = end_y
  496.     @width = width
  497.     @height = height
  498.     @tilesize = tilesize
  499.   end
  500.  
  501.   def screen_tile_x
  502.     Graphics.width / 32
  503.   end
  504.  
  505.   def screen_tile_y
  506.     Graphics.height / 32
  507.   end
  508.  
  509.   #--------------------------------------------------------------------------
  510.   # * Sets the scale for the map
  511.   #--------------------------------------------------------------------------
  512.   def set_scale(scale)
  513.     @scale = scale
  514.   end
  515.  
  516.   #--------------------------------------------------------------------------
  517.   # * Size of a tile
  518.   #--------------------------------------------------------------------------
  519.   def tilesize
  520.     32
  521.   end
  522.  
  523.   #--------------------------------------------------------------------------
  524.   # * Width and height of the map, both locally and globally
  525.   #--------------------------------------------------------------------------
  526.   def width
  527.     end_x - @start_x
  528.   end
  529.  
  530.   def height
  531.     end_y - @start_y
  532.   end
  533.  
  534.   #--------------------------------------------------------------------------
  535.   # * Starting and end positions, relative to the screen or map
  536.   #--------------------------------------------------------------------------
  537.   def start_x
  538.     @screen_local ? [[$game_player.x - screen_tile_x / 2, @map.width - screen_tile_x].min, 0].max : 0
  539.   end
  540.  
  541.   def start_y
  542.     @screen_local ? [[$game_player.y - screen_tile_y / 2, @map.height - screen_tile_y].min, 0].max : 0
  543.   end
  544.  
  545.   def end_x
  546.     @screen_local ? [[screen_tile_x, @local_x + screen_tile_x / 2 + 1].max, @map.width].min : @map.width
  547.   end
  548.  
  549.   def end_y
  550.     @screen_local ? [[screen_tile_y, @local_y + screen_tile_y / 2 + 1].max, @map.height].min : @map.height
  551.   end
  552.  
  553.   #--------------------------------------------------------------------------
  554.   # * Draw tile onto image. x and y values are absolute coords. They should
  555.   # be re-mapped based on the start_x and start_y values
  556.   #--------------------------------------------------------------------------
  557.   def draw_tile(x, y, tile, rect)
  558.     ox = (x - @start_x) * tilesize
  559.     oy = (y - @start_y) * tilesize
  560.     @map_image.blt(ox, oy, tile, rect)
  561.   end
  562.  
  563.   def draw_character(x, y, width, height, bmp, rect)
  564.     ox = (x - @start_x) * tilesize
  565.     oy = (y - @start_y) * tilesize
  566.  
  567.     ox = ox - width / 4 if width > 32
  568.     oy = oy - height / 2 if height > 32
  569.     @map_image.blt(ox, oy, bmp, rect)
  570.   end
  571.  
  572.   #--------------------------------------------------------------------------
  573.   # * Get bitmap for the specified character
  574.   #--------------------------------------------------------------------------
  575.   def get_character_bitmap(name)
  576.     charmap = Cache.character(name)
  577.     sign = name[/^[\!\$]./]
  578.     if sign && sign.include?('$')
  579.       cw = charmap.width / 3
  580.       ch = charmap.height / 4
  581.     else
  582.       cw = charmap.width / 12
  583.       ch = charmap.height / 8
  584.     end
  585.     return charmap, cw, ch
  586.   end
  587.  
  588.   #--------------------------------------------------------------------------
  589.   # * Draw the character onto the tile
  590.   #--------------------------------------------------------------------------
  591.   def set_character_bitmap(character, x, y)
  592.     charmap, cw, ch = get_character_bitmap(character.character_name)
  593.     index = character.character_index
  594.     pattern = character.pattern < 3 ? character.pattern : 1
  595.     sx = (index % 4 * 3 + pattern) * cw
  596.     sy = (index / 4 * 4 + (character.direction - 2) / 2) * ch
  597.     @src_rect.set(sx, sy, cw, ch)
  598.     draw_character(x, y, cw, ch, charmap, @src_rect)
  599.   end
  600.  
  601.   #--------------------------------------------------------------------------
  602.   # * create the shadow map
  603.   #--------------------------------------------------------------------------
  604.   def make_shadow_map
  605.     for s in 0 ... 16
  606.       x = s % 4
  607.       y = s / 4
  608.       if s & 0b1000 == 0b1000
  609.         @shadow_bitmap.fill_rect(x*tilesize+16, y*@tilesize+16, 16, 16, SHADOW_COLOR)
  610.       end
  611.       if s & 0b0100 == 0b0100
  612.         @shadow_bitmap.fill_rect(x*tilesize, y*@tilesize+16, 16, 16, SHADOW_COLOR)
  613.       end
  614.       if s & 0b0010 == 0b0010
  615.         @shadow_bitmap.fill_rect(x*tilesize+16, y*@tilesize, 16, 16, SHADOW_COLOR)
  616.       end
  617.       if s & 0b0001 == 0b0001
  618.         @shadow_bitmap.fill_rect(x*tilesize, y*@tilesize, 16, 16, SHADOW_COLOR)
  619.       end
  620.     end
  621.   end
  622.  
  623.   def draw_parallax
  624.     image = Cache.parallax(@map.parallax_name)
  625.     @src_rect.set(0, 0, image.width, image.height)
  626.     @map_image.blt(0, 0, image, @src_rect)
  627.   end
  628.  
  629.   #--------------------------------------------------------------------------
  630.   # * Draw the shadow map
  631.   #--------------------------------------------------------------------------
  632.   def draw_shadow_map
  633.     for x in @start_x ... @end_x
  634.       for y in @start_y ... @end_y
  635.       _x, _y = x*@tilesize, y*@tilesize
  636.         s = @map.data[x, y, 3]  & 0b1111
  637.         if s != 0
  638.           x_ = (s % 4) * @tilesize
  639.           y_ = (s / 4) * @tilesize
  640.           @src_rect.set(x_, y_, @tilesize, @tilesize)
  641.           draw_tile(x, y, @shadow_bitmap, @src_rect)
  642.         end
  643.       end
  644.     end
  645.   end
  646.  
  647.   #--------------------------------------------------------------------------
  648.   # * Draw the specified layer
  649.   #--------------------------------------------------------------------------
  650.   def draw_layer(layer)
  651.     for x in @start_x ... @end_x
  652.       for y in @start_y ... @end_y
  653.         _x, _y = x*@tilesize, y*@tilesize
  654.         tile_id = @map.data[x, y, layer]
  655.         next if tile_id == 0
  656.         get_bitmap(tile_id)
  657.         draw_tile(x, y, @tile, @tile_rect)
  658.       end
  659.     end
  660.   end
  661.  
  662.   #-----------------------------------------------------------------------------
  663.   # Draw game regions
  664.   #-----------------------------------------------------------------------------
  665.   def draw_regions
  666.     if $imported["TH_RegionOverlay"]
  667.       image = SceneManager.scene.instance_variable_get(:@spriteset).instance_variable_get(:@region_map).bitmap
  668.       @src_rect.set(@start_x * tilesize, @start_y * tilesize, image.width, image.height)
  669.       @map_image.blt(0, 0, image, @src_rect, 255)
  670.     end
  671.   end
  672.  
  673.   def draw_passages
  674.     if $imported["TH_OverlayPassageMap"]
  675.       image = SceneManager.scene.instance_variable_get(:@spriteset).instance_variable_get(:@passage_map).bitmap
  676.       @src_rect.set(@start_x * tilesize, @start_y * tilesize, image.width, image.height)
  677.       @map_image.blt(0, 0, image, @src_rect, 255)
  678.     end
  679.   end
  680.  
  681.   #--------------------------------------------------------------------------
  682.   # * Draw the game player
  683.   #--------------------------------------------------------------------------
  684.   def draw_player
  685.     set_character_bitmap($game_player, $game_player.x, $game_player.y) if @map_id == $game_map.map_id
  686.   end
  687.  
  688.   def draw_followers
  689.   end
  690.  
  691.   #--------------------------------------------------------------------------
  692.   # * Draw map events
  693.   #--------------------------------------------------------------------------
  694.   def draw_events
  695.     @map.events.values.each do |event|
  696.       canDraw = event.pages[0].list.any? do |cmd|
  697.         cmd.code == 108 && cmd.parameters[0] =~ /<screenshot:\s*tile\s*>/i
  698.       end
  699.       next unless @draw_events || canDraw
  700.       id = event.pages[0].graphic.tile_id
  701.       char_name = event.pages[0].graphic.character_name
  702.       if id > 0
  703.         normal_tile(id)
  704.         draw_tile(event.x, event.y, @tilemap, @src_rect)
  705.       elsif char_name != ""
  706.         set_character_bitmap(event.pages[0].graphic, event.x, event.y)
  707.       end
  708.     end
  709.   end
  710.  
  711.   #--------------------------------------------------------------------------
  712.   # * Draw map vehicles
  713.   #--------------------------------------------------------------------------
  714.   def draw_vehicles
  715.     $game_map.vehicles.each do |vehicle|
  716.       set_character_bitmap(vehicle, vehicle.x, vehicle.y) if @map_id == vehicle.map_id
  717.     end
  718.   end
  719.  
  720.   #--------------------------------------------------------------------------
  721.   # * Draw map sprites
  722.   #--------------------------------------------------------------------------
  723.   def draw_sprites
  724.     draw_events
  725.     draw_vehicles if @draw_vehicles
  726.     draw_player if @draw_player
  727.     draw_followers if @draw_followers
  728.   end
  729.  
  730.   #--------------------------------------------------------------------------
  731.   # * Highlight damage tiles
  732.   #--------------------------------------------------------------------------
  733.   def draw_damage
  734.     @tile.clear
  735.     @tile.fill_rect(0, 0, @tilesize, @tilesize, DAMAGE_COLOR)
  736.     @src_rect.set(0, 0, @tilesize, @tilesize)
  737.     for x in @start_x ... @end_x
  738.       for y in @start_y ... @end_y
  739.         _x, _y = x*@tilesize, y*@tilesize
  740.         if damage_floor?(x, y)
  741.           draw_tile(x, y, @tile, @src_rect)
  742.         end
  743.       end
  744.     end
  745.   end
  746.  
  747.   def draw_screen_effects
  748.   end
  749.   #--------------------------------------------------------------------------
  750.   # * Draw the map
  751.   #--------------------------------------------------------------------------
  752.   def draw_map
  753.     make_shadow_map if @draw_shadow
  754.     draw_parallax
  755.     draw_layer(0)
  756.     draw_layer(1)
  757.     draw_shadow_map
  758.     draw_layer(2)
  759.     draw_damage if @draw_damage
  760.     draw_regions if @draw_regions
  761.     draw_passages if @draw_passages
  762.     draw_sprites
  763.     draw_screen_effects
  764.   end
  765.  
  766.   #--------------------------------------------------------------------------
  767.   # * Scale the map
  768.   #--------------------------------------------------------------------------
  769.   def scale_map
  770.     nw = @width * @scale
  771.     nh = @height * @scale
  772.     @src_rect.set(0, 0, @width, @height)
  773.     scaled_map = Bitmap.new(nw, nh)
  774.     scaled_rect = Rect.new(0, 0, nw, nh)
  775.     scaled_map.stretch_blt(scaled_rect, @map_image, @src_rect)
  776.     @map_image = scaled_map
  777.   end
  778.  
  779.   #--------------------------------------------------------------------------
  780.   # * Take a mapshot of the map
  781.   #--------------------------------------------------------------------------
  782.   def mapshot
  783.     @screen_local = false
  784.     redraw
  785.     export(TH::Map_Saver::Mapshot_Directory)
  786.     $game_message.add("Mapshot taken")
  787.   end
  788.  
  789.   #--------------------------------------------------------------------------
  790.   # * Take a screenshot of the map
  791.   #--------------------------------------------------------------------------
  792.   def screenshot
  793.     @screen_local = true
  794.     redraw
  795.     export(TH::Map_Saver::Screenshot_Directory)
  796.     $game_message.add("Screenshot taken")
  797.   end
  798.  
  799.   #--------------------------------------------------------------------------
  800.   # * Get the format to export to
  801.   #--------------------------------------------------------------------------
  802.   def get_format
  803.     TH::Map_Saver::Export_Format
  804.   end
  805.  
  806.   #--------------------------------------------------------------------------
  807.   # * Export the map to a file
  808.   #--------------------------------------------------------------------------
  809.   def export(dirName="")
  810.     format = get_format
  811.     #name = @map.display_name != "" ? @map.display_name : @map_info.name
  812.     name = sprintf("Map%03d" %[@map_id])
  813.     Dir.mkdir(dirName) unless File.directory?(dirName)
  814.     name =
  815.     filename = "%s\\%s.%s" %[dirName, name, format]
  816.     t1 = Time.now
  817.     @map_image.save(filename)
  818.     t2 = Time.now
  819.     $game_message.add("Exported in %f seconds" %[t2 - t1])
  820.   end
  821. end
  822.  
  823. class Bitmap
  824.  
  825.   def save(filename, options = {})
  826.     options.merge!(format: File.extname(filename)[1..-1].to_sym)
  827.     retval = false
  828.     #bitmap = Gdiplus::Bitmap.new(:hbitmap, hbitmap)
  829.     #bitmap = Gdiplus::Bitmap.new(:gdidib, *gdidib)
  830.     # this seems to be the fastest one (RGSS 3.0.1, Windows 8 64-bit)
  831.     bitmap = Gdiplus::Bitmap.new(:scan0, width, height, scan0)
  832.     if bitmap
  833.       retval = bitmap.save(:file, filename, options[:format])
  834.       bitmap.dispose
  835.     end
  836.     retval
  837.   end
  838.  
  839. private
  840.  
  841.   def _data_struct(offset = 0)
  842.     @_data_struct ||= (DL::CPtr.new((object_id << 1) + 16).ptr + 8).ptr
  843.     (@_data_struct + offset).ptr.to_i
  844.   end
  845.  
  846.   def gdidib
  847.      [_data_struct(8), _data_struct(16)]
  848.   end
  849.  
  850.   def hbitmap
  851.     _data_struct(44)
  852.   end
  853.  
  854.   def scan0
  855.     _data_struct(12)
  856.   end
  857.  
  858. end
  859.  
  860. # ★ GDI+ interface
  861. # ★★★★★★★★★★★★
  862. #
  863. # Author : Cremno
  864. #
  865.  
  866. module Gdiplus
  867.   DLL = 'gdiplus.dll'
  868.  
  869.   def self.get_function name, import, export = 'L'
  870.     Win32API.new DLL, name, import, export
  871.   end
  872.  
  873.   FUNCTIONS = {
  874.     GdiplusStartup: get_function('GdiplusStartup', 'PPP'),
  875.     GdiplusShutdown: get_function('GdiplusShutdown', 'P', 'V'),
  876.     GdipDisposeImage: get_function('GdipDisposeImage', 'P'),
  877.     GdipSaveImageToFile: get_function('GdipSaveImageToFile', 'PPPP'),
  878.     GdipCreateBitmapFromGdiDib: get_function('GdipCreateBitmapFromGdiDib', 'LLP'),
  879.     GdipCreateBitmapFromHBITMAP: get_function('GdipCreateBitmapFromHBITMAP', 'LLP'),
  880.     GdipCreateBitmapFromScan0: get_function('GdipCreateBitmapFromScan0', 'LLLLPP')
  881.   }
  882.  
  883.   @@token = [0].pack('I')
  884.   def self.token
  885.     @@token
  886.   end
  887.  
  888.   @@clsids = {}
  889.   def self.clsids
  890.     @@clsids
  891.   end
  892.  
  893.   def self.gen_clsids
  894.     return unless @@clsids.empty?
  895.     func = Win32API.new('rpcrt4.dll', 'UuidFromString', 'PP', 'L')
  896.     {
  897.       bmp:  '557cf400-1a04-11d3-9a73-0000f81ef32e',
  898.       jpeg: '557cf401-1a04-11d3-9a73-0000f81ef32e',
  899.       gif:  '557cf402-1a04-11d3-9a73-0000f81ef32e',
  900.       tiff: '557cf405-1a04-11d3-9a73-0000f81ef32e',
  901.       png:  '557cf406-1a04-11d3-9a73-0000f81ef32e'
  902.     }.each_pair do |k, v|
  903.       clsid = [0].pack('I')
  904.       func.call(v, clsid)
  905.       @@clsids[k] = clsid
  906.     end
  907.     @@clsids[:jpg] = @@clsids[:jpeg]
  908.     @@clsids[:tif] = @@clsids[:tiff]
  909.   end
  910.  
  911.   # TODO: prepend prefix (Gdip or Gdiplus) automatically
  912.   def self.call(*args)
  913.     name = args.shift
  914.     func = FUNCTIONS[name]
  915.     v = func.call(*args)
  916.     if v && v != 0
  917.       msgbox "GDI+ error: #{v}\n\nFunction: #{name}\nArguments: #{args.inspect}"
  918.       false
  919.     else
  920.       true
  921.     end
  922.   end
  923.  
  924.   def self.startup
  925.     call :GdiplusStartup, @@token, [1, 0, 0, 0].pack('L4'), 0
  926.   end
  927.  
  928.   def self.shutdown
  929.     call :GdiplusShutdown, @@token
  930.   end
  931.  
  932.   class Image
  933.  
  934.     attr_reader :instance
  935.     def initialize
  936.       @instance = 0
  937.       true
  938.     end
  939.  
  940.     def save(destination, *args)
  941.       case destination
  942.       when :file
  943.         filename = args.shift << "\0"
  944.         filename.encode!('UTF-16LE')
  945.         argv = [:GdipSaveImageToFile, filename, Gdiplus.clsids[args.shift], 0]
  946.       else
  947.         raise ArgumentError, "unknown GDI+ image destination: #{source}"
  948.       end
  949.       argv.insert(1, @instance)
  950.       Gdiplus.call *argv
  951.     end
  952.  
  953.     def dispose
  954.       Gdiplus.call :GdipDisposeImage, @instance
  955.     end
  956.   end
  957.  
  958.   class Bitmap < Image
  959.  
  960.     def initialize source, *args
  961.       case source
  962.       when :gdidib
  963.         argv = [:GdipCreateBitmapFromGdiDib, args.shift, args.shift]
  964.       when :hbitmap
  965.         argv = [:GdipCreateBitmapFromHBITMAP, args.shift, 0]
  966.       when :scan0
  967.         w = args.shift
  968.         h = args.shift
  969.         argv = [:GdipCreateBitmapFromScan0, w, h, w * -4, 0x26200a, args.shift]
  970.       else
  971.         raise ArgumentError, "unknown GDI+ bitmap source: #{source}"
  972.       end
  973.       argv.push([0].pack('I'))
  974.       retval = Gdiplus.call *argv
  975.       @instance = retval ? argv.last.unpack('I').first : 0
  976.       retval
  977.     end
  978.   end
  979. end
  980.  
  981. if Gdiplus.startup
  982.   Gdiplus.gen_clsids
  983.   class << SceneManager
  984.     alias_method :run_wo_gdip_shutdown, :run
  985.     def run
  986.       run_wo_gdip_shutdown
  987.       Gdiplus.shutdown
  988.     end
  989.   end
  990. end
  991.  
  992. #==============================================================================
  993. # * Compatibility add-ons
  994. #==============================================================================
  995. #Yami overlays
  996. if $imported["YSE-OverlayMapping"]
  997.   class Map_Saver
  998.     def draw_overlay_map_ground
  999.       filename = YSA::OVERLAY::GROUND
  1000.       filename += $game_map.map_id.to_s
  1001.       filename += "-" + $game_variables[YSA::OVERLAY::GROUND_VARIABLE].to_s
  1002.       p filename
  1003.       image = Cache.overlay(filename)
  1004.       @src_rect.set(@start_x*tilesize, @start_y*tilesize, image.width, image.height)
  1005.       @map_image.blt(0, 0, image, @src_rect)
  1006.     end
  1007.  
  1008.     def draw_overlay_map_parallax
  1009.       filename = YSA::OVERLAY::PARALLAX
  1010.       filename += $game_map.map_id.to_s
  1011.       filename += "-" + $game_variables[YSA::OVERLAY::PARALLAX_VARIABLE].to_s
  1012.       image = Cache.overlay(filename)
  1013.       @src_rect.set(@start_x*tilesize, @start_y*tilesize, image.width, image.height)
  1014.       @map_image.blt(0, 0, image, @src_rect)
  1015.     end
  1016.  
  1017.     def draw_overlay_map_light
  1018.       filename = YSA::OVERLAY::LIGHT
  1019.       filename += $game_map.map_id.to_s
  1020.       filename += "-" + $game_variables[YSA::OVERLAY::LIGHT_VARIABLE].to_s
  1021.       image = Cache.overlay(filename)
  1022.       @src_rect.set(@start_x*tilesize, @start_y*tilesize, image.width, image.height)
  1023.       @map_image.blt(0, 0, image, @src_rect, 10)
  1024.     end
  1025.  
  1026.     def draw_overlay_map_shadow
  1027.       filename = YSA::OVERLAY::SHADOW
  1028.       filename += $game_map.map_id.to_s
  1029.       filename += "-" + $game_variables[YSA::OVERLAY::SHADOW_VARIABLE].to_s
  1030.       image = Cache.overlay(filename)
  1031.       @src_rect.set(@start_x*tilesize, @start_y*tilesize, image.width, image.height)
  1032.       @map_image.blt(0, 0, image, @src_rect, 10)
  1033.     end
  1034.  
  1035.     alias :th_map_overlay_draw_map :draw_map
  1036.     def draw_map
  1037.       th_map_overlay_draw_map
  1038.       draw_overlay_map_ground if $game_switches[YSA::OVERLAY::GROUND_SWITCH]
  1039.       draw_overlay_map_parallax if $game_switches[YSA::OVERLAY::PARALLAX_SWITCH]
  1040.       draw_overlay_map_shadow if $game_switches[YSA::OVERLAY::SHADOW_SWITCH]
  1041.       draw_overlay_map_light if $game_switches[YSA::OVERLAY::LIGHT_SWITCH]
  1042.     end
  1043.   end
  1044. end
  1045.  
  1046. if $imported["TH_AreaOverlay"]
  1047.   class Map_Saver
  1048.     def draw_overlay_area_map
  1049.       image = SceneManager.scene.instance_variable_get(:@spriteset).instance_variable_get(:@area_map).bitmap
  1050.       @src_rect.set(@start_x * tilesize, @start_y * tilesize, image.width, image.height)
  1051.       @map_image.blt(0, 0, image, @src_rect, 255)
  1052.     end
  1053.  
  1054.     alias :th_area_overlay_draw_map :draw_map
  1055.     def draw_map
  1056.       th_area_overlay_draw_map
  1057.       draw_overlay_area_map
  1058.     end
  1059.   end
  1060. end


作者:Hime 按F7可以截图

评分

参与人数 1星屑 +50 收起 理由
VIPArcher + 50 认可答案

查看全部评分

回复 支持 1 反对 0

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-11-16 22:01

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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