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

Project1

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

[转载] 文字拡張功能

[复制链接]

Lv5.捕梦者

梦石
0
星屑
22973
在线时间
8639 小时
注册时间
2011-12-31
帖子
3367
跳转到指定楼层
1
发表于 2012-3-1 17:23:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 tseyik 于 2012-3-4 13:10 编辑

原出處
http://rmrk.net/index.php/topic,44810.0.html
RM在文本模式可用不同指令加上不同效果(如顔色、icon)
這個脚本就是把這指令拡張到其他地方
这个脚本允许你使用特殊的信息代码,在任何一个窗口,而不仅仅是信息窗口和帮助窗口。要添加一个图标旁边的菜单命令?这个脚本,你可以做的多。

注:在文本中使用特殊的消息代码,将让这个文本将不会自動收缩,如果超出其指定的宽度。可能會不正常顕示。

使用方法
只要在指令前面加上\*
如\c[5]Hand Axe\c[0]; 改成 \*\c[5]Hand Axe\c[0]
効果

  1. #==============================================================================
  2. #    Global Text Codes [VXA]
  3. #    Version: 1.0
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: January 5, 2012
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #
  9. #    This script allows you to use special message codes in any window, not
  10. #   just message windows and help windows. Want to add an icon next to the
  11. #   menu commands? With this script you can do that and more.
  12. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  13. #  Instructions:
  14. #
  15. #    Simply paste this script into its own slot above Main and below Materials
  16. #   and other custom scripts.
  17. #
  18. #    There are two settings for this script - automatic and manual. If set to
  19. #   automatic, then all you will need to do is put any of the special message
  20. #   codes in anything and they will automatically work. If set to manual, then
  21. #   you will also need to type the following code somewhere in the text field
  22. #   to activate it: \*
  23. #
  24. #    The following default codes are available:
  25. #
  26. # \c[n] - Set the colour of the text being drawn to the nth colour of the
  27. #     Windowskin palette. 0 is the normal color and 16 is the system color.
  28. # \i[n] - Draw icon with index n.
  29. # \p[n] - Draw the name of the actor in the xth position in the party. 1 is
  30. #     the party leader, 2 is the second member, etc.
  31. # \n[n] - Draw the name of the actor with ID n
  32. # \v[n] - Draw the value of variable with ID n.
  33. # \g - Draws the unit of currency.
  34. #
  35. #    Depending on whether you are using any custom message script, you may have
  36. #   additional message codes at your disposal. This script is mostly compatible
  37. #   with my ATS and every code except \x and ones related to message control
  38. #   will work.
  39. #==============================================================================

  40. $imported = {} unless $imported
  41. $imported[:MAGlobalTextCodes] = true
  42. #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  43. #  Editable Region
  44. #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  45. #  MAGTC_MANUAL_CODES - If this is true, then you must put a \* code in any
  46. # field that you want to have codes interpreted in. Otherwise, codes will
  47. # always automatically be interpreted. The recommended value for this is true,
  48. # as the process for drawing text with codes is much slower than the process
  49. # for drawing text without codes.
  50. MAGTC_MANUAL_CODES = true
  51. #  MAGTC RCODES - This feature is designed to overcome the space limitations in
  52. # much of the database - since codes take so much of that space, it might be
  53. # difficult to write everything you want into one of those fields. This feature
  54. # permits you to write the term you want in to the following array, and then
  55. # access it in the database with the code \r[n], where n is the ID you assign
  56. # to the phrase in the following way:
  57. #
  58. #    n => "replacement",
  59. #
  60. # Please note that: it is =>, not =; the replacement must be within quotation
  61. # marks; and there must be a comma after every line. If using double quotation
  62. # marks ("", not ''), then you need to use two backslashes to access codes
  63. # instead of one (\\c[1], not \c[1]).
  64. #
  65. #  EXAMPLE:
  66. #   0 => "\\i[112]\\c[14]New Game\\c[0]",
  67. #
  68. #  Under the New Game field in the Terms of the Database, all I would then need
  69. # to put is:
  70. #    \*\r[0]
  71. #  and it would be the same as if I had put:
  72. #    \*\i[112]\c[14]New Game\c[0]
  73. MAGTC_RCODES = { # <- Do not touch
  74.   0 => "\\i[112]\\c[14]New Game\\c[0]", # Example
  75.   1 => "", # You can make as many of these as you want
  76.   2 => "",
  77. #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  78. #  END Editable Region
  79. #//////////////////////////////////////////////////////////////////////////////
  80. }
  81. MAGTC_RCODES.default = ""

  82. #==============================================================================
  83. # ** Window_Base
  84. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  85. #  Summary of Changes:
  86. #    aliased methods - draw_text; convert_escape_characters; process_new_line;
  87. #      reset_font_settings
  88. #    new methods - magtc_align_x; magtc_test_process_escape_character;
  89. #      magtc_calc_line_width
  90. #==============================================================================

  91. class Window_Base
  92.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93.   # * Draw Text
  94.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95.   alias ma_gtc_drwtxt_3fs1 draw_text
  96.   def draw_text(*args, &block)
  97.     # Get the arguments
  98.     if args[0].is_a?(Rect)
  99.         x, y, w, h = args[0].x, args[0].y, args[0].width, args[0].height
  100.         text, align = *args[1, 2]
  101.       else
  102.         x, y, w, h, text, align = *args[0, 6]
  103.       end
  104.     align = 0 unless align
  105.     #  Draw normally if text is not a string, draw normally if the text is not
  106.     # long enough to hold a code, and draw normally when the script is set to
  107.     # manual and \* is not included in the text
  108.       if !text.is_a?(String) || text.size < 2 || (MAGTC_MANUAL_CODES && text[/\\\*/].nil?)
  109.         ma_gtc_drwtxt_3fs1(*args, &block) # Run Original Method
  110.       else
  111.       @magtc_reset_font = contents.font.dup # Do not automatically reset font
  112.       @magtc_rect, @magtc_align = Rect.new(x, y, w, h), align
  113.       # Get first line of the text to test for alignment
  114.       @magtc_test_line = convert_escape_characters(text[/.*/])
  115.       y += [(h - calc_line_height(@magtc_test_line)) / 2, 0].max
  116.       # Draw text with message codes
  117.         draw_text_ex(magtc_align_x(x), y, text)
  118.       @magtc_reset_font = nil # Do not automatically reset font
  119.       @magtc_rect, @magtc_align = nil, nil # Reset Rect and Alignment
  120.       end
  121.   end
  122.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  123.   # * Convert Escape Characters
  124.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  125.   alias ma_gtc_convescchar_5tk9 convert_escape_characters
  126.   def convert_escape_characters(text, *args, &block)
  127.     # Remove \* codes
  128.     new_text = text.gsub(/\\\*/, "")
  129.     # Substitute for the R Codes
  130.     new_text.gsub!(/\\[Rr]\[(\d+)\]/, MAGTC_RCODES[$1.to_i].to_s)
  131.     ma_gtc_convescchar_5tk9(new_text, *args, &block) # Call Original Method
  132.   end
  133.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  134.   # * Reset Font Settings
  135.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  136.   alias magtc_resetfonts_4ga5 reset_font_settings
  137.   def reset_font_settings(*args, &block)
  138.     magtc_resetfonts_4ga5(*args, &block) # Call Original Method
  139.     contents.font = @magtc_reset_font if @magtc_reset_font
  140.   end
  141.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142.   # * Process New Line
  143.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144.   alias magtc_prcsnewl_5gn9 process_new_line
  145.   def process_new_line(text, pos, *args, &block)
  146.     magtc_prcsnewl_5gn9(text, pos, *args, &block) # Run Original Method
  147.     if @magtc_align && @magtc_rect
  148.       @magtc_test_line = text[/.*/] # Get new line
  149.       pos[:x] = magtc_align_x       # Get the correct x, depending on alignment
  150.     end
  151.   end
  152.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  153.   # * Get Alignment X
  154.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  155.   def magtc_align_x(start_x = @magtc_rect.x)
  156.     return start_x unless (@magtc_rect && @magtc_align && @magtc_test_line) || @magtc_align != 0
  157.     tw = magtc_calc_line_width(@magtc_test_line)
  158.     case @magtc_align
  159.     when 1 then return start_x + ((@magtc_rect.width - tw) / 2)
  160.     when 2 then return start_x + (@magtc_rect.width - tw)
  161.     end
  162.     start_x
  163.   end
  164.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165.   # * Calc Line Width
  166.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167.   def magtc_calc_line_width(line)
  168.     # Remove all escape codes
  169.     line = line.clone
  170.     line.gsub!(/[\n\r\f]/, "")
  171.     real_contents = contents # Preserve Real Contents
  172.     # Create a dummy contents
  173.     self.contents = Bitmap.new(@magtc_rect.width, @magtc_rect.height)
  174.     reset_font_settings
  175.     pos = {x: 0, y: 0, new_x: 0, height: calc_line_height(line)}
  176.     tw = 0
  177.     while line[/^(.*?)\e(.*)/]
  178.       tw += text_size($1).width
  179.       line = $2
  180.       # Remove all ancillaries to the code, like parameters
  181.       code = obtain_escape_code(line)
  182.       magtc_test_process_escape_character(code, line, pos)
  183.     end
  184.     #  Add width of remaining text, as well as the value of pos[:x] under the
  185.     # assumption that any additions to it are because the special code is
  186.     # replaced by something which requires space (like icons)
  187.     tw += text_size(line).width + pos[:x]
  188.     self.contents.dispose # Dispose dummy contents
  189.     self.contents = real_contents # Restore real contents
  190.     return tw
  191.   end
  192.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  193.   # * Test Process Escape Character
  194.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195.   def magtc_test_process_escape_character(code, text, pos)
  196.     if $imported[:ATS_SpecialMessageCodes] && ['X', 'HL'].include?(code.upcase)
  197.       obtain_escape_param(text)
  198.       return
  199.     end
  200.     process_escape_character(code, text, pos)
  201.   end
  202. end
复制代码

评分

参与人数 1星屑 +50 收起 理由
无双sxa + 50 我很赞同

查看全部评分

Lv1.梦旅人

梦石
0
星屑
154
在线时间
664 小时
注册时间
2011-9-25
帖子
241
2
发表于 2012-3-1 18:22:34 | 只看该作者
感谢LZ~刚还在吐槽物品颜色脚本有冲突神马的,呵呵
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
49
在线时间
152 小时
注册时间
2012-1-12
帖子
456
3
发表于 2012-3-1 21:40:58 | 只看该作者
这是VX的还是XP的还是2000的还是ACE的?...

点评

是ACE的  发表于 2012-3-1 22:16
应该是ace的。  发表于 2012-3-1 21:42
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-11-25 16:47

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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