じ☆ve冰风 发表于 2024-4-19 21:47:06

draw_text必备扩展

非常实用,而且脚本易修改。
另外脚本中不再置字体名、粗体以及斜体等的改变
(因为那玩意性价比太低了 - - !)#===========================================================================#*draw_text必备扩展#============================================================================begin!c   改用n号颜色 *注 颜色在color处自定!s   改用n号大小!k   空n像素v    n号变量i      描绘id为n的物品的图标s      描绘id为n的特技的图标w      描绘id为n的武器的图标a      描绘id为n的防具的图标\\n   手动换行(附带自动换行)=endclass Window_Base < Windowdef 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\[(+)\]/) { "\001[#{$1}]" }    text_copy.gsub!(/!s\[(+)\]/) { "\002[#{$1}]" }    text_copy.gsub!(/!k\[(+)\]/) { "\003[#{$1}]" }    text_copy.gsub!(/i\[(+)\]/) { "\020[#{$1}]" }    text_copy.gsub!(/s\[(+)\]/) { "\021[#{$1}]" }    text_copy.gsub!(/w\[(+)\]/) { "\022[#{$1}]" }    text_copy.gsub!(/a\[(+)\]/) { "\023[#{$1}]" }    text_copy.gsub!(/v\[(+)\]/) { $game_variables[$1.to_i] }    text_copy.gsub!(/\\n/) { "\030" }    # 描绘每一个字    while ((c = text_copy.slice!(/./m)) != nil)      #颜色      if c == "\001"      text_copy.sub!(/\[(+)\]/, "")      self.contents.font.color = text_color($1.to_i)      next      end      #大小      if c == "\002"      text_copy.sub!(/\[(+)\]/, "")      self.contents.font.size = $1.to_i      next      end      #空像素      if c == "\003"      text_copy.sub!(/\[(+)\]/, "")      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!(/\[(+)\]/, "")      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!(/\[(+)\]/, "")      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!(/\[(+)\]/, "")      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!(/\[(+)\]/, "")      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_copyendend复制代码
             本帖来自P1论坛作者恐惧剑刃,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=343165若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页: [1]
查看完整版本: draw_text必备扩展