Setting up the mining UI
This commit is contained in:
		
							parent
							
								
									bdf58a624f
								
							
						
					
					
						commit
						600bfbe5c8
					
				
							
								
								
									
										42
									
								
								mm.py
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								mm.py
									
									
									
									
									
								
							@ -65,11 +65,30 @@ def get_inventory():
 | 
				
			|||||||
    GROUP BY inventory_item.id;
 | 
					    GROUP BY inventory_item.id;
 | 
				
			||||||
    """, (current_user_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()
 | 
					    fall = cursor.fetchall()
 | 
				
			||||||
    inventory = {item[0]:item[1:] for item in fall}
 | 
					    inventory = {item[0]:item[1:] for item in fall}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cursor.close()
 | 
					    cursor.close()
 | 
				
			||||||
    return inventory
 | 
					    return stakes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def mint():
 | 
					def mint():
 | 
				
			||||||
    cursor = conn.cursor()
 | 
					    cursor = conn.cursor()
 | 
				
			||||||
@ -164,9 +183,9 @@ def get_store_ui():
 | 
				
			|||||||
            if id == store_item_id:
 | 
					            if id == store_item_id:
 | 
				
			||||||
                owned = True
 | 
					                owned = True
 | 
				
			||||||
        store_ui.append([sg.Text(f"{name}: Mine {claim} {resource.capitalize()}"),
 | 
					        store_ui.append([sg.Text(f"{name}: Mine {claim} {resource.capitalize()}"),
 | 
				
			||||||
                        sg.Button(f"Buy {price} {resource[0:3]}",
 | 
					                            sg.Button(f"Buy {price} {resource[0:3]}",
 | 
				
			||||||
                                key=("-BUY-",id),
 | 
					                                    key=("-BUY-",id),
 | 
				
			||||||
                                disabled=owned)])
 | 
					                                    disabled=owned)])
 | 
				
			||||||
    return store_ui
 | 
					    return store_ui
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def inventory_row(item_id, si_id, tier):
 | 
					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)))]
 | 
					    return [sg.pin(sg.Column([row], key=("-IROW-",item_id)))]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def moon_row(id,source):
 | 
					def moon_row(id,source):
 | 
				
			||||||
    wells_ui = []
 | 
					    wbtns = []
 | 
				
			||||||
    for name,(supply,ts) in source[1].items():
 | 
					    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"),
 | 
					    row = [sg.Image("moon.png"),
 | 
				
			||||||
            sg.Column(layout=[wells_ui]),
 | 
					            sg.Column([wbtns])]
 | 
				
			||||||
            sg.Button("Destroy", key=("-DESTROY-",id))]
 | 
					    return [sg.pin(sg.Column([row, [sg.Button("Destroy", key=("-DESTROY-",id))]], key=("-MROW-",id)))]
 | 
				
			||||||
    return [sg.pin(sg.Column([row], key=("-MROW-",id)))]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_inventory_ui():
 | 
					def get_inventory_ui():
 | 
				
			||||||
    inventory_ui = []
 | 
					    inventory_ui = []
 | 
				
			||||||
@ -204,7 +223,6 @@ layout = [
 | 
				
			|||||||
    [sg.Text(banks, key='-BANKS-')],
 | 
					    [sg.Text(banks, key='-BANKS-')],
 | 
				
			||||||
    [sg.HorizontalSeparator()],
 | 
					    [sg.HorizontalSeparator()],
 | 
				
			||||||
    [sg.Button("Sell All", key="-SELLALL-")],
 | 
					    [sg.Button("Sell All", key="-SELLALL-")],
 | 
				
			||||||
    [sg.HorizontalSeparator()],
 | 
					 | 
				
			||||||
    [[sg.Column(get_store_ui(), size=(400, 280),),
 | 
					    [[sg.Column(get_store_ui(), size=(400, 280),),
 | 
				
			||||||
      sg.Column(get_inventory_ui(), key="-ICOL-", vertical_alignment='t')]],
 | 
					      sg.Column(get_inventory_ui(), key="-ICOL-", vertical_alignment='t')]],
 | 
				
			||||||
    [sg.HorizontalSeparator()],
 | 
					    [sg.HorizontalSeparator()],
 | 
				
			||||||
@ -242,7 +260,7 @@ while True:
 | 
				
			|||||||
            id = mint()
 | 
					            id = mint()
 | 
				
			||||||
            moons = get_moons()
 | 
					            moons = get_moons()
 | 
				
			||||||
            window.extend_layout(window["-MCOL-"], [moon_row(id,moons[id])])
 | 
					            window.extend_layout(window["-MCOL-"], [moon_row(id,moons[id])])
 | 
				
			||||||
        elif event.startswith("Mine-"):
 | 
					        elif event.startswith("-MINE-"):
 | 
				
			||||||
            print("Mine")
 | 
					            print("Mine")
 | 
				
			||||||
        elif event == "-SELLALL-":
 | 
					        elif event == "-SELLALL-":
 | 
				
			||||||
            inv = get_inventory()
 | 
					            inv = get_inventory()
 | 
				
			||||||
@ -250,7 +268,7 @@ while True:
 | 
				
			|||||||
                window[("-IROW-",item)].update(visible=False)
 | 
					                window[("-IROW-",item)].update(visible=False)
 | 
				
			||||||
            for item in store:
 | 
					            for item in store:
 | 
				
			||||||
                window[("-BUY-",item)].update(disabled=False)
 | 
					                window[("-BUY-",item)].update(disabled=False)
 | 
				
			||||||
            sell_all()
 | 
					                sell_all()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
window.close()
 | 
					window.close()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user