[XP] Mouse Map Menu

Started by nathmatt, August 07, 2010, 10:27:20 am

Previous topic - Next topic

Shalaren

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Mouse Map Menu by Nathmatt
# Version: 1.26
# Type: Menu
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
module Mouse_Map_Menu

  Version = 1.26
  #============================================================================
  # Mouse_Map_Menu::Config
  #----------------------------------------------------------------------------
  #  This module performs the the configurations.
  #============================================================================
  module Config
    Condition = 0               # 0 for Horizontal 1 for Vertical
    Icons     = ['040-Item09', '040-Item09']  # Array of menu icons
    Key       = ['M', 'N']           # Array of keys that will call the scene
    Scenes    = [Scene_Item, Scene_Achievements]    # Array of scenes add Back to to return to map
                                # when not on map Scene_End if you are
    Mouse     = false           # The mouse graphic while over a command
                                # or false for none
    Back      = false           # The picture back for each icon or false for none
    Window    = false           # The picture used like a window for the icons
                                # or false for none
    X         = 0               # The x co-ordanance is by 32
    Y         = 14              # The y co-ordanance is by 32
  end
  #============================================================================
  # Mouse_Map_Menu::Processor
  #----------------------------------------------------------------------------
  #  This class performs the mouse processing.
  #============================================================================
  class Processor
   
    attr_reader   :event_disabled
    attr_accessor :menu_disabled
   
    CON    = Config::Condition
    ICONS  = Config::Icons
    KEY    = Config::Key
    SCENES = Config::Scenes
    MOUSE  = Config::Mouse
    BACK   = Config::Back
    WINDOW = Config::Window
    SIZE   = ICONS.size
    X      = Config::X * 32
    Y      = Config::Y * 32
    W      = (CON == 0 ? SIZE * 32 : 32)
    H      = (CON == 1 ? SIZE * 32 : 32)
   
    def main
      return if @window != nil
      @window,@back,@menu = Sprite.new,Sprite.new,Sprite.new
      @window.z,@back.z,@menu.z = 100,150,200
      @window.x = @back.x = @menu.x = X
      @window.y = @back.y = @menu.y = Y
      @window.bitmap = RPG::Cache.picture(WINDOW) if WINDOW != false
      @back.bitmap = Bitmap.new(W,H)
      @menu.bitmap = Bitmap.new(W,H)
      @disabled = []
      (0...SIZE).each{|i|draw_command(i)}
    end
   
    def draw_command(i)
      x,y = (CON == 0 ? (i * 32) : 0),(CON == 1 ? (i * 32) : 0)
      rect = Rect.new(x,y,32,32)
      @menu.bitmap.fill_rect(rect,Color.new(0,0,0,0))
      if BACK != false
        item = RPG::Cache.picture(BACK)
        @back.bitmap.stretch_blt(rect,item,Rect.new(0,0,item.width,item.height))
      end
      item = RPG::Cache.icon(ICONS[i])
      opacity = (@disabled[i] ? 128 : 255)
      @menu.bitmap.fill_rect(rect,Color.new(0,0,0,0))
      @menu.bitmap.blt(x+4,y+4,item,Rect.new(0,0,24,24),opacity)
    end
   
    def update
      dispose if @menu_disabled
      main    if !@menu_disabled
      return if @menu == nil
      check_mouse
      check_opacity
      i = check_keys
      @event_disabled = (i != false)
      if i != false
        if SCENES[i] == 'Back'
          $scene = ($scene.is_a?(Scene_Map) ? Scene_End.new : Scene_Map.new)
          return
        end
        $scene = SCENES[i].new
      end
    end
     
    def check_mouse
      return if MOUSE == false
      i = over_button?
      if $MCES != nil
        $MCES.mouse_menu = (i != false)
        return
      end
      if i != false
        $mouse.set_cursor(MOUSE)
      else
        $mouse.set_cursor(Mouse::MOUSE_ICON)
      end
    end
   
    def check_keys
      return over_button? if Input.trigger?(Input::Key['Mouse Left'])
      (0...SIZE).each{|i|
      return i if Config::Key[i] != nil &&
        Input.trigger?(Input::Key[Config::Key[i]])}
      return false
    end
   
    def over_button?
      (0...SIZE).each{|i|
      x,y = (CON == 0 ? (X + i * 32) : X),(CON == 1 ? (Y + i * 32) : Y)
      if $mouse.x >= x && $mouse.y >= y && $mouse.x <= x + 32 && $mouse.y <= y + 32
        return i
      end}
      return false
    end

    def dispose
      [@window,@back,@menu].each{|s|s.dispose if s != nil && !s.disposed?}
      @window = @back = @menu = nil
    end
    def mouse_in_area?
      return false if @menu == nil || @menu.disposed?
      s = @menu
      b = s.bitmap
      return $game_player.screen_x <= s.x + b.width &&
         $game_player.screen_y <= s.y + b.height &&
         $game_player.screen_x >= s.x && $game_player.screen_y >= s.y
    end
   
   
    def check_opacity
      if mouse_in_area?
        @menu.opacity -= 25 if @menu.opacity > 80
      elsif @menu.opacity <= 255
        @menu.opacity += 25
      end
      [@window,@back,@menu].each{|s|s.opacity = @menu.opacity if !s.disposed?}
    end
   
  end

