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. # 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 # Make this work with common event calls (create and dispose the info
# window in start_message and end_message). # 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. # TODO: Add calling a contact at a particular time forcing rematch readiness.
# Add trainer comments for this. # Add trainer comments for this.
# TODO: Allow individual trainers to never arrange a rematch by themself, thus # TODO: Allow individual trainers to never arrange a rematch by themself, thus
@@ -70,8 +67,8 @@ class Phone
return true return true
end end
# Event, 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 # Map ID, event ID, trainer type, name, versions_count = 1, start_version = 0, common event ID = 0
# Map ID, name, common event ID # Map ID, name, common event ID
def add(*args) def add(*args)
if args[0].is_a?(Game_Event) if args[0].is_a?(Game_Event)
@@ -82,9 +79,11 @@ class Phone
contact = get(true, trainer_type, name, args[3] || 0) contact = get(true, trainer_type, name, args[3] || 0)
if contact if contact
contact.visible = true contact.visible = true
@contacts.delete(contact)
@contacts.push(contact)
else else
contact = Contact.new(true, args[0].map_id, args[0].id, 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 contact.increment_version
@contacts.push(contact) @contacts.push(contact)
end end
@@ -96,9 +95,11 @@ class Phone
contact = get(true, trainer_type, name, args[4] || 0) contact = get(true, trainer_type, name, args[4] || 0)
if contact if contact
contact.visible = true contact.visible = true
@contacts.delete(contact)
@contacts.push(contact)
else else
contact = Contact.new(true, args[0], args[1], 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 contact.increment_version
@contacts.push(contact) @contacts.push(contact)
end end
@@ -108,6 +109,8 @@ class Phone
contact = get(false, name) contact = get(false, name)
if contact if contact
contact.visible = true contact.visible = true
@contacts.delete(contact)
@contacts.push(contact)
else else
contact = Contact.new(false, *args) contact = Contact.new(false, *args)
@contacts.push(contact) @contacts.push(contact)
@@ -251,7 +254,7 @@ class Phone
@variant_beaten = 0 @variant_beaten = 0
@time_to_ready = 0 @time_to_ready = 0
@rematch_flag = 0 # 0=counting down, 1=ready for rematch, 2=ready and told player @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 else
# Non-trainer # Non-trainer
@map_id = args[0] @map_id = args[0]
@@ -280,6 +283,10 @@ class Phone
end end
end end
def can_hide?
return trainer?
end
def common_event_call? def common_event_call?
return @common_event_id > 0 return @common_event_id > 0
end end
@@ -373,7 +380,13 @@ class Phone
def make_incoming def make_incoming
return if !can_make? return if !can_make?
contact = get_random_trainer_for_incoming_call 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) call = generate_trainer_dialogue(contact)
play(call, contact) play(call, contact)
end end
@@ -403,7 +416,7 @@ class Phone
end end
end end
def start_message(contact) def start_message(contact = nil)
pbMessage(_INTL("......\\wt[5] ......\\1")) pbMessage(_INTL("......\\wt[5] ......\\1"))
end end
@@ -434,7 +447,7 @@ class Phone
end_message(contact) end_message(contact)
end end
def end_message(contact) def end_message(contact = nil)
pbMessage(_INTL("Click!\\wt[10]\n......\\wt[5] ......\\1")) pbMessage(_INTL("Click!\\wt[10]\n......\\wt[5] ......\\1"))
end end

View File

@@ -182,7 +182,11 @@ MenuHandlers.add(:pokegear_menu, :phone, {
"order" => 20, "order" => 20,
# "condition" => proc { next $PokemonGlobal.phone && $PokemonGlobal.phone.contacts.length > 0 }, # "condition" => proc { next $PokemonGlobal.phone && $PokemonGlobal.phone.contacts.length > 0 },
"effect" => proc { |menu| "effect" => proc { |menu|
pbFadeOutIn { PokemonPhoneScene.new.start } pbFadeOutIn {
scene = PokemonPhone_Scene.new
screen = PokemonPhoneScreen.new(scene)
screen.pbStartScreen
}
next false 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 class Window_PhoneList < Window_CommandPokemon
def drawCursor(index, rect) def drawCursor(index, rect)
@@ -20,17 +22,57 @@ end
#=============================================================================== #===============================================================================
# #
#=============================================================================== #===============================================================================
class PokemonPhoneScene class PokemonPhone_Scene
def start def pbStartScene
# Get list of contacts @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 = [] @contacts = []
$PokemonGlobal.phone.contacts.each do |contact| $PokemonGlobal.phone.contacts.each do |contact|
@contacts.push(contact) if contact.visible? @contacts.push(contact) if contact.visible?
end 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 # Create list of commands (display names of contacts) and count rematches
commands = [] commands = []
rematch_count = 0 rematch_count = 0
@@ -38,95 +80,126 @@ class PokemonPhoneScene
commands.push(contact.display_name) commands.push(contact.display_name)
rematch_count += 1 if contact.can_rematch? rematch_count += 1 if contact.can_rematch?
end end
# Create viewport and sprites # Set list's commands
@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
@sprites["list"].commands = commands @sprites["list"].commands = commands
@sprites["list"].page_item_max.times do |i| @sprites["list"].index = commands.length - 1 if @sprites["list"].index >= commands.length
@sprites["rematch[#{i}]"] = IconSprite.new(468, 62 + (i * 32), @viewport) if @sprites["list"].top_row > @sprites["list"].itemCount - @sprites["list"].page_item_max - 1
j = i + @sprites["list"].top_item @sprites["list"].top_row = @sprites["list"].itemCount - @sprites["list"].page_item_max - 1
if j < @contacts.length && @contacts[j].can_rematch?
@sprites["rematch[#{i}]"].setBitmap("Graphics/UI/Phone/icon_rematch")
end
end end
@sprites["header"] = Window_UnformattedTextPokemon.newWithSize( # Set info text
_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
infotext = _INTL("Registered<br>") infotext = _INTL("Registered<br>")
infotext += _INTL(" <r>{1}<br>", @sprites["list"].commands.length) infotext += _INTL(" <r>{1}<br>", @sprites["list"].commands.length)
infotext += _INTL("Waiting for a rematch<r>{1}", rematch_count) infotext += _INTL("Waiting for a rematch<r>{1}", rematch_count)
@sprites["info"].text = infotext @sprites["info"].text = infotext
@sprites["icon"] = IconSprite.new(70, 102, @viewport) pbRefreshScreen
if @contacts[0].trainer? end
filename = GameData::TrainerType.charset_filename(@contacts[0].trainer_type)
else def pbRefreshScreen
filename = sprintf("Graphics/Characters/phone%03d", @contacts[0].common_event_id) # 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 end
@sprites["icon"].setBitmap(filename) # Get the selected contact
charwidth = @sprites["icon"].bitmap.width contact = @contacts[@sprites["list"].index]
charheight = @sprites["icon"].bitmap.height if contact
@sprites["icon"].x = 86 - (charwidth / 8) # Redraw contact's portrait
@sprites["icon"].y = 134 - (charheight / 8) if contact.trainer?
@sprites["icon"].src_rect = Rect.new(0, 0, charwidth / 4, charheight / 4) filename = GameData::TrainerType.charset_filename(contact.trainer_type)
# Start scene else
pbFadeInAndShow(@sprites) filename = sprintf("Graphics/Characters/phone%03d", contact.common_event_id)
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)
# Redraw contact's location text
map_name = (contact.map_id > 0) ? pbGetMapNameFromId(contact.map_id) : ""
@sprites["bottom"].text = "<ac>" + map_name
else
@sprites["icon"].setBitmap(nil)
@sprites["bottom"].text = ""
end
end
def pbChooseContact
pbActivateWindow(@sprites, "list") { pbActivateWindow(@sprites, "list") {
oldindex = -1 index = -1
loop do loop do
Graphics.update Graphics.update
Input.update Input.update
pbUpdateSpriteHash(@sprites) pbUpdateSpriteHash(@sprites)
# Cursor moved, update display # Cursor moved, update display
if @sprites["list"].index != oldindex pbRefreshScreen if @sprites["list"].index != index
contact = @contacts[@sprites["list"].index] index = @sprites["list"].index
if contact.trainer?
filename = GameData::TrainerType.charset_filename(contact.trainer_type)
else
filename = sprintf("Graphics/Characters/phone%03d", contact.common_event_id)
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)
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
end
end
# Get inputs # Get inputs
if Input.trigger?(Input::BACK) if Input.trigger?(Input::BACK)
pbPlayCloseMenuSE pbPlayCloseMenuSE
break return nil
elsif Input.trigger?(Input::USE) elsif Input.trigger?(Input::USE)
index = @sprites["list"].index return @contacts[index] if index >= 0
Phone::Call.make_outgoing(@contacts[index]) if index >= 0
end end
end end
} }
pbFadeOutAndHide(@sprites) end
def pbEndScene
pbFadeOutAndHide(@sprites) { pbUpdate }
pbDisposeSpriteHash(@sprites) pbDisposeSpriteHash(@sprites)
@viewport.dispose @viewport.dispose
end 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 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, { MenuHandlers.add(:debug_menu, :ready_rematches, {
"name" => _INTL("Ready All Phone Rematches"), "name" => _INTL("Ready All Phone Rematches"),
"parent" => :battle_menu, "parent" => :battle_menu,

View File

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