Skip to content

Commit

Permalink
selection list and bodies menu new appearance
Browse files Browse the repository at this point in the history
the choose object window is still not finished but the appearance for it is kinda finished
  • Loading branch information
Karam-Sabbagh committed Jan 21, 2022
1 parent b5215e0 commit 91934c4
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 39 deletions.
Binary file added Engine/Gui/Images/Choose_rect_body_button_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Engine/Gui/Images/replaced/Add_body_image(big).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.
Binary file added Engine/Gui/Images/replaced/Untitled.xcf
Binary file not shown.
36 changes: 20 additions & 16 deletions Engine/Gui/Pygame_gui_setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from pygame_gui.core import ObjectID

class Gui:
def __init__(self, pygame, pygame_ui_screen, pygame_gui):
self.pygame_gui = pygame_gui

self.pygame = pygame

self.pygame_ui_screen = pygame_ui_screen
Expand Down Expand Up @@ -45,10 +48,16 @@ def make_selection_list(self):
pygame_selection_list_rect = self.pygame.Rect(0, 0, self.selection_list_width, (self.selection_list_length))
pygame_selection_list_rect.topright = (self.selection_list_pos_x, 0)

selection_list_items = []
for i in range(20):
selection_list_items.append(("", f"#Add_body_button_{i}"))

print(selection_list_items)

self.selection_list = self.pygame_gui.elements.UISelectionList(
pygame_selection_list_rect,
starting_height=100,
item_list=[("+", "#Add_body_button")] * 20,
item_list=[],
manager=self.ui_manager,
allow_multi_select=False,
anchors={"left": "left",
Expand All @@ -57,7 +66,8 @@ def make_selection_list(self):
"bottom": "bottom"}
)


self.selection_list.set_item_list(selection_list_items)

def make_choose_object_window(self):
"""
makes a window to let the user select the object
Expand All @@ -70,18 +80,18 @@ def make_choose_object_window(self):
object_id="#choose_object_window")
self.ui_window_exist = True

self.pygame_gui.elements.UIButton(relative_rect=self.pygame.Rect(0, 0, 90, 70),
text="coming...",
self.pygame_gui.elements.UIButton(relative_rect=self.pygame.Rect(0, 0, 80+4, 80+4),
text="Rect",
manager=self.ui_manager,
container=self.ui_window,
object_id="#choose_rect_button"
object_id="#Choose_rect_body_button"
)

def check_events(self, event):
"""
:param event: it's from pygame.event.get()
:param event: it"s from pygame.event.get()
this function is for checking pygame_gui things
and it's used for like checking button press or ui window close
and it"s used for like checking button press or ui window close
"""
if event.type == self.pygame_gui.UI_WINDOW_CLOSE:
if event.ui_object_id == "#choose_object_window":
Expand All @@ -91,12 +101,12 @@ def check_events(self, event):

def check_each_selection_list_item(self):
"""
it just checks the click of each button and item in the selection list that's made with self.make_selection_list
it just checks the click of each button and item in the selection list that"s made with self.make_selection_list
"""
i = 1
for each_item in self.selection_list.item_list:
button_element = each_item["button_element"]
# sometimes the button is slided up and not really shown so pygame_gui remove this button when it's not seen able and makes it None
# sometimes the button is slided up and not really shown so pygame_gui remove this button when it"s not seen able and makes it None
if button_element != None:
"""
button element have
Expand All @@ -109,18 +119,12 @@ def check_each_selection_list_item(self):
if button_element.pressed and button_element.is_selected:
print("button", i, "pressed")
self.make_choose_object_window()

button_rect = button_element.relative_rect
# the pressed button x position
button_pos_x = button_rect.x
# the pressed button y position
button_pos_y = button_rect.y
i += 1

def draw(self, time_delta):
"""
draws everything about pygame_gui and also does somethings for them
:param time_delta: it is like time_delta = clock.tick(FPS) so it's just FPS of the screen at the second
:param time_delta: it is like time_delta = clock.tick(FPS) so it"s just FPS of the screen at the second
"""
self.check_each_selection_list_item()

