How to show that the item is Selected in my Itemlist?

DanicronDanicron Posts: 27Member
edited October 2018 in Programming

At the Moment my Shop script works great, however ive noticed that when i select an item the only way i know which item i selected is by the output log in the editor, so my question is, is there a way to have a selection mask over the item in the ItemList, or would it be easier to have a separate Label that showed which item was selected on screen?
edit : oops forgot to add the code :smile:
extends ItemList

export (NodePath) var path_to_buystuff_node
var buystuff



var SHOP_ITEMS = {

   #Swords
    "LongSword":{"sold":false,"Damage":4, "type":"Sword", "cost":10},
    "Rapier":{"sold":false, "Damage":7, "type":"Sword", "cost":25},
    "Scimitar":{"sold":false, "Damage":12, "type":"Sword", "cost":40},
    "BroadSword":{"sold":false, "Damage":20, "type":"Sword", "cost":60},
    "BastardSword":{"sold":false, "Damage":35, "type":"Sword", "cost":100},  
    "Excalibur":{"sold":false, "Damage":150, "type":"Sword", "cost":500},
    #Daggers
    "RogueDagger":{"sold":false, "Damage":3, "type":"Dagger", "cost":10},
    "Shank":{"sold":false, "Damage":10, "type":"Dagger", "cost":20},
    "LongKnife":{"sold":false, "Damage":18, "type":"Dagger", "cost":30},
    "AssassinBlade":{"sold":false, "Damage":30, "type":"Dagger", "cost":50},
    "MurderWeapon":{"sold":false, "Damage":60, "type":"Dagger", "cost":80},
}
var selected_item_name = null;
func _ready():
    buystuff = get_node(path_to_buystuff_node)
    add_item("Weapon Name", null, false);
    add_item("Damage", null, false);
    add_item("Weapon Type", null, false);
    add_item("Cost", null, false);
    # Add each item.
    for item_name in SHOP_ITEMS:
        add_item(item_name, null, SHOP_ITEMS[item_name]["sold"]);
        add_item(str(SHOP_ITEMS[item_name]["Damage"]), null, false);
        add_item(SHOP_ITEMS[item_name]["type"], null, false);
        add_item(str(SHOP_ITEMS[item_name]["cost"]), null, false);
    # Connect the item_selected signal so we know when a item in the list is selected.
    connect("item_selected", self, "shop_item_selected");
func shop_item_selected(index):
    # Get the name of the selected item
    selected_item_name = get_item_text(index);
    # Check if name is a name of a item in the shop (and the type/cost of a item)
    if (SHOP_ITEMS.has(selected_item_name) == true):
        print ("Item selected: ", selected_item_name, " | Cost: ", SHOP_ITEMS[selected_item_name]["cost"]); 



func _on_Button_pressed():
    get_node("/root/global").goto_scene("res://TownMap.tscn")


func _on_Buy_pressed():
    if (buystuff.current_tab == 0)  &&  Coins.warrior_coins >= SHOP_ITEMS[selected_item_name]["cost"]:
        Coins.warrior_coins -= SHOP_ITEMS[selected_item_name]["cost"]
    if (buystuff.current_tab == 1) && Coins.mage_coins >= SHOP_ITEMS[selected_item_name]["cost"]:
        Coins.mage_coins -= SHOP_ITEMS[selected_item_name]["cost"]
    if (buystuff.current_tab == 2) && Coins.thief_coins >= SHOP_ITEMS[selected_item_name]["cost"]:
        Coins.thief_coins -= SHOP_ITEMS[selected_item_name]["cost"]

Tags :

Best Answer

  • TwistedTwiglegTwistedTwigleg Posts: 1,499
    Accepted Answer

    @Danicron said:
    At the Moment my Shop script works great, however ive noticed that when i select an item the only way i know which item i selected is by the output log in the editor, so my question is, is there a way to have a selection mask over the item in the ItemList, or would it be easier to have a separate Label that showed which item was selected on screen?

    It would probably be easiest to use a label. The problem with applying a selection mask would be figuring out where to place the mask, and at what size.
    It is doable, but it may be fairly complex. That said, I have never tried placing a selection mask over a item in a ItemList, so who knows? It may be really easy.

    If you can, I would just use a label as it is much easier, and then add a selection mask later if you need/want to.

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 1,499Admin
    Accepted Answer

    @Danicron said:
    At the Moment my Shop script works great, however ive noticed that when i select an item the only way i know which item i selected is by the output log in the editor, so my question is, is there a way to have a selection mask over the item in the ItemList, or would it be easier to have a separate Label that showed which item was selected on screen?

    It would probably be easiest to use a label. The problem with applying a selection mask would be figuring out where to place the mask, and at what size.
    It is doable, but it may be fairly complex. That said, I have never tried placing a selection mask over a item in a ItemList, so who knows? It may be really easy.

    If you can, I would just use a label as it is much easier, and then add a selection mask later if you need/want to.

  • DanicronDanicron Posts: 27Member

    Yeah i think you are right i decided to go with the label anyways and managed to get that to work great :):)

Sign In or Register to comment.