From 600bfbe5c87d3c964a64fb4911a9302f99cc26ca Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 20 Feb 2023 12:49:32 +0700 Subject: [PATCH] Setting up the mining UI --- mm.py | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/mm.py b/mm.py index e19d4ff..3729bc2 100644 --- a/mm.py +++ b/mm.py @@ -65,11 +65,30 @@ def get_inventory(): GROUP BY inventory_item.id; """, (current_user_id,)) + inventory = {item[0]:item[1:] for item in cursor.fetchall()} + + cursor.close() + return inventory + +def get_stakes(source_id): + stakes = {} + cursor = conn.cursor() + + cursor.execute(""" + SELECT staking_event.id,well_id,staking_event.source_id, + inventory_item_id,staking_event.created_at,expiration_at + FROM staking_event + INNER JOIN resource_well ON resource_well.id = well_id + INNER JOIN staking_source on staking_event.source_id = staking_source.id + WHERE staking_event.source_id = ? AND staking_source.user_id = ?; + """, (source_id,current_user_id)) + fall = cursor.fetchall() inventory = {item[0]:item[1:] for item in fall} cursor.close() - return inventory + return stakes + def mint(): cursor = conn.cursor() @@ -164,9 +183,9 @@ def get_store_ui(): if id == store_item_id: owned = True store_ui.append([sg.Text(f"{name}: Mine {claim} {resource.capitalize()}"), - sg.Button(f"Buy {price} {resource[0:3]}", - key=("-BUY-",id), - disabled=owned)]) + sg.Button(f"Buy {price} {resource[0:3]}", + key=("-BUY-",id), + disabled=owned)]) return store_ui def inventory_row(item_id, si_id, tier): @@ -177,13 +196,13 @@ def inventory_row(item_id, si_id, tier): return [sg.pin(sg.Column([row], key=("-IROW-",item_id)))] def moon_row(id,source): - wells_ui = [] + wbtns = [] for name,(supply,ts) in source[1].items(): - wells_ui.append(sg.Text(name)) + col = sg.Col([[sg.Text(name)], [sg.Button("Mine", key=("-MINE-",id,name))]]) + wbtns.append(col) 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)))] + sg.Column([wbtns])] + return [sg.pin(sg.Column([row, [sg.Button("Destroy", key=("-DESTROY-",id))]], key=("-MROW-",id)))] def get_inventory_ui(): inventory_ui = [] @@ -204,7 +223,6 @@ layout = [ [sg.Text(banks, key='-BANKS-')], [sg.HorizontalSeparator()], [sg.Button("Sell All", key="-SELLALL-")], - [sg.HorizontalSeparator()], [[sg.Column(get_store_ui(), size=(400, 280),), sg.Column(get_inventory_ui(), key="-ICOL-", vertical_alignment='t')]], [sg.HorizontalSeparator()], @@ -242,7 +260,7 @@ while True: id = mint() moons = get_moons() window.extend_layout(window["-MCOL-"], [moon_row(id,moons[id])]) - elif event.startswith("Mine-"): + elif event.startswith("-MINE-"): print("Mine") elif event == "-SELLALL-": inv = get_inventory() @@ -250,7 +268,7 @@ while True: window[("-IROW-",item)].update(visible=False) for item in store: window[("-BUY-",item)].update(disabled=False) - sell_all() + sell_all() window.close()