Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.90 KB | None | 0 0
  1. module Mouse
  2.   def Mouse.pos
  3.     x, y = Mouse.screen_to_client(*Mouse.global_pos)
  4.     width, height = Mouse.client_size
  5.     begin
  6.       if (x >= 0 and y >= 0 and x < width and y < height)
  7.         return x, y
  8.       else
  9.         return -100,-100
  10.       end
  11.     rescue
  12.       return -100,-100
  13.     end
  14.   end
  15. end
  16. class Scene_Title
  17.   alias start_mapmenuhud_settings start
  18.   def start
  19.     start_mapmenuhud_settings
  20.     $game_system.menu_disabled = DISABLE_STANDART_MENU
  21.     $game_switches[CONTROLL_SWITCH_ID] = START_UP_MENU_STATUS
  22.   end
  23. end
  24. class Scene_Map
  25.   alias start_mapmousehud start unless $@
  26.   def start
  27.     start_mapmousehud
  28.     @mmhud = Window_MapMouseHUD.new(X,Y,ITEMS)
  29.   end
  30.   alias update_mapmousehud update unless $@
  31.   def update
  32.     update_mapmousehud
  33.     @mmhud.update if !$game_map.interpreter.running? && !$game_message.visible && $game_switches[CONTROLL_SWITCH_ID]
  34.     if $game_switches[CONTROLL_SWITCH_ID] && !$game_message.visible
  35.       @mmhud.change_visibility(true)
  36.     else
  37.       @mmhud.change_visibility(false)
  38.     end
  39.   end
  40.   alias terminate_mapmousehud terminate unless $@
  41.   def terminate
  42.     terminate_mapmousehud
  43.     @mmhud.dispose
  44.   end
  45. end
  46. class Window_MapMouseHUD < Window_Base
  47.   def initialize(x,y,items = [])
  48.     super(x,y,32+items.length+items.length*24,56)
  49.     @items = []
  50.     @actors = []
  51.     @scene = nil
  52.     if self.y - 56 < 0
  53.       @help = Window_Base.new(x,y+112+DISCRITION_Y,DISCRIPTION_WIDTH,56)
  54.     else
  55.       @help = Window_Base.new(x,y-56+DISCRITION_Y,DISCRIPTION_WIDTH,56)
  56.     end
  57.     @cursor = [Sprite.new,Sprite.new]
  58.     @cursor[0].visible = false
  59.     @cursor[1].visible = false
  60.     @c_id = nil
  61.     @help.visible = false
  62.     @help.opacity = DISCRIPTION_OPACITY
  63.     x = ACTOR_X
  64.     y = ACTOR_Y
  65.     width = ACTOR_WIDTH
  66.     if ACTOR_AUTO
  67.       x = self.x + self.width
  68.       y = self.y
  69.       width = 544 - self.width - self.x
  70.     end
  71.     #@actor = Window_Base.new(x,y,width,56)
  72.    # @help.z = #@actor.z + 1
  73.     self.visible = $game_switches[CONTROLL_SWITCH_ID]
  74.     #@actor.visible = $game_switches[CONTROLL_SWITCH_ID]
  75.     draw_items(items)
  76.     #draw_party
  77.     create_cursor
  78.   end
  79.   def create_cursor
  80. =begin
  81.     @cursor[0].bitmap = Bitmap.new(24,24)
  82.     @cursor[0].bitmap.fill_rect(0,0,@cursor[0].bitmap.width,@cursor[0].bitmap.height,CURSOR_COLOR)
  83.     @cursor[0].bitmap.clear_rect(2,2,@cursor[0].bitmap.width-4,@cursor[0].bitmap.height-4)
  84.     width = (@actor.width-32) / $game_party.members.size
  85.     if $game_party.members.size == 1
  86.       width = width / 2.5
  87.     end
  88. =end
  89.     @cursor[1].bitmap = Bitmap.new(width,24)
  90.     @cursor[1].bitmap.fill_rect(0,0,@cursor[1].bitmap.width,@cursor[1].bitmap.height,CURSOR_COLOR)
  91.     @cursor[1].bitmap.clear_rect(2,2,@cursor[1].bitmap.width-4,@cursor[1].bitmap.height-4)
  92.     #@cursor[0].z = 101
  93.     @cursor[1].z = 101
  94.     #@cursor[0].x = -1000
  95.     #@cursor[1].x = -1000
  96.   end
  97.   def draw_items(items)
  98.     @items = []
  99.     self.contents.clear
  100.     for i in 0...items.length
  101.       draw_icon(items[i][0],i + i*24, 0)
  102.       @items.push(MapMouseHUD_Item.new(self.x + 16 + i + i*24,self.y+16,items[i][1],items[i][2],items[i][3]))
  103.     end
  104.   end
  105.   def draw_party
  106.     @actors = []
  107.     @actor.contents.clear
  108.     a = 0
  109.     platz = (@actor.width-32) / $game_party.members.size
  110.     if $game_party.members.size == 1
  111.       platz = platz / 2.5
  112.     end
  113.     for i in $game_party.members
  114.       x = a*(platz)
  115.       draw_member(x,a,platz)
  116.       @actors.push(MapMouseHUD_Character.new(@actor.x + 16 + x,@actor.y + 16,a,platz))
  117.       a += 1
  118.     end
  119.   end
  120.   def draw_member(x,id,platz)
  121.     actor = $game_party.members[id]
  122.     width = platz - 20
  123.     @actor.draw_actor_hp_gauge(actor,x+20,-8,width)
  124.     @actor.draw_actor_mp_gauge(actor,x+20,0,width)
  125.     bitmap = Cache.character(actor.character_name)
  126.     sign = actor.character_name[/^[\!\$]./]
  127.     if sign != nil and sign.include?('$')
  128.       cw = bitmap.width / 3
  129.       ch = bitmap.height / 4
  130.     else
  131.       cw = bitmap.width / 12
  132.       ch = bitmap.height / 8
  133.     end
  134.     n = actor.character_index
  135.     src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  136.     head = Bitmap.new(cw,ch)
  137.     head.blt(0,0, bitmap, src_rect)
  138.     @actor.contents.blt(x,0,head,Rect.new(0,0,cw,ch))
  139.     if $game_party.members.size == 1
  140.       draw_actor_state(actor, platz + 2, 0, platz - 2)
  141.     end
  142.   end
  143.   def draw_actor_state(actor, x, y, width = 96)
  144.     count = 0
  145.     for state in actor.states
  146.       @actor.contents.fill_rect(x,y,24,24,SLOT_COLORS[0])
  147.       @actor.contents.fill_rect(x+2,y+2,20,20,SLOT_COLORS[1])
  148.       draw_icon(state.icon_index, x + 24 * count, y)
  149.       count += 1
  150.       break if (24 * count > width - 24)
  151.     end
  152.   end
  153.   def draw_icon(icon_index, x, y, enabled = true)
  154.     self.contents.fill_rect(x,y,24,24,SLOT_COLORS[0])
  155.     self.contents.fill_rect(x+1,y+1,22,22,SLOT_COLORS[1])
  156.     bitmap = Cache.system("Iconset")
  157.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  158.     self.contents.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  159.   end
  160.   def hit?
  161.     if Mouse.pos != nil
  162.       return Mouse.pos[0] >= self.x && Mouse.pos[0] <= self.x+self.width && Mouse.pos[1] >= self.y && Mouse.pos[1] <= self.y+self.height
  163.     else
  164.       return false
  165.     end
  166.   end
  167.   def actor_hit?
  168.     return
  169.     if Mouse.pos != nil
  170.       return Mouse.pos[0] >= @actor.x && Mouse.pos[0] <= @actor.x+@actor.width && Mouse.pos[1] >= @actor.y && Mouse.pos[1] <= @actor.y+@actor.height
  171.     else
  172.       return false
  173.     end
  174.   end
  175.   def change_visibility(switch)
  176.     #@actor.visible = switch
  177.     self.visible = switch
  178.   end
  179.   def update_items
  180.     id = 0
  181.     for i in @items
  182.       if i.hit?
  183.         if !i.choose
  184.           i.call_item_scene
  185.           @scene = nil
  186.           @c_id = nil
  187.         else
  188.           @c_id = id
  189.           @scene = i.scene[0]
  190.         end
  191.       end
  192.       id += 1
  193.     end
  194.   end
  195.   def update_actors
  196.     for i in @actors
  197.       if i.hit?
  198.         i.call_item_scene(@scene)
  199.         @scene = nil
  200.         @c_id = nil
  201.       end
  202.     end
  203.   end
  204.   def update_cursor(item = nil)
  205.     if item != nil
  206.       if item.methods.include?("desc")
  207.         @cursor[0].x = item.x
  208.         @cursor[0].y = item.y
  209.       else
  210.         @cursor[1].x = item.x
  211.         @cursor[1].y = item.y
  212.       end
  213.     elsif @c_id != nil
  214.       @cursor[0].x = @items[@c_id].x
  215.     end
  216.     update_cursor_visibility
  217.   end
  218.   def update_cursor_visibility
  219.     if hit? || @c_id != nil
  220.       @cursor[0].visible = true
  221.     else
  222.       @cursor[0].visible = false
  223.     end
  224.     @cursor[1].visible = actor_hit?
  225.   end
  226.   def update
  227.     return if Mouse.pos.nil?
  228.     update_cursor
  229.     if Mouse.click?(1)
  230.       if @scene == nil || @c_id != nil
  231.         update_items
  232.       end
  233.       if @c_id != nil
  234.         #update_actors
  235.       elsif !actor_hit?
  236.         @scene = nil
  237.         @c_id = nil
  238.       end
  239.     else
  240.       for i in @items + @actors
  241.         if i.hit?
  242.           update_cursor(i)
  243.           if !@help.visible
  244.             @help.visible = true
  245.           end
  246.           @help.x = i.x if SLIDE_TO_ICON
  247.           @help.contents.clear
  248.           if i.methods.include?("desc")
  249.             text = i.desc
  250.           else
  251.             text = i.name
  252.           end
  253.           @help.contents.draw_text(0,0,DISCRIPTION_WIDTH-32,24,text,1)
  254.           break
  255.         else
  256.           if @help.visible
  257.             @help.visible = false
  258.             @help.contents.clear
  259.           end
  260.         end
  261.       end
  262.     end
  263.   end
  264.   def dispose
  265.     @items = []
  266.     @actors = []
  267.     @scene = nil
  268.     @c_id = nil
  269.     @help.dispose
  270.     #@actor.dispose
  271.     for i in @cursor
  272.       i.dispose
  273.     end
  274.     self.contents.dispose
  275.     super
  276.   end
  277. end
  278. class MapMouseHUD_Item
  279.   attr_reader :x
  280.   attr_reader :y
  281.   attr_reader :desc
  282.   attr_reader :scene
  283.   attr_reader :choose
  284.   def initialize(x,y,scene,choose_actor,description)
  285.     @x = x
  286.     @y = y
  287.     @scene = scene
  288.     @choose = choose_actor
  289.     @desc = description
  290.   end
  291.   def hit?
  292.     if Mouse.pos != nil
  293.       return Mouse.pos[0] >= @x && Mouse.pos[0] <= @x+24 && Mouse.pos[1] >= @y && Mouse.pos[1] <= @y+24
  294.     else
  295.       return false
  296.     end
  297.   end
  298.   def call_item_scene
  299.     $scene = eval("#{@scene[0]}.new(#{@scene[1]})")
  300.   end
  301. end
  302. class MapMouseHUD_Character
  303.   attr_reader :x
  304.   attr_reader :y
  305.   attr_reader :name
  306.   def initialize(x,y,mem_id,width)
  307.     @x = x
  308.     @y = y
  309.     @width = width
  310.     @id = mem_id
  311.     @name = $game_party.members[@id].name
  312.   end
  313.   def hit?
  314.     if Mouse.pos != nil
  315.       return Mouse.pos[0] >= @x && Mouse.pos[0] <= @x+@width && Mouse.pos[1] >= @y && Mouse.pos[1] <= @y+24
  316.     else
  317.       return false
  318.     end
  319.   end
  320.   def call_item_scene(scene)
  321.     $scene = eval("#{scene}.new(#{@id})")
  322.   end
  323. end
  324. if RETURN_TO_MAP
  325. class Scene_File
  326.  def return_scene
  327.    if @from_title
  328.      $scene = Scene_Title.new
  329.    elsif @from_event
  330.      $scene = Scene_Map.new
  331.    else
  332.      $scene = Scene_Map.new
  333.    end
  334.   end
  335. end
  336. class Scene_Equip
  337.  def return_scene
  338.    $scene = Scene_Map.new
  339.  end
  340. end
  341. class Scene_Status
  342.  def return_scene
  343.    $scene = Scene_Map.new
  344.  end
  345. end
  346. class Scene_Item
  347.  def return_scene
  348.    $scene = Scene_Map.new
  349.  end
  350. end
  351. class Scene_Skill
  352.  def return_scene
  353.    $scene = Scene_Map.new
  354.  end
  355. end
  356. class Scene_End
  357.  def return_scene
  358.    $scene = Scene_Map.new
  359.  end
  360. end
  361. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement