Project1

标题: 【伪·紫菜单】因为写得太挫所以发水区 [打印本页]

作者: kuerlulu    时间: 2014-7-20 08:46
标题: 【伪·紫菜单】因为写得太挫所以发水区

RUBY 代码复制
  1. #encoding:utf-8
  2. # 一个子窗口
  3. #  其实功能好扩展我会乱说?
  4. class Sub_Window < Window_Base
  5.   #--------------------------------------------------------------------------
  6.   # ● 初始化对象
  7.   #--------------------------------------------------------------------------
  8.   def initialize(x, y)
  9.     super(x, y, window_width, fitting_height(visible_line_number))
  10.     self.openness = 0
  11.     activate
  12.   end
  13.   #--------------------------------------------------------------------------
  14.   # ● 获取窗口的宽度
  15.   #--------------------------------------------------------------------------
  16.   def window_width
  17.     return 128
  18.   end
  19.   #--------------------------------------------------------------------------
  20.   # ● 获取显示行数
  21.   #--------------------------------------------------------------------------
  22.   def visible_line_number
  23.     return 1
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 设置
  27.   #--------------------------------------------------------------------------
  28.   def setup(text, *mode)
  29.     create_contents
  30.     self.contents.draw_text(self.contents.rect, text)
  31.     case mode
  32.     when [:bar]
  33.       @var = 0
  34.       @vartemp = @var
  35.       @bar = Sprite.new
  36.       @bar.x,@bar.y,@bar.z,@bar.opacity = self.x+14,self.y+14,100,205
  37.       @bar.bitmap = Bitmap.new(74, 20)
  38.       @bar.bitmap.fill_rect(@bar.bitmap.rect, Color.new(255,255,255))
  39.       self.contents.draw_text(self.contents.rect, @var, 2)
  40.     end
  41.     open
  42.   end
  43.   #--------------------------------------------------------------------------
  44.   # ● 刷新
  45.   #--------------------------------------------------------------------------
  46.   def update
  47.     super
  48.     if @bar
  49.       @var += 1 if Input.press?(:UP) && @var != 100
  50.       @var -= 1 if Input.press?(:DOWN) && @var != 0
  51.       if @var != @vartemp
  52.         @vartemp = @var
  53.         update_bar
  54.       end
  55.     end
  56.   end
  57.   def dispose
  58.     (@bar.bitmap.dispose;@bar.dispose) if @bar
  59.     super
  60.   end
  61.   def update_bar
  62.     self.contents.clear
  63.     self.contents.draw_text(self.contents.rect, @var, 2)
  64.     @bar.bitmap.clear
  65.     @bar.bitmap.fill_rect(@bar.bitmap.rect, Color.new(255,255,255))
  66.     @bar.bitmap.fill_rect(0, 0, @bar.bitmap.width*@var/100, 20, Color.new(102,204,255))
  67.   end
  68. end
  69.  
  70. # 子菜单管理器
  71. #  其实是场景我会瞎说?
  72. class Window_WithSub
  73.   attr_reader :x,:y       # 坐标
  74.   attr_reader :index      # 当前光标位置
  75.   attr_reader :windows    # 窗口数组
  76.   attr_reader :value      # 传参借位
  77.   attr_reader :methd      # 方法数组
  78.   # hash 格式:
  79.   #{ :command1 => method(:symbol1),
  80.   #  :command2 => { :command21 => method(:symbol2) } }
  81.   def initialize(x, y, hash, &block)
  82.     @x,@y,@index = x,y,0
  83.     @last = @index
  84.     instance_eval(&block) if block_given?
  85.     @windows,@methd = [],[]
  86.     create_windows(hash)
  87.     main
  88.   end
  89.   def main
  90.     loop do
  91.       Graphics.update
  92.       Input.update
  93.       break dispose if Input.trigger?(:LEFT)
  94.       update
  95.     end
  96.   end
  97.   def create_windows(hash)
  98.     hash.each do |key, value|
  99.       if (value.is_a? Method)||(value.is_a? Symbol)
  100.         @windows.push(new_window(key, value))
  101.       elsif value.is_a? Hash
  102.         @value = value
  103.         @windows.push(new_window(key, method(:new_sub)))
  104.       end
  105.     end
  106.   end
  107.   def new_sub
  108.     Window_WithSub.new(self.x+60, self.y+40, @value)
  109.   end
  110.   def new_window(sym, obj)
  111.     w = Sub_Window.new(self.x, self.y + 48 * @windows.size)
  112.     if obj.is_a? Method
  113.       w.setup(sym.to_s)
  114.       @methd[@windows.size] = obj
  115.     elsif obj.is_a? Symbol
  116.       w.setup("" , obj)
  117.       @methd[@windows.size] = ->{}
  118.     end
  119.     return w
  120.   end
  121.   def update
  122.     if Input.trigger?(:UP)
  123.       Sound.play_cursor
  124.       @index == 0 ? @index = @windows.size-1 : @index -= 1
  125.     elsif Input.trigger?(:DOWN)
  126.       Sound.play_cursor
  127.       @index == @windows.size-1 ? @index = 0 : @index += 1
  128.     elsif Input.trigger?(:RIGHT)
  129.       if @methd[@index].inspect == "#<Method: Game_Interpreter#m1>"
  130.         Sound.play_buzzer
  131.       else
  132.         Sound.play_ok
  133.         @methd[@index].call
  134.       end
  135.     elsif Input.trigger?(:LEFT)
  136.       Sound.play_cancel
  137.     end
  138.     @windows.each { |w| w.update }
  139.     activate(@windows[@index])
  140.     if @last != @index
  141.       @last = @index
  142.     end
  143.   end
  144.   def dispose
  145.     @windows.each { |w| w.dispose }
  146.   end
  147.   def activate(window)
  148.     @windows.each_with_index do |w,i|
  149.       w.cursor_rect.empty
  150.       w.cursor_rect.set(Rect.new(0, 0, 104, 24)) if w == window
  151.     end
  152.   end
  153. end
  154.  
  155. class Game_Interpreter
  156.   def m1;end
  157.   def callsubw
  158.     subw = Window_WithSub.new(60, 60, {
  159.       :物品 => method(:m1),
  160.       :装备 => method(:m1),
  161.       :技能 => method(:m1),
  162.       :状态 => method(:m1),
  163.       :笔记 => method(:m1),
  164.       :系统 => {
  165.         :音乐 => { :var => :bar },
  166.         :音效 => method(:m1),
  167.         :读档 => method(:m1),
  168.         :标题 => method(:m1)},
  169.       :读档 => method(:m1),
  170. })
  171.   end
  172. end


