✨
This commit is contained in:
150
main.py
150
main.py
@@ -17,47 +17,48 @@ WORD_BORDER_COLOR = "#fffcf2"
|
||||
WORD_SHADOW_COLOR = "#000000"
|
||||
|
||||
# Drawing constants
|
||||
SCREEN_WIDTH = 2560
|
||||
SCREEN_HEIGHT = 1440
|
||||
PAGE_MARGIN = 20
|
||||
SCREEN_WIDTH = 5120
|
||||
SCREEN_HEIGHT = 2880
|
||||
|
||||
PAGE_BORDER_RADIUS = 40
|
||||
PAGE_MARGIN = 30
|
||||
PAGE_BORDER_RADIUS = 80
|
||||
PAGE_BORDER_WIDTH = 20
|
||||
|
||||
WORD_WIDTH = 432
|
||||
WORD_HEIGHT = 90
|
||||
WORD_MARGIN = 20
|
||||
WORD_BORDER_RADIUS = 60
|
||||
WORD_BORDER_WIDTH = 8
|
||||
WORD_FONT_SIZE = 44
|
||||
WORD_SHADOW_SIZE = 8
|
||||
|
||||
WORD_WIDTH = 228
|
||||
WORD_HEIGHT = 55
|
||||
WORD_MARGIN = 16
|
||||
WORD_BORDER_RADIUS = 30
|
||||
WORD_BORDER_WIDTH = 6
|
||||
WORD_FONT_SIZE = 30
|
||||
WORD_SHADOW_SIZE = 5
|
||||
|
||||
GRID_WIDTH = 5
|
||||
GRID_HEIGHT = 18
|
||||
GRID_WIDTH = 6
|
||||
GRID_HEIGHT = 25
|
||||
|
||||
WORD_PAGE_WIDTH = PAGE_BORDER_WIDTH*2+(WORD_WIDTH+WORD_MARGIN)*GRID_WIDTH+WORD_MARGIN
|
||||
WORD_PAGE_HEIGHT = SCREEN_HEIGHT-PAGE_MARGIN*2
|
||||
|
||||
TAB_WIDTH = 80
|
||||
TAB_HEIGHT = 80
|
||||
TAB_WIDTH = 120
|
||||
TAB_HEIGHT = 160
|
||||
TAB_MARGIN = 30
|
||||
TAB_POS = Vector2(WORD_PAGE_WIDTH+PAGE_MARGIN*2,PAGE_MARGIN)
|
||||
|
||||
TEXT_PAGE_POS = Vector2(WORD_PAGE_WIDTH+PAGE_MARGIN*2,TAB_HEIGHT+PAGE_MARGIN*2)
|
||||
TEXT_PAGE_WIDTH = SCREEN_WIDTH-(WORD_PAGE_WIDTH+PAGE_MARGIN*3)
|
||||
TEXT_PAGE_HEIGHT = SCREEN_HEIGHT-(TAB_HEIGHT+PAGE_MARGIN*3)
|
||||
|
||||
TEXT_MARGIN = 20
|
||||
TEXT_TOP_MARGIN = 35
|
||||
TEXT_WIDTH = TEXT_PAGE_WIDTH - TEXT_MARGIN*2
|
||||
TEXT_HEIGHT = TEXT_PAGE_HEIGHT - TEXT_MARGIN*2
|
||||
TEXT_MARGIN = 40
|
||||
TEXT_TOP_MARGIN = 68
|
||||
TEXT_WIDTH = TEXT_PAGE_WIDTH - PAGE_BORDER_WIDTH*2 - TEXT_MARGIN*2
|
||||
TEXT_HEIGHT = TEXT_PAGE_HEIGHT - PAGE_BORDER_WIDTH*2 - TEXT_MARGIN*2
|
||||
|
||||
WORD_SLOT_SPACING = " "*12
|
||||
WORD_SLOT_NUDGING = 22
|
||||
WORD_SLOT_SPACING = " "*16
|
||||
WORD_SLOT_NUDGING = 25
|
||||
WORD_SLOT_NUDGE_DOWN = -5
|
||||
|
||||
INDICATOR_SIZE = 40
|
||||
INDICATOR_BORDER = 10
|
||||
INDICATOR_MARGIN = 30
|
||||
INDICATOR_SIZE = 80
|
||||
INDICATOR_BORDER = 20
|
||||
INDICATOR_MARGIN = 60
|
||||
INDICATOR_POS = Vector2(TEXT_PAGE_WIDTH-(INDICATOR_SIZE+INDICATOR_MARGIN),TEXT_PAGE_HEIGHT-(INDICATOR_SIZE+INDICATOR_MARGIN))
|
||||
|
||||
class WordColor(Enum):
|
||||
@@ -67,17 +68,19 @@ class WordColor(Enum):
|
||||
Blue = 3 # Verbs
|
||||
Grey = 4 # Other
|
||||
Purple = 5 # Places
|
||||
Yellow = 6 # Not used for words
|
||||
Yellow = 6 # Titles
|
||||
Orange = 7 # Classes
|
||||
|
||||
def color(self):
|
||||
return [
|
||||
"#b03334",
|
||||
"#6a5f31",
|
||||
"#4b7a28",
|
||||
"#62a032",
|
||||
"#297cb7",
|
||||
"#767978",
|
||||
"#623a75",
|
||||
"#f0de50",
|
||||
"#bda627",
|
||||
"#b76c2d",
|
||||
][self.value]
|
||||
|
||||
class SolvedState(Enum):
|
||||
@@ -144,11 +147,16 @@ def draw_page(page: Page, screen: pygame.surface.Surface, font: pygame.font.Font
|
||||
if page.text is not None:
|
||||
for i, t in enumerate(page.text):
|
||||
text = font.render(t,False,"#000000")
|
||||
# x,y = text.get_size()
|
||||
screen.blit(text,(
|
||||
pos = Vector2(
|
||||
page.position.x + PAGE_BORDER_WIDTH + TEXT_MARGIN,
|
||||
page.position.y + PAGE_BORDER_WIDTH + TEXT_MARGIN + TEXT_TOP_MARGIN + i*(WORD_FONT_SIZE+TEXT_TOP_MARGIN)
|
||||
))
|
||||
)
|
||||
if i == 0:
|
||||
width,_ = text.get_size()
|
||||
text = pygame.transform.scale2x(text)
|
||||
pos.y = page.position.y + PAGE_BORDER_WIDTH + TEXT_MARGIN
|
||||
pos.x = page.position.x + PAGE_BORDER_WIDTH + TEXT_MARGIN + (TEXT_WIDTH-width*2)//2
|
||||
screen.blit(text,pos)
|
||||
|
||||
if page.slots != []:
|
||||
pygame.draw.circle(
|
||||
@@ -243,7 +251,7 @@ def draw_word(word: Word, screen: pygame.surface.Surface, font: pygame.font.Font
|
||||
))
|
||||
|
||||
def draw_tab(n: int, screen: pygame.surface.Surface, font: pygame.font.Font, selected: bool):
|
||||
pos = TAB_POS + Vector2((TAB_WIDTH+PAGE_MARGIN)*n,0)
|
||||
pos = TAB_POS + Vector2((TAB_WIDTH+TAB_MARGIN)*n,0)
|
||||
|
||||
pygame.draw.rect(
|
||||
screen,
|
||||
@@ -280,6 +288,7 @@ def main(data: dict):
|
||||
pygame.init()
|
||||
pygame.font.init()
|
||||
font = pygame.font.SysFont("Comic Code",WORD_FONT_SIZE,True)
|
||||
print(font.size(WORD_SLOT_SPACING))
|
||||
screen = pygame.display.set_mode((1280, 720),pygame.RESIZABLE)
|
||||
drawer = pygame.surface.Surface((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
clock = pygame.time.Clock()
|
||||
@@ -289,7 +298,7 @@ def main(data: dict):
|
||||
pages = [word_page] + [
|
||||
Page(
|
||||
False,
|
||||
[p],
|
||||
p,
|
||||
TEXT_PAGE_POS,
|
||||
Vector2(TEXT_PAGE_WIDTH,TEXT_PAGE_HEIGHT),
|
||||
[]
|
||||
@@ -320,37 +329,42 @@ def main(data: dict):
|
||||
if width > TEXT_WIDTH:
|
||||
return text+[word]
|
||||
else:
|
||||
if text[-1] == "":
|
||||
space = ""
|
||||
text[-1] += space+word
|
||||
return text
|
||||
|
||||
for p in pages[1:]:
|
||||
new_text = [""]
|
||||
text_words = p.text[0].split(" ")
|
||||
for w in text_words:
|
||||
res = re.findall(r"\[(.*?)\/(\d)\]([^\[])?",w)
|
||||
if res == []:
|
||||
new_text = add_to_text(new_text,w)
|
||||
else:
|
||||
if new_text[0] != "":
|
||||
new_text = add_to_text(new_text,"")
|
||||
new_text = []
|
||||
for t in p.text:
|
||||
new_text.append("")
|
||||
text_words = t.split(" ")
|
||||
for w in text_words:
|
||||
res = re.findall(r"\[(.*?)\/(\d)\]([^\[ ]*)",w)
|
||||
if res == []:
|
||||
new_text = add_to_text(new_text,w)
|
||||
else:
|
||||
if new_text[0] != "":
|
||||
new_text = add_to_text(new_text,"")
|
||||
|
||||
for slot in res:
|
||||
new_text = add_to_text(new_text,WORD_SLOT_SPACING,"")
|
||||
height = WORD_FONT_SIZE*len(new_text)
|
||||
width, _ = font.size(new_text[-1])
|
||||
new_text = add_to_text(new_text,slot[2],"")
|
||||
pos = Vector2(
|
||||
TEXT_MARGIN + width - WORD_WIDTH,
|
||||
TEXT_MARGIN + height - WORD_HEIGHT//2 + TEXT_TOP_MARGIN*len(new_text)
|
||||
)
|
||||
# if new_text[-1] != WORD_SLOT_SPACING+slot[2]:
|
||||
pos.x += WORD_SLOT_NUDGING
|
||||
new_slot = WordSlot(WordColor(int(slot[1])),p,pos)
|
||||
word_slots.append(new_slot)
|
||||
p.slots.append((slot[0],new_slot))
|
||||
for slot in res:
|
||||
new_text = add_to_text(new_text,WORD_SLOT_SPACING+slot[2],"")
|
||||
height = WORD_FONT_SIZE*len(new_text)
|
||||
width, _ = font.size(new_text[-1])
|
||||
extra_width, _ = font.size(slot[2])
|
||||
pos = Vector2(
|
||||
TEXT_MARGIN + width - extra_width - WORD_WIDTH,
|
||||
TEXT_MARGIN + height - WORD_HEIGHT//2 + TEXT_TOP_MARGIN*len(new_text) + WORD_SLOT_NUDGE_DOWN
|
||||
)
|
||||
# if new_text[-1] != WORD_SLOT_SPACING+slot[2]:
|
||||
pos.x += WORD_SLOT_NUDGING
|
||||
new_slot = WordSlot(WordColor(int(slot[1])),p,pos)
|
||||
word_slots.append(new_slot)
|
||||
p.slots.append((slot[0].replace("%"," "),new_slot))
|
||||
|
||||
p.text = new_text
|
||||
|
||||
|
||||
words: list[Word] = []
|
||||
for i,w in enumerate(data["words"]):
|
||||
slot = word_slots[i]
|
||||
@@ -359,6 +373,12 @@ def main(data: dict):
|
||||
word.slot = slot
|
||||
words.append(word)
|
||||
|
||||
all_words = [w.word for w in words]
|
||||
for p in pages:
|
||||
not_present = [s[0] for s in p.slots if s[0] not in all_words]
|
||||
if not_present:
|
||||
print(not_present)
|
||||
|
||||
def focused():
|
||||
x, y = pygame.mouse.get_pos()
|
||||
ratio_x = (screen.get_width() / drawer.get_width())
|
||||
@@ -381,12 +401,12 @@ def main(data: dict):
|
||||
return w
|
||||
|
||||
for i in range(len(pages)-1):
|
||||
pos = TAB_POS + Vector2((TAB_WIDTH+PAGE_MARGIN)*i,0)
|
||||
pos = TAB_POS + Vector2((TAB_WIDTH+TAB_MARGIN)*i,0)
|
||||
rect = pygame.Rect(
|
||||
pos.x - PAGE_MARGIN//2,
|
||||
pos.y - PAGE_MARGIN//2,
|
||||
TAB_WIDTH + PAGE_MARGIN,
|
||||
TAB_HEIGHT + PAGE_MARGIN
|
||||
pos.x - TAB_MARGIN//2,
|
||||
pos.y - TAB_MARGIN//2,
|
||||
TAB_WIDTH + TAB_MARGIN,
|
||||
TAB_HEIGHT + TAB_MARGIN
|
||||
)
|
||||
if rect.collidepoint(scaled_xy):
|
||||
return i+1
|
||||
@@ -505,10 +525,10 @@ def main(data: dict):
|
||||
frame = pygame.transform.scale(drawer,screen.get_size())
|
||||
screen.blit(frame,frame.get_rect())
|
||||
|
||||
if focused() is not None:
|
||||
pygame.mouse.set_cursor(*pygame.cursors.tri_left)
|
||||
else:
|
||||
pygame.mouse.set_cursor(*pygame.cursors.arrow)
|
||||
# if focused() is not None:
|
||||
# pygame.mouse.set_cursor(*pygame.cursors.tri_left)
|
||||
# else:
|
||||
# pygame.mouse.set_cursor(*pygame.cursors.arrow)
|
||||
|
||||
# flip() the display to put your work on screen
|
||||
pygame.display.flip()
|
||||
|
||||
Reference in New Issue
Block a user