Rewrote phone UI code, added "CommonEvent" trainer comment for that phone contact to run instead of default phone messages, added phone signal icon to phone

This commit is contained in:
Maruno17
2022-09-10 19:41:12 +01:00
parent 662d023ff5
commit 25a8d727ab
5 changed files with 215 additions and 94 deletions

View File

@@ -1,10 +1,7 @@
# TODO: Add an information window with details of the person in a phone call.
# Make this work with common event calls (create and dispose the info
# window in start_message and end_message).
# TODO: Rewrite the Phone UI. Have more than one method. Choosable icons/marks
# for each contact? Show an icon representing phone signal.
# TODO: Add a trainer comment for giving a trainer a common event ID.
# TODO: Add calling a contact at a particular time forcing rematch readiness.
# Add trainer comments for this.
# TODO: Allow individual trainers to never arrange a rematch by themself, thus
@@ -70,8 +67,8 @@ class Phone
return true
end
# Event, trainer type, name, versions_count = 1, start_version = 0
# Map ID, event ID, trainer type, name, versions_count = 1, start_version = 0
# Event, trainer type, name, versions_count = 1, start_version = 0, common event ID = 0
# Map ID, event ID, trainer type, name, versions_count = 1, start_version = 0, common event ID = 0
# Map ID, name, common event ID
def add(*args)
if args[0].is_a?(Game_Event)
@@ -82,9 +79,11 @@ class Phone
contact = get(true, trainer_type, name, args[3] || 0)
if contact
contact.visible = true
@contacts.delete(contact)
@contacts.push(contact)
else
contact = Contact.new(true, args[0].map_id, args[0].id,
trainer_type, name, args[3] || 1, args[4] || 0)
trainer_type, name, args[3], args[4], args[5])
contact.increment_version
@contacts.push(contact)
end
@@ -96,9 +95,11 @@ class Phone
contact = get(true, trainer_type, name, args[4] || 0)
if contact
contact.visible = true
@contacts.delete(contact)
@contacts.push(contact)
else
contact = Contact.new(true, args[0], args[1],
trainer_type, name, args[4] || 1, args[5] || 0)
trainer_type, name, args[4], args[5], args[6])
contact.increment_version
@contacts.push(contact)
end
@@ -108,6 +109,8 @@ class Phone
contact = get(false, name)
if contact
contact.visible = true
@contacts.delete(contact)
@contacts.push(contact)
else
contact = Contact.new(false, *args)
@contacts.push(contact)
@@ -251,7 +254,7 @@ class Phone
@variant_beaten = 0
@time_to_ready = 0
@rematch_flag = 0 # 0=counting down, 1=ready for rematch, 2=ready and told player
@common_event_id = 0
@common_event_id = args[6] || 0
else
# Non-trainer
@map_id = args[0]
@@ -280,6 +283,10 @@ class Phone
end
end
def can_hide?
return trainer?
end
def common_event_call?
return @common_event_id > 0
end
@@ -373,7 +380,13 @@ class Phone
def make_incoming
return if !can_make?
contact = get_random_trainer_for_incoming_call
if contact
return if !contact
if contact.common_event_call?
if !pbCommonEvent(contact.common_event_id)
pbMessage(_INTL("{1}'s messages not defined.\nCouldn't call common event {2}.",
contact.display_name, contact.common_event_id))
end
else
call = generate_trainer_dialogue(contact)
play(call, contact)
end
@@ -403,7 +416,7 @@ class Phone
end
end
def start_message(contact)
def start_message(contact = nil)
pbMessage(_INTL("......\\wt[5] ......\\1"))
end
@@ -434,7 +447,7 @@ class Phone
end_message(contact)
end
def end_message(contact)
def end_message(contact = nil)
pbMessage(_INTL("Click!\\wt[10]\n......\\wt[5] ......\\1"))
end

View File

@@ -182,7 +182,11 @@ MenuHandlers.add(:pokegear_menu, :phone, {
"order" => 20,
# "condition" => proc { next $PokemonGlobal.phone && $PokemonGlobal.phone.contacts.length > 0 },
"effect" => proc { |menu|
pbFadeOutIn { PokemonPhoneScene.new.start }
pbFadeOutIn {
scene = PokemonPhone_Scene.new
screen = PokemonPhoneScreen.new(scene)
screen.pbStartScreen
}
next false
}
})

View File

