Refactor: double hats

This commit is contained in:
chardub
2025-02-20 17:10:24 -05:00
parent d099d788f4
commit 0f416eecaf
23 changed files with 208 additions and 147 deletions

View File

@@ -143,10 +143,9 @@ def generate_front_trainer_sprite_bitmap(allowEasterEgg=true, pokeball = nil,
clothes_id = nil, hat_id = nil, hat2_id=nil, hair_id = nil,
skin_tone_id = nil, hair_color = nil, hat_color = nil, clothes_color = nil,
hat2_color = nil)
echoln hat_id
clothes_id = $Trainer.clothes if !clothes_id
hat_id = $Trainer.hat if !hat_id
hat2_id = $Trainer.hat if !hat2_id
hat2_id = $Trainer.hat2 if !hat2_id
hair_id = $Trainer.hair if !hair_id
skin_tone_id = $Trainer.skin_tone if !skin_tone_id
@@ -202,8 +201,8 @@ def generate_front_trainer_sprite_bitmap(allowEasterEgg=true, pokeball = nil,
baseBitmap.bitmap.blt(0, 0, outfitBitmap.bitmap, outfitBitmap.bitmap.rect)
end
baseBitmap.bitmap.blt(0, 0, hairBitmapWrapper.bitmap, hairBitmapWrapper.bitmap.rect) if hairBitmapWrapper
baseBitmap.bitmap.blt(0, 0, hatBitmap.bitmap, hatBitmap.bitmap.rect) if hatBitmap
baseBitmap.bitmap.blt(0, 0, hat2Bitmap.bitmap, hat2Bitmap.bitmap.rect) if hat2Bitmap
baseBitmap.bitmap.blt(0, 0, hatBitmap.bitmap, hatBitmap.bitmap.rect) if hatBitmap
baseBitmap.bitmap.blt(44, 42, ballBitmap, ballBitmap.rect) if ballBitmap
return baseBitmap

View File

@@ -27,12 +27,12 @@ def getPresenter(itemType, view, stock, adapter, versions)
end
end
def getAdapter(itemType, stock, isShop)
def getAdapter(itemType, stock, isShop, is_secondary=false)
case itemType
when :CLOTHES
return ClothesMartAdapter.new(stock, isShop)
when :HAT
return HatsMartAdapter.new(stock, isShop)
return HatsMartAdapter.new(stock, isShop,is_secondary)
when :HAIR
return HairMartAdapter.new(stock, isShop)
end
@@ -71,38 +71,45 @@ def hairShop(outfits_list = [],free=false, customMessage=nil)
genericOutfitsShopMenu(stock, :HAIR, true,!free,customMessage)
end
def switchHatsPosition()
hat1 = $Trainer.hat
hat2 = $Trainer.hat2
hat1_color = $Trainer.hat_color
hat2_color = $Trainer.hat2_color
$Trainer.hat = hat2
$Trainer.hat2 = hat1
$Trainer.hat_color = hat1_color
$Trainer.hat_color = hat2_color
SWAP_HAT_POSITIONS_CAPTION = "Switch hats position"
def set_hat_adapter_options(adapter)
slot1_hat = $Trainer.hat ? "Swap #{get_hat_by_id($Trainer.hat).name}" : "(Empty slot)"
slot2_hat = $Trainer.hat2 ? "Swap #{get_hat_by_id($Trainer.hat2).name}" : "(Empty slot)"
options = [slot1_hat,slot2_hat]
options << SWAP_HAT_POSITIONS_CAPTION if $Trainer.hat && $Trainer.hat2
options << "Cancel"
hat_options_choice = optionsMenu(options)
if options[hat_options_choice] == SWAP_HAT_POSITIONS_CAPTION
hat1 = $Trainer.hat
hat2 = $Trainer.hat2
$Trainer.hat = hat2
$Trainer.hat2 = hat1
pbSEPlay("GUI naming tab swap start")
return set_hat_adapter_options(adapter)
end
if hat_options_choice == options.length #cancel
return nil
end
is_secondary = hat_options_choice ==1
adapter.set_secondary_hat(is_secondary)
return adapter
pbSEPlay("GUI naming tab swap start")
end
def openSelectOutfitMenu(stock = [], itemType)
adapter = getAdapter(itemType, stock, false)
if adapter.is_a?(HatsMartAdapter)
adapter = set_hat_adapter_options(adapter)
return if !adapter
end
SWAP_HAT_POSITIONS_CAPTION = "Switch hats position"
#unused
# def set_hat_adapter_options(adapter)
# slot1_hat = $Trainer.hat ? "Swap #{get_hat_by_id($Trainer.hat).name}" : "(Empty slot)"
# slot2_hat = $Trainer.hat2 ? "Swap #{get_hat_by_id($Trainer.hat2).name}" : "(Empty slot)"
# options = [slot1_hat,slot2_hat]
# options << SWAP_HAT_POSITIONS_CAPTION if $Trainer.hat && $Trainer.hat2
# options << "Cancel"
# hat_options_choice = optionsMenu(options)
# if options[hat_options_choice] == SWAP_HAT_POSITIONS_CAPTION
# switchHatsPosition()
# return nil
# end
# if hat_options_choice == options.length #cancel
# return nil
# end
# is_secondary = hat_options_choice ==1
# adapter.set_secondary_hat(is_secondary)
# return adapter
# end
#is_secondary only used for hats
def openSelectOutfitMenu(stock = [], itemType =nil, is_secondary=false)
adapter = getAdapter(itemType, stock, false, is_secondary)
view = ClothesShopView.new()
presenter = ClothesShopPresenter.new(view, stock, adapter)
presenter.pbBuyScreen
@@ -117,30 +124,42 @@ def changeClothesMenu()
openSelectOutfitMenu(stock, :CLOTHES)
end
def changeHatMenu()
def changeHatMenu(is_secondary_hat = false)
stock = []
$Trainer.unlocked_hats.each { |outfit_id|
outfit = get_hat_by_id(outfit_id)
stock << outfit if outfit
}
stock << :REMOVE_HAT
openSelectOutfitMenu(stock, :HAT)
openSelectOutfitMenu(stock, :HAT, is_secondary_hat)
end
def changeOutfit()
hat1_name = get_hat_by_id($Trainer.hat) ? get_hat_by_id($Trainer.hat).name : "(Empty)"
hat2_name = get_hat_by_id($Trainer.hat2) ? get_hat_by_id($Trainer.hat2).name : "(Empty)"
commands = []
commands[cmdHat = commands.length] = _INTL("Change hat")
commands[cmdClothes = commands.length] = _INTL("Change clothes")
commands[cmdHat = commands.length] = _INTL("Change hat 1 (#{hat1_name})")
commands[cmdHat2 = commands.length] = _INTL("Change hat 2 (#{hat2_name})")
commands[switchHats = commands.length] = _INTL("Switch hat positions")
commands[cmdQuit = commands.length] = _INTL("Quit")
cmd = pbMessage(_INTL("What would you like to do?"), commands, cmdQuit + 1)
#TODO change this into a graphical menu with icons
loop do
cmd = pbMessage(_INTL("What would you like to do?"), commands, cmdQuit + 1)
if cmd == cmdClothes
changeClothesMenu()
break
elsif cmd == cmdHat
changeHatMenu()
break
elsif cmd == cmdHat2
changeHatMenu(true)
break
elsif cmd == switchHats
switchHatsPosition()
break
else
break
end

View File

@@ -13,7 +13,7 @@ class ClothesShopPresenter < PokemonMartScreen
@scene.pbEndBuyScene
end
def playerHatActionsMenu(item)
def playerHatActionsMenu(item, is_secondary=false)
is_player_hat = item.id == @adapter.worn_clothes
options = []
if is_player_hat
@@ -22,10 +22,10 @@ class ClothesShopPresenter < PokemonMartScreen
options << "Wear"
end
remove_dye_option_available = $Trainer.hat_color != 0
remove_dye_option_available = $Trainer.hat_color(@adapter.is_secondary_hat) != 0
options << "Remove dye" if remove_dye_option_available
options << "Mark as favorite" if $Trainer.favorite_hat != item.id
options << "Unmark as favorite" if $Trainer.favorite_hat == item.id
options << "Mark as favorite" if $Trainer.favorite_hat(@adapter.is_secondary_hat) != item.id
options << "Unmark as favorite" if $Trainer.favorite_hat(@adapter.is_secondary_hat) == item.id
options << "Cancel"
# if $Trainer.hat_color != 0
@@ -38,21 +38,22 @@ class ClothesShopPresenter < PokemonMartScreen
else
# wear
putOnClothes(item)
$Trainer.hat_color = @adapter.get_dye_color(item)
$Trainer.set_hat_color(@adapter.get_dye_color(item),@adapter.is_secondary_hat)
return false
end
elsif choice == 1 && remove_dye_option_available
if pbConfirm(_INTL("Are you sure you want to remove the dye from the {1}?", item.name))
$Trainer.hat_color = 0
$Trainer.set_hat_color(0,@adapter.is_secondary_hat)
end
return true
elsif options[choice] == "Mark as favorite"
$Trainer.favorite_hat = item.id
pbSEPlay("GUI storage show party panel")
pbMessage("The #{item.name} is now your favorite!")
echoln "marked #{item.id} as favorite hat"
slot = @adapter.is_secondary_hat ? "slot 1" : "slot 2"
$Trainer.set_favorite_hat(item.id,@adapter.is_secondary_hat)
pbSEPlay("GUI storage show party panel")
pbMessage("The #{item.name} is now your favorite (#{slot})!")
echoln "marked #{item.id} as favorite hat"
elsif options[choice] == "Unmark as favorite"
$Trainer.favorite_hat = nil
$Trainer.set_favorite_hat(nil,@adapter.is_secondary_hat)
pbSEPlay("GUI storage show party panel")
pbMessage("The #{item.name} is no longer marked as your favorite!")
end
@@ -80,9 +81,9 @@ class ClothesShopPresenter < PokemonMartScreen
$Trainer.clothes_color = 0
end
elsif options[choice] == "Mark as favorite"
$Trainer.favorite_clothes = item.id
pbSEPlay("GUI storage show party panel")
pbMessage("The #{item.name} is now your favorite!")
$Trainer.favorite_clothes = item.id
pbSEPlay("GUI storage show party panel")
pbMessage("The #{item.name} is now your favorite!")
elsif options[choice] == "Unmark favorite"
$Trainer.favorite_clothes = nil
pbSEPlay("GUI storage show party panel")

View File

@@ -3,34 +3,23 @@ class HatsMartAdapter < OutfitsMartAdapter
DEFAULT_DESCRIPTION = "A headgear that trainers can wear."
def initialize(stock = nil, isShop = nil, isSecondaryHat = false)
super(stock,isShop)
@is_secondary_hat = isSecondaryHat
super(stock,isShop,isSecondaryHat)
end
def toggleEvent(item)
if !@isShop
if @is_secondary_hat
$Trainer.hat2 = nil
$Trainer.set_hat(nil,@is_secondary_hat)
@worn_clothes = nil
if pbConfirmMessage(_INTL("Do you want to take off your hat?"))
$Trainer.set_hat(nil,@is_secondary_hat)
@worn_clothes = nil
if pbConfirmMessage(_INTL("Do you want to take off your hat?"))
$Trainer.hat2 = nil
@worn_clothes = nil
end
else
$Trainer.hat = nil
@worn_clothes = nil
if pbConfirmMessage(_INTL("Do you want to take off your hat?"))
$Trainer.hat = nil
@worn_clothes = nil
end
end
end
end
def set_secondary_hat(value)
echoln "WOWOWO setting secondary hat value"
@is_secondary_hat = value
end
@@ -48,7 +37,7 @@ class HatsMartAdapter < OutfitsMartAdapter
def getDisplayName(item)
return getName(item) if !item.name
name = item.name
name = "* #{name}" if item.id == $Trainer.favorite_hat
name = "* #{name}" if item.id == $Trainer.favorite_hat(@is_secondary_hat)
return name
end
@@ -63,24 +52,13 @@ class HatsMartAdapter < OutfitsMartAdapter
end
def updateTrainerPreview(item, previewWindow)
if @is_secondary_hat
if item.is_a?(Outfit)
previewWindow.hat2 = item.id
$Trainer.hat2 = item.id# unless $Trainer.hat==nil
set_dye_color(item,previewWindow)
else
$Trainer.hat2=nil
previewWindow.hat2= nil
end
if item.is_a?(Outfit)
previewWindow.hat = item.id
$Trainer.set_hat(item.id,@is_secondary_hat)# unless $Trainer.hat==nil
set_dye_color(item,previewWindow)
else
if item.is_a?(Outfit)
previewWindow.hat = item.id
$Trainer.hat = item.id# unless $Trainer.hat==nil
set_dye_color(item,previewWindow)
else
$Trainer.hat=nil
previewWindow.hat= nil
end
$Trainer.set_hat(nil,@is_secondary_hat)
previewWindow.hat= nil
end
@@ -100,18 +78,18 @@ class HatsMartAdapter < OutfitsMartAdapter
def set_dye_color(item,previewWindow)
if !isShop?
$Trainer.dyed_hats= {} if ! $Trainer.dyed_hats
$Trainer.dyed_hats= {} if !$Trainer.dyed_hats
if $Trainer.dyed_hats.include?(item.id)
dye_color = $Trainer.dyed_hats[item.id]
$Trainer.hat_color = dye_color
$Trainer.set_hat_color(dye_color,@is_secondary_hat)
previewWindow.hat_color = dye_color
else
$Trainer.hat_color=0
$Trainer.set_hat_color(0,@is_secondary_hat)
previewWindow.hat_color=0
end
#echoln $Trainer.dyed_hats
else
$Trainer.hat_color=0
$Trainer.set_hat_color(0,@is_secondary_hat)
previewWindow.hat_color=0
end
end
@@ -126,28 +104,18 @@ class HatsMartAdapter < OutfitsMartAdapter
end
def get_current_clothes()
return $Trainer.hat
return $Trainer.hat(@is_secondary_hat)
end
def putOnOutfit(item)
return unless item.is_a?(Outfit)
if @is_secondary_hat
echoln "broder"
putOnSecondaryHat(item.id)
else
putOnHat(item.id)
end
putOnHat(item.id,false,@is_secondary_hat)
@worn_clothes = item.id
end
def reset_player_clothes()
if @is_secondary_hat
$Trainer.hat2 = @worn_clothes
$Trainer.hat2_color = $Trainer.dyed_hats[@worn_clothes] if $Trainer.dyed_hats && $Trainer.dyed_hats[@worn_clothes]
else
$Trainer.hat = @worn_clothes
$Trainer.hat_color = $Trainer.dyed_hats[@worn_clothes] if $Trainer.dyed_hats && $Trainer.dyed_hats[@worn_clothes]
end
$Trainer.set_hat(@worn_clothes,@is_secondary_hat)
$Trainer.set_hat_color($Trainer.dyed_hats[@worn_clothes],@is_secondary_hat) if $Trainer.dyed_hats && $Trainer.dyed_hats[@worn_clothes]
end
def get_unlocked_items_list()

View File

@@ -16,8 +16,8 @@ def obtainHat(outfit_id,secondary=false)
$Trainer.unlocked_hats << outfit_id if !$Trainer.unlocked_hats.include?(outfit_id)
obtainOutfitMessage(outfit)
if pbConfirmMessage("Would you like to put it on right now?")
putOnHat(outfit_id, false, ) if !secondary
putOnSecondaryHat(outfit_id, false, ) if secondary
putOnHat(outfit_id, false, false) if !secondary
putOnHat(outfit_id, false, true) if secondary
return true
end
return false
@@ -67,12 +67,12 @@ def putOnClothes(outfit_id, silent = false)
putOnOutfitMessage(outfit) if !silent
end
def putOnHat(outfit_id, silent = false)
def putOnHat(outfit_id, silent = false, is_secondary=false)
$Trainer.dyed_hats= {} if ! $Trainer.dyed_hats
$Trainer.last_worn_hat = $Trainer.hat
$Trainer.set_last_worn_hat($Trainer.hat,is_secondary)
outfit = get_hat_by_id(outfit_id)
$Trainer.hat = outfit_id
$Trainer.set_hat(outfit_id,is_secondary)
dye_color = $Trainer.dyed_hats[outfit_id]
if dye_color
@@ -85,24 +85,6 @@ def putOnHat(outfit_id, silent = false)
putOnOutfitMessage(outfit) if !silent
end
def putOnSecondaryHat(outfit_id, silent = false)
$Trainer.dyed_hats= {} if ! $Trainer.dyed_hats
$Trainer.last_worn_hat = $Trainer.hat2
outfit = get_hat_by_id(outfit_id)
$Trainer.hat2 = outfit_id
dye_color = $Trainer.dyed_hats[outfit_id]
if dye_color
$Trainer.hat2_color = dye_color
else
$Trainer.hat2_color = nil
end
$game_map.refreshPlayerOutfit()
putOnOutfitMessage(outfit) if !silent
end
def putOnHairFullId(full_outfit_id)
outfit_id = getSplitHairFilenameAndVersionFromID(full_outfit_id)[1]
@@ -193,7 +175,7 @@ def isWearingClothes(outfitId)
end
def isWearingHat(outfitId)
return $Trainer.hat == outfitId
return $Trainer.hat == outfitId || $Trainer.hat2 == outfitId
end
def isWearingHairstyle(outfitId, version = nil)
@@ -309,13 +291,18 @@ end
def randomizePlayerOutfitUnlocked()
$Trainer.hat = $Trainer.unlocked_hats.sample
$Trainer.hat2 = $Trainer.unlocked_hats.sample
$Trainer.clothes = $Trainer.unlocked_clothes.sample
dye_hat = rand(2)==0
dye_hat2 = rand(2)==0
dye_clothes = rand(2)==0
dye_hair = rand(2)==0
$Trainer.hat2 = nil if rand(3)==0
$Trainer.hat_color = dye_hat ? rand(255) : 0
$Trainer.hat2_color = dye_hat2 ? rand(255) : 0
$Trainer.clothes_color = dye_clothes ? rand(255) : 0
$Trainer.hair_color = dye_hair ? rand(255) : 0
@@ -328,8 +315,12 @@ end
def randomizePlayerOutfit()
$Trainer.hat = $PokemonGlobal.hats_data.keys.sample
$Trainer.hat2 = $PokemonGlobal.hats_data.keys.sample
$Trainer.hat2 = nil if(rand(3)==0)
$Trainer.clothes = $PokemonGlobal.clothes_data.keys.sample
$Trainer.hat_color = rand(2)==0 ? rand(255) : 0
$Trainer.hat2_color = rand(2)==0 ? rand(255) : 0
$Trainer.clothes_color = rand(2)==0 ? rand(255) : 0
$Trainer.hair_color = rand(2)==0 ? rand(255) : 0