mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-09 22:24:58 +00:00
Refactor: double hats
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user