mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-20 13:59:57 +00:00
Beginnings of fast travel
This commit is contained in:
parent
19ab472f00
commit
ddc43b2114
10 changed files with 266 additions and 9 deletions
34
scripts/Data_FastTravel.rb
Normal file
34
scripts/Data_FastTravel.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
class FastTravel
|
||||
class Zone
|
||||
attr_reader :name
|
||||
attr_reader :maps
|
||||
def initialize(name, maps)
|
||||
@name = name
|
||||
@maps = maps
|
||||
end
|
||||
end
|
||||
|
||||
ZONES = {
|
||||
:red => Zone.new(tr("The Refuge"), {
|
||||
:gate => tr("city gate"),
|
||||
:elevator => tr("elevator deck"),
|
||||
:apartments => tr("apartments"),
|
||||
:cafe => tr("cafe"),
|
||||
:office => tr("office"),
|
||||
}),
|
||||
:green => Zone.new(tr("The Glen"), {
|
||||
:whatever => tr(""),
|
||||
}),
|
||||
:blue => Zone.new(tr("The Barrens"), {
|
||||
:entrance => tr("entrance"),
|
||||
:outpost => tr("outpost"),
|
||||
:cliffs => tr("cliffs"),
|
||||
:quarry => tr("quarry"),
|
||||
:mineshaft => tr("mineshaft entrance"),
|
||||
:factory => tr("old factory"),
|
||||
:dorms => tr("dormitories"),
|
||||
:swamp => tr("shrimp swamp"),
|
||||
:docks => tr("docks"),
|
||||
}),
|
||||
}
|
||||
end
|
||||
142
scripts/FastTravel.rb
Normal file
142
scripts/FastTravel.rb
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
class FastTravel
|
||||
MARGIN = 30
|
||||
TITLE_TOP_MARGIN = 32
|
||||
TITLE_MARGIN = 100
|
||||
ITEM_SPACING = 28
|
||||
ACTIVE_MARGIN = MARGIN * 2 + 20
|
||||
|
||||
def initialize
|
||||
@viewport = Viewport.new(0, 0, 640, 480)
|
||||
@bg = Sprite.new(@viewport)
|
||||
@bg.bitmap = Bitmap.new(640, 480)
|
||||
@bg.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0, 128))
|
||||
@title = Sprite.new(@viewport)
|
||||
@title.bitmap = Bitmap.new(320, TITLE_MARGIN)
|
||||
@title.bitmap.font.size = 40
|
||||
@title.y = TITLE_TOP_MARGIN
|
||||
@title.x = MARGIN
|
||||
@data_sprites = []
|
||||
@viewport.z = 9998
|
||||
|
||||
self.visible = false
|
||||
@index = 0
|
||||
@fade_in = false
|
||||
@fade_out = false
|
||||
end
|
||||
|
||||
def dispose
|
||||
@bg.dispose
|
||||
@title.dispose
|
||||
@data_sprites.each do |spr|
|
||||
spr.dispose
|
||||
end
|
||||
@viewport.dispose
|
||||
end
|
||||
|
||||
def open
|
||||
self.visible = true
|
||||
self.opacity = 0
|
||||
@fade_in = true
|
||||
@data = $game_fasttravel.unlocked_maps.sort
|
||||
zone = ZONES[$game_fasttravel.zone]
|
||||
|
||||
# Create title
|
||||
@title.bitmap.clear
|
||||
@title.bitmap.draw_text(0, 0, @title.bitmap.width, @title.bitmap.height, zone.name)
|
||||
|
||||
# Create menu options
|
||||
@data.each_with_index do |item, i|
|
||||
spr = Sprite.new(@viewport)
|
||||
spr.bitmap = Bitmap.new(320, ITEM_SPACING)
|
||||
spr.x = MARGIN
|
||||
spr.y = TITLE_MARGIN + TITLE_TOP_MARGIN + ITEM_SPACING * i
|
||||
spr.opacity = 0
|
||||
spr.bitmap.draw_text(0, 0, spr.bitmap.width, spr.bitmap.height, zone.maps[item])
|
||||
@data_sprites << spr
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @fade_in
|
||||
self.opacity += 20
|
||||
active_spr = nil
|
||||
@data_sprites.each do |spr|
|
||||
spr.opacity += 10
|
||||
spr.opacity = 128 if spr.opacity > 128
|
||||
active_spr = spr if !active_spr && spr.x < MARGIN * 2
|
||||
end
|
||||
if active_spr
|
||||
active_spr.x += 6
|
||||
active_spr.x = MARGIN * 2 if active_spr.x > MARGIN * 2
|
||||
elsif self.opacity == 255
|
||||
@fade_in = false
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if @fade_out
|
||||
self.opacity -= 20
|
||||
@data_sprites.each do |spr|
|
||||
spr.opacity -= 10
|
||||
end
|
||||
if self.opacity == 0
|
||||
@fade_out = false
|
||||
self.visible = false
|
||||
@data_sprites.each do |spr|
|
||||
spr.dispose
|
||||
end
|
||||
@data_sprites = []
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
return if !self.visible
|
||||
|
||||
# Adjust position and visibility
|
||||
@data_sprites.each_with_index do |spr, i|
|
||||
if i == @index
|
||||
if spr.x < ACTIVE_MARGIN
|
||||
spr.x += 6
|
||||
spr.x = ACTIVE_MARGIN if spr.x > ACTIVE_MARGIN
|
||||
end
|
||||
spr.opacity += 10 if spr.opacity < 255
|
||||
else
|
||||
if spr.x > MARGIN * 2
|
||||
spr.x -= 6
|
||||
spr.x = MARGIN * 2 if spr.x < MARGIN * 2
|
||||
end
|
||||
spr.opacity -= 10 if spr.opacity > 128
|
||||
spr.opacity = 128 if spr.opacity < 128
|
||||
end
|
||||
end
|
||||
|
||||
if Input.trigger?(Input::UP)
|
||||
@index = (@index - 1) % @data.size
|
||||
$game_system.se_play($data_system.cursor_se)
|
||||
end
|
||||
if Input.trigger?(Input::DOWN)
|
||||
@index = (@index + 1) % @data.size
|
||||
$game_system.se_play($data_system.cursor_se)
|
||||
end
|
||||
|
||||
if Input.trigger?(Input::CANCEL)
|
||||
$game_system.se_play($data_system.cancel_se)
|
||||
@fade_out = true
|
||||
end
|
||||
end
|
||||
|
||||
# Attributes
|
||||
def visible
|
||||
@viewport.visible
|
||||
end
|
||||
def visible=(val)
|
||||
@viewport.visible = val
|
||||
end
|
||||
def opacity=(val)
|
||||
@bg.opacity = val
|
||||
@title.opacity = val
|
||||
end
|
||||
def opacity
|
||||
@bg.opacity
|
||||
end
|
||||
end
|
||||
26
scripts/Game_FastTravel.rb
Normal file
26
scripts/Game_FastTravel.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class Game_FastTravel
|
||||
attr_reader :zone
|
||||
attr_accessor :enabled
|
||||
alias :enabled? :enabled
|
||||
|
||||
def initialize
|
||||
@unlocked = {}
|
||||
@zone = nil
|
||||
@enabled = false
|
||||
end
|
||||
|
||||
def unlock(map)
|
||||
@unlocked[@zone] << map
|
||||
end
|
||||
|
||||
def zone=(zone)
|
||||
@zone = zone
|
||||
unless @unlocked.include? zone
|
||||
@unlocked[zone] = []
|
||||
end
|
||||
end
|
||||
|
||||
def unlocked_maps
|
||||
@unlocked[@zone]
|
||||
end
|
||||
end
|
||||
|
|
@ -38,6 +38,7 @@ class Game_Temp
|
|||
attr_accessor :name_calling # name input: calling flag
|
||||
attr_accessor :menu_calling # menu calling flag
|
||||
attr_accessor :item_menu_calling # item menu calling flag
|
||||
attr_accessor :travel_menu_calling # fast travel menu calling flag
|
||||
attr_accessor :menu_beep # menu: play sound effect flag
|
||||
attr_accessor :save_calling # save calling flag
|
||||
attr_accessor :debug_calling # debug calling flag
|
||||
|
|
@ -89,6 +90,7 @@ class Game_Temp
|
|||
@name_max_char = 0
|
||||
@menu_calling = false
|
||||
@item_menu_calling = false
|
||||
@travel_menu_calling = false
|
||||
@menu_beep = false
|
||||
@save_calling = false
|
||||
@debug_calling = false
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ def save
|
|||
Marshal.dump($game_map, file)
|
||||
Marshal.dump($game_player, file)
|
||||
Marshal.dump($game_oneshot, file)
|
||||
Marshal.dump($game_fasttravel, file)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -41,6 +42,7 @@ def load
|
|||
$game_map = Marshal.load(file)
|
||||
$game_player = Marshal.load(file)
|
||||
$game_oneshot = Marshal.load(file)
|
||||
$game_fasttravel = Marshal.load(file)
|
||||
# If magic number is different from when saving
|
||||
# (if editing was added with editor)
|
||||
if $game_system.magic_number != $data_system.magic_number
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ class Scene_Map
|
|||
@item_icon.zoom_x = 2.0
|
||||
@item_icon.zoom_y = 2.0
|
||||
@item_id = 0
|
||||
# Make fast travel menu
|
||||
@fast_travel = FastTravel.new
|
||||
# Transition run
|
||||
Graphics.transition
|
||||
# Main loop
|
||||
|
|
@ -51,6 +53,7 @@ class Scene_Map
|
|||
# Dispose of menu
|
||||
@menu.dispose
|
||||
@item_menu.dispose
|
||||
@fast_travel.dispose
|
||||
# Dispose of item icon
|
||||
@item_icon.dispose
|
||||
# If switching to title screen
|
||||
|
|
@ -72,7 +75,7 @@ class Scene_Map
|
|||
# move in an instant)
|
||||
$game_map.update
|
||||
$game_system.map_interpreter.update
|
||||
$game_player.update if !@menu.visible && !@item_menu.visible
|
||||
$game_player.update if !@menu.visible && !@item_menu.visible && !@fast_travel.visible
|
||||
$game_followers.each{|f| f.update}
|
||||
# Update system (timer), screen
|
||||
$game_system.update
|
||||
|
|
@ -121,6 +124,8 @@ class Scene_Map
|
|||
end
|
||||
# Hide icon when item menu is visible
|
||||
@item_icon.visible = !@item_menu.visible
|
||||
# Update fast travel
|
||||
@fast_travel.update
|
||||
# If game over
|
||||
if $game_temp.gameover
|
||||
# Switch to game over screen
|
||||
|
|
@ -150,8 +155,9 @@ class Scene_Map
|
|||
return
|
||||
end
|
||||
# Process menu opening
|
||||
unless $game_system.map_interpreter.running? or
|
||||
$game_system.menu_disabled
|
||||
unless $game_system.map_interpreter.running? ||
|
||||
$game_system.menu_disabled ||
|
||||
@fast_travel.visible
|
||||
if !@menu.visible && Input.trigger?(Input::MENU)
|
||||
$game_temp.menu_calling = true
|
||||
$game_temp.menu_beep = true
|
||||
|
|
@ -187,6 +193,8 @@ class Scene_Map
|
|||
call_menu
|
||||
elsif $game_temp.item_menu_calling
|
||||
call_item_menu
|
||||
elsif $game_temp.travel_menu_calling
|
||||
call_travel_menu
|
||||
elsif $game_temp.save_calling
|
||||
call_save
|
||||
elsif $game_temp.debug_calling
|
||||
|
|
@ -270,6 +278,14 @@ class Scene_Map
|
|||
# Open the menu
|
||||
@item_menu.open
|
||||
end
|
||||
def call_travel_menu
|
||||
# Clear menu call flag
|
||||
$game_temp.travel_menu_calling = false
|
||||
# Straighten player position
|
||||
$game_player.straighten
|
||||
# Open the menu
|
||||
@fast_travel.open
|
||||
end
|
||||
#--------------------------------------------------------------------------
|
||||
# * Save Call
|
||||
#--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -116,6 +116,23 @@ def green_ambient
|
|||
ambient -50, -50, -50
|
||||
end
|
||||
|
||||
# Travel
|
||||
def enable_travel
|
||||
$game_fasttravel.enabled = true
|
||||
end
|
||||
|
||||
def disable_travel
|
||||
$game_fasttravel.disabled = true
|
||||
end
|
||||
|
||||
def set_zone(zone)
|
||||
$game_fasttravel.zone = zone
|
||||
end
|
||||
|
||||
def unlock_map(map)
|
||||
$game_fasttravel.unlock(map)
|
||||
end
|
||||
|
||||
# Misc
|
||||
def watcher_tell_time
|
||||
hour = Time.now.hour
|
||||
|
|
|
|||
|
|
@ -118,15 +118,26 @@ class Window_MainMenu < Window_Selectable
|
|||
|
||||
# Select menu item
|
||||
if Input.trigger?(Input::ACTION)
|
||||
$game_system.se_play($data_system.decision_se)
|
||||
self.active = false
|
||||
self.opacity = 127
|
||||
#case @index
|
||||
#else
|
||||
print "oh no you don't"
|
||||
case @index
|
||||
when 0
|
||||
if Input.trigger?(Input::ACTION)
|
||||
if $game_fasttravel.enabled?
|
||||
$game_system.se_play($data_system.decision_se)
|
||||
$game_temp.travel_menu_calling = true
|
||||
@fade_out = true
|
||||
else
|
||||
$game_system.se_play($data_system.buzzer_se)
|
||||
$game_temp.message_ed_text = tr("You cannot fast travel right now.")
|
||||
$game_temp.message_proc = Proc.new { self.active = true; self.opacity = 255 }
|
||||
end
|
||||
end
|
||||
else
|
||||
$game_system.se_play($data_system.buzzer_se)
|
||||
self.active = true
|
||||
self.opacity = 255
|
||||
#end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ Game_Player
|
|||
Game_Oneshot
|
||||
Game_Light
|
||||
Game_Follower
|
||||
Game_FastTravel
|
||||
|
||||
Sprite_Character
|
||||
Sprite_Battler
|
||||
|
|
@ -34,6 +35,8 @@ Sprite_Timer
|
|||
Sprite_Light
|
||||
Spriteset_Map
|
||||
|
||||
FastTravel
|
||||
|
||||
Window_Base
|
||||
Window_Selectable
|
||||
Window_Command
|
||||
|
|
@ -101,6 +104,7 @@ i18n_Language
|
|||
Data_Item
|
||||
Data_Footsteps
|
||||
Data_SpecialEventData
|
||||
Data_FastTravel
|
||||
|
||||
# Script Functions
|
||||
Script
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ class Translator
|
|||
end
|
||||
|
||||
# Hacky translation helper function
|
||||
# def tr(text)
|
||||
# $tr.script(Kernel.caller.first.split(':', 3)[1], text)
|
||||
# end
|
||||
def tr(text)
|
||||
$tr.script(Kernel.caller.first.split(':', 3)[1], text)
|
||||
text
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue