Project1

标题: 用图片数字替换文本数字怎么能实现? [打印本页]

作者: shengfeng    时间: 2020-11-13 16:19
标题: 用图片数字替换文本数字怎么能实现?
请教大神
作者: alexncf125    时间: 2020-11-13 21:09
本帖最后由 alexncf125 于 2020-11-14 13:58 编辑


图片放进Graphics/Systems文件夹
  1. class Window_Base < Window
  2.   alias textnum_to_imgnum_process_escape_character process_escape_character
  3.   def process_escape_character(code, text, pos)
  4.     textnum_to_imgnum_process_escape_character(code, text, pos)
  5.     case code.upcase
  6.     when 'Z'
  7.       process_draw_imgnum(obtain_escape_param(text), pos)
  8.     end
  9.   end
  10.   
  11.   def process_draw_imgnum(num, pos)
  12.     draw_imgnum(num, pos[:x], pos[:y])
  13.     pos[:x] += 13
  14.   end
  15.   
  16.   def draw_imgnum(num, x, y)
  17.     bitmap = Cache.system("Number")
  18.     rect = Rect.new(13 * num, 0, 13, 16)
  19.     contents.blt(x, y + 4, bitmap, rect)
  20.     bitmap.dispose
  21.   end
  22. end
复制代码


\Z[0]123\Z[4]567\Z[8]9

位置偏移问题已在脚本中修正, 图片没更新

如果你是想要自动替换而不是手动加\Z[]替换的话, 只能说抱歉了, 因为我不懂得弄~~
作者: 魔法丶小肉包    时间: 2020-11-14 12:48
alexncf125 发表于 2020-11-13 21:09
图片放进Graphics/Systems文件夾

自动替换其实思路很简单w提供一下我个人觉得比较简单的思路

首先呢,因为图片正好是做成0123456789的等距格式,所以很方便将其分割开来显示。
所以考虑在Window_Base里写
RUBY 代码复制
  1. def draw_picture_number(name, index, x, y)
  2.     bitmap = Cache.system(name)
  3.     rect = Rect.new(index % 10 * 15, index / 10 * 15, 15, 15)
  4.     contents.blt(x, y, bitmap, rect, 255)
  5.     bitmap.dispose
  6.   end

那么这样就分割开来了,index为0的时候就会绘制0这部分,为9的时候就会绘制9这部分...
而15则是间距问题,可以随便改的,我是对应自己使用的图片来定制w
接下来则是关键部分,Window_Base中的process_normal_character(c, pos)方法中的参数c固定是一个字符
那么就去匹配这个c,如果为数字的话,就执行draw_picture_number
所以就是
RUBY 代码复制
  1. class Window_Base
  2.   def process_normal_character(c, pos)
  3.     text_width = text_size(c).width
  4.     if c =~ /(\d)/
  5.       draw_picture_number("Number", $1[0].to_i, pos[:x], pos[:y])
  6.     else
  7.       draw_text(pos[:x], pos[:y], text_width * 2, pos[:height], c)
  8.     end
  9.     pos[:x] += text_width
  10.   end
  11.   def draw_picture_number(name, index, x, y)
  12.     bitmap = Cache.system(name)
  13.     rect = Rect.new(index % 10 * 15, index / 10 * 15, 15, 15)
  14.     contents.blt(x, y, bitmap, rect, 255)
  15.     bitmap.dispose
  16.   end
  17. end







作者: alexncf125    时间: 2020-11-14 12:56
魔法丶小肉包 发表于 2020-11-14 12:48
自动替换其实思路很简单w提供一下我个人觉得比较简单的思路

首先呢,因为图片正好是做成0123456789的等 ...


原来有process_normal_character这个方法
我都没留意没看到~~




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