diff --git a/mm.py b/mm.py index b49a7a4..e19d4ff 100644 --- a/mm.py +++ b/mm.py @@ -76,6 +76,7 @@ def mint(): rand_hash = "%010x" % random.randrange(16 ** 16) cursor.execute('BEGIN') + source_id = -1 try: cursor.execute(""" INSERT INTO staking_source (user_id, address) VALUES (?, ?) @@ -94,7 +95,8 @@ def mint(): conn.rollback() finally: cursor.close() - get_moons() + + return source_id def buy_item(item_id): cursor = conn.cursor() @@ -167,12 +169,21 @@ def get_store_ui(): disabled=owned)]) return store_ui -def inventory_row(id, si_id, tier): +def inventory_row(item_id, si_id, tier): name = store[si_id][0] row = [sg.Text(f"{name} - Tier {tier+1}"), - sg.Button("Upgrade", key=("-UPGRADE-",id)), - sg.Button("Sell", key=("-SELL-",id))] - return [sg.pin(sg.Column([row], key=("-IROW-",id)))] + sg.Button("Upgrade", key=("-UPGRADE-",item_id)), + sg.Button("Sell", key=("-SELL-",item_id))] + return [sg.pin(sg.Column([row], key=("-IROW-",item_id)))] + +def moon_row(id,source): + wells_ui = [] + for name,(supply,ts) in source[1].items(): + wells_ui.append(sg.Text(name)) + row = [sg.Image("moon.png"), + sg.Column(layout=[wells_ui]), + sg.Button("Destroy", key=("-DESTROY-",id))] + return [sg.pin(sg.Column([row], key=("-MROW-",id)))] def get_inventory_ui(): inventory_ui = [] @@ -185,12 +196,7 @@ def get_sources_ui(): staking_sources = get_moons() sources_ui = [] for id,source in staking_sources.items(): - wells_ui = [] - for name,(supply,ts) in source[1].items(): - wells_ui.append(sg.Text(name)) - sources_ui.append([sg.Image("moon.png"), - sg.Column(layout=[wells_ui]), - sg.Button("Destroy", key=("-DESTROY-",id))]) + sources_ui.append(moon_row(id,source)) return sources_ui layout = [ @@ -200,10 +206,10 @@ layout = [ [sg.Button("Sell All", key="-SELLALL-")], [sg.HorizontalSeparator()], [[sg.Column(get_store_ui(), size=(400, 280),), - sg.Column(get_inventory_ui(), key="-COL-", vertical_alignment='t')]], + sg.Column(get_inventory_ui(), key="-ICOL-", vertical_alignment='t')]], [sg.HorizontalSeparator()], [sg.Button("Mint Moon", key="-MINT-")], - [sg.Column(layout=get_sources_ui(), size=(1200, 500), + [sg.Column(layout=get_sources_ui(), key="-MCOL-", size=(1200, 500), scrollable=True, vertical_scroll_only=True)] ] @@ -216,7 +222,6 @@ while True: elif type(event) is tuple: if event[0] == "-UPGRADE-": sg.Window.Layout([[sg.Text("IT WORKED")]]) - print('asdf') elif event[0] == "-SELL-": id = event[1] inv = get_inventory() @@ -227,12 +232,16 @@ while True: id = event[1] item_id = buy_item(id) window[("-BUY-",id)].update(disabled=True) - window.extend_layout(window["-COL-"], [inventory_row(item_id,id,0)]) + window.extend_layout(window["-ICOL-"], [inventory_row(item_id,id,0)]) elif event[0] == "-DESTROY-": - destroy(event[1]) + id = event[1] + destroy(id) + window[("-MROW-",id)].update(visible=False) else: if event == "-MINT-": - mint() + id = mint() + moons = get_moons() + window.extend_layout(window["-MCOL-"], [moon_row(id,moons[id])]) elif event.startswith("Mine-"): print("Mine") elif event == "-SELLALL-":