#===============================================================================
#
# Yanfly Engine RD - Common Event Menu
# Last Date Updated: 2009.06.12
# Level: Normal, Hard
#
# Similar to the Common Event Shop, the Common Event Menu lets you create your
# menus to list various common event options. Now, you don't have to use all of
# those obnoxiously tedious Show Choice branches and conditional branches just
# to let the player get somewhere in range.
#
# This script lets you create your own generated common event menus with ease.
# Set the style of the menu, the nature of the menu, and the contents of the
# menu. Afterwards, set the switches (if required) for the common events to
# even appear, any pictures to go along with it, and descriptions on what the
# common event can do for the player.
#
#===============================================================================
# Updates:
# ----------------------------------------------------------------------------
# o 2009.06.12 - Finished script.
# o 2009.06.11 - Started script.
#===============================================================================
# Instructions
#===============================================================================
#
# First, bind CE_MENU_VARIABLE to the variable you wish to launch common event
# menus with.
#
# Scroll down and edit the CE_MENU_HASH. This will reflect what common events
# appear in those menus, the style of the menu, and the title associated with
# the menu.
#
# Scroll down and edit the CE_MENU_ITEMS. This will determine how common events
# can be shown, what switches they require, and if it will display any pictures
# along with it.
#
# Then, to launch the menu, just change the CE_MENU_VARIABLE variable to the
# menu ID you want to launch. Simple as that.
#
#===============================================================================
# Style Names
# "General" - A very normal kind of menu.
# "Compact" - A smaller version of the General style.
# "Double" - Displays two columns for the menu.
# "Bottom" - Aligns the choices at the bottom of the screen.
# "Lefty" - Aligns the choices to the left side of the screen.
# "Righty" - Aligns the choices to the right side of the screen.
# "Gimmick" - A pretty gimmicky style.
#===============================================================================
#
# Compatibility
# - Alias: Game_Interpreter: command_122
#
#===============================================================================
$imported = {} if $imported == nil
$imported["CommonEventMenu"] = true
module YE
module EVENT
# This is the variable that triggers the kind of shop you want to open.
CE_MENU_VARIABLE = 70
#-------------------------------------------------------------------------
# Use the following hash to determine what common events you can launch
# from that menu ID. You can set the style, whether or not the player can
# cancel out of the menu, and the title of the menu. Of course, you also
# set what common events can be launched from this menu, too.
#
# Style Name - Style name used. Look in the instructions to view styles.
# Cancel - Can the player cancel out of the menu?
# Title - Title used for the menu.
# [Array] - Common events allowed to be choosen in the menu.
#-------------------------------------------------------------------------
CE_MENU_HASH ={ # Follow the example.
# MenuID => [ Style Name, Cancel, Title
1 => [ "Map Screen", false, "World Map",
[11, 25, 13, 14, 32, 15, 33, 24, 39, 40, 35, 36, 37, 38, 34, 26, 27, 28, 29, 30, 31,]
], # The above array lists the common events selectable.
2 => [ "Synthesis", true, "Item Synthesis",
[1, 2, 3, 4, 5, 6, 7, 8]
], # The above array lists the common events selectable.
3 => [ "Double", true, "Double the columns!",
[15, 16, 17]
], # The above array lists the common events selectable.
} # Do not remove this.
#-------------------------------------------------------------------------
# Use the following hash to determine how you want your common events to
# appear. To hide some items, set a switch number to the value shown. To
# display a picture along with the common event, include the picture name.
# To change the font size used, set the size. And finally, you can adjust
# the description given to the common event to be launched.
#
# Switch - Switch required to be on for it to appear. nil for no switch.
# Picture - Picture shown in the display window. nil for no picture shown.
# Size - Font size used for the display window.
# Descrip - Description used for event. Use | to create a new line.
#-------------------------------------------------------------------------
CE_MENU_ITEMS ={ # Follow the example.
# ItemID => [Switch, Picture, Size, Description]
1 => [ nil, "Items1", 16, "Items"],
2 => [ nil, "Materials1", 16, "Materials"],
3 => [ nil, "Ingredients1", 16, "Ingredients"],
4 => [ nil, "Garments1", 16, "Garments"],
5 => [ nil, "Weapons1", 16, "Weapons"],
6 => [ nil, "Accessories1", 16, "Accessories"],
7 => [ nil, "Special1", 16, "Special"],
8 => [ nil, "Recipes1", 16, "Recipes"],
11 => [ nil, "LN-Elirica Atelier", 16, "Elirica's Atelier"],
25 => [ nil, "LN-Brume Forest", 16, "Brume Forest"],
13 => [ nil, "LN-Ceresburg", 16, "Ceresburg"],
14 => [ nil, "LN-Galetown", 16, "Galetown"],
15 => [ nil, "LN-Chiharu Village", 16, "Chiharu Village"],
24 => [ nil, "LN-Larisa Landing", 16, "Larisa Landing"],
32 => [ nil, "LN-Alvina Village", 16, "Alvina Village"],
33 => [ nil, "LN-Elf Village", 16, "Elf Village"],
34 => [ 185, "LN-Puni Caravan", 16, "Puni Caravan"],
35 => [ nil, "LN-Tamarind Beach", 16, "Tamarind Beach"],
36 => [ nil, "LN-Old Mine", 16, "Old Mine"],
37 => [ nil, "LN-Amaterasu Highlands", 16, "Amaterasu Highlands"],
38 => [ nil, "LN-Ornella Marsh", 16, "Ornella Marsh"],
26 => [ nil, "LN-Air Mana", 16, "Air Mana Shrine"],
27 => [ nil, "LN-Earth Mana", 16, "Earth Mana Shrine"],
28 => [ nil, "LN-Water Mana", 16, "Water Mana Shrine"],
29 => [ nil, "LN-Fire Mana", 16, "Fire Mana Shrine"],
30 => [ nil, "LN-Light Mana", 16, "Light Mana Shrine"],
31 => [ nil, "LN-Darkness Mana", 16, "Darkness Mana Shrine"],
39 => [ nil, "LN-Ernesta Colosseum", 16, "Ernesta Colosseum"],
40 => [ nil, "LN-Azazel Tower", 16, "Azazel Tower"],
} # Do not remove this.
end # EVENT
end # YE
#===============================================================================
# Editting anything past this point may potentially result in causing computer
# damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
# Therefore, edit at your own risk.
#===============================================================================
#===============================================================================
# Game_Interpreter
#===============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# alias control variables
#--------------------------------------------------------------------------
alias command_122_cemenu command_122 unless $@
def command_122
n = command_122_cemenu
if @params[0] == YE::EVENT::CE_MENU_VARIABLE and !$game_temp.in_battle and
$game_variables[YE::EVENT::CE_MENU_VARIABLE] != 0
$scene = Scene_Common_Event_Menu.new
end
return n
end
end # Game_Interpreter
#===============================================================================
# Scene_Common_Event_Menu
#===============================================================================
class Scene_Common_Event_Menu < Scene_Base
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize
menu_id = $game_variables[YE::EVENT::CE_MENU_VARIABLE]
@style = YE::EVENT::CE_MENU_HASH[menu_id][0]
@cancel = YE::EVENT::CE_MENU_HASH[menu_id][1]
@title = YE::EVENT::CE_MENU_HASH[menu_id][2]
@items = YE::EVENT::CE_MENU_HASH[menu_id][3]
end
#--------------------------------------------------------------------------
# start
#--------------------------------------------------------------------------
def start
super
@spriteset = Spriteset_Map.new
create_windows
refresh_display
end
#--------------------------------------------------------------------------
# create_windows
#--------------------------------------------------------------------------
def create_windows
#---
if @style == "General" # General Style
@title_window = Window_Base.new(0, 0, 544, 56)
@title_window.contents.draw_text(4, 0, 504, 24, @title, 1)
@command_width = 272
@columns = 1
create_command_window
@command_window.x = 0
@command_window.y = 56
@command_window.height = 360
@display_window = Window_Event_Display.new(272, 56, 272, 360, "tall")
return
end
#---
if @style == "Compact" # Compact Style
@title_window = Window_Base.new(48, 48, 448, 56)
@title_window.contents.draw_text(4, 0, 408, 24, @title, 1)
@command_width = 224
@columns = 1
create_command_window
@command_window.x = 48
@command_window.y = 104
@command_window.height = 264
@display_window = Window_Event_Display.new(272, 104, 224, 264, "tall")
return
end
#---
if @style == "Double" # Double Style
@title_window = Window_Base.new(0, 0, 544, 56)
@title_window.contents.draw_text(4, 0, 504, 24, @title, 1)
@command_width = Graphics.width
@columns = 2
create_command_window
@command_window.x = 0
@command_window.y = 56
@command_window.height = 232
@display_window = Window_Event_Display.new(0, 288, 544, 128, "wide")
return
end
#---
if @style == "Bottom" # Bottom Style
@title_window = Window_Base.new(0, 0, Graphics.width, 56)
@title_window.contents.draw_text(4, 0, Graphics.width-40, 24, @title, 1)
@command_width = Graphics.width
@columns = 2
create_command_window
@command_window.x = 0
@command_window.y = Graphics.height - 128
@command_window.height = 128
return
end
#---
if @style == "Lefty" # Lefty Style
@title_window = Window_Base.new(0, 0, 200, 56)
@title_window.contents.draw_text(4, 0, 160, 24, @title, 1)
@command_width = 200
@columns = 1
create_command_window
@command_window.x = 0
@command_window.y = 56
@command_window.height = Graphics.height - 56 - 128
@display_window = Window_Event_Display.new(0, 288, 200, 128, "no text")
return
end
#---
if @style == "Righty" # Righty Style
@title_window = Window_Base.new(344, 0, 200, 56)
@title_window.contents.draw_text(4, 0, 160, 24, @title, 1)
@command_width = 200
@columns = 1
create_command_window
@command_window.x = 344
@command_window.y = 56
@command_window.height = Graphics.height - 56 - 128
@display_window = Window_Event_Display.new(344, 288, 200, 128, "no text")
return
end
#---
if @style == "Gimmick" # Compact Style
@title_window = Window_Base.new(48, 48, 448, 56)
@title_window.contents.draw_text(4, 0, 408, 24, @title, 1)
@dummy_window = Window_Base.new(48, 104, 448, 264)
@command_width = 224
@columns = 1
create_command_window
@command_window.x = 48
@command_window.y = 104
@command_window.height = 264
@display_window = Window_Event_Display.new(272, 104, 224, 264, "tall")
@command_window.opacity = 0
@display_window.opacity = 0
return
end
#---
if @style == "Town" # Town Style
@title_window = Window_Base.new(0, 0, Graphics.width, 56)
@title_window.contents.draw_text(4, 0, Graphics.width-40, 24, @title, 1)
@command_width = Graphics.width
@columns = 2
create_command_window
@command_window.x = 0
@command_window.y = Graphics.height - 108
@command_window.height = 108
return
end
#---
if @style == "Synthesis" # Synthesis Menu
@title_window = Window_Base.new(0, 0, 544, 56)
@title_window.contents.draw_text(4, 0, 504, 24, @title, 1)
@dummy_window = Window_Base.new(0, 56, 544, 80)
@dummy_window_2 = Window_Base.new(0, 136, 384, 280)
@dummy_window_3 = Window_Base.new(384, 136, 160, 140)
@dummy_window_4 = Window_Base.new(384, 276, 160, 140)
@command_width = 500
@columns = 4
create_command_window
@command_window.x = 16
@command_window.y = 56
@command_window.height = 264
@display_window = Window_Event_Display.new(416, 148, 324, 364, "tall")
@command_window.opacity = 0
@display_window.opacity = 0
return
end
#---
if @style == "Map Screen" # Map Screen
@title_window = Window_Base.new(0, 0, 200, 56)
@title_window.contents.draw_text(4, 0, 160, 24, @title, 1)
@command_width = 200
@columns = 1
create_command_window
@command_window.x = 0
@command_window.y = 56
@command_window.height = Graphics.height - 56 - 0
@display_window = Window_Event_Display.new(184, -22, 376, 454, "no text")
@display_window.opacity = 0
return
end
end
#--------------------------------------------------------------------------
# create_command_window
#--------------------------------------------------------------------------
def create_command_window
commands = []
@data = []
for item_id in @items
next unless YE::EVENT::CE_MENU_ITEMS.include?(item_id)
next if YE::EVENT::CE_MENU_ITEMS[item_id][0] != nil and
!$game_switches[YE::EVENT::CE_MENU_ITEMS[item_id][0]]
item_name = $data_common_events[item_id].name
commands.push(item_name)
@data.push(item_id)
end
@command_window = Window_Command.new(@command_width, commands, @columns)
@last_id = commands.size + 1
end
#--------------------------------------------------------------------------
# terminate
#--------------------------------------------------------------------------
def terminate
super
@spriteset.dispose
@title_window.dispose if @title_window != nil
@command_window.dispose if @command_window != nil
@display_window.dispose if @display_window != nil
@dummy_window.dispose if @dummy_window != nil
@dummy_window_2.dispose if @dummy_window_2 != nil
@dummy_window_3.dispose if @dummy_window_3 != nil
@dummy_window_4.dispose if @dummy_window_4 != nil
end
#--------------------------------------------------------------------------
# update
#--------------------------------------------------------------------------
def update
super
@spriteset.update
$game_map.update
update_input
end
#--------------------------------------------------------------------------
# update_input
#--------------------------------------------------------------------------
def update_input
@command_window.update
if @last_id != @command_window.index
@last_id = @command_window.index
refresh_display
end
if Input.trigger?(Input::B) and @cancel
Sound.play_cancel
$game_variables[YE::EVENT::CE_MENU_VARIABLE] = 0
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
if @data == []
Sound.play_buzzer
return
end
Sound.play_decision
$game_temp.common_event_id = @data[@command_window.index]
$game_variables[YE::EVENT::CE_MENU_VARIABLE] = 0
$scene = Scene_Map.new
end
end
#--------------------------------------------------------------------------
# refresh_display
#--------------------------------------------------------------------------
def refresh_display
return if @display_window == nil
@display_window.refresh(@data[@command_window.index])
end
end # Scene_Common_Event_Menu
#===============================================================================
# Window_Event_Display
#===============================================================================
class Window_Event_Display < Window_Base
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize(x, y, w, h, type = "tall")
super(x, y, w, h)
@type = type
menu_id = $game_variables[YE::EVENT::CE_MENU_VARIABLE]
first_item = YE::EVENT::CE_MENU_VARIABLE[menu_id]
end
#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh(id = nil)
self.contents.clear
return if id == nil
return unless YE::EVENT::CE_MENU_ITEMS.include?(id)
txsize = YE::EVENT::CE_MENU_ITEMS[id][2]
self.contents.font.size = txsize
if YE::EVENT::CE_MENU_ITEMS[id][1] != nil # Draw a picture.
name = YE::EVENT::CE_MENU_ITEMS[id][1]
bitmap = Cache.picture(name)
rect = Rect.new(0, 0, bitmap.width, bitmap.height)
self.contents.blt(0, 6, bitmap, rect)
if @type == "tall"
dy = bitmap.height + (txsize / 2)
dx = 0
elsif @type == "wide"
dx = bitmap.width + (txsize / 2)
dy = 0
end
bitmap.dispose
else
dy = 0
dx = 0
end
return if @type == "no text"
text = YE::EVENT::CE_MENU_ITEMS[id][3]
nwidth = Graphics.width
buf = text.gsub(/\\N(\[\d+\])/i) { "\\__#{$1}" }
lines = buf.split(/(?:[|]|\\n)/i)
lines.each_with_index { |l, i|
l.gsub!(/\\__(\[\d+\])/i) { "\\N#{$1}" }
self.contents.draw_text(dx, i * txsize + dy, nwidth, WLH, l, 0) }
end
end # Window_Event_Display
#===============================================================================
#
# END OF FILE
#
#===============================================================================