Menü rendszer
This commit is contained in:
BIN
screenshots/2026-09-16-13-03.png
Normal file
BIN
screenshots/2026-09-16-13-03.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
@@ -12,6 +12,8 @@ controls = [
|
||||
Control(arcade.key.S, "Le"),
|
||||
Control(arcade.key.A, "Bal"),
|
||||
Control(arcade.key.D, "Jobb"),
|
||||
Control(arcade.key.ENTER, "Választ"),
|
||||
Control(arcade.key.LSHIFT, "Vissza"),
|
||||
]
|
||||
|
||||
def key_press(key):
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
import arcade
|
||||
import assets
|
||||
import controls
|
||||
import menu
|
||||
import text
|
||||
import renderers
|
||||
|
||||
text = text.TextRenderer(6, 186, 210)
|
||||
panel = renderers.NineSlicesPanel(0,100,230,100)
|
||||
|
||||
m = []
|
||||
|
||||
def switch():
|
||||
pass
|
||||
global m
|
||||
m = [
|
||||
menu.MenuItem("1", 100, 90, None, None, None, None, None, None),
|
||||
menu.MenuItem("2", 100, 70 , None, None, None, None, None, None)
|
||||
]
|
||||
|
||||
m[0].down = m[1]
|
||||
m[1].up = m[0]
|
||||
m[0].select()
|
||||
|
||||
def update(dt):
|
||||
controltext = ""
|
||||
@@ -16,6 +27,8 @@ def update(dt):
|
||||
for c in controls.controls:
|
||||
controltext += f"{c.label}: {c.pressed}-{c.held}\n"
|
||||
|
||||
for i in m:
|
||||
i.update()
|
||||
text.reset(controltext)
|
||||
text.type_all()
|
||||
|
||||
@@ -24,6 +37,8 @@ def draw(game):
|
||||
arcade.LBWH(0, 0, game.screen_width, game.screen_height),
|
||||
arcade.color.RED,
|
||||
)
|
||||
for i in m:
|
||||
i.render()
|
||||
|
||||
panel.render()
|
||||
text.render()
|
||||
58
src/menu.py
Normal file
58
src/menu.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import arcade
|
||||
import assets
|
||||
import text
|
||||
import controls
|
||||
|
||||
# Választható menüelem több menüelem közt, ha nincs valamelyik irányba másik menüelem, az irányra None értéket adunk
|
||||
class MenuItem:
|
||||
def __init__(self, label, x, y, left, right, up, down, action, data=None):
|
||||
self.left = left
|
||||
self.right = right
|
||||
self.up = up
|
||||
self.down = down
|
||||
self.action = action
|
||||
self.data = data
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.text = text.TextRenderer(x, y)
|
||||
self.selected = False
|
||||
self.text.reset(label)
|
||||
self.text.type_all()
|
||||
|
||||
def select(self):
|
||||
self.selected = True
|
||||
|
||||
def update(self):
|
||||
if not self.selected:
|
||||
return
|
||||
|
||||
if controls.is_control_pressed(4) and self.action: # Választ
|
||||
self.action(self.data)
|
||||
return
|
||||
|
||||
if controls.is_control_pressed(0) and self.up: # Fel
|
||||
self.selected = False
|
||||
self.up.select()
|
||||
|
||||
if controls.is_control_pressed(1) and self.down: # Le
|
||||
self.selected = False
|
||||
self.down.select()
|
||||
|
||||
if controls.is_control_pressed(2) and self.left: # Bal
|
||||
self.selected = False
|
||||
self.left.select()
|
||||
|
||||
if controls.is_control_pressed(3) and self.right: # Jobb
|
||||
self.selected = False
|
||||
self.right.select()
|
||||
|
||||
|
||||
def render(self):
|
||||
self.text.render()
|
||||
|
||||
if self.selected:
|
||||
arcade.draw_texture_rect(
|
||||
assets.sprites["cursor"],
|
||||
arcade.LBWH(self.x - 16, self.y - 6, 16, 16),
|
||||
pixelated=True
|
||||
)
|
||||
Reference in New Issue
Block a user