mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
add more english
This commit is contained in:
@@ -120,7 +120,10 @@ class BaseBox():
|
||||
self.wait = 0
|
||||
|
||||
def load_text(self):
|
||||
self.name = OutlinedText(self.text_name, tex.skin_config["song_box_name"].font_size, ray.WHITE, outline_thickness=5, vertical=True)
|
||||
font_size = tex.skin_config["song_box_name"].font_size
|
||||
if len(self.text_name) >= 30:
|
||||
font_size -= int(10 * tex.screen_scale)
|
||||
self.name = OutlinedText(self.text_name, font_size, ray.WHITE, outline_thickness=5, vertical=True)
|
||||
if self.back_color is not None:
|
||||
self.shader = ray.load_shader('shader/dummy.vs', 'shader/colortransform.fs')
|
||||
source_rgb = (142, 212, 30)
|
||||
|
||||
@@ -3,6 +3,7 @@ from typing import Callable
|
||||
import pyray as ray
|
||||
|
||||
from libs.global_data import PlayerNum
|
||||
from libs.global_data import global_data
|
||||
from libs.utils import OutlinedText, global_tex
|
||||
from libs.config import get_config
|
||||
from libs.audio import audio
|
||||
@@ -98,6 +99,7 @@ class Indicator:
|
||||
self.don_fade = global_tex.get_animation(6)
|
||||
self.blue_arrow_move = global_tex.get_animation(7)
|
||||
self.blue_arrow_fade = global_tex.get_animation(8)
|
||||
self.select_text = OutlinedText(global_tex.skin_config["indicator_text"].text[global_data.config["general"]["language"]], global_tex.skin_config["indicator_text"].font_size, ray.WHITE, spacing=-3)
|
||||
|
||||
def update(self, current_time_ms: float):
|
||||
"""Update the indicator's animations."""
|
||||
@@ -109,7 +111,8 @@ class Indicator:
|
||||
"""Draw the indicator at the given position with the given fade."""
|
||||
tex = global_tex
|
||||
tex.draw_texture('indicator', 'background', x=x, y=y, fade=fade)
|
||||
tex.draw_texture('indicator', 'text', frame=self.state.value, x=x, y=y, fade=fade)
|
||||
tex.draw_texture('indicator', 'text', frame=self.state.value, x=x, y=y, fade=fade, color=ray.BLACK)
|
||||
self.select_text.draw(ray.BLANK, x=x+global_tex.skin_config["indicator_text"].x, y=y, fade=fade)
|
||||
tex.draw_texture('indicator', 'drum_face', index=self.state.value, x=x, y=y, fade=fade)
|
||||
if self.state == Indicator.State.SELECT:
|
||||
tex.draw_texture('indicator', 'drum_kat', fade=min(fade, self.don_fade.attribute), x=x, y=y)
|
||||
@@ -127,15 +130,14 @@ class CoinOverlay:
|
||||
"""Coin overlay for the game."""
|
||||
def __init__(self):
|
||||
"""Initialize the coin overlay."""
|
||||
pass
|
||||
self.free_play = OutlinedText(global_tex.skin_config["free_play"].text[global_data.config["general"]["language"]], global_tex.skin_config["free_play"].font_size, ray.WHITE, spacing=5, outline_thickness=4)
|
||||
def update(self, current_time_ms: float):
|
||||
"""Update the coin overlay. Unimplemented"""
|
||||
pass
|
||||
def draw(self, x: int = 0, y: int = 0):
|
||||
"""Draw the coin overlay.
|
||||
Only draws free play for now."""
|
||||
tex = global_tex
|
||||
tex.draw_texture('overlay', 'free_play', x=x, y=y)
|
||||
self.free_play.draw(ray.BLACK, x=global_tex.screen_width//2 - self.free_play.texture.width//2, y=global_tex.skin_config["free_play"].y)
|
||||
|
||||
class AllNetIcon:
|
||||
"""All.Net status icon for the game."""
|
||||
|
||||
@@ -15,12 +15,13 @@ from libs.config import get_config
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class SkinInfo:
|
||||
def __init__(self, x: float, y: float, font_size: int, width: float, height: float):
|
||||
def __init__(self, x: float, y: float, font_size: int, width: float, height: float, text: dict[str, str]):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.font_size = font_size
|
||||
self.text = text
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__dict__}"
|
||||
@@ -78,7 +79,7 @@ class TextureWrapper:
|
||||
|
||||
data = json.loads((self.graphics_path / "skin_config.json").read_text())
|
||||
self.skin_config: dict[str, SkinInfo] = {
|
||||
k: SkinInfo(v.get('x', 0), v.get('y', 0), v.get('font_size', 0), v.get('width', 0), v.get('height', 0)) for k, v in data.items()
|
||||
k: SkinInfo(v.get('x', 0), v.get('y', 0), v.get('font_size', 0), v.get('width', 0), v.get('height', 0), v.get('text', dict())) for k, v in data.items()
|
||||
}
|
||||
self.screen_width = int(self.skin_config["screen"].width)
|
||||
self.screen_height = int(self.skin_config["screen"].height)
|
||||
@@ -88,7 +89,7 @@ class TextureWrapper:
|
||||
self.parent_graphics_path = Path("Skins") / parent
|
||||
parent_data = json.loads((self.parent_graphics_path / "skin_config.json").read_text())
|
||||
for k, v in parent_data.items():
|
||||
self.skin_config[k] = SkinInfo(v.get('x', 0) * self.screen_scale, v.get('y', 0) * self.screen_scale, v.get('font_size', 0) * self.screen_scale, v.get('width', 0) * self.screen_scale, v.get('height', 0) * self.screen_scale)
|
||||
self.skin_config[k] = SkinInfo(v.get('x', 0) * self.screen_scale, v.get('y', 0) * self.screen_scale, v.get('font_size', 0) * self.screen_scale, v.get('width', 0) * self.screen_scale, v.get('height', 0) * self.screen_scale, v.get('text', dict()))
|
||||
|
||||
def unload_textures(self):
|
||||
"""Unload all textures and animations."""
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import string
|
||||
import ctypes
|
||||
import hashlib
|
||||
import sys
|
||||
@@ -135,7 +136,7 @@ for file in Path('cache/image').iterdir():
|
||||
|
||||
class OutlinedText:
|
||||
"""Create an outlined text object."""
|
||||
def __init__(self, text: str, font_size: int, color: ray.Color, outline_thickness=5.0, vertical=False):
|
||||
def __init__(self, text: str, font_size: int, color: ray.Color, outline_thickness=5.0, vertical=False, spacing=1):
|
||||
"""
|
||||
Create an outlined text object.
|
||||
|
||||
@@ -158,7 +159,7 @@ class OutlinedText:
|
||||
if vertical:
|
||||
self.texture = self._create_text_vertical(text, font_size, color, ray.BLANK, self.font)
|
||||
else:
|
||||
self.texture = self._create_text_horizontal(text, font_size, color, ray.BLANK, self.font)
|
||||
self.texture = self._create_text_horizontal(text, font_size, color, ray.BLANK, self.font, spacing=spacing)
|
||||
ray.gen_texture_mipmaps(self.texture)
|
||||
ray.set_texture_filter(self.texture, ray.TextureFilter.TEXTURE_FILTER_TRILINEAR)
|
||||
outline_size = ray.ffi.new('float*', self.outline_thickness)
|
||||
@@ -358,19 +359,25 @@ class OutlinedText:
|
||||
ray.unload_image(image)
|
||||
return texture
|
||||
|
||||
def _create_text_horizontal(self, text: str, font_size: int, color: ray.Color, bg_color: ray.Color, font: Optional[ray.Font]=None, padding: int=10):
|
||||
def _create_text_horizontal(self, text: str, font_size: int, color: ray.Color, bg_color: ray.Color, font: Optional[ray.Font]=None, padding: int=10, spacing: int=1):
|
||||
if font:
|
||||
text_size = ray.measure_text_ex(font, text, font_size, 0)
|
||||
text_size = ray.measure_text_ex(font, text, font_size, spacing)
|
||||
for char in text:
|
||||
if char in string.whitespace:
|
||||
text_size.x += 2
|
||||
total_width = text_size.x + (padding * 2)
|
||||
total_height = text_size.y + (padding * 2)
|
||||
else:
|
||||
total_width = ray.measure_text(text, font_size) + (padding * 2)
|
||||
total_height = font_size + (padding * 2)
|
||||
|
||||
image = ray.gen_image_color(int(total_width), int(total_height), bg_color)
|
||||
|
||||
if font:
|
||||
text_image = ray.image_text_ex(font, text, font_size, 0, color)
|
||||
text_image = ray.image_text_ex(font, text, font_size, spacing, color)
|
||||
else:
|
||||
text_image = ray.image_text(text, font_size, color)
|
||||
|
||||
text_x = padding
|
||||
text_y = padding
|
||||
ray.image_draw(image, text_image,
|
||||
@@ -378,7 +385,6 @@ class OutlinedText:
|
||||
ray.Rectangle(text_x, text_y, text_image.width, text_image.height),
|
||||
ray.WHITE)
|
||||
ray.unload_image(text_image)
|
||||
|
||||
ray.export_image(image, f'cache/image/{self.hash}.png')
|
||||
texture = ray.load_texture_from_image(image)
|
||||
ray.unload_image(image)
|
||||
|
||||
Reference in New Issue
Block a user