epic-utils 0.2.2__tar.gz → 0.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: epic-utils
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Dependencies i regurlarly use
5
5
  Author: Epic099
6
6
  Author-email:
@@ -18,7 +18,13 @@ class Vector2():
18
18
  @property
19
19
  def this(self):
20
20
  return [self.x, self.y]
21
-
21
+ def set(self, x : float, y : float):
22
+ self.x = x
23
+ self.y = y
24
+ def setX(self, x : float):
25
+ self.x = x
26
+ def setY(self, y : float):
27
+ self.y = y
22
28
  @property
23
29
  def sqrMagnitude(self):
24
30
  return self.x**2 + self.y**2
@@ -163,6 +169,14 @@ class Vector2Int():
163
169
  def this(self):
164
170
  return [self.x, self.y]
165
171
 
172
+ def set(self, x : int, y : int):
173
+ self.x = int(x)
174
+ self.y = int(y)
175
+ def setX(self, x : int):
176
+ self.x = int(x)
177
+ def setY(self, y : int):
178
+ self.y = int(y)
179
+
166
180
  @property
167
181
  def sqrMagnitude(self):
168
182
  return self.x**2 + self.y**2
@@ -297,7 +311,7 @@ class Vector2Int():
297
311
  return Vector2Int(self.x**value, self.y**value)
298
312
 
299
313
  def __str__(self):
300
- return f"Vector2({self.x}, {self.y})"
314
+ return f"Vector2Int({self.x}, {self.y})"
301
315
 
302
316
  class Vector3():
303
317
  def __init__(self, x : float, y : float, z : float):
@@ -307,7 +321,16 @@ class Vector3():
307
321
  @property
308
322
  def this(self):
309
323
  return [self.x, self.y, self.z]
310
-
324
+ def set(self, x : float, y : float, z : float):
325
+ self.x = x
326
+ self.y = y
327
+ self.z = z
328
+ def setX(self, x : float):
329
+ self.x = x
330
+ def setY(self, y : float):
331
+ self.y = y
332
+ def setZ(self, z : float):
333
+ self.z = z
311
334
  @property
312
335
  def sqrMagnitude(self):
313
336
  return self.x**2 + self.y**2 + self.z**2
@@ -537,7 +560,16 @@ class Vector3Int():
537
560
  @property
538
561
  def this(self):
539
562
  return [self.x, self.y, self.z]
540
-
563
+ def set(self, x : int, y : int, z : int):
564
+ self.x = int(x)
565
+ self.y = int(y)
566
+ self.z = int(z)
567
+ def setX(self, x : int):
568
+ self.x = int(x)
569
+ def setY(self, y : int):
570
+ self.y = int(y)
571
+ def setZ(self, z : int):
572
+ self.z = int(z)
541
573
  @property
542
574
  def sqrMagnitude(self):
543
575
  return self.x**2 + self.y**2 + self.z**2
@@ -0,0 +1,198 @@
1
+ from .core import Vector2, Color
2
+ import os
3
+ os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
4
+ import pygame as pg
5
+
6
+ class UIObject:
7
+ def __init__(self, parent, position : Vector2, size : Vector2, backgroundColor : Color = Color.White, anchorPoint : Vector2 = Vector2.zero):
8
+ if position.x > 1:
9
+ position.x = position.x / parent.size.x
10
+ if position.y > 1:
11
+ position.y = position.y / parent.size.y
12
+ if size.x > 1:
13
+ size.x = size.x / parent.size.x
14
+ if size.y > 1:
15
+ size.y = size.y / parent.size.y
16
+ self.position = position
17
+ self.size = size
18
+
19
+ self.absoluteSize : Vector2 = Vector2(size.x * parent.size.x, size.y * parent.size.y)
20
+ self.absolutePosition : Vector2 = Vector2(position.x * parent.size.x + anchorPoint.x*self.absoluteSize.x, position.y * parent.size.y + anchorPoint.y*self.absoluteSize.y)
21
+ self.anchorPoint : Vector2 = anchorPoint
22
+ self.backgroundColor : Color = backgroundColor
23
+ self.children = []
24
+ self.parent = parent
25
+ self.parent.addChild(self)
26
+ def get_Rect(self):
27
+ self.absolutePosition : Vector2 = Vector2(self.position.x * self.parent.size.x + self.anchorPoint.x*self.absoluteSize.x, self.position.y * self.parent.size.y + self.anchorPoint.y*self.absoluteSize.y)
28
+ self.absoluteSize : Vector2 = Vector2(self.size.x * self.parent.size.x, self.size.y * self.parent.size.y)
29
+ return pg.Rect(self.absolutePosition.x, self.absolutePosition.y, self.absoluteSize.x, self.absoluteSize.y)
30
+
31
+ def draw(self, screen : pg.Surface):
32
+ screen.fill(self.backgroundColor.toTuple(), self.get_Rect())
33
+ def addChild(self, child):
34
+ self.children.append(child)
35
+ def removeChild(self, child):
36
+ self.children.remove(child)
37
+
38
+ def delete(self):
39
+ self.parent.removeChild(self)
40
+ del self
41
+
42
+
43
+ class TextLabel(UIObject):
44
+ def __init__(self, parent, position : Vector2, size : Vector2, text : str, font : pg.font.Font, textColor : Color, backgroundColor : Color = Color.White, anchorPoint : Vector2 = Vector2(0, 0), textCenter : Vector2 = Vector2(0.5, 0.5)):
45
+ super().__init__(parent, position, size, backgroundColor=backgroundColor, anchorPoint=anchorPoint)
46
+ self.text : str = text
47
+ self.font = font
48
+ self.textColor : Color = textColor
49
+ self.text_center = textCenter
50
+ self.renderedText = self.font.render(self.text, True, self.textColor.toTuple())
51
+ def changeText(self, text : str):
52
+ self.text = text
53
+ self.renderedText = self.font.render(self.text, True, self.textColor.toTuple())
54
+ def draw(self, screen : pg.Surface):
55
+ super().draw(screen)
56
+ screen.blit(self.renderedText, (self.absolutePosition.x + (self.absoluteSize.x - self.renderedText.get_width()) * self.text_center.x, self.absolutePosition.y + (self.absoluteSize.y - self.renderedText.get_height()) * self.text_center.y))
57
+
58
+ class Dropdown(UIObject):
59
+ Dropdowns = []
60
+ def __init__(self, parent, position : Vector2, size : Vector2, options : list, font : pg.font.Font, textColor : Color, backgroundColor : Color = Color.White, dropdownColor : Color = Color(50, 50, 50), anchorPoint : Vector2 = Vector2(0, 0), textCenter : Vector2 = Vector2(0.5, 0.5)):
61
+ super().__init__(parent, position, size, backgroundColor=backgroundColor, anchorPoint=anchorPoint)
62
+ self.options = options
63
+ self.font = font
64
+ self.dropdownColor = dropdownColor
65
+ self.textColor = textColor
66
+ self.text_center = textCenter
67
+ self.renderedOptions = []
68
+ self.opened = False
69
+ for option in self.options:
70
+ self.renderedOptions.append(self.font.render(option, True, self.textColor.toTuple()))
71
+ self.selectedOption = 0
72
+ Dropdown.Dropdowns.append(self)
73
+ def draw(self, screen : pg.Surface):
74
+ super().draw(screen)
75
+ #show selected option
76
+ #render selected option but center it according to the textcentered property so a value of 0.5 and 0.5 centers the text vertically and horizontally
77
+
78
+ screen.blit(self.renderedOptions[self.selectedOption], (self.absolutePosition.x + (self.absoluteSize.x - self.renderedOptions[self.selectedOption].get_width()) * self.text_center.x, self.absolutePosition.y + (self.absoluteSize.y - self.renderedOptions[self.selectedOption].get_height()) * self.text_center.y))
79
+ #if opened then draw each option
80
+ if self.opened:
81
+ for i in range(len(self.options)):
82
+ screen.fill(self.dropdownColor.toTuple(), pg.Rect(self.absolutePosition.x, self.absolutePosition.y + (i+1) * self.absoluteSize.y, self.absoluteSize.x, self.absoluteSize.y))
83
+ screen.blit(self.renderedOptions[i], (self.absolutePosition.x + (self.absoluteSize.x - self.renderedOptions[i].get_width()) * self.text_center.x, self.absolutePosition.y + (i+1) * self.absoluteSize.y + (self.absoluteSize.y - self.renderedOptions[i].get_height()) * self.text_center.y))
84
+ def setOptions(self, options : list):
85
+ self.options = options
86
+ self.renderedOptions = []
87
+ for option in self.options:
88
+ self.renderedOptions.append(self.font.render(option, True, self.textColor.toTuple()))
89
+ def handleMouseEvent(self, pos=None):
90
+ if pos == None:
91
+ pos = pg.mouse.get_pos()
92
+ has_opened = False
93
+ if self.get_Rect().collidepoint(pos):
94
+ self.opened = not self.opened
95
+ has_opened = True
96
+ if self.opened:
97
+ for i in range(len(self.options)):#
98
+ if pg.Rect(self.absolutePosition.x, self.absolutePosition.y + (i+1) * self.absoluteSize.y, self.absoluteSize.x, self.absoluteSize.y).collidepoint(pg.mouse.get_pos()):
99
+ self.changeSelectedOption(i)
100
+ self.opened = False
101
+ if self.opened and not has_opened:
102
+ self.opened = False
103
+ def getSelected(self):
104
+ return self.options[self.selectedOption]
105
+ def getSelectedIndex(self):
106
+ return self.selectedOption
107
+ def changeSelectedOption(self, option : int):
108
+ self.selectedOption = option
109
+ def delete(self):
110
+ Dropdown.Dropdowns.remove(self)
111
+ super().delete()
112
+
113
+ class TextButton(UIObject):
114
+ TextButtons = []
115
+ def __init__(self, parent, position : Vector2, size : Vector2, text : str, font : pg.font.Font, textColor : Color, backgroundColor : Color = Color.White, anchorPoint : Vector2 = Vector2(0, 0), textCenter : Vector2 = Vector2(0.5, 0.5), activaton_function = None, activation_args = []):
116
+ super().__init__(parent, position, size, backgroundColor=backgroundColor, anchorPoint=anchorPoint)
117
+ self.text : str = text
118
+ self.font = font
119
+ self.textColor : Color = textColor
120
+ self.text_center = textCenter
121
+ self.renderedText = self.font.render(self.text, True, self.textColor.toTuple())
122
+ self.activation_function = activaton_function
123
+ self.activation_args = activation_args
124
+ TextButton.TextButtons.append(self)
125
+
126
+ def changeText(self, text : str):
127
+ self.text = text
128
+ self.renderedText = self.font.render(self.text, True, self.textColor.toTuple())
129
+ def draw(self, screen : pg.Surface):
130
+ super().draw(screen)
131
+ screen.blit(self.renderedText, (self.absolutePosition.x + (self.absoluteSize.x - self.renderedText.get_width()) * self.text_center.x, self.absolutePosition.y + (self.absoluteSize.y - self.renderedText.get_height()) * self.text_center.y))
132
+ def handleMouseEvent(self, pos=None):
133
+ if pos == None:
134
+ pos = pg.mouse.get_pos()
135
+ if self.get_Rect().collidepoint(pos):
136
+ print("pressed")
137
+ if self.activation_function != None:
138
+ self.activation_function(*self.activation_args)
139
+ def delete(self):
140
+ TextButton.TextButtons.remove(self)
141
+ super().delete()
142
+ class Application:
143
+
144
+ def __init__(self, size : Vector2, title : str, updateFunction = None):
145
+ self.size : Vector2 = size
146
+ self.title : str = title
147
+ self.paused = False
148
+ self.running = True
149
+ self.clock = pg.time.Clock()
150
+ self.fps = 60
151
+ self.display = pg.display.set_mode(self.size.toTuple())
152
+ self.updateFunction = updateFunction
153
+ self.children = []
154
+ pg.display.set_caption(self.title)
155
+
156
+
157
+ #Init Pygame
158
+ pg.init()
159
+
160
+ def setFPS(self, fps : int):
161
+ self.fps = fps
162
+ def addChild(self, child : UIObject):
163
+ self.children.append(child)
164
+ def clearScreen(self):
165
+ self.display.fill(Color.Black.toTuple())
166
+ def drawChildren(self, obj : UIObject):
167
+ for child in obj.children:
168
+ child.draw(self.display)
169
+ if (len(child.children) > 0):
170
+ self.drawChildren(child)
171
+ def setPaused(self, paused : bool):
172
+ self.paused = paused
173
+ def stop(self):
174
+ self.running = False
175
+ def draw(self):
176
+ self.clearScreen()
177
+ self.drawChildren(self)
178
+ def run(self):
179
+ while self.running:
180
+ if self.paused:
181
+ self.clock.tick(self.fps)
182
+ continue
183
+ for event in pg.event.get():
184
+ if event.type == pg.MOUSEBUTTONDOWN:
185
+ pos = pg.mouse.get_pos()
186
+ for dropdown in Dropdown.Dropdowns:
187
+ dropdown.handleMouseEvent(pos=pos)
188
+ for button in TextButton.TextButtons:
189
+ button.handleMouseEvent(pos=pos)
190
+ elif event.type == pg.QUIT:
191
+ print("Terminated")
192
+ self.running = False
193
+ self.draw()
194
+ pg.display.update()
195
+ if self.updateFunction != None:
196
+ self.updateFunction(pg.event.get())
197
+ self.clock.tick(self.fps)
198
+ pg.quit()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: epic-utils
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Dependencies i regurlarly use
5
5
  Author: Epic099
