查看: 93|回复: 0

[转载发布] draw_text必备扩展

[复制链接]
  • TA的每日心情
    开心
    7 天前
  • 签到天数: 37 天

    连续签到: 3 天

    [LV.5]常住居民I

    2028

    主题

    32

    回帖

    7260

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    0
    卡币
    5184
    OK点
    16
    积分
    7260
    发表于 同元一千年八月四日(秋) | 显示全部楼层 |阅读模式
    非常实用,而且脚本易修改。
    另外脚本中不再置字体名、粗体以及斜体等的改变
    (因为那玩意性价比太低了 - - !)
    1. #===========================================================================#  *  draw_text必备扩展#============================================================================begin!c[n]   改用n号颜色 *注 颜色在color处自定!s[n]   改用n号大小!k[n]   空n像素v[n]    n号变量i[n]        描绘id为n的物品的图标s[n]        描绘id为n的特技的图标w[n]        描绘id为n的武器的图标a[n]        描绘id为n的防具的图标\\n   手动换行(附带自动换行)=endclass Window_Base < Window  def dl_draw_text(x, y, text)    #初始化数据    color_copy = self.contents.font.color.clone    text_copy = text    text_x,text_y = x,y    #正则    text_copy.gsub!(/!c\[([0-9]+)\]/) { "\001[#{$1}]" }    text_copy.gsub!(/!s\[([0-9]+)\]/) { "\002[#{$1}]" }    text_copy.gsub!(/!k\[([0-9]+)\]/) { "\003[#{$1}]" }    text_copy.gsub!(/i\[([0-9]+)\]/) { "\020[#{$1}]" }    text_copy.gsub!(/s\[([0-9]+)\]/) { "\021[#{$1}]" }    text_copy.gsub!(/w\[([0-9]+)\]/) { "\022[#{$1}]" }    text_copy.gsub!(/a\[([0-9]+)\]/) { "\023[#{$1}]" }    text_copy.gsub!(/v\[([0-9]+)\]/) { $game_variables[$1.to_i] }    text_copy.gsub!(/\\n/) { "\030" }    # 描绘每一个字    while ((c = text_copy.slice!(/./m)) != nil)      #颜色      if c == "\001"        text_copy.sub!(/\[([0-9]+)\]/, "")        self.contents.font.color = text_color($1.to_i)        next      end      #大小      if c == "\002"        text_copy.sub!(/\[([0-9]+)\]/, "")        self.contents.font.size = $1.to_i        next      end      #空像素      if c == "\003"        text_copy.sub!(/\[([0-9]+)\]/, "")        text_x += $1.to_i        if text_x > self.width - 40          text_x = 40 + text_x - self.width          text_y += self.contents.font.size        end        next      end      #物品      if c == "\020"        text_copy.sub!(/\[([0-9]+)\]/, "")        if !$data_items[$1.to_i].nil? and $data_items[$1.to_i].icon_name != ""          next if text_x + 24 > self.width - 32          bitmap = RPG::Cache.icon($data_items[$1.to_i].icon_name)          self.contents.blt(text_x, text_y, bitmap, Rect.new(0, 0, 24, 24))          text_x += 24        end        next      end      #特技      if c == "\021"        text_copy.sub!(/\[([0-9]+)\]/, "")        if !$data_skills[$1.to_i].nil? and $data_skills[$1.to_i].icon_name != ""          next if text_x + 24 > self.width - 32          bitmap = RPG::Cache.icon($data_skills[$1.to_i].icon_name)          self.contents.blt(text_x, text_y, bitmap, Rect.new(0, 0, 24, 24))          text_x += 24        end        next      end      #武器      if c == "\022"        text_copy.sub!(/\[([0-9]+)\]/, "")        if !$data_weapons[$1.to_i].nil? and $data_weapons[$1.to_i].icon_name != ""          next if text_x + 24 > self.width - 32          bitmap = RPG::Cache.icon($data_weapons[$1.to_i].icon_name)          self.contents.blt(text_x, text_y, bitmap, Rect.new(0, 0, 24, 24))          text_x += 24        end        next      end      #防具      if c == "\023"        text_copy.sub!(/\[([0-9]+)\]/, "")        if !$data_armors[$1.to_i].nil? and $data_armors[$1.to_i].icon_name != ""          next if text_x + 24 > self.width - 32          bitmap = RPG::Cache.icon($data_armors[$1.to_i].icon_name)          self.contents.blt(text_x, text_y, bitmap, Rect.new(0, 0, 24, 24))          text_x += 24        end        next      end      #换行      if c == "\030"        text_y += self.contents.font.size        next      end      cx = self.contents.text_size(c).width      self.contents.draw_text(text_x, text_y, cx, self.contents.font.size, c)      text_x += cx      #自动换行      if text_x > self.width - 40        text_x = 0        text_y += self.contents.font.size      end    end    self.contents.font.color = color_copy  endend复制代码
    复制代码
                 本帖来自P1论坛作者恐惧剑刃,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=343165  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
    天天去同能,天天有童年!
    回复 论坛版权

    使用道具 举报

    ahome_bigavatar:guest
    ahome_bigavatar:welcomelogin
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2024-5-17 19:12 , Processed in 0.048146 second(s), 43 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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