Project1

标题: 鼠标系统 [打印本页]

作者: 淡/jk忘    时间: 2009-7-7 09:45
提示: 作者被禁止或删除 内容自动屏蔽
作者: 我不宅    时间: 2009-7-7 11:27
还是键盘吧!
作者: 藏剑江南    时间: 2009-7-8 21:15
我也想了解鼠标操作系统。。。但好像主站关于这方面的好像不多。。基本还是键盘流的。。。
作者: redant    时间: 2009-7-8 21:47
本帖最后由 redant 于 2009-7-8 21:49 编辑
  1. #==============================================================================
  2. # 修改自redant
  3. class Window_Picture_Command2 < Window_Selectable
  4.    attr_accessor :last_index
  5.    attr_accessor :active
  6.   attr_accessor :icon_name
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #     width    : 窗口的宽
  10.   #     commands : 命令字符串序列
  11.   #--------------------------------------------------------------------------
  12.   def initialize(commands,type=2)
  13.     # 由命令的个数计算出窗口的高
  14.     super(0, 0, 640, 480)
  15.     @item_max = commands.size
  16.     @commands = commands
  17.      @name_sprite = nil
  18.     @dash = []
  19.     @sprite = []
  20.     @icon_name = icon_name
  21.     @last_icon = @icon_name
  22.       @count = 0
  23.     @type = type
  24.     @move_index = self.index
  25.     self.opacity = 0
  26.     self.contents = Bitmap.new(width - 32, @item_max * 32)
  27.     refresh
  28.     self.index = 0
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # ● 刷新
  32.   #--------------------------------------------------------------------------
  33.   def refresh
  34.     self.contents.clear
  35.   @name_sprite.dispose unless @name_sprite.nil?

  36.   
  37.     for sprite in @sprite
  38.       sprite.dispose unless sprite.nil?
  39.     end
  40.     @name_sprite = nil
  41.     draw_com_name #if Momo_IconCommand::COM_NAME_DROW
  42.     @sprite = []

  43.      
  44.     for i in 0...@item_max
  45.       
  46.       draw_picture_item(i, @type)
  47.     end
  48.    
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● 释放
  52.   #--------------------------------------------------------------------------
  53.   def dispose
  54.     super
  55.     for index in @dash
  56.      if @sprite[index] != nil
  57.        @sprite[index].dispose
  58.        @sprite[index].bitmap.dispose
  59.      end
  60.     end
  61.   end  
  62.   #--------------------------------------------------------------------------
  63.   # ● 描绘图片项目
  64.   #     index : 项目编号
  65.   #     type  : 描绘类型
  66.   #     type = 1 只支持键盘
  67.   #     type = 2 双面支持
  68.   #--------------------------------------------------------------------------
  69.   def draw_picture_item(index, type)
  70.     @sprite[index] = Sprite.new
  71.         @sprite[index].z = 9998
  72.     if @commands[index][0] == nil
  73.       p "图片名设置有误"
  74.     end
  75.     if @commands[index][1] == nil
  76.       p "图片X坐标设置有误"
  77.     end
  78.     if @commands[index][2] == nil
  79.       p "图片Y坐标设置有误"
  80.     end
  81.     bitmap = RPG::Cache.picture(@commands[index][0])
  82.    
  83.    
  84.    
  85.     @sprite[index].bitmap = bitmap
  86.     @sprite[index].x = @commands[index][1]
  87.     @sprite[index].y = @commands[index][2]
  88.     @sprite[index].index = index
  89.     for i in [email protected]
  90.       @sprite[i].update
  91.     end
  92.    
  93.     # @sprite[index].update
  94.     if $xiaoshi == true
  95.       @sprite[index].opacity = 0
  96.     end
  97.    
  98.     if @sprite[index].index != self.index
  99.       @sprite[index].opacity = 155
  100.     else
  101.       @sprite[index].opacity = 255
  102.     end
  103.     @dash.push(index)
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # ● 刷新图片项目
  107.   #--------------------------------------------------------------------------
  108.   def update_item
  109.     if Mouse.get_mouse_pos != nil
  110.     $mouse_x,$mouse_y = Mouse.get_mouse_pos
  111.     end
  112.     if @type == 2 and $stop == false
  113.     for index in @dash
  114.      if @sprite[index] != nil
  115.       top_x = @sprite[index].x
  116.       top_y = @sprite[index].y
  117.       bottom_x = top_x + @sprite[index].bitmap.width
  118.       bottom_y = top_y + @sprite[index].bitmap.height
  119.       if ($mouse_x > top_x) and ($mouse_y > top_y) and
  120.            ($mouse_x < bottom_x) and ($mouse_y < bottom_y)
  121.            self.index = @sprite[index].index
  122.            if @move_index != self.index

  123.              if $xiaoshi == true
  124.                else
  125.            Se.ok
  126.          end
  127.          
  128.            @move_index = self.index
  129.          end
  130.        end
  131.     if $xiaoshi == true
  132.       @sprite[index].opacity = 0
  133.       else
  134.       if @sprite[index].index != self.index
  135.          @sprite[index].opacity = 240
  136.       
  137.   
  138.       else
  139.         @sprite[index].opacity = 255
  140.       end
  141.     end
  142.    
  143.    
  144.     end
  145.   end
  146.     elsif @type == 1
  147.      for index in @dash
  148.         if @sprite[index].index != self.index
  149.          @sprite[index].opacity = 155
  150.        else
  151.         @sprite[index].opacity = 255
  152.        end
  153.      end  
  154.    end
  155.   
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 图片项目无效化
  159.   #     index : 项目编号
  160.   #--------------------------------------------------------------------------
  161.   def disable_item(index)
  162.     @sprite[index].opacity = 155
  163.   end
  164.   
  165.   #--------------------------------------------------------------------------
  166.   # ● 刷新
  167.   #--------------------------------------------------------------------------
  168.   alias window_picture_command_update update
  169.   def update
  170.    
  171.      window_picture_command_update
  172.     update_item
  173.    icon_update
  174.     com_name_update
  175.    
  176.    
  177.     if @active
  178.      @count += 1
  179.      icon_flash
  180.      @count = 0 if @count == 20
  181.    else
  182.      @count = 0
  183.    end
  184.    
  185.     if self.active
  186.     # 判断当前光标位置
  187.     case @last_index
  188.      when 0 # 攻击
  189.       # 方向键下被按下的情况下
  190.       if Input.repeat?(Input::DOWN)
  191.           # 光标指向物品
  192.           $game_system.se_play($data_system.cursor_se)
  193.           @index = 3      
  194.       end
  195.       # 方向键上被按下的情况下
  196.       if Input.repeat?(Input::UP)
  197.         # 光标指向攻击
  198.           $game_system.se_play($data_system.cursor_se)
  199.           @index = 3      
  200.       end
  201.       # 方向键右被按下的情况下
  202.       if Input.repeat?(Input::RIGHT)
  203.           # 光标指向防御
  204.           $game_system.se_play($data_system.cursor_se)
  205.           @index = 2      
  206.       end
  207.       # 方向键左被按下的情况下
  208.       if Input.repeat?(Input::LEFT)
  209.         # 光标指向法术
  210.           $game_system.se_play($data_system.cursor_se)
  211.           @index = 1
  212.       end
  213.      when 1 # 法术
  214.       # 方向键下被按下的情况下
  215.       if Input.repeat?(Input::DOWN)
  216.           # 光标指向物品
  217.           $game_system.se_play($data_system.cursor_se)
  218.           @index = 3      
  219.       end
  220.       # 方向键上被按下的情况下
  221.       if Input.repeat?(Input::UP)
  222.         # 光标指向攻击
  223.           $game_system.se_play($data_system.cursor_se)
  224.           @index = 0      
  225.       end
  226.       # 方向键右被按下的情况下
  227.       if Input.repeat?(Input::RIGHT)
  228.           # 光标指向防御
  229.           $game_system.se_play($data_system.cursor_se)
  230.           @index = 2      
  231.       end
  232.       # 方向键左被按下的情况下
  233.       if Input.repeat?(Input::LEFT)
  234.         # 光标指向法术
  235.           $game_system.se_play($data_system.cursor_se)
  236.           @index = 2
  237.       end
  238.      when 2 # 防御
  239.       # 方向键下被按下的情况下
  240.       if Input.repeat?(Input::DOWN)
  241.           # 光标指向物品
  242.           $game_system.se_play($data_system.cursor_se)
  243.           @index = 3      
  244.       end
  245.       # 方向键上被按下的情况下
  246.       if Input.repeat?(Input::UP)
  247.         # 光标指向攻击
  248.           $game_system.se_play($data_system.cursor_se)
  249.           @index = 0      
  250.       end
  251.       # 方向键右被按下的情况下
  252.       if Input.repeat?(Input::RIGHT)
  253.           # 光标指向防御
  254.           $game_system.se_play($data_system.cursor_se)
  255.           @index = 1      
  256.       end
  257.       # 方向键左被按下的情况下
  258.       if Input.repeat?(Input::LEFT)
  259.         # 光标指向技能
  260.           $game_system.se_play($data_system.cursor_se)
  261.           @index = 1
  262.       end
  263.      when 3 # 物品
  264.       # 方向键下被按下的情况下
  265.       if Input.repeat?(Input::DOWN)
  266.           # 光标指向物品
  267.           $game_system.se_play($data_system.cursor_se)
  268.           @index = 0      
  269.       end
  270.       # 方向键上被按下的情况下
  271.       if Input.repeat?(Input::UP)
  272.         # 光标指向攻击
  273.           $game_system.se_play($data_system.cursor_se)
  274.           @index = 0      
  275.       end
  276.       # 方向键右被按下的情况下
  277.       if Input.repeat?(Input::RIGHT)
  278.           # 光标指向防御
  279.           $game_system.se_play($data_system.cursor_se)
  280.           @index = 2      
  281.       end
  282.       # 方向键左被按下的情况下
  283.       if Input.repeat?(Input::LEFT)
  284.         # 光标指向法术
  285.           $game_system.se_play($data_system.cursor_se)
  286.           @index = 1
  287.       end

  288.     end      
  289.       @last_index = self.index
  290.     end
  291.    
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # ● 更新光标举行
  295.   #--------------------------------------------------------------------------
  296.   def update_cursor_rect
  297.     if @index < 0
  298.       self.cursor_rect.empty
  299.       return
  300.     end
  301.     row = @index / @column_max
  302.     if row < self.top_row
  303.       self.top_row = row
  304.     end
  305.     if row > self.top_row + (self.page_row_max - 1)
  306.       self.top_row = row - (self.page_row_max - 1)
  307.     end
  308.     cursor_width = self.width / @column_max - 32
  309.     x = @index % @column_max * (cursor_width + 32)
  310.     y = @index / @column_max * 32 - self.oy
  311.     self.cursor_rect.set(x+5000, y, cursor_width, 32)
  312.   end
  313.   
  314.   #######################

  315.    def draw_com_name
  316.     @name_sprite = Sprite_Comm_Name.new(nil, get_com_name)
  317.   end
  318. ####################
  319.   def icon_update
  320.    for i in [email protected]
  321.       @sprite[i].update
  322.     end
  323.   end

  324.   
  325.    def icon_flash
  326.     if @count % 20 == 0 or @count == 2
  327.       @sprite[index].flash(Color.new(255, 255, 255, 128), 10)
  328.     end
  329.   end
  330.   ############
  331.   def text_reset
  332.     @count = 0
  333.     @x_plus = 0
  334.     self.bitmap.clear
  335.      src_rect = Rect.new(0, -5, 560, 128)
  336.       back_help = Bitmap.new("Graphics/system/menu/back/特技框.png")
  337.       self.bitmap.blt(0, -5, back_help, src_rect, 255)
  338.    
  339.     #定义蓝色(很PL 不是吗?) Momo_IconCommand::COM_NAME_COLOR
  340.       self.bitmap.font.size = 16
  341.       #文字的大小
  342.    
  343.    
  344.   case @name
  345.     when "攻击"
  346.       self.bitmap.font.color = Color.new(255, 10, 10, 255)
  347.     when "特技"
  348.       self.bitmap.font.color = Color.new(255, 255, 0, 255)     
  349.     when "物品"
  350.       self.bitmap.font.color = Color.new(5, 255, 0, 255)
  351.     when"防御"
  352.       self.bitmap.font.color = Color.new(5, 20, 255, 255)
  353.     end
  354.      self.bitmap.draw_text(25, 0, 260, 32, @name)
  355.    end
  356.    
  357.   
  358.   def com_name_update
  359.    # if move_index?
  360.       @name_sprite.name = get_com_name

  361.    
  362. if self.x<100#80
  363.     @name_sprite.x =  self.x + 275
  364.   elsif self.x < 200#150
  365.     @name_sprite.x = self.x + 279
  366.     else self.x < 300#220
  367.     @name_sprite.x = self.x + 282
  368.       end

  369.    if self.y<200#190
  370.     @name_sprite.y =  145
  371.   elsif self.y < 300#250
  372.     @name_sprite.y = 210
  373.     else self.y < 400#320
  374.     @name_sprite.y= 295
  375.       end
  376.    
  377.    
  378. # 文字出现的坐标 以固定在下面

  379.     #+ Momo_IconCommand::COM_NAME_Y_PLUS
  380.     @name_sprite.z = 9998 #self.z + 1
  381.     @name_sprite.active = self.active
  382.     @name_sprite.visible = self.visible
  383.     @name_sprite.update
  384. end
  385. def get_com_name
  386.     make_name_set if @name_set.nil?
  387.     name = @name_set[self.index]   
  388.     name = "" if name.nil?
  389.     return name
  390.   end
  391.   def make_name_set
  392.     @name_set = []
  393.     @name_set[0] = Momo_IconCommand::ATTACK_NAME
  394.     @name_set[1] = Momo_IconCommand::SKILL_NAME
  395.     @name_set[2] = Momo_IconCommand::GUARD_NAME
  396.     @name_set[3] = Momo_IconCommand::ITEM_NAME
  397.     #@name_set[4] = Momo_IconCommand::ESCAPE_NAME
  398.   end
  399.   def move_index?
  400.     return self.index != @last_index
  401.   end
  402.   def need_reset
  403.     @name_sprite.need_reset = true# if Momo_IconCommand::COM_NAME_DROW
  404.   end
  405. def need_reset?
  406.     return (@name != @last_name or @need_reset)
  407.   end
  408. end
  409. #==============================================================================
  410. # ■ Se
  411. #------------------------------------------------------------------------------
  412. # ■ 音效模块
  413. #==============================================================================
  414. module Se
  415.   def self.ok
  416.     $game_system.se_play($data_system.cursor_se)
  417.   end
  418.   def self.no
  419.     $game_system.se_play($data_system.cancel_se)
  420.   end
  421. end
  422. #==============================================================================
  423. # ■ Sprite
  424. #------------------------------------------------------------------------------
  425. # ■ index 选择光标
  426. #==============================================================================
  427. class Sprite
  428.   attr_accessor :index
  429.   
  430. end
复制代码
不一定适合你 是我自己的
注意看开头 应该会用吧  比图标战斗还少点功能没实现

QQ截图未命名.jpg (46.39 KB, 下载次数: 4)

QQ截图未命名.jpg

作者: angelwangm    时间: 2009-7-8 21:59
谢谢蚂蚁,收下
作者: 阿强    时间: 2009-7-9 07:01
提示: 作者被禁止或删除 内容自动屏蔽
作者: END66RPG    时间: 2009-7-9 09:53
不要
作者: END66RPG    时间: 2009-7-9 09:53
啊啊啊
作者: redant    时间: 2009-7-9 12:04
你仔细看下 你的那个脚本是不需要的了
直接复制过去  

看看其实有些代码是一样的 = = 我就是拷过去的
作者: 风中承诺    时间: 2009-7-9 13:27
那个模式的确很好。
作者: aq5888123    时间: 2009-7-10 12:54
看看




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