diff --git a/farm/Field_Representation.py b/farm/Field_Representation.py index f47d98f..9906942 100644 --- a/farm/Field_Representation.py +++ b/farm/Field_Representation.py @@ -51,6 +51,7 @@ class Field: colors.append(CHEMTRANT) colors.append(TENESENT) colors.append(CIBUTRANT) + colors.append(ARTISENT) def __init__(self): @@ -92,7 +93,8 @@ class Field: MAGINENT: cv.imread("maginent.jpg", cv.IMREAD_COLOR), CHEMTRANT: cv.imread("chemtrant.jpg", cv.IMREAD_COLOR), TENESENT: cv.imread("tenesent.jpg", cv.IMREAD_COLOR), - CIBUTRANT: cv.imread("cibutrant.jpg", cv.IMREAD_COLOR) + CIBUTRANT: cv.imread("cibutrant.jpg", cv.IMREAD_COLOR), + ARTISENT: cv.imread("artisent.jpg", cv.IMREAD_COLOR) } def reset(self): diff --git a/farm/artisent.jpg b/farm/artisent.jpg new file mode 100644 index 0000000..c6e40d5 Binary files /dev/null and b/farm/artisent.jpg differ diff --git a/farm/farm_overlay.py b/farm/farm_overlay.py new file mode 100644 index 0000000..ebc753d --- /dev/null +++ b/farm/farm_overlay.py @@ -0,0 +1,66 @@ +# Run tkinter code in another thread +import threading +import tkinter as tk +from tkinter import ttk + + +class FarmOverlay(threading.Thread): + + def __init__(self): + threading.Thread.__init__(self) + + self.run_mode = 'init' + + self.root = tk.Tk + + self.ButtonFrame = tk.Frame + + self.StartButton = tk.Button + self.StopButton = tk.Button + self.TkPosition = '133x52+60+600' + + self.StatusLabel = tk.Label + + self.start() + + def run(self): + self.root = tk.Tk() + self.ButtonFrame = tk.Frame(self.root) + self.StartButton = tk.Button(self.ButtonFrame, text="Start", command=self.start_button_callback, width='8') + self.StartButton.grid(row=0, column=0) + self.StopButton = tk.Button(self.ButtonFrame, text="Stop", command=self.stop_button_callback, width='8', + state=tk.DISABLED) + self.StopButton.grid(row=0, column=1) + + self.ButtonFrame.grid(row=3, column=0, columnspan=2) + + self.StatusLabel = tk.Label(self.root, text="", font=("Helvetica", 10, "bold"), + background="grey") + self.StatusLabel.grid(row=4, column=0, columnspan=2) + + # self.ClearButton.pack(side="top") + self.root.geometry(self.TkPosition) + self.root.overrideredirect(1) # fenster ohne aussen rum :-) + # self.root.attributes('-alpha', 0.7) # fenster transparent + self.root.attributes('-topmost', 1) # fenster immer im vordergrund + # self.root.wm_attributes("-disabled", True) + self.root.configure(background='black') + self.root.mainloop() + + def start_button_callback(self): + self.StartButton.configure(state=tk.DISABLED) + self.StopButton.configure(state=tk.NORMAL) + self.StatusLabel.configure(text='') + self.run_mode = 'started' + + def stop_button_callback(self): + self.StartButton.configure(state=tk.NORMAL) + self.StopButton.configure(state=tk.DISABLED) + self.run_mode = 'stopped' + + def get_run_mode(self): + return self.run_mode + + def update_status_label(self, mode, energy_to_go): + text = mode + ": " + str(energy_to_go) + self.StatusLabel.configure(text=text) diff --git a/farm/main_farm_ui.py b/farm/main_farm_ui.py new file mode 100644 index 0000000..93be0af --- /dev/null +++ b/farm/main_farm_ui.py @@ -0,0 +1,35 @@ +from Field_Representation import Field +from time import time +import cv2 as cv +import keyboard +from farm_overlay import FarmOverlay + + +def run(): + field = Field() + overlay = FarmOverlay() + + while True: + if overlay.run_mode == 'stopped': + overlay.update_status_label("stopped", "0") + overlay.run_mode = 'init' + continue + elif overlay.run_mode == 'started': + cv.waitKey(500) + elif overlay.run_mode == 'init': + continue + else: + # boelk + pass + + while True: + if overlay.run_mode == 'stopped': + break + + cords = field.assess_playfield_and_make_move() + print(cords) + cv.waitKey(1000) + + +if __name__ == "__main__": + run() diff --git a/utils.py b/utils.py index 6d77d82..1eb06af 100644 --- a/utils.py +++ b/utils.py @@ -12,6 +12,7 @@ import cv2 as cv import pydirectinput import keyboard + def mse(imageA, imageB): # the 'Mean Squared Error' between the two images is the # sum of the squared difference between the two images; @@ -173,3 +174,21 @@ def check_for_ok_button(cap_win, vis, conf): for pointi in pointis: dig_point(pointi[0] + offset_left, pointi[1] + offset_down, 150) +def check_for_craft_button(cap_win, vis, conf): + screenshot = cap_win.get_screenshot() + needle = cv.imread("play.jpg", cv.IMREAD_UNCHANGED) + rectangles = vis.find(screenshot, needle, 0.7, 1) + if len(rectangles) == 1: + pointis = vis.get_click_points(rectangles) + for pointi in pointis: + dig_point(pointi[0], pointi[1], 150) + + +def get_click_point(rectangle): + # Loop over all the rectangles + x, y, w, h = rectangle + # Determine the center position + center_x = x + int(w / 2) + center_y = y + int(h / 2) + # Save the points + return int(center_x), int(center_y)