Refactored phone/rematches code, added Phone.rematches_enabled/Phone.rematch_variant/map metadata flag "NoPhoneSignal", changed event layout, trainer contacts can use Common Events for their calls, etc.

This commit is contained in:
Maruno17
2022-08-13 16:52:42 +01:00
parent c79b970d6b
commit aa9b1a9e23
9 changed files with 851 additions and 412 deletions

View File

@@ -5,7 +5,7 @@ class Window_PhoneList < Window_CommandPokemon
def drawCursor(index, rect)
selarrow = AnimatedBitmap.new("Graphics/Pictures/phoneSel")
if self.index == index
pbCopyBitmap(self.contents, selarrow.bitmap, rect.x, rect.y)
pbCopyBitmap(self.contents, selarrow.bitmap, rect.x, rect.y + 2)
end
return Rect.new(rect.x + 28, rect.y + 8, rect.width - 16, rect.height)
end
@@ -22,44 +22,60 @@ end
#===============================================================================
class PokemonPhoneScene
def start
commands = []
@trainers = []
if $PokemonGlobal.phoneNumbers
$PokemonGlobal.phoneNumbers.each do |num|
if num[0] # if visible
if num.length == 8 # if trainer
@trainers.push([num[1], num[2], num[6], (num[4] >= 2)])
else # if NPC
@trainers.push([num[1], num[2], num[3]])
end
end
end
# Get list of contacts
@contacts = []
$PokemonGlobal.phone.contacts.each do |contact|
@contacts.push(contact) if contact.visible?
end
if @trainers.length == 0
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
@contacts.each do |contact|
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", "phonebg", @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"].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/Pictures/phoneRematch")
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.new(0, 0, 0)
mapname = (@trainers[0][2]) ? pbGetMapNameFromId(@trainers[0][2]) : ""
@sprites["header"].windowskin = nil
@sprites["bottom"] = Window_AdvancedTextPokemon.newWithSize(
"", 162, Graphics.height - 64, Graphics.width - 158, 64, @viewport
)
@sprites["bottom"].text = "<ac>" + mapname
@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)
addBackgroundPlane(@sprites, "bg", "phonebg", @viewport)
@sprites["info"].windowskin = nil
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 @trainers[0].length == 4
filename = GameData::TrainerType.charset_filename(@trainers[0][0])
if @contacts[0].trainer?
filename = GameData::TrainerType.charset_filename(@contacts[0].trainer_type)
else
filename = sprintf("Graphics/Characters/phone%03d", @trainers[0][0])
filename = sprintf("Graphics/Characters/phone%03d", @contacts[0].common_event_id)
end
@sprites["icon"].setBitmap(filename)
charwidth = @sprites["icon"].bitmap.width
@@ -67,33 +83,7 @@ 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)
@trainers.each do |trainer|
if trainer.length == 4
displayname = _INTL("{1} {2}", GameData::TrainerType.get(trainer[0]).name,
pbGetMessageFromHash(MessageTypes::TrainerNames, trainer[1]))
commands.push(displayname) # trainer's display name
else
commands.push(trainer[1]) # NPC's display name
end
end
@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
next if j >= commands.length
trainer = @trainers[j]
if trainer.length == 4 && trainer[3]
@sprites["rematch[#{i}]"].setBitmap("Graphics/Pictures/phoneRematch")
end
end
rematchcount = 0
@trainers.each do |trainer|
rematchcount += 1 if trainer.length == 4 && trainer[3]
end
infotext = _INTL("Registered<br>")
infotext += _INTL(" <r>{1}<br>", @sprites["list"].commands.length)
infotext += _INTL("Waiting for a rematch<r>{1}", rematchcount)
@sprites["info"].text = infotext
# Start scene
pbFadeInAndShow(@sprites)
pbActivateWindow(@sprites, "list") {
oldindex = -1
@@ -101,12 +91,13 @@ class PokemonPhoneScene
Graphics.update
Input.update
pbUpdateSpriteHash(@sprites)
# Cursor moved, update display
if @sprites["list"].index != oldindex
trainer = @trainers[@sprites["list"].index]
if trainer.length == 4
filename = GameData::TrainerType.charset_filename(trainer[0])
contact = @contacts[@sprites["list"].index]
if contact.trainer?
filename = GameData::TrainerType.charset_filename(contact.trainer_type)
else
filename = sprintf("Graphics/Characters/phone%03d", trainer[0])
filename = sprintf("Graphics/Characters/phone%03d", contact.common_event_id)
end
@sprites["icon"].setBitmap(filename)
charwidth = @sprites["icon"].bitmap.width
@@ -114,24 +105,23 @@ 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)
mapname = (trainer[2]) ? pbGetMapNameFromId(trainer[2]) : ""
@sprites["bottom"].text = "<ac>" + mapname
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
next if j >= commands.length
trainer = @trainers[j]
if trainer.length == 4 && trainer[3]
if j < @contacts.length && @contacts[j].can_rematch?
@sprites["rematch[#{i}]"].setBitmap("Graphics/Pictures/phoneRematch")
end
end
end
# Get inputs
if Input.trigger?(Input::BACK)
pbPlayCloseMenuSE
break
elsif Input.trigger?(Input::USE)
index = @sprites["list"].index
pbCallTrainer(@trainers[index][0], @trainers[index][1]) if index >= 0
Phone::Call.make_outgoing(@contacts[index]) if index >= 0
end
end
}