Project1

标题: 这个脚本怎么改才能让图片居中显示 [打印本页]

作者: huct08    时间: 2014-2-26 16:11
标题: 这个脚本怎么改才能让图片居中显示
RUBY 代码复制
  1. =begin
  2.  ■ Information      ╒═════════════════════════════════════════════════════════╛
  3.  EST - LIVING STATUS MENU v1.2
  4.  by Estriole
  5.  
  6.  ■ License          ╒═════════════════════════════════════════════════════════╛
  7.  Free to use in all project (except the one containing pornography)
  8.  as long as i credited (ESTRIOLE).
  9.  
  10.  ■ Support          ╒═════════════════════════════════════════════════════════╛
  11.  While I'm flattered and I'm glad that people have been sharing and asking
  12.  support for scripts in other RPG Maker communities, I would like to ask that
  13.  you please avoid posting my scripts outside of where I frequent because it
  14.  would make finding support and fixing bugs difficult for both of you and me.
  15.    
  16.  If you're ever looking for support, I can be reached at the following:
  17.  ╔═════════════════════════════════════════════╗
  18.  ║       [url=http://www.rpgmakervxace.net/]http://www.rpgmakervxace.net/[/url]         ║
  19.  ╚═════════════════════════════════════════════╝
  20.  pm me : Estriole.
  21.  
  22.  ■ Introduction     ╒═════════════════════════════════════════════════════════╛
  23.  This script is requested by Furrari fullbuster from [url=http://www.rpgmakervxace.net/]http://www.rpgmakervxace.net/[/url]
  24.  it change status menu to be more lively and beautiful. first... it will
  25.  use potrait as the actor picture in status (you need to provide your own). if
  26.  the actor didnt have pictures. then it will use rescue picture.
  27.  second... you can use as many pictures of the same actor as you want to make it
  28.  animated. (require the basic knowledge on how to animate pictures and graphic
  29.  editing skills too). all the animating things is done with notetags (will fill
  30.  your notetags if you use a lot of pictures so not recommended for symphony user).
  31.  third... you can make the animation only run once or make it looped.
  32.  fourth... i give you some actor sound feature too. this script will play random
  33.  sound of the actor (you need to put notetags on how many sound this actor has).
  34.  else it will not play sound. combination of ANIMATED and SOUND make me name this
  35.  script LIVING STATUS MENU :D.
  36.  last one... use background image as status menu background.
  37.  
  38.  also... although this script is making your status menu COOL... you have to
  39.  remember that it have potential to increase your project size by quite a lot
  40.  (if you animate the potrait complexly. heck. even rotating magic circle take
  41.  me 12 images to make it not to choppy)
  42.  
  43.  so... WARNING FOR LAZY PEOPLE... don't use this script !!!!
  44.  
  45.  ■ Features         ╒═════════════════════════════════════════════════════════╛
  46.  * use potrait
  47.  * infinite number of potrait per actor to make it animated or just slideshow
  48.  * can do one time only animation or looped animation
  49.  * can play random sound of the actor
  50.  * use image as background
  51.  
  52.  ■ Changelog        ╒═════════════════════════════════════════════════════════╛
  53.  v1.0 2013.05.16           Initial Release
  54.  v1.1 2013.05.23     add compatibility to custom resolution. just change the
  55.                      DESCRIPTION_LINE_MOD in module estriole to change where
  56.                      the description drawn. for images you just need to resize it.
  57.  v1.2 2014.01.01     Happy New Year! add ability to have different background each actor
  58.                      just add another background.jpg (or .png) inside the
  59.                      living_status/actor_x/ folder
  60.                      change x to id of the actor using that background
  61.  
  62.  ■ Compatibility    ╒═════════════════════════════════════════════════════════╛
  63.  Definitely not compatible with YANFLY status menu script. :D.
  64.  tell me if another script not. since this have lots of overwrite in window_status
  65.  this script is expected to not compatible with script that modify that window.
  66.  
  67.  ■ How to use     ╒═════════════════════════════════════════════════════════╛
  68.  i will try to explain how to use this script. this is quite confusing if you
  69.  don't understand basic animation.
  70.  
  71.  >>>>  Graphic related  <<<<<<
  72.  -1) set background image.
  73.  put the image of your status menu background in folder
  74.  /Graphics/Pictures/living_status/
  75.  name it "background"
  76.  
  77.  from below... it's better to use png for potraits since it contain transparency.
  78.  0) set rescue potrait (so the game won't crash when you still didn't have
  79.  complete actor potrait).
  80.  put the image in
  81.  /graphics/pictures/living_status/
  82.  name the image "rescue.png"
  83.  now your game won't crash when you're developing it. so you can slowly adding
  84.  potrait one by one. also when you missing some image when animating. this picture
  85.  will also shown to tell you that image is missing.
  86.  
  87.  1) set actor potrait
  88.  create image size with the max width 325 pixel. (best result is 200 or 325 pixel)
  89.  put it in folder
  90.  /graphics/pictures/living_status/actor_x/
  91.  (change _x to _actorid)
  92.  name the image "1.png" (since png has transparency)
  93.  example
  94.  /graphics/pictures/living_status/actor_1/1.png
  95.  will set that picture as the 'first' picture of the actor 1.
  96.  
  97.  by doing so you already have potrait status menu. if you want it animated
  98.  another step must be done. BUT if you don't understand basic animation/frame/etc
  99.  Stop at this point rather than boiling your head. your status menu is already
  100.  pretty at this point if you done it right...
  101.  
  102.  2) animating actor potrait
  103.  basically you create another image which slightly different from first picture.
  104.  name it in sequence such as 2.png, 3.png, 4.png, etc.
  105.  put the images in they same folder as the 1.png.
  106.  now you have to understand frames before executing this section.
  107.  first define frame max for that actor potrait. by giving the actor notetags:
  108.  
  109.  <frame_max: 60>
  110.  
  111.  it will set the frame 0 to 60. so the animation will occur in 60 frames.
  112.  if you don't set the notetags by default frame max is what you set in module ESTRIOLE.
  113.  
  114.  second define how many pictures that actor animate. give actor notetags:
  115.  
  116.  <anim_max: 12>
  117.  
  118.  it means that actor have 12 pictures to animate
  119.  
  120.  third set the timing of the animation change. give notetags to actor
  121.  <frame_anim_1: 0, 5>
  122.  means 1.png will shown from 0 to 5 frame
  123.  <frame_anim_2: 5, 10>
  124.  means 2.png will shown from 5 to 10 frame
  125.  <frame_anim_3: 10, 15>
  126.  means 3.png will shown from 10 to 15 frame
  127.  <frame_anim_4: 15, 20>
  128.  means 4.png will shown from 15 to 20 frame
  129.  done that until all your pictures given animation set.
  130.  warning... the first number in notetags must be lower than second number.
  131.  also one picture can only used once. (still thinking another way to prevent that
  132.  i have a way already using array and another for. but will make user hard to use).
  133.  also if at that frame no image specified... it will automatically use 1.png.
  134.  
  135.  now you got yourself animated picture.
  136.  
  137.  3) making looped animation
  138.  after setting above. you could give notetags to loop animation. give the actor:
  139.  <loop_to: x>
  140.  x -> frame number
  141.  <loop_to: 0>
  142.  will loop it back to frame 0 continuosly.
  143.  <loop_to: 100>
  144.  will loop it back to frame 100 continuosly. useful when you want to make actor
  145.  talking animation + another animation. then loop without the talking animation.
  146.  
  147.  >>>>  Sound related  <<<<<<
  148.  1) put the actor voice files in
  149.  /Audio/SE/living_status/actor_#/
  150.  name it sequentialy.
  151.  ex:
  152.  /Audio/SE/living_status/actor_1/1.ogg
  153.  /Audio/SE/living_status/actor_1/2.ogg
  154.  /Audio/SE/living_status/actor_1/3.ogg
  155.  will give the actor 3 sounds.
  156.  2) set the notetags telling that this actor has three sounds
  157.  <op_voices_num: 3>
  158.  here you go... now your actor will tell random sound everytime you view their
  159.  status menu :D.
  160.  
  161.  if you're confused. just look at the demo project folder.
  162.  
  163.  ■ Author's Notes   ╒═════════════════════════════════════════════════════════╛
  164.  This script is quite hard to use. need to understand basic of animating
  165.  pictures. also only one layer provided so it's limited animation.
  166.  future patch plan (if i'm not busy)
  167.  - sound effect in animation
  168.  - tell me...
  169.    
  170. =end
  171.  
  172. ###       CONFIGURATION       ##################################################
  173. module ESTRIOLE
  174.   module STATUS
  175.     USE_DESCRIPTION = true #true will show actor description   
  176.     DEFAULT_FRAME_MAX = 300 #default frame max of actor animation
  177.     DESCRIPTION_LINE_MOD = 14 #change this if you're using custom resolution.
  178.                               #if not 14 is ok. 14 means you draw the description
  179.                               #at 14th line
  180.   end
  181. end
  182.  
  183. class RPG::Actor < RPG::BaseItem
  184.   def frame_max
  185.     return nil if !note[/<frame_max:(.*)>/i]
  186.     a = note[/<frame_max:(.*)>/i].scan(/:(.*)/).flatten[0].scan(/(?:"(.*?)"| (\w+)|(\w+),|,(\w+))/).flatten.compact
  187.     return noteargs = a[0].to_i
  188.   end
  189.   def anim_max
  190.     return 1 if !note[/<anim_max:(.*)>/i]
  191.     a = note[/<anim_max:(.*)>/i].scan(/:(.*)/).flatten[0].scan(/(?:"(.*?)"| (\w+)|(\w+),|,(\w+))/).flatten.compact
  192.     return noteargs = a[0].to_i
  193.   end
  194.   def frame_change(index)
  195.     return nil if !note[/<frame_anim_#{index}:(.*)>/i]
  196.     a = note[/<frame_anim_#{index}:(.*)>/i].scan(/:(.*)/).flatten[0].scan(/(?:"(.*?)"| (\w+)|(\w+),|,(\w+))/).flatten.compact
  197.     return noteargs = [a[0].to_i,a[1].to_i]
  198.   end
  199.   def anim_loop_to?
  200.     return nil if !note[/<loop_to:(.*)>/i]
  201.     a = note[/<loop_to:(.*)>/i].scan(/:(.*)/).flatten[0].scan(/(?:"(.*?)"| (\w+)|(\w+),|,(\w+))/).flatten.compact
  202.     return noteargs = a[0].to_i   
  203.   end
  204.   def voices_num
  205.     return nil if !note[/<op_voices_num:(.*)>/i]
  206.     a = note[/<op_voices_num:(.*)>/i].scan(/:(.*)/).flatten[0].scan(/(?:"(.*?)"| (\w+)|(\w+),|,(\w+))/).flatten.compact
  207.     return noteargs = a[0].to_i
  208.   end
  209. end
  210.  
  211. class Scene_Status < Scene_MenuBase
  212.   include ESTRIOLE::STATUS
  213.   alias est_living_status_start start
  214.   def start
  215.     est_living_status_start
  216.     @frame_count = 0
  217.     play_random_actor_sound
  218.   end
  219.   alias est_living_status_next_actor next_actor
  220.   def next_actor
  221.     @status_window.actor_anim_index = 1
  222.     @frame_count = 0
  223.     est_living_status_next_actor
  224.     4.times do update end
  225.     RPG::SE.stop
  226.     play_random_actor_sound
  227.   end
  228.   alias est_living_status_prev_actor prev_actor  
  229.   def prev_actor
  230.     @status_window.actor_anim_index = 1
  231.     @frame_count = 0
  232.     est_living_status_prev_actor
  233.     4.times do update end
  234.     RPG::SE.stop
  235.     play_random_actor_sound
  236.   end
  237.   def play_random_actor_sound
  238.     return unless @actor.actor.voices_num
  239.     a = ([email]1..@actor.actor.voices_num[/email]).to_a.sample
  240.     RPG::SE.new("/living_status/actor_#{@actor.actor.id}/#{a}", 100, 100).play
  241.   end
  242.  
  243.   def update
  244.     super
  245.     frame_max = DEFAULT_FRAME_MAX
  246.     frame_max = @actor.actor.frame_max if @actor.actor.frame_max
  247.     old_index = @status_window.actor_anim_index
  248.     @frame_count = @actor.actor.anim_loop_to? if @frame_count == frame_max && @actor.actor.anim_loop_to?
  249.     @frame_count += 1
  250.     @frame_count = [@frame_count,frame_max].min
  251.     @status_window.actor_anim_index = 1
  252.     anim_max = 3
  253.     anim_max = @actor.actor.anim_max if @actor.actor.anim_max
  254.     for i in 1..anim_max
  255.       @status_window.actor_anim_index = i if @actor.actor.frame_change(i) &&
  256.                                              @frame_count >= @actor.actor.frame_change(i)[0] &&
  257.                                              @frame_count <= @actor.actor.frame_change(i)[1]
  258.     end   
  259.     @status_window.refresh if old_index != @status_window.actor_anim_index
  260.   end
  261. end
  262.  
  263. class Window_Status < Window_Selectable
  264.   include ESTRIOLE::STATUS
  265.   attr_accessor :actor_anim_index
  266.   attr_reader :actor_potrait
  267.   def initialize(actor)
  268.     super(0, 0, Graphics.width, Graphics.height)
  269.     @actor = actor
  270.     create_background
  271.     create_potrait
  272.     refresh
  273.     activate
  274.   end
  275.   def terminate
  276.     super
  277.     dispose_background
  278.     dispose_potrait
  279.   end
  280.   def create_potrait
  281.     @actor_potrait = Sprite.new
  282.     @actor_potrait.x = 304 - 50
  283.     @actor_potrait.y = line_height * 3
  284.     @actor_potrait.z = self.z if !USE_DESCRIPTION
  285.     @actor_anim_index = 1
  286.   end
  287.   def create_background
  288.     @background_sprite = Sprite.new
  289.     @background_sprite.bitmap = Cache.picture("/living_status/actor_#{@actor.actor.id}/background") rescue Cache.picture("/living_status/background") rescue nil
  290.     self.opacity = 0 if @background_sprite.bitmap
  291.     @background_sprite.bitmap = SceneManager.background_bitmap if @background_sprite.bitmap == nil
  292.   end
  293.   def dispose_background
  294.     @background_sprite.dispose
  295.   end  
  296.   def dispose_potrait
  297.     @actor_potrait.dispose
  298.   end
  299.   def actor=(actor)
  300.     return if @actor == actor
  301.     @actor = actor
  302.     dispose_background
  303.     create_background
  304.     refresh
  305.   end
  306.   def refresh
  307.     contents.clear
  308.     draw_block1   (line_height * 0)
  309.     draw_horz_line(line_height * 2)
  310.     draw_block2   (line_height * 3)
  311.     draw_custom_horz_line(line_height * 6,200)
  312.     draw_block3   (line_height * 7)
  313.     draw_horz_line(line_height * (DESCRIPTION_LINE_MOD-1)) if USE_DESCRIPTION
  314.     draw_block4   (line_height * DESCRIPTION_LINE_MOD) if USE_DESCRIPTION
  315.   end
  316.   def draw_actor_name(actor, x, y, width = 325)
  317.     change_color(system_color)
  318.     draw_text(x, y, width, line_height, "Name  ")   
  319.     change_color(normal_color)
  320.     draw_text(x+80, y, width-80, line_height, actor.name)
  321.   end  
  322.   def draw_actor_class(actor, x, y, width = 325)
  323.     text = actor.class.name
  324.     change_color(system_color)
  325.     draw_text(x, y, width, line_height, "Class ")
  326.     change_color(normal_color)
  327.     draw_text(x+80, y, width-80, line_height, text)
  328.   end
  329.   def draw_basic_info(x, y)
  330.     draw_actor_level(@actor, x, y + line_height * 0)
  331.     draw_actor_icons(@actor, x + 70, y + line_height * 0)
  332.     draw_actor_hp(@actor, x, y + line_height * 1,170)
  333.     draw_actor_mp(@actor, x, y + line_height * 2,170)
  334.   end  
  335.   def draw_exp_info(x, y)
  336.     s1 = @actor.max_level? ? "-------" : @actor.exp
  337.     s2 = @actor.max_level? ? "-------" : @actor.next_level_exp - @actor.exp
  338.     change_color(system_color)
  339.     draw_text(x, y + line_height * 0, 180, line_height, "EXP")
  340.     draw_text(x, y + line_height * 1, 180, line_height, "Next")
  341.     change_color(normal_color)
  342.     draw_text(x, y + line_height * 0, 180, line_height, s1, 2)
  343.     draw_text(x, y + line_height * 1, 180, line_height, s2, 2)
  344.   end
  345.   def draw_parameters(x, y)
  346.     6.times {|i| draw_actor_param(@actor, x, y + line_height * i, i + 2) }
  347.   end
  348.   def draw_actor_param(actor, x, y, param_id)
  349.     change_color(system_color)
  350.     draw_text(x, y, 120, line_height, Vocab::param(param_id))
  351.     change_color(normal_color)
  352.     draw_text(x + 100, y, 36, line_height, actor.param(param_id), 2)
  353.   end
  354.   def draw_block1(y)
  355.     draw_actor_name(@actor, 20, y)
  356.     draw_actor_class(@actor, 20, y + line_height)
  357.     draw_exp_info(304, y)
  358.   end
  359.   def draw_block2(y)
  360.     draw_basic_info(20, y)
  361.     draw_potraits(288, y)
  362.   end
  363.   def draw_potraits(x,y)
  364.     @actor_potrait.bitmap = Cache.picture("/living_status/actor_#{@actor.actor.id}/#{@actor_anim_index}") rescue rescue_potrait
  365.   end
  366.   def rescue_potrait
  367.     Cache.picture("/living_status/rescue")
  368.   end
  369.   def draw_block3(y)
  370.     draw_parameters(20, y)
  371.   end
  372.   def draw_block4(y)
  373.     draw_description(4, y)
  374.   end
  375.   def draw_horz_line(y)
  376.     line_y = y + line_height / 2 - 1
  377.     contents.fill_rect(0, line_y, contents_width, 2, line_color)
  378.   end
  379.   def draw_custom_horz_line(y,w)
  380.     line_y = y + line_height / 2 - 1
  381.     contents.fill_rect(0, line_y, w, 2, line_color)
  382.   end
  383.   def line_color
  384.     color = normal_color
  385.     color.alpha = 48
  386.     color
  387.   end
  388.   def draw_description(x, y)
  389.     draw_text_ex(x, y, @actor.description)
  390.   end
  391. end



目前图片靠左上角,看着实在蛋疼

作者: Sion    时间: 2014-2-26 20:04
你先传个范例工程贝。

PS:脚本作者说他的脚本不能用在 H 游戏里。




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1