Expand Down
73 changes: 62 additions & 11 deletions Engine/Gui/Theme.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,91 @@
{
"#Add_body_button":
"#Choose_rect_body_button":
{
"images": {
"normal_image": {
"path": "Engine/Gui/Images/Add_body_image.png"
"path": "Engine/Gui/Images/Choose_rect_body_button_image.png"
}
}
},
"button": {
"colours": {
"normal_bg": "#dcdcdc",
"hovered_bg": "#aaaaaa",
"active_bg": "#336dff",
"normal_text": "#141414",
"hovered_text": "#141414",
"selected_text": "#141414",
"normal_border": "#afafaf"
},
"misc": {
"border_width": "4"
}
},

"window":
{
"colours":
{
"dark_bg":"#969696",
"dark_bg":"#dcdcdc",
"normal_border": "#000000"
},

"misc":
{
"shape": "rounded_rectangle",
"shape_corner_radius": "10",
"border_width": "1",
"shape_corner_radius": "5",
"border_width": "0",
"shadow_width": "15",
"title_bar_height": "30"
"title_bar_height": "28"
}
},
"window.#title_bar":
{
"colours":
{
"normal_bg": "#464646",
"hovered_bg": "#505050",
"active_bg": "#1e06bd",
"normal_text": "#e6e6e6",
"hovered_text": "#e6e6e6"
}
},
"window.#close_button":
{
"colours":
{
"normal_bg": "#6e6e6e",
"hovered_bg": "#f51616",
"active_bg": "#f55050",
"normal_text": "#e6e6e6",
"hovered_text": "#e6e6e6"
}
},

"selection_list":
{
"misc": {
"list_item_height": "70",
"list_item_width": "70"
},
"list_item_height": "70",
"list_item_width": "70"
},
"colours":
{
"dark_bg":"#969696",
"dark_bg":"#dcdcdc",
"normal_border": "#000000"
}
}
},
"@selection_list_item":
{
"images": {
"normal_image": {
"path": "Engine/Gui/Images/Add_body_image.png"
}
},
"colours":
{
"normal_bg": "#dcdcdc",
"selected_bg": "#0a4bf0",
"active_bg": "#4242ff"
}
}
}
Binary file not shown.
10 changes: 5 additions & 5 deletions Engine/Physics_Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def generate_polygon_vertices(self, number_of_vertices, scale_x, scale_y):
vertices = []
rotation = math.pi / 4
for i in range(number_of_vertices):
r = 2 * math.pi / number_of_vertices * i + rotation # the '2' here means two of pie
r = 2 * math.pi / number_of_vertices * i + rotation # the "2" here means two of pie
vertex = (math.cos(r) * scale_x, math.sin(r) * scale_y) # Rotation + Scaling + Translation
vertices.append(vertex)

Expand Down Expand Up @@ -252,7 +252,7 @@ def circle_shape_draw(self, circle, body, fixture, out_line_thickness=4):

def round_number(self, x):
"""
this function is for rounding a float number and it's useful when rounding two numbers that are related to each other to make them kind of equal
this function is for rounding a float number and it"s useful when rounding two numbers that are related to each other to make them kind of equal
:param x: the number that u want to round
"""
return float(int(round(x)))
Expand All @@ -272,7 +272,7 @@ def body_check_hit(self, body, point_pos):
"""
this function checks if a point position is inside a body and if so it will return True
:param body: just the body that you wanna test on
:param point_pos: the position of the point that you wanna check that's inside the body or not
:param point_pos: the position of the point that you wanna check that"s inside the body or not
"""
point_pos = tuple((point_pos[0]/self.PPM, point_pos[1]/self.PPM))

Expand All @@ -287,8 +287,8 @@ def body_check_hit(self, body, point_pos):

def set_body_position(self, body, new_pos):
"""
this function updates any body's position
:param body: the body that you want to change it's position
this function updates any body"s position
:param body: the body that you want to change it"s position
:param new_pos: the updated position that you wish pass it just in pixels
"""
new_pos = tuple((new_pos[0] / self.PPM, new_pos[1] / self.PPM))
Expand Down
Binary file added Engine/__pycache__/Physics_Engine.cpython-39.pyc
Binary file not shown.
Binary file added Engine/__pycache__/Physics_Engine.pypy38.pyc
Binary file not shown.
Binary file not shown.
17 changes: 10 additions & 7 deletions PhiziBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
SCREEN_HEIGHT = 800

pygame_ui_screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption('PhiziBox')
pygame_ui_screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("PhiziBox")

background_colour = (15, 15, 15)
background_colour = (35, 35, 35)
pygame_ui_screen.fill(background_colour)

clock = pygame.time.Clock()
Expand All @@ -25,7 +26,7 @@
start_tick = pygame.time.get_ticks()
seconds = 0

if __name__ == '__main__':
if __name__ == "__main__":
# -- FOR SPAWNING BODIES IN THE GUI --
# for default pressing properties:
check_keys = [pygame.K_p, pygame.K_c, pygame.K_k, pygame.K_r, pygame.K_n]
Expand Down Expand Up @@ -151,15 +152,15 @@ def spawn_bodies_with_keys():

# text:
pygame.font.init()
font = pygame.font.SysFont('arial', 25)
font = pygame.font.SysFont("arial", 25)
text_color = (180, 180, 180)

FPS = 60

running_game = True

while running_game:
time_delta = clock.tick(0)
time_delta = clock.tick(FPS)
seconds = (pygame.time.get_ticks() - start_tick) / 1000

for event in pygame.event.get():
Expand Down Expand Up @@ -190,14 +191,16 @@ def spawn_bodies_with_keys():

# show FPS text

text_seconds = font.render(('FPS: ' + (str(int(fps)))), True, (text_color))
text_seconds = font.render(("FPS: " + (str(int(fps)))), True, (text_color))
pygame_ui_screen.blit(text_seconds, (20, 15))

# show bodies amount
text_seconds = font.render(('Bodies Amount: ' + (str(int(Phy_Eng.bodies_amount)))), True, (text_color))
text_seconds = font.render(("Bodies Amount: " + (str(int(Phy_Eng.bodies_amount)))), True, (text_color))
pygame_ui_screen.blit(text_seconds, (20, 50))

pygame_gui_setup.draw(time_delta)

pygame.display.flip()
pygame.display.update()

pygame.quit()

0 comments on commit 91934c4

Please sign in to comment.