Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###############################################################################
- # Dark Paladin Single Character Menu v1.2
- # Platform: VX Ace
- # Author: Dark Paladin
- # Description: A menu system for a single Character.
- # Terms of use: You MAY use this script for your Non-commercial Projects.
- # You MAY use this script for Commercial projects without my permission.
- # Credit is appreciated but not needed.
- # This script requires: N/A Cachext Included
- ###############################################################################
- #==============================================================================
- # CONFIG AREA
- #==============================================================================
- module DKP_Menu_Config
- Enable_Background = true # true/false Use Background?
- Menu_Background = "Background2" # Set the name of the background pic
- # Place Image in "Graphics/DPmenu/Main/" Or change it in the cachext module.
- Status_Opacity = 0 # Status Window Opacity
- Help_Opacity = 0 # Item Help Window Opacity
- Item_Opacity = 0 # Item Window Opacity
- Command_Opacity = 0 # Command Window Opacity
- CategoryW_Opacity = 0 # Category Window Opacity
- end
- module Cachext
- #--------------------------------------------------------------------------
- # DKP Cachext
- # Do not edit unless you really know what your doing!
- # Platform: VX Ace
- # Author: Dark paladin
- # Description: Module for menu background.
- # -------------------------------------------------------------------------
- #--------------------------------------------------------------------------
- # *Graphics
- #--------------------------------------------------------------------------
- #You can edit the stuff in purple between the "" to change folder location.
- #--------------------------------------------------------------------------
- # *Menu Graphics Folder
- #--------------------------------------------------------------------------
- def self.dpmenu(filename)# You can change the Folder names here for background image.
- load_bitmap("Graphics/DPmenu/Main/", filename)
- end
- #==============================================================================
- # END CONFIG AREA
- #==============================================================================
- #--------------------------------------------------------------------------
- # * Load Bitmap
- #--------------------------------------------------------------------------
- def self.load_bitmap(folder_name, filename, hue = 0)
- @cachext ||= {}
- if filename.empty?
- empty_bitmap
- elsif hue == 0
- normal_bitmap(folder_name + filename)
- else
- hue_changed_bitmap(folder_name + filename, hue)
- end
- end
- #--------------------------------------------------------------------------
- # * Create Empty Bitmap
- #--------------------------------------------------------------------------
- def self.empty_bitmap
- Bitmap.new(32, 32)
- end
- #--------------------------------------------------------------------------
- # * Create/Get Normal Bitmap
- #--------------------------------------------------------------------------
- def self.normal_bitmap(path)
- @cachext[path] = Bitmap.new(path) unless include?(path)
- @cachext[path]
- end
- #--------------------------------------------------------------------------
- # * Create/Get Hue-Changed Bitmap
- #--------------------------------------------------------------------------
- def self.hue_changed_bitmap(path, hue)
- key = [path, hue]
- unless include?(key)
- @cachext[key] = normal_bitmap(path).clone
- @cachext[key].hue_change(hue)
- end
- @cachext[key]
- end
- #--------------------------------------------------------------------------
- # * Check Cache Existence
- #--------------------------------------------------------------------------
- def self.include?(key)
- @cachext[key] && !@cachext[key].disposed?
- end
- #--------------------------------------------------------------------------
- # * Clear Cache
- #--------------------------------------------------------------------------
- def self.clear
- @cachext ||= {}
- @cachext.clear
- GC.start
- end
- end
- #==============================================================================
- # ** Window_ItemCategory
- #------------------------------------------------------------------------------
- # This window is for selecting a category of normal items and equipment
- # on the item screen or shop screen.
- #==============================================================================
- class Window_ItemCategory < Window_HorzCommand
- include DKP_Menu_Config
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :item_window
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- super(0, 0)
- end
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- 244
- end
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 2
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- super
- @item_window.category = current_symbol if @item_window
- end
- #--------------------------------------------------------------------------
- # * Create Command List
- #--------------------------------------------------------------------------
- def make_command_list
- add_command(Vocab::item, :item)
- add_command(Vocab::key_item, :key_item)
- end
- #--------------------------------------------------------------------------
- # * Set Item Window
- #--------------------------------------------------------------------------
- def item_window=(item_window)
- @item_window = item_window
- update
- end
- end
- #==============================================================================
- # ** Window_MenuStatus
- #------------------------------------------------------------------------------
- # This window displays party member status on the menu screen.
- #==============================================================================
- class Window_MenuStatus < Window_Selectable
- include DKP_Menu_Config
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :pending_index # Pending position (for formation)
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(x, y)
- super(x, y, window_width, window_height)
- @pending_index = -1
- self.opacity = Status_Opacity
- refresh
- end
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 300
- end
- #--------------------------------------------------------------------------
- # * Get Window Height
- #--------------------------------------------------------------------------
- def window_height
- return 370
- end
- #--------------------------------------------------------------------------
- # * Get Number of Items
- #--------------------------------------------------------------------------
- def item_max
- return 1
- end
- #--------------------------------------------------------------------------
- # * Get Item Height
- #--------------------------------------------------------------------------
- def item_height
- (height - standard_padding * 2) / 4
- end
- #--------------------------------------------------------------------------
- # Simple Status
- #--------------------------------------------------------------------------
- def draw_actor_hp(actor, x, y, width = 200)
- draw_gauge(x, y, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)
- change_color(system_color)
- draw_text(x, y, 30, line_height, Vocab::hp_a)
- draw_current_and_max_values(x, y, width, actor.hp, actor.mhp,
- hp_color(actor), normal_color)
- end
- def draw_actor_name(actor, x, y, width = 112)
- change_color(hp_color(actor))
- draw_text(x, y, width / 2, line_height, actor.name)
- end
- def draw_actor_simple_status(actor, x, y)
- draw_actor_name(actor, 187, 25)
- draw_actor_icons(actor, 0, y + line_height * 8)
- draw_actor_hp(actor, 40, 100 + line_height * 1)
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- actor = $game_party.members[0]
- enabled = $game_party.battle_members.include?(actor)
- rect = item_rect(index)
- draw_item_background(index)
- draw_actor_face(actor, rect.x + 1, rect.y + 1, enabled)
- draw_actor_simple_status(actor, rect.x + 108, rect.y + line_height / 2)
- end
- #--------------------------------------------------------------------------
- # * Draw Background for Item
- #--------------------------------------------------------------------------
- def draw_item_background(index)
- if index == @pending_index
- contents.fill_rect(item_rect(index), pending_color)
- end
- end
- #--------------------------------------------------------------------------
- # * Processing When OK Button Is Pressed
- #--------------------------------------------------------------------------
- def process_ok
- super
- $game_party.menu_actor = $game_party.members[index]
- end
- #--------------------------------------------------------------------------
- # * Restore Previous Selection Position
- #--------------------------------------------------------------------------
- def select_last
- select($game_party.menu_actor.index || 0)
- end
- #--------------------------------------------------------------------------
- # * Set Pending Position (for Formation)
- #--------------------------------------------------------------------------
- def pending_index=(index)
- last_pending_index = @pending_index
- @pending_index = index
- redraw_item(@pending_index)
- redraw_item(last_pending_index)
- end
- end
- #==============================================================================
- # ** Window_Help
- #------------------------------------------------------------------------------
- # This window shows skill and item explanations along with actor status.
- #==============================================================================
- class DKPWindow_Help < Window_Base
- include DKP_Menu_Config
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(line_number = 4)
- super(0, 0, 244, fitting_height(line_number))
- self.opacity = Help_Opacity
- end
- #--------------------------------------------------------------------------
- # * Set Text
- #--------------------------------------------------------------------------
- def set_text(text)
- if text != @text
- @text = text
- refresh
- end
- end
- #--------------------------------------------------------------------------
- # * Clear
- #--------------------------------------------------------------------------
- def clear
- set_text("")
- end
- #--------------------------------------------------------------------------
- # * Set Item
- # item : Skills and items etc.
- #--------------------------------------------------------------------------
- def set_item(item)
- set_text(item ? item.description : "")
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_text_ex(0, 0, word_wrapping(@text))
- end
- #--------------------------------------------------------------------------
- # * Word Wrap
- #--------------------------------------------------------------------------
- def word_wrapping(text, pos = 0)
- current_text_position = 0
- for i in 0..(text.length - 1)
- if text[i] == "\n"
- current_text_position = 0
- next
- end
- current_text_position += contents.text_size(text[i]).width
- if (pos + current_text_position) >= (contents.width)
- current_element = i
- while(text[current_element] != " ")
- break if current_element == 0
- current_element -= 1
- end
- temp_text = ""
- for j in 0..(text.length - 1)
- temp_text += text[j]
- temp_text += "\n" if j == current_element
- end
- text = temp_text
- i = current_element
- current_text_position = 0
- end
- end
- return text
- end
- end
- #==============================================================================
- # ** Window_Gold
- #------------------------------------------------------------------------------
- # This window displays the party's gold.
- #==============================================================================
- class Window_Gold < Window_Base
- include DKP_Menu_Config
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- super(0, 0, window_width, fitting_height(1))
- self.opacity = 0
- self.z = 1000
- refresh
- end
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 160
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_currency_value(value, currency_unit, 4, 0, contents.width - 8)
- end
- #--------------------------------------------------------------------------
- # * Get Party Gold
- #--------------------------------------------------------------------------
- def value
- $game_party.gold
- end
- #--------------------------------------------------------------------------
- # Get Currency Unit
- #--------------------------------------------------------------------------
- def currency_unit
- Vocab::currency_unit
- end
- #--------------------------------------------------------------------------
- # * Open Window
- #--------------------------------------------------------------------------
- def open
- refresh
- super
- end
- end
- class Window_ItemList < Window_Selectable
- include DKP_Menu_Config
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(x, y, width, height)
- super
- @category = :none
- @data = []
- self.opacity = Item_Opacity
- end
- #--------------------------------------------------------------------------
- # * Set Category
- #--------------------------------------------------------------------------
- def category=(category)
- return if @category == category
- @category = category
- refresh
- self.oy = 0
- end
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 1
- end
- #--------------------------------------------------------------------------
- # * Get Number of Items
- #--------------------------------------------------------------------------
- def item_max
- @data ? @data.size : 1
- end
- #--------------------------------------------------------------------------
- # * Get Item
- #--------------------------------------------------------------------------
- def item
- @data && index >= 0 ? @data[index] : nil
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Selection Item
- #--------------------------------------------------------------------------
- def current_item_enabled?
- enable?(@data[index])
- end
- #--------------------------------------------------------------------------
- # * Include in Item List?
- #--------------------------------------------------------------------------
- def include?(item)
- case @category
- when :item
- item.is_a?(RPG::Item) && !item.key_item?
- when :key_item
- item.is_a?(RPG::Item) && item.key_item?
- else
- false
- end
- end
- #--------------------------------------------------------------------------
- # * Display in Enabled State?
- #--------------------------------------------------------------------------
- def enable?(item)
- $game_party.usable?(item)
- end
- #--------------------------------------------------------------------------
- # * Create Item List
- #--------------------------------------------------------------------------
- def make_item_list
- @data = $game_party.all_items.select {|item| include?(item) }
- @data.push(nil) if include?(nil)
- end
- #--------------------------------------------------------------------------
- # * Restore Previous Selection Position
- #--------------------------------------------------------------------------
- def select_last
- select(@data.index($game_party.last_item.object) || 0)
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- if item
- rect = item_rect(index)
- rect.width -= 4
- draw_item_name(item, rect.x, rect.y, enable?(item))
- draw_item_number(rect, item)
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Number of Items
- #--------------------------------------------------------------------------
- def draw_item_number(rect, item)
- draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
- end
- #--------------------------------------------------------------------------
- # * Update Help Text
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_item(item)
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- make_item_list
- create_contents
- draw_all_items
- end
- end
- #==============================================================================
- # ** Window_MenuCommand
- #------------------------------------------------------------------------------
- # This command window appears on the menu screen.
- #==============================================================================
- class Window_MenuCommand < Window_Command
- include DKP_Menu_Config
- #--------------------------------------------------------------------------
- # * Initialize Command Selection Position (Class Method)
- #--------------------------------------------------------------------------
- def self.init_command_position
- @@last_command_symbol = nil
- end
- #--------------------------------------------------------------------------
- # * Get Digit Count
- #--------------------------------------------------------------------------
- def col_max
- return 3
- end
- #--------------------------------------------------------------------------
- # * Get Spacing for Items Arranged Side by Side
- #--------------------------------------------------------------------------
- def spacing
- return 100
- end
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- super(0, Graphics.height- 47)
- activate
- select_last
- end
- #--------------------------------------------------------------------------
- # * Get Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 544
- end
- #--------------------------------------------------------------------------
- # * Get Number of Lines to Show
- #--------------------------------------------------------------------------
- def visible_line_number
- return 1
- end
- #--------------------------------------------------------------------------
- # * Create Command List
- #--------------------------------------------------------------------------
- def make_command_list
- add_main_commands
- add_save_command
- add_game_end_command
- end
- #--------------------------------------------------------------------------
- # * Add Main Commands to List
- #--------------------------------------------------------------------------
- def add_main_commands
- add_command(Vocab::item, :item, main_commands_enabled)
- end
- #--------------------------------------------------------------------------
- # * Add Save to Command List
- #--------------------------------------------------------------------------
- def add_save_command
- add_command(Vocab::save, :save, save_enabled)
- end
- #--------------------------------------------------------------------------
- # * Add Exit Game to Command List
- #--------------------------------------------------------------------------
- def add_game_end_command
- add_command(Vocab::game_end, :game_end)
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Main Commands
- #--------------------------------------------------------------------------
- def main_commands_enabled
- $game_party.exists
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Save
- #--------------------------------------------------------------------------
- def save_enabled
- !$game_system.save_disabled
- end
- #--------------------------------------------------------------------------
- # * Processing When OK Button Is Pressed
- #--------------------------------------------------------------------------
- def process_ok
- @@last_command_symbol = current_symbol
- super
- end
- #--------------------------------------------------------------------------
- # * Restore Previous Selection Position
- #--------------------------------------------------------------------------
- def select_last
- select_symbol(@@last_command_symbol)
- end
- end
- class Game_Interpreter
- def command_351
- return if $game_party.in_battle
- SceneManager.call(Scene_Item)
- Window_MenuCommand::init_command_position
- Fiber.yield
- end
- end
- class Scene_Map < Scene_Base
- def call_menu
- SceneManager.call(Scene_Item)
- Window_MenuCommand::init_command_position
- end
- end
- #==============================================================================
- # ** Scene_Item
- #------------------------------------------------------------------------------
- # This class performs the item screen processing.
- #==============================================================================
- class Scene_Item < Scene_ItemBase
- include DKP_Menu_Config
- #--------------------------------------------------------------------------
- # * Start Processing
- #--------------------------------------------------------------------------
- def start
- super
- create_help_window
- create_status_window
- if Enable_Background != false then create_Image_Background end
- create_gold_window
- create_command_window
- create_category_window
- create_item_window
- #@category_window.deactivate
- end
- #--------------------------------------------------------------------------
- # * Create Category Window
- #--------------------------------------------------------------------------
- def create_category_window
- @category_window = Window_ItemCategory.new
- @category_window.viewport = @viewport
- @category_window.help_window = @help_window
- @category_window.y = 120
- @category_window.opacity = CategoryW_Opacity
- @category_window.set_handler(:ok, method(:on_category_ok))
- @category_window.set_handler(:cancel, method(:return_item))
- end
- #--------------------------------------------------------------------------
- # * Create Item Window
- #--------------------------------------------------------------------------
- def create_item_window
- @item_window = Window_ItemList.new(0, 170, 244, 200)
- @item_window.viewport = @viewport
- @item_window.help_window = @help_window
- @item_window.set_handler(:ok, method(:on_item_ok))
- @item_window.set_handler(:cancel, method(:on_item_cancel))
- @category_window.item_window = @item_window
- end
- #--------------------------------------------------------------------------
- # * Create Command Window
- #--------------------------------------------------------------------------
- def create_command_window
- @command_window = Window_MenuCommand.new
- @command_window.opacity = Command_Opacity
- @command_window.set_handler(:item, method(:command_item))
- @command_window.set_handler(:save, method(:command_save))
- @command_window.set_handler(:game_end, method(:command_game_end))
- @command_window.set_handler(:cancel, method(:return_scene))
- end
- #--------------------------------------------------------------------------
- # * Deactivate category
- #--------------------------------------------------------------------------
- def return_item
- @category_window.deactivate
- @command_window.activate
- @command_window.select_last
- end
- #--------------------------------------------------------------------------
- # * [Save] Command
- #--------------------------------------------------------------------------
- def command_save
- SceneManager.call(Scene_Save)
- end
- #--------------------------------------------------------------------------
- # * [Exit Game] Command
- #--------------------------------------------------------------------------
- def command_game_end
- SceneManager.call(Scene_End)
- end
- #--------------------------------------------------------------------------
- # * [Item] Command
- #--------------------------------------------------------------------------
- def command_item
- @category_window.activate
- @command_window.deactivate
- end
- #--------------------------------------------------------------------------
- # * Create Gold Window
- #--------------------------------------------------------------------------
- def create_gold_window
- @gold_window = Window_Gold.new
- @gold_window.x = Graphics.width - @gold_window.width
- @gold_window.y = Graphics.height - 100
- end
- #--------------------------------------------------------------------------
- # * Create Background Image
- #--------------------------------------------------------------------------
- def create_Image_Background
- bitmap = Cachext.dpmenu(Menu_Background)
- @background_sprite.bitmap = bitmap
- end
- #--------------------------------------------------------------------------
- # * Create Status Window
- #--------------------------------------------------------------------------
- def create_status_window
- @status_window = Window_MenuStatus.new(244, 0)
- end
- #--------------------------------------------------------------------------
- # * Create Help Window
- #--------------------------------------------------------------------------
- def create_help_window
- @help_window = DKPWindow_Help.new
- @help_window.viewport = @viewport
- end
- #--------------------------------------------------------------------------
- # * Category [OK]
- #--------------------------------------------------------------------------
- def on_category_ok
- @item_window.activate
- @item_window.select_last
- end
- #--------------------------------------------------------------------------
- # * Item [OK]
- #--------------------------------------------------------------------------
- def on_item_ok
- $game_party.last_item.object = item
- determine_item
- end
- def determine_item
- if item.for_friend?
- show_sub_window(@actor_window)
- @actor_window.select_for_item(item)
- else
- use_item
- activate_item_window
- end
- end
- def cursor_left?
- @item_window.index % 1 == 0
- end
- def show_sub_window(window)
- width_remain = Graphics.width - window.width
- window.x = cursor_left? ? width_remain : 0
- @viewport.rect.x = @viewport.ox = cursor_left? ? 0 : window.width
- @viewport.rect.width = width_remain
- window.show.activate
- end
- #--------------------------------------------------------------------------
- # * Item [Cancel]
- #--------------------------------------------------------------------------
- def on_item_cancel
- @item_window.unselect
- @category_window.activate
- end
- #--------------------------------------------------------------------------
- # * Play SE When Using Item
- #--------------------------------------------------------------------------
- def play_se_for_item
- Sound.play_use_item
- end
- #--------------------------------------------------------------------------
- # * Use Item
- #--------------------------------------------------------------------------
- def use_item
- super
- @item_window.redraw_current_item
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement