|
本帖最后由 百里_飞柳 于 2018-4-7 22:54 编辑
- #--------------------------------------------------------------------------
- # ● 逐个字开始描绘
- #--------------------------------------------------------------------------
- def play_onetext
- tx = @text_array.shift #获取并删除文字数组第一个字。
- cw = contents.text_size(tx).width #获取描绘这个字需要的宽度。
- if @text_pos[:x] + cw > Helpset::Width_MAX #如果描绘的坐标X加上宽度超过 xxx ,就换行。
- @text_pos[:x] = 0
- @text_pos[:y] += 24 #假如行距是 32 。
- end
- self.contents.draw_text(@text_pos[:x], @text_pos[:y], cw, 32, tx) #描绘这个文字。
- @text_pos[:x] += cw #宽度累加。
- end
复制代码
你这里是把文字拆成了一个个的字符并进行绘制,而如果你想加入转义符的话,那就再在这之间加入个判定
以及,你这个split后的 \ 符号变成什么了,是 \\ 还是 \e ,如果字符串是 '' 形式,则为 \\,否则我ruby里测试是自动替换成 \e
- #--------------------------------------------------------------------------
- # ● 逐个字开始描绘
- #--------------------------------------------------------------------------
- def play_onetext
- tx = @text_array.shift #获取并删除文字数组第一个字。
- if tx == '\e' # 此处修改成你字符串中 \ 符号变更
- # 读取出转义符
- t_ = ''; code = ""
- while t_ != '['
- code += t_
- t_ = @text_array.shift
- end
- # 读取出方括号内参数
- t_ = ''; param = ""
- while t_ != ']'
- param += t_
- t_ = @text_array.shift
- end
- # 分析
- case code
- when "c"
- self.contents.font.color = text_color(param.to_i)
- end
- return # 防止绘制转义符
- end
- cw = contents.text_size(tx).width #获取描绘这个字需要的宽度。
- if @text_pos[:x] + cw > Helpset::Width_MAX #如果描绘的坐标X加上宽度超过 xxx ,就换行。
- @text_pos[:x] = 0
- @text_pos[:y] += 24 #假如行距是 32 。
- end
- self.contents.draw_text(@text_pos[:x], @text_pos[:y], cw, 32, tx) #描绘这个文字。
- @text_pos[:x] += cw #宽度累加。
- end
复制代码
当然这只是抛砖引玉,只考虑了有[]传入参数的转义符,具体你可以自己尝试,仿照默认的window message绘制也可以 |
评分
-
查看全部评分
|