@@ -1,5 +1,7 @@
# TODO: Choosable icons/marks for each contact?
# TODO: Allow rearranging contacts.
#===============================================================================
# Phone screen
# Phone list of contacts
#===============================================================================
class Window_PhoneList < Window_CommandPokemon
def drawCursor(index, rect)
@@ -20,17 +22,57 @@ end
#===============================================================================
#
#===============================================================================
class PokemonPhoneScene
def start
# Get list of contacts
class PokemonPhone_Scene
def pbStartScene
@sprites = {}
# Create viewport
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@viewport.z = 99999
# Background
addBackgroundPlane(@sprites, "bg", "Phone/bg", @viewport)
# List of contacts
@sprites["list"] = Window_PhoneList.newEmpty(152, 32, Graphics.width - 142, Graphics.height - 80, @viewport)
@sprites["list"].windowskin = nil
# Rematch readiness icons
if Phone.rematches_enabled
@sprites["list"].page_item_max.times do |i|
@sprites["rematch_#{i}"] = IconSprite.new(468, 62 + (i * 32), @viewport)
end
end
# Phone signal icon
@sprites["signal"] = IconSprite.new(Graphics.width - 32, 0, @viewport)
if Phone::Call.can_make?
@sprites["signal"].setBitmap("Graphics/UI/Phone/icon_signal")
else
@sprites["signal"].setBitmap("Graphics/UI/Phone/icon_nosignal")
end
# Title text
@sprites["header"] = Window_UnformattedTextPokemon.newWithSize(
_INTL("Phone"), 2, -18, 128, 64, @viewport
)
@sprites["header"].baseColor = Color.new(248, 248, 248)
@sprites["header"].shadowColor = Color.black
@sprites["header"].windowskin = nil
# Info text about all contacts
@sprites["info"] = Window_AdvancedTextPokemon.newWithSize("", -8, 224, 180, 160, @viewport)
@sprites["info"].windowskin = nil
# Portrait of contact
@sprites["icon"] = IconSprite.new(70, 102, @viewport)
# Contact's location text
@sprites["bottom"] = Window_AdvancedTextPokemon.newWithSize(
"", 162, Graphics.height - 64, Graphics.width - 158, 64, @viewport
)
@sprites["bottom"].windowskin = nil
# Start scene
pbRefreshList
pbFadeInAndShow(@sprites) { pbUpdate }
end
def pbRefreshList
@contacts = []
$PokemonGlobal.phone.contacts.each do |contact|
@contacts.push(contact) if contact.visible?
end
if @contacts.length == 0
pbMessage(_INTL("There are no phone numbers stored."))
return
end
# Create list of commands (display names of contacts) and count rematches
commands = []
rematch_count = 0
@@ -38,62 +80,35 @@ class PokemonPhoneScene
commands.push(contact.display_name)
rematch_count += 1 if contact.can_rematch?
end
# Create viewport and sprites
@sprites = {}
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@viewport.z = 99999
addBackgroundPlane(@sprites, "bg", "Phone/bg", @viewport)
@sprites["list"] = Window_PhoneList.newEmpty(152, 32, Graphics.width - 142, Graphics.height - 80, @viewport)
@sprites["list"].windowskin = nil
# Set list's commands
@sprites["list"].commands = commands
@sprites["list"].page_item_max.times do |i|
@sprites["rematch[#{i}]"] = IconSprite.new(468, 62 + (i * 32), @viewport)
j = i + @sprites["list"].top_item
if j < @contacts.length && @contacts[j].can_rematch?
@sprites["rematch[#{i}]"].setBitmap("Graphics/UI/Phone/icon_rematch")
@sprites["list"].index = commands.length - 1 if @sprites["list"].index >= commands.length
if @sprites["list"].top_row > @sprites["list"].itemCount - @sprites["list"].page_item_max - 1
@sprites["list"].top_row = @sprites["list"].itemCount - @sprites["list"].page_item_max - 1
end
end
@sprites["header"] = Window_UnformattedTextPokemon.newWithSize(
_INTL("Phone"), 2, -18, 128, 64, @viewport
)
@sprites["header"].baseColor = Color.new(248, 248, 248)
@sprites["header"].shadowColor = Color.black
@sprites["header"].windowskin = nil
@sprites["bottom"] = Window_AdvancedTextPokemon.newWithSize(
"", 162, Graphics.height - 64, Graphics.width - 158, 64, @viewport
)
@sprites["bottom"].windowskin = nil
map_name = (@contacts[0].map_id > 0) ? pbGetMapNameFromId(@contacts[0].map_id) : ""
@sprites["bottom"].text = "<ac>" + map_name
@sprites["info"] = Window_AdvancedTextPokemon.newWithSize("", -8, 224, 180, 160, @viewport)
@sprites["info"].windowskin = nil
# Set info text
infotext = _INTL("Registered<br>")
infotext += _INTL(" <r>{1}<br>", @sprites["list"].commands.length)
infotext += _INTL("Waiting for a rematch<r>{1}", rematch_count)
@sprites["info"].text = infotext
@sprites["icon"] = IconSprite.new(70, 102, @viewport)
if @contacts[0].trainer?
filename = GameData::TrainerType.charset_filename(@contacts[0].trainer_type)
else
filename = sprintf("Graphics/Characters/phone%03d", @contacts[0].common_event_id)
pbRefreshScreen
end
@sprites["icon"].setBitmap(filename)
charwidth = @sprites["icon"].bitmap.width
charheight = @sprites["icon"].bitmap.height
@sprites["icon"].x = 86 - (charwidth / 8)
@sprites["icon"].y = 134 - (charheight / 8)
@sprites["icon"].src_rect = Rect.new(0, 0, charwidth / 4, charheight / 4)
# Start scene
pbFadeInAndShow(@sprites)
pbActivateWindow(@sprites, "list") {
oldindex = -1
loop do
Graphics.update
Input.update
pbUpdateSpriteHash(@sprites)
# Cursor moved, update display
if @sprites["list"].index != oldindex
def pbRefreshScreen
# Redraw rematch readiness icons
if @sprites["rematch_0"]
@sprites["list"].page_item_max.times do |i|
@sprites["rematch_#{i}"].clearBitmaps
j = i + @sprites["list"].top_item
if j < @contacts.length && @contacts[j].can_rematch?
@sprites["rematch_#{i}"].setBitmap("Graphics/UI/Phone/icon_rematch")
end
end
end
# Get the selected contact
contact = @contacts[@sprites["list"].index]
if contact
# Redraw contact's portrait
if contact.trainer?
filename = GameData::TrainerType.charset_filename(contact.trainer_type)
else
@@ -105,28 +120,86 @@ class PokemonPhoneScene
@sprites["icon"].x = 86 - (charwidth / 8)
@sprites["icon"].y = 134 - (charheight / 8)
@sprites["icon"].src_rect = Rect.new(0, 0, charwidth / 4, charheight / 4)
# Redraw contact's location text
map_name = (contact.map_id > 0) ? pbGetMapNameFromId(contact.map_id) : ""
@sprites["bottom"].text = "<ac>" + map_name
@sprites["list"].page_item_max.times do |i|
@sprites["rematch[#{i}]"].clearBitmaps
j = i + @sprites["list"].top_item
if j < @contacts.length && @contacts[j].can_rematch?
@sprites["rematch[#{i}]"].setBitmap("Graphics/UI/Phone/icon_rematch")
end
else
@sprites["icon"].setBitmap(nil)
@sprites["bottom"].text = ""
end
end
def pbChooseContact
pbActivateWindow(@sprites, "list") {
index = -1
loop do
Graphics.update
Input.update
pbUpdateSpriteHash(@sprites)
# Cursor moved, update display
pbRefreshScreen if @sprites["list"].index != index
index = @sprites["list"].index
# Get inputs
if Input.trigger?(Input::BACK)
pbPlayCloseMenuSE
break
return nil
elsif Input.trigger?(Input::USE)
index = @sprites["list"].index
Phone::Call.make_outgoing(@contacts[index]) if index >= 0
return @contacts[index] if index >= 0
end
end
}
pbFadeOutAndHide(@sprites)
end
def pbEndScene
pbFadeOutAndHide(@sprites) { pbUpdate }
pbDisposeSpriteHash(@sprites)
@viewport.dispose
end
def pbUpdate
pbUpdateSpriteHash(@sprites)
end
end
#===============================================================================
#
#===============================================================================
class PokemonPhoneScreen
def initialize(scene)
@scene = scene
end
def pbStartScreen
if $PokemonGlobal.phone.contacts.none? { |con| con.visible? }
pbMessage(_INTL("There are no phone numbers stored."))
return
end
@scene.pbStartScene
loop do
contact = @scene.pbChooseContact
break if !contact
commands = []
commands.push(_INTL("Call"))
commands.push(_INTL("Delete")) if contact.can_hide?
commands.push(_INTL("Cancel"))
cmd = pbShowCommands(nil, commands, -1)
cmd -= 1 if cmd >=1 && !contact.can_hide?
case cmd
when 0 # Call
Phone::Call.make_outgoing(contact)
when 1 # Delete
name = contact.display_name
if pbConfirmMessage(_INTL("Are you sure you want to delete {1} from your phone?", name))
contact.visible = false
@scene.pbRefreshList
pbMessage(_INTL("{1} was deleted from your phone contacts.", name))
if $PokemonGlobal.phone.contacts.none? { |con| con.visible? }
pbMessage(_INTL("There are no phone numbers stored."))
break
end
end
end
end
@scene.pbEndScene
end
end

View File

@@ -388,6 +388,17 @@ MenuHandlers.add(:debug_menu, :reset_trainers, {
}
})
MenuHandlers.add(:debug_menu, :toggle_rematches_possible, {
"name" => _INTL("Toggle Phone Rematches Possible"),
"parent" => :battle_menu,
"description" => _INTL("Toggles whether trainers in the phone can be rebattled."),
"effect" => proc {
Phone.rematches_enabled = !Phone.rematches_enabled
pbMessage(_INTL("Trainers in the phone can now be rebattled.")) if Phone.rematches_enabled
pbMessage(_INTL("Trainers in the phone cannot be rebattled.")) if !Phone.rematches_enabled
}
})
MenuHandlers.add(:debug_menu, :ready_rematches, {
"name" => _INTL("Ready All Phone Rematches"),
"parent" => :battle_menu,

View File

@@ -519,6 +519,7 @@ module Compiler
endifswitch = []
vanishifswitch = []
regspeech = nil
common_event = 0
commands.each do |command|
if command[/^Battle\:\s*([\s\S]+)$/i]
battles.push($~[1])
@@ -558,6 +559,9 @@ module Compiler
elsif command[/^RegSpeech\:\s*([\s\S]+)$/i]
regspeech = $~[1].gsub(/^\s+/, "").gsub(/\s+$/, "")
push_comment(firstpage.list, command) if rewriteComments
elsif command[/^CommonEvent\:\s*(\d+)$/i]
common_event = $~[1].to_i
push_comment(firstpage.list, command) if rewriteComments
end
end
return nil if battles.length <= 0
@@ -600,11 +604,19 @@ module Compiler
push_text(firstpage.list, regspeech, 2)
push_choices(firstpage.list, ["Yes", "No"], 2, 2)
push_choice(firstpage.list, 0, "Yes", 3)
if common_event > 0
if battleid > 0
push_script(firstpage.list, sprintf("Phone.add(get_self,\n %s, %d, %d, %d\n)", brieftrcombo, battles.length, battleid, common_event), 3)
else
push_script(firstpage.list, sprintf("Phone.add(get_self,\n %s, %d, nil, %d\n)", brieftrcombo, battles.length, common_event), 3)
end
else
if battleid > 0
push_script(firstpage.list, sprintf("Phone.add(get_self,\n %s, %d, %d\n)", brieftrcombo, battles.length, battleid), 3)
else
push_script(firstpage.list, sprintf("Phone.add(get_self,\n %s, %d\n)", brieftrcombo, battles.length), 3)
end
end
push_choice(firstpage.list, 1, "No", 3)
push_choices_end(firstpage.list, 3)
push_branch_end(firstpage.list, 2)
@@ -679,11 +691,19 @@ module Compiler
push_text(lastpage.list, regspeech, 1)
push_choices(lastpage.list, ["Yes", "No"], 2, 1)
push_choice(lastpage.list, 0, "Yes", 2)
if common_event > 0
if battleid > 0
push_script(lastpage.list, sprintf("Phone.add(get_self,\n %s, %d, %d, %d\n)", brieftrcombo, battles.length, battleid, common_event), 2)
else
push_script(lastpage.list, sprintf("Phone.add(get_self,\n %s, %d, nil, %d\n)", brieftrcombo, battles.length, common_event), 2)
end
else
if battleid > 0
push_script(lastpage.list, sprintf("Phone.add(get_self,\n %s, %d, %d\n)", brieftrcombo, battles.length, battleid), 2)
else
push_script(lastpage.list, sprintf("Phone.add(get_self,\n %s, %d\n)", brieftrcombo, battles.length), 2)
end
end
push_choice(lastpage.list, 1, "No", 2)
push_choices_end(lastpage.list, 2)
push_branch_end(lastpage.list, 1)