Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions game_engine/ui/designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,48 +784,61 @@ def __init__(self):
coords = list(self.unconverted_objectCoords)
coords[0] += self.objectSize[0] * self.win_scale
R_initial, G_initial, B_initial = 0, 0, 0
size_initial = 0

with open("items/info.json", "r") as json_file:
data = json.loads(json_file.read())
light = data[self.objectName]["lights"]

if light:
R_initial, G_initial, B_initial = light["RGB"]
size_initial = light["size"]

scrollbar_area = "{}_scrollbar_area".format(self.objectName)
light_editor_surf, light_editor_coor = UI.window("light_editor", coords, (230, 220), (30, 30, 30), 2)
light_editor_surf, light_editor_coor = UI.window("light_editor", coords, (330, 250), (30, 30, 30), 2)
UI.window("light_editor_close_button", (5, 5), (20, 20), (0, 30, 5), "button", win_name="light_editor")
UI.add_images({(0, 0): IMAGES.closeButton}, "light_editor_close_button")
UI.window(scrollbar_area, (5, 25), (200, 120), (30, 30, 30), text_bool=False, win_name="light_editor")
UI.text("R\nG\nB", 25, (70, 12), (200, 200, 200), scrollbar_area, font="impact")
UI.window("R", (100, 20), (100, 20), (200, 200, 200), "scrollbar", win_name=scrollbar_area)
UI.window("G", (100, 50), (100, 20), (200, 200, 200), "scrollbar", win_name=scrollbar_area)
UI.window("B", (100, 80), (100, 20), (200, 200, 200), "scrollbar", win_name=scrollbar_area)
R = UI.listen("R")
G = UI.listen("G")
B = UI.listen("B")
UI.window(scrollbar_area, (5, 25), (300, 140), (30, 30, 30), text_bool=False, win_name="light_editor")

UI.window("Size", (170, 20), (100, 20), (200, 200, 200), "scrollbar", win_name=scrollbar_area)
UI.window("R", (170, 50), (100, 20), (200, 200, 200), "scrollbar", win_name=scrollbar_area)
UI.window("G", (170, 80), (100, 20), (200, 200, 200), "scrollbar", win_name=scrollbar_area)
UI.window("B", (170, 110), (100, 20), (200, 200, 200), "scrollbar", win_name=scrollbar_area)
size = UI.listen("Size") * 5
R = UI.listen("R") * 255 / 100

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked the way you implemented and adjusted the new scrollbar_area.

Tested. And works as intended. 👍

G = UI.listen("G") * 255 / 100
B = UI.listen("B") * 255 / 100
UI.text(
f"Size : {size}\n R : {int(R)}\n G : {int(G)}\n B : {int(B)}",
25,
(70, 12),
(200, 200, 200),
scrollbar_area,
font="impact",
)
UI.window(
"light_editor_save_button", (45, 145), (130, 40), (110, 110, 110), "button", win_name="light_editor"
"light_editor_save_button", (100, 175), (130, 40), (110, 110, 110), "button", win_name="light_editor"
)
UI.text("SAVE", 25, (32, 5), (200, 200, 200), "light_editor_save_button", font="impact")

color_view = pygame.Surface((40, 100))
color_view = pygame.Surface((40, 130))
color_view.fill((R, G, B))
UI.add_images({(10, 10): color_view}, scrollbar_area)

try:
self.screen.blit(light_editor_surf, light_editor_coor)
except TypeError: # It will trigger when one of the buttons clicked.
if not self.light_editor_prompt_bool:
if light_editor_surf.item_coords == (45, 145):
light.update({"coords": [0, 0], "size": 100, "RGB": (int(R), int(G), int(B))})
if light_editor_surf.item_coords == (100, 175):
light.update({"coords": [0, 0], "size": int(size), "RGB": (int(R), int(G), int(B))})
R_initial, G_initial, B_initial = int(R), int(G), int(B)
size_initial = int(size)

with open("items/info.json", "w") as json_file_w:
json.dump(data, json_file_w)

elif light_editor_surf.item_coords == (5, 5):
if R == R_initial and B == B_initial and G == G_initial:
if R == R_initial and B == B_initial and G == G_initial and size == size_initial:
self.light_editor_bool = False
else:
self.light_editor_prompt_bool = True
Expand Down Expand Up @@ -882,8 +895,9 @@ def __init__(self):
elif light_editor_prompt_surf.item_coords == (140, 135):
self.light_editor_prompt_bool = False
elif light_editor_prompt_surf.item_coords == (260, 135):
light.update({"coords": [0, 0], "size": 100, "RGB": (int(R), int(G), int(B))})
light.update({"coords": [0, 0], "size": int(size), "RGB": (int(R), int(G), int(B))})

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfectly added dynamic value, thanks for this improvement @Hazim-AS

R_initial, G_initial, B_initial = int(R), int(G), int(B)
size_initial = int(size)

with open("items/info.json", "w") as json_file_w:
json.dump(data, json_file_w)
Expand Down
Loading