我还是太年轻了
以及颜文字功能好像有bug的说搞基编辑模式下按颜文字会清空已编辑的内容
作者: taroxd    时间: 2014-7-20 08:48
大触收下我的膝盖
作者: 克莉丝    时间: 2014-7-20 08:52
大触收下我的膝盖

来水区都是大触
作者: 柳泖    时间: 2014-7-20 08:56
大触收下我的膝盖
作者: 小路比仔    时间: 2014-7-20 09:03
嘛……我连看都看不懂脚本内容啦~大大请不要妄自菲薄哦
作者: 月华风    时间: 2014-7-20 09:10
大触请收下我的膝盖
作者: 鑫晴    时间: 2014-7-20 09:32

大触收下我的膝盖
作者: 恐惧剑刃    时间: 2014-7-20 10:22
用图片做底效果不差
这么快都有人收藏了!!!我的帖子就没见有人收藏过( ̄︿ ̄)
作者: satgo1546    时间: 2014-7-20 10:36
难道这个帖子就是你写的(?
作者: 你最珍贵    时间: 2014-7-20 11:05
这就是昨晚触手们研究的结果吗
作者: 荒风之歌    时间: 2014-7-20 11:09
大触请收下膝盖……可怜我不会脚本么么哒~
作者: 江户川洛奇    时间: 2014-7-20 11:22

大触请收下我的膝盖
作者: chd114    时间: 2014-7-20 11:39
73旁边那两种颜色的进度条是代表什么?
作者: FacLos    时间: 2014-7-20 11:42
漏了两行的字符
RUBY 代码复制
  1. #by kuerlulu
  2. #转载请保留此信息

作者: 楼主是我的女仆    时间: 2014-7-20 14:34
这个脚本是你写的还是@chd114 写的?
作者: chd114    时间: 2014-7-20 14:40
楼主是我的女仆 发表于 2014-7-19 21:34
这个脚本是你写的还是@chd114 写的?

不是我写的(ノ゚∀゚)ノ
作者: 李光兆    时间: 2014-7-20 18:50
大触请让我们做朋友吧_(:з」∠)_帮我写写(免费的高端霸气上档次的)脚本就好
作者: 机械守护者    时间: 2014-7-21 17:19
收下我的膝盖




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