Skip to content

Commit

Permalink
working on choose object menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Karam-Sabbagh committed Jan 23, 2022
1 parent 91934c4 commit b2374d3
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 21 deletions.
Binary file modified Engine/Gui/Images/Add_body_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Engine/Gui/Images/Choose_rect_body_button_image.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 38 additions & 3 deletions Engine/Gui/Pygame_gui_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,55 @@ def make_choose_object_window(self):
makes a window to let the user select the object
"""
if not self.ui_window_exist:
self.ui_window = self.pygame_gui.elements.ui_window.UIWindow(self.pygame.Rect(self.screen_width/3, self.screen_height/3, 400, 300),
ui_window_width = 400
ui_window_height = 300

self.ui_window = self.pygame_gui.elements.ui_window.UIWindow(self.pygame.Rect(self.screen_width/3, self.screen_height/3, ui_window_width, ui_window_height),
window_display_title="Choose Object",
resizable=False,
manager=self.ui_manager,
object_id="#choose_object_window")
self.ui_window_exist = True

self.pygame_gui.elements.UIButton(relative_rect=self.pygame.Rect(0, 0, 80+4, 80+4),
buttons_width = 80+4
buttons_spacing = 4

first_button_pos_x = 0
first_button_pos_y = 0
buttons_pos_y_on_line = 1

self.pygame_gui.elements.UIButton(relative_rect=self.pygame.Rect(first_button_pos_x+buttons_spacing, first_button_pos_x+buttons_spacing, buttons_width, buttons_width),
text="Rect",
manager=self.ui_manager,
container=self.ui_window,
object_id="#Choose_rect_body_button"
object_id="#Choose_dynamic_rect_body_button"
)

def make_button_pos(number_of_button_order, buttons_pos_y_on_line):
pos_x = first_button_pos_x+buttons_spacing+((buttons_width+buttons_spacing)*number_of_button_order)

if (number_of_button_order+1)*((buttons_width+buttons_spacing)) < (ui_window_width-4):
pos_y = (first_button_pos_y+buttons_spacing)*buttons_pos_y_on_line
else:
buttons_pos_y_on_line += 1
number_of_button_order = 1
pos_x = first_button_pos_x+buttons_spacing
pos_y = (first_button_pos_y+buttons_spacing+buttons_width)*(buttons_pos_y_on_line-1)

return pos_x, pos_y, buttons_pos_y_on_line

make_pos = make_button_pos(1, buttons_pos_y_on_line)
pos = make_pos[0], make_pos[1]
buttons_pos_y_on_line = make_pos[2]

self.pygame_gui.elements.UIButton(relative_rect=self.pygame.Rect(pos[0], pos[1], buttons_width, buttons_width),
text="Poly",
manager=self.ui_manager,
container=self.ui_window,
object_id="#Choose_dynamic_poly_body_button"
)


def check_events(self, event):
"""
:param event: it"s from pygame.event.get()
Expand Down
33 changes: 21 additions & 12 deletions Engine/Gui/Theme.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
{
"#Choose_rect_body_button":
"#Choose_dynamic_rect_body_button":
{
"images": {
"images": {
"normal_image": {
"path": "Engine/Gui/Images/Choose_dynamic_rect_body_button_image.png"
}
}
},
"#Choose_dynamic_poly_body_button":
{
"images": {
"normal_image": {
"path": "Engine/Gui/Images/Choose_rect_body_button_image.png"
"path": "Engine/Gui/Images/Choose_dynamic_poly_body_button_image.png"
}
}
},
"button": {
"colours": {
"normal_bg": "#dcdcdc",
"hovered_bg": "#aaaaaa",
"active_bg": "#336dff",
"normal_text": "#141414",
"hovered_text": "#141414",
"selected_text": "#141414",
"hovered_bg": "#9696a0",
"active_bg": "#0a4bf0",
"normal_text": "#282828",
"hovered_text": "#323232",
"active_text": "#373737",
"normal_border": "#afafaf"
},
"misc": {
Expand Down Expand Up @@ -45,9 +53,10 @@
{
"normal_bg": "#464646",
"hovered_bg": "#505050",
"active_bg": "#1e06bd",
"active_bg": "#323296",
"normal_text": "#e6e6e6",
"hovered_text": "#e6e6e6"
"hovered_text": "#e6e6e6",
"active_text": "#e6e6e6"
}
},
"window.#close_button":
Expand All @@ -65,8 +74,8 @@
"selection_list":
{
"misc": {
"list_item_height": "70",
"list_item_width": "70"
"list_item_height": "80",
"list_item_width": "80"
},
"colours":
{
Expand Down
Binary file modified Engine/Gui/__pycache__/Pygame_gui_setup.cpython-39.pyc
Binary file not shown.
11 changes: 6 additions & 5 deletions Engine/Physics_Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, pygame_ui_screen, pygame, gravity):
self.gravity = gravity
self.do_sleep = True

self.world = world(gravity=gravity, do_sleep=self.do_sleep)
self.world = world(gravity=self.gravity, do_sleep=self.do_sleep)

# noinspection PyStatementEffect
self.pygame_ui_screen = pygame_ui_screen
Expand All @@ -27,9 +27,10 @@ def __init__(self, pygame_ui_screen, pygame, gravity):
# dynamic: 2

self.shapes_colors = {
staticBody: {"fill_color": (125, 125, 130, 255), "out_line_color": (130, 130, 130, 255)},
staticBody: {"fill_color": (149, 149, 149, 255), "out_line_color": (86, 86, 86, 255)},
kinematicBody: {"fill_color": (150, 150, 150, 255), "out_line_color": (130, 130, 130, 255)},
dynamicBody: {"fill_color": (255, 255, 255, 255), "out_line_color": (190, 190, 190, 255)},
dynamicBody: {"fill_color": (255, 255, 255, 255), "out_line_color": (160, 160, 160, 255)},
# 149, 149, 149 86, 86, 86
"edge_chain": {"out_line_color": (40, 110, 40, 255)},
"circle_shape": {"fill_color": (70, 70, 70, 255), "out_line_color": (110, 110, 110, 255)},
"out_line_color": (190, 190, 190, 255)
Expand Down Expand Up @@ -296,8 +297,8 @@ def set_body_position(self, body, new_pos):
body.position = self.Box2D.b2Vec2(new_pos[0], new_pos[1])

def reset_world(self):
for body in self.world.bodies:
self.world.DestroyBody(body)
del(self.world)
self.world = world(gravity=self.gravity, do_sleep=self.do_sleep)

self.bodies_amount = 0
self.hold_able_bodies = []
Expand Down
Binary file modified Engine/__pycache__/Physics_Engine.cpython-39.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion PhiziBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def spawn_bodies_with_keys():
mouse_y = pygame.mouse.get_pos()[1]
# smallest circle radius can be around 1.0000001
Phy_Eng.create_dynamic_circle(pos_x=mouse_x,
pos_y=mouse_y, radius=1.0000001, density=0.25, friction=0)
pos_y=mouse_y, radius=1.0000001, density=0.75, friction=0)

if released_press_keys[pygame.K_c]:
mouse_x = pygame.mouse.get_pos()[0]
Expand Down

0 comments on commit b2374d3

Please sign in to comment.