6
6
  Author-email:
@@ -1,7 +1,7 @@
1
1
  from setuptools import setup, find_packages
2
2
  setup(
3
3
  name='epic-utils',
4
- version='0.2.2',
4
+ version='0.2.4',
5
5
  author='Epic099',
6
6
  author_email='',
7
7
  description='Dependencies i regurlarly use',
@@ -1,87 +0,0 @@
1
- from .core import Vector2, Color
2
- import os
3
- os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
4
- import pygame as pg
5
-
6
- class UIObject:
7
- def __init__(self, parent, position : Vector2, size : Vector2, backgroundColor : Color = Color.White, anchorPoint : Vector2 = Vector2.zero):
8
- self.position = position
9
- self.size = size
10
- self.anchorPoint : Vector2 = anchorPoint
11
- self.backgroundColor : Color = backgroundColor
12
- self.children = []
13
- self.parent = parent
14
- self.parent.addChild(self)
15
- def get_Rect(self):
16
- return pg.Rect(self.position.x, self.position.y, self.size.x, self.size.y)
17
- def draw(self, screen : pg.Surface):
18
- screen.fill(self.backgroundColor.toTuple(), self.get_Rect())
19
- def addChild(self, child):
20
- self.children.append(child)
21
- def removeChild(self, child):
22
- self.children.remove(child)
23
-
24
- def delete(self):
25
- self.parent.removeChild(self)
26
- del self
27
-
28
-
29
- class TextLabel(UIObject):
30
- def __init__(self, parent, position : Vector2, size : Vector2, text : str, font : pg.font.Font, textColor : Color, backgroundColor : Color = Color.White, anchorPoint : Vector2 = Vector2(0, 0)):
31
- super().__init__(parent, position, size, backgroundColor=backgroundColor, anchorPoint=anchorPoint)
32
- self.text : str = text
33
- self.font = font
34
- self.textColor : Color = textColor
35
- self.renderedText = self.font.render(self.text, True, self.textColor.toTuple())
36
- def changeText(self, text : str):
37
- self.text = text
38
- self.renderedText = self.font.render(self.text, True, self.textColor.toTuple())
39
- def draw(self, screen : pg.Surface):
40
- super().draw(screen)
41
- screen.blit(self.renderedText, (self.position.x, self.position.y))
42
-
43
- class Application:
44
- def __init__(self, size : Vector2, title : str, updateFunction = None):
45
- self.size : Vector2 = size
46
- self.title : str = title
47
- self.running = True
48
- self.clock = pg.time.Clock()
49
- self.fps = 60
50
- self.display = pg.display.set_mode(self.size.toTuple())
51
- self.updateFunction = updateFunction
52
- self.children = []
53
- pg.display.set_caption(self.title)
54
-
55
-
56
- #Init Pygame
57
- pg.font.init()
58
-
59
- def setFPS(self, fps : int):
60
- self.fps = fps
61
- def addChild(self, child : UIObject):
62
- self.children.append(child)
63
- def drawChildren(self, obj : UIObject):
64
- for child in obj.children:
65
- child.draw(self.display)
66
- if (len(child.children) > 0):
67
- self.drawChildren(child)
68
- def draw(self):
69
- self.drawChildren(self)
70
- def run(self):
71
- while self.running:
72
- for event in pg.event.get():
73
- if event.type == pg.QUIT:
74
- self.running = False
75
- self.draw()
76
- pg.display.update()
77
- if self.updateFunction != None:
78
- self.updateFunction(pg.event.get())
79
- self.clock.tick(self.fps)
80
-
81
-
82
- if __name__ == "__main__":
83
- app = Application(Vector2(800, 600), "Test")
84
-
85
- l = TextLabel(app, Vector2(0, 0), Vector2(100, 100), "Hello World", pg.font.SysFont("Calibri", 36), Color(0, 0, 0))
86
-
87
- app.run()
File without changes