end

$mouse_map_menu = Mouse_Map_Menu::Processor.new

class Scene_Map

  alias mouse_map_menu_main main
  def main
    $mouse_map_menu.main
    mouse_map_menu_main
    $mouse_map_menu.dispose
  end

  alias mouse_map_menu_update update
  def update
    $mouse_map_menu.update
    mouse_map_menu_update
  end

end

class Game_Event < Game_Character

  alias start_event_menu start
  def start
    return if $mouse_map_menu.event_disabled
    start_event_menu
  end

end

if $MCES != nil
class MCES::Processor

  attr_accessor :mouse_menu

  alias mouse_menu_check_mouse check_mouse
  def check_mouse
    if @mouse_menu
      $mouse.set_cursor(Mouse_Map_Menu::Config::Mouse)
      return
    end
    mouse_menu_check_mouse
  end

end
end

KK20

August 09, 2013, 08:42:48 pm #81 Last Edit: August 09, 2013, 08:43:58 pm by KK20
Is the achievements script located above this script?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Shalaren

I like how something as simple as that causes a problem. yeah it is now and its working! thanks :)

KK20

No problem. When you start up the game, it will run through all your scripts in your database in order and essentially 'load' them. When you put the achievements script above this script, the game knows there is a class called Scene_Achievements (because it loaded the achievements script before loading this script). When you swap the scripts' positions, the game has no idea that there is a class Scene_Achievements--it doesn't exist in memory yet. Instead, the game will now treat Scene_Achievements as a constant variable, hence the error 'uninitialized constant'.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Shalaren

so to disable the menu by a script call I called
$mouse_map_menu.menu_disabled = 1

which worked, but how do I enable the menu now?
I tried
$mouse_map_menu.menu_enabled = 1

which crashed so then I tried
$mouse_map_menu.menu_disabled = enable

which crashed too so I tried changing the number up to 10... nothing worked

what script call am I looking for?

Wizered67

I didn't look at it too much, but I think it would be $mouse_map_menu.menu_disabled = 0 (or false).

Shalaren

I'm on my phone right now, but I'm pretty sure I tried that too and it didn't work, he game didn't crah but it didn't return the menu

KK20


...
    def update
      dispose if @menu_disabled
      main    if !@menu_disabled
...

Wouldn't you just use true/false?
$mouse_map_menu.menu_disabled =
false


Commence facepalming?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Shalaren

*bangs head against wall upon realizing how obvious that it*
level of embarrassment: 9001

Wizered67

Ha ha isn't that exactly what I said? :P