Switched to Linux and it changed the line encoding, probably, cause every file is showing as changed.

This commit is contained in:
csd4ni3l
2025-11-09 17:56:56 +01:00
parent d1b238b239
commit a4ec759599
22 changed files with 2414 additions and 2414 deletions

View File

@@ -1,41 +1,41 @@
import arcade, arcade.gui
from utils.constants import CUSTOM_DIFFICULTY_SETTINGS, slider_style, button_style
from utils.preload import button_texture, button_hovered_texture
class CustomDifficulty(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.pypresence_client = pypresence_client
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.box = self.anchor.add(arcade.gui.UIBoxLayout(size_between=self.window.height / 10), anchor_x="center", anchor_y="top")
self.custom_settings = {}
self.custom_setting_labels = {}
def set_custom_setting(self, key, value):
value = int(value)
self.custom_settings[key] = value
self.custom_setting_labels[key].text = f"{next(setting_list[1] for setting_list in CUSTOM_DIFFICULTY_SETTINGS if setting_list[0] == key)}: {value}"
def on_show_view(self):
super().on_show_view()
self.box.add(arcade.gui.UILabel(text="Custom Difficulty Selector", font_size=32))
self.box.add(arcade.gui.UISpace(height=self.window.height / 20))
for custom_setting_key, custom_setting_name, min_value, max_value in CUSTOM_DIFFICULTY_SETTINGS:
self.custom_settings[custom_setting_key] = int((max_value - min_value) / 2)
self.custom_setting_labels[custom_setting_key] = self.box.add(arcade.gui.UILabel(text=f"{custom_setting_name}: {int((max_value - min_value) / 2)}", font_size=28))
slider = self.box.add(arcade.gui.UISlider(step=1, min_value=min_value, max_value=max_value, value=int((max_value - min_value) / 2), style=slider_style, width=self.window.width / 2, height=self.window.height / 15))
slider._render_steps = lambda surface: None
slider.on_change = lambda event, key=custom_setting_key: self.set_custom_setting(key, event.new_value)
self.play_button = self.anchor.add(arcade.gui.UITextureButton(text="Play", style=button_style, texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10), anchor_x="center", anchor_y="bottom")
self.play_button.on_click = lambda event: self.play()
def play(self):
from game.play import Game
self.window.show_view(Game(self.pypresence_client, self.custom_settings["size"], self.custom_settings["source_count"], self.custom_settings["house_count"]))
import arcade, arcade.gui
from utils.constants import CUSTOM_DIFFICULTY_SETTINGS, slider_style, button_style
from utils.preload import button_texture, button_hovered_texture
class CustomDifficulty(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.pypresence_client = pypresence_client
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.box = self.anchor.add(arcade.gui.UIBoxLayout(size_between=self.window.height / 10), anchor_x="center", anchor_y="top")
self.custom_settings = {}
self.custom_setting_labels = {}
def set_custom_setting(self, key, value):
value = int(value)
self.custom_settings[key] = value
self.custom_setting_labels[key].text = f"{next(setting_list[1] for setting_list in CUSTOM_DIFFICULTY_SETTINGS if setting_list[0] == key)}: {value}"
def on_show_view(self):
super().on_show_view()
self.box.add(arcade.gui.UILabel(text="Custom Difficulty Selector", font_size=32))
self.box.add(arcade.gui.UISpace(height=self.window.height / 20))
for custom_setting_key, custom_setting_name, min_value, max_value in CUSTOM_DIFFICULTY_SETTINGS:
self.custom_settings[custom_setting_key] = int((max_value - min_value) / 2)
self.custom_setting_labels[custom_setting_key] = self.box.add(arcade.gui.UILabel(text=f"{custom_setting_name}: {int((max_value - min_value) / 2)}", font_size=28))
slider = self.box.add(arcade.gui.UISlider(step=1, min_value=min_value, max_value=max_value, value=int((max_value - min_value) / 2), style=slider_style, width=self.window.width / 2, height=self.window.height / 15))
slider._render_steps = lambda surface: None
slider.on_change = lambda event, key=custom_setting_key: self.set_custom_setting(key, event.new_value)
self.play_button = self.anchor.add(arcade.gui.UITextureButton(text="Play", style=button_style, texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10), anchor_x="center", anchor_y="bottom")
self.play_button.on_click = lambda event: self.play()
def play(self):
from game.play import Game
self.window.show_view(Game(self.pypresence_client, self.custom_settings["size"], self.custom_settings["source_count"], self.custom_settings["house_count"]))

View File

@@ -1,43 +1,43 @@
import arcade, arcade.gui
from utils.preload import button_texture, button_hovered_texture
from utils.constants import big_button_style, button_style
class DifficultySelector(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout())
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10), anchor_x='center', anchor_y='center')
self.pypresence_client = pypresence_client
self.pypresence_client.update(state='In Menu', details='In Difficulty Selector', start=self.pypresence_client.start_time)
def on_show_view(self):
super().on_show_view()
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda event: self.main_exit()
self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5)
self.box.add(arcade.gui.UILabel(text="Difficulty Selector", font_size=32))
for difficulty in ["7x7", "8x8", "9x9", "10x10", "11x11", "12x12", "Custom"]:
button = self.box.add(arcade.gui.UITextureButton(text=difficulty, width=self.window.width / 2, height=self.window.height / 10, texture=button_texture, texture_hovered=button_hovered_texture, style=big_button_style))
if not difficulty == "Custom":
button.on_click = lambda e, difficulty=difficulty: self.play(int(difficulty.split("x")[0]))
else:
button.on_click = lambda e: self.custom_difficulty()
def custom_difficulty(self):
from menus.custom_difficulty import CustomDifficulty
self.window.show_view(CustomDifficulty(self.pypresence_client))
def play(self, difficulty):
from game.play import Game
self.window.show_view(Game(self.pypresence_client, difficulty))
def main_exit(self):
from menus.main import Main
import arcade, arcade.gui
from utils.preload import button_texture, button_hovered_texture
from utils.constants import big_button_style, button_style
class DifficultySelector(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout())
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10), anchor_x='center', anchor_y='center')
self.pypresence_client = pypresence_client
self.pypresence_client.update(state='In Menu', details='In Difficulty Selector', start=self.pypresence_client.start_time)
def on_show_view(self):
super().on_show_view()
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda event: self.main_exit()
self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5)
self.box.add(arcade.gui.UILabel(text="Difficulty Selector", font_size=32))
for difficulty in ["7x7", "8x8", "9x9", "10x10", "11x11", "12x12", "Custom"]:
button = self.box.add(arcade.gui.UITextureButton(text=difficulty, width=self.window.width / 2, height=self.window.height / 10, texture=button_texture, texture_hovered=button_hovered_texture, style=big_button_style))
if not difficulty == "Custom":
button.on_click = lambda e, difficulty=difficulty: self.play(int(difficulty.split("x")[0]))
else:
button.on_click = lambda e: self.custom_difficulty()
def custom_difficulty(self):
from menus.custom_difficulty import CustomDifficulty
self.window.show_view(CustomDifficulty(self.pypresence_client))
def play(self, difficulty):
from game.play import Game
self.window.show_view(Game(self.pypresence_client, difficulty))
def main_exit(self):
from menus.main import Main
self.window.show_view(Main(self.pypresence_client))

View File

@@ -1,74 +1,74 @@
import arcade, arcade.gui, asyncio, pypresence, time, copy, json
from utils.preload import button_texture, button_hovered_texture
from utils.constants import big_button_style, discord_presence_id
from utils.utils import FakePyPresence
class Main(arcade.gui.UIView):
def __init__(self, pypresence_client=None):
super().__init__()
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout())
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10), anchor_x='center', anchor_y='center')
self.pypresence_client = pypresence_client
with open("settings.json", "r") as file:
self.settings_dict = json.load(file)
if self.settings_dict.get('discord_rpc', True):
if self.pypresence_client == None: # Game has started
try:
asyncio.get_event_loop()
except:
asyncio.set_event_loop(asyncio.new_event_loop())
try:
self.pypresence_client = pypresence.Presence(discord_presence_id)
self.pypresence_client.connect()
self.pypresence_client.start_time = time.time()
except:
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = time.time()
elif isinstance(self.pypresence_client, FakePyPresence): # the user has enabled RPC in the settings in this session.
# get start time from old object
start_time = copy.deepcopy(self.pypresence_client.start_time)
try:
self.pypresence_client = pypresence.Presence(discord_presence_id)
self.pypresence_client.connect()
self.pypresence_client.start_time = start_time
except:
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = start_time
self.pypresence_client.update(state='In Menu', details='In Main Menu', start=self.pypresence_client.start_time)
else: # game has started, but the user has disabled RPC in the settings.
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = time.time()
self.pypresence_client.update(state='In Menu', details='In Main Menu', start=self.pypresence_client.start_time)
def on_show_view(self):
super().on_show_view()
self.title_label = self.box.add(arcade.gui.UILabel(text="Connect the Current", font_name="Roboto", font_size=48))
self.play_button = self.box.add(arcade.gui.UITextureButton(text="Play", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10, style=big_button_style))
self.play_button.on_click = lambda event: self.play()
self.tutorial_button = self.box.add(arcade.gui.UITextureButton(text="Tutorial", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10, style=big_button_style))
self.tutorial_button.on_click = lambda event: self.tutorial()
self.settings_button = self.box.add(arcade.gui.UITextureButton(text="Settings", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10, style=big_button_style))
self.settings_button.on_click = lambda event: self.settings()
def play(self):
from menus.difficulty_selector import DifficultySelector
self.window.show_view(DifficultySelector(self.pypresence_client))
def tutorial(self):
from menus.tutorial import Tutorial
self.window.show_view(Tutorial(self.pypresence_client))
def settings(self):
from menus.settings import Settings
self.window.show_view(Settings(self.pypresence_client))
import arcade, arcade.gui, asyncio, pypresence, time, copy, json
from utils.preload import button_texture, button_hovered_texture
from utils.constants import big_button_style, discord_presence_id
from utils.utils import FakePyPresence
class Main(arcade.gui.UIView):
def __init__(self, pypresence_client=None):
super().__init__()
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout())
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10), anchor_x='center', anchor_y='center')
self.pypresence_client = pypresence_client
with open("settings.json", "r") as file:
self.settings_dict = json.load(file)
if self.settings_dict.get('discord_rpc', True):
if self.pypresence_client == None: # Game has started
try:
asyncio.get_event_loop()
except:
asyncio.set_event_loop(asyncio.new_event_loop())
try:
self.pypresence_client = pypresence.Presence(discord_presence_id)
self.pypresence_client.connect()
self.pypresence_client.start_time = time.time()
except:
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = time.time()
elif isinstance(self.pypresence_client, FakePyPresence): # the user has enabled RPC in the settings in this session.
# get start time from old object
start_time = copy.deepcopy(self.pypresence_client.start_time)
try:
self.pypresence_client = pypresence.Presence(discord_presence_id)
self.pypresence_client.connect()
self.pypresence_client.start_time = start_time
except:
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = start_time
self.pypresence_client.update(state='In Menu', details='In Main Menu', start=self.pypresence_client.start_time)
else: # game has started, but the user has disabled RPC in the settings.
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = time.time()
self.pypresence_client.update(state='In Menu', details='In Main Menu', start=self.pypresence_client.start_time)
def on_show_view(self):
super().on_show_view()
self.title_label = self.box.add(arcade.gui.UILabel(text="Connect the Current", font_name="Roboto", font_size=48))
self.play_button = self.box.add(arcade.gui.UITextureButton(text="Play", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10, style=big_button_style))
self.play_button.on_click = lambda event: self.play()
self.tutorial_button = self.box.add(arcade.gui.UITextureButton(text="Tutorial", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10, style=big_button_style))
self.tutorial_button.on_click = lambda event: self.tutorial()
self.settings_button = self.box.add(arcade.gui.UITextureButton(text="Settings", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=self.window.height / 10, style=big_button_style))
self.settings_button.on_click = lambda event: self.settings()
def play(self):
from menus.difficulty_selector import DifficultySelector
self.window.show_view(DifficultySelector(self.pypresence_client))
def tutorial(self):
from menus.tutorial import Tutorial
self.window.show_view(Tutorial(self.pypresence_client))
def settings(self):
from menus.settings import Settings
self.window.show_view(Settings(self.pypresence_client))

View File

@@ -1,284 +1,284 @@
import copy, pypresence, json, os
import arcade, arcade.gui
from utils.constants import button_style, dropdown_style, slider_style, settings, discord_presence_id, settings_start_category
from utils.utils import FakePyPresence
from utils.preload import button_texture, button_hovered_texture
from arcade.gui import UIBoxLayout, UIAnchorLayout
class Settings(arcade.gui.UIView):
def __init__(self, pypresence_client, *args):
super().__init__()
self.args = args
with open("settings.json", "r") as file:
self.settings_dict = json.load(file)
self.pypresence_client = pypresence_client
self.pypresence_client.update(state='In Settings', details='Modifying Settings', start=self.pypresence_client.start_time)
self.slider_labels = {}
self.sliders = {}
self.on_radiobuttons = {}
self.off_radiobuttons = {}
self.current_category = settings_start_category
self.modified_settings = {}
def create_layouts(self):
self.anchor = self.add_widget(UIAnchorLayout(size_hint=(1, 1)))
self.box = UIBoxLayout(space_between=50, align="center", vertical=False)
self.anchor.add(self.box, anchor_x="center", anchor_y="top", align_x=10, align_y=-75)
self.top_box = UIBoxLayout(space_between=self.window.width / 160, vertical=False)
self.anchor.add(self.top_box, anchor_x="left", anchor_y="top", align_x=10, align_y=-10)
self.key_layout = self.box.add(UIBoxLayout(space_between=20, align='left'))
self.value_layout = self.box.add(UIBoxLayout(space_between=13, align='left'))
def on_show_view(self):
super().on_show_view()
self.create_layouts()
self.ui.push_handlers(self)
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda event: self.main_exit()
self.top_box.add(self.back_button)
self.display_categories()
self.display_category(settings_start_category)
def display_categories(self):
for category in settings:
category_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=category, style=button_style, width=self.window.width / 10, height=50)
if not category == "Credits":
category_button.on_click = lambda event, category=category: self.display_category(category)
else:
category_button.on_click = lambda event: self.credits()
self.top_box.add(category_button)
def display_category(self, category):
if hasattr(self, 'apply_button'):
self.anchor.remove(self.apply_button)
del self.apply_button
if hasattr(self, 'credits_label'):
self.anchor.remove(self.credits_label)
del self.credits_label
self.current_category = category
self.key_layout.clear()
self.value_layout.clear()
for setting in settings[category]:
label = arcade.gui.UILabel(text=setting, font_name="Roboto", font_size=28, text_color=arcade.color.WHITE )
self.key_layout.add(label)
setting_dict = settings[category][setting]
if setting_dict['type'] == "option":
dropdown = arcade.gui.UIDropdown(options=setting_dict['options'], width=200, height=50, default=self.settings_dict.get(setting_dict["config_key"], setting_dict["options"][0]), active_style=dropdown_style, dropdown_style=dropdown_style, primary_style=dropdown_style)
dropdown.on_change = lambda _, setting=setting, dropdown=dropdown: self.update(setting, dropdown.value, "option")
self.value_layout.add(dropdown)
elif setting_dict['type'] == "bool":
button_layout = self.value_layout.add(arcade.gui.UIBoxLayout(space_between=50, vertical=False))
on_radiobutton = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="ON", style=button_style, width=150, height=50)
self.on_radiobuttons[setting] = on_radiobutton
on_radiobutton.on_click = lambda _, setting=setting: self.update(setting, True, "bool")
button_layout.add(on_radiobutton)
off_radiobutton = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="OFF", style=button_style, width=150, height=50)
self.off_radiobuttons[setting] = off_radiobutton
off_radiobutton.on_click = lambda _, setting=setting: self.update(setting, False, "bool")
button_layout.add(off_radiobutton)
if self.settings_dict.get(setting_dict["config_key"], setting_dict["default"]):
self.set_highlighted_style(on_radiobutton)
self.set_normal_style(off_radiobutton)
else:
self.set_highlighted_style(off_radiobutton)
self.set_normal_style(on_radiobutton)
elif setting_dict['type'] == "slider":
if setting == "FPS Limit":
if self.settings_dict.get(setting_dict["config_key"]) == 0:
label_text = "FPS Limit: Disabled"
else:
label_text = f"FPS Limit: {self.settings_dict.get(setting_dict['config_key'], setting_dict['default'])}"
else:
label_text = f"{setting}: {int(self.settings_dict.get(setting_dict['config_key'], setting_dict['default']))}"
label.text = label_text
self.slider_labels[setting] = label
slider = arcade.gui.UISlider(width=400, height=50, value=self.settings_dict.get(setting_dict["config_key"], setting_dict["default"]), min_value=setting_dict['min'], max_value=setting_dict['max'], style=slider_style)
slider.on_change = lambda _, setting=setting, slider=slider: self.update(setting, slider.value, "slider")
self.sliders[setting] = slider
self.value_layout.add(slider)
self.apply_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='Apply', style=button_style, width=200, height=100)
self.apply_button.on_click = lambda event: self.apply_settings()
self.anchor.add(self.apply_button, anchor_x="right", anchor_y="bottom", align_x=-10, align_y=10)
def apply_settings(self):
for config_key, value in self.modified_settings.items():
self.settings_dict[config_key] = value
if self.settings_dict['window_mode'] == "Fullscreen":
self.window.set_fullscreen(True)
else:
self.window.set_fullscreen(False)
width, height = map(int, self.settings_dict['resolution'].split('x'))
self.window.set_size(width, height)
if self.settings_dict['vsync']:
self.window.set_vsync(True)
display_mode = self.window.display.get_default_screen().get_mode()
refresh_rate = display_mode.rate
self.window.set_update_rate(1 / refresh_rate)
self.window.set_draw_rate(1 / refresh_rate)
elif not self.settings_dict['fps_limit'] == 0:
self.window.set_vsync(False)
self.window.set_update_rate(1 / self.settings_dict['fps_limit'])
self.window.set_draw_rate(1 / self.settings_dict['fps_limit'])
else:
self.window.set_vsync(False)
self.window.set_update_rate(1 / 99999999)
self.window.set_draw_rate(1 / 99999999)
if self.settings_dict['discord_rpc']:
if isinstance(self.pypresence_client, FakePyPresence): # the user has enabled RPC in the settings in this session.
start_time = copy.deepcopy(self.pypresence_client.start_time)
self.pypresence_client.close()
del self.pypresence_client
try:
self.pypresence_client = pypresence.Presence(discord_presence_id)
self.pypresence_client.connect()
self.pypresence_client.update(state='In Settings', details='Modifying Settings', start=start_time)
self.pypresence_client.start_time = start_time
except:
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = start_time
else:
if not isinstance(self.pypresence_client, FakePyPresence):
start_time = copy.deepcopy(self.pypresence_client.start_time)
self.pypresence_client.update()
self.pypresence_client.close()
del self.pypresence_client
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = start_time
self.ui_cleanup()
self.ui = arcade.gui.UIManager()
self.ui.enable()
self.create_layouts()
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda event: self.main_exit()
self.top_box.add(self.back_button)
self.display_categories()
self.display_category(self.current_category)
with open("settings.json", "w") as file:
file.write(json.dumps(self.settings_dict, indent=4))
def update(self, setting=None, button_state=None, setting_type="bool"):
setting_dict = settings[self.current_category][setting]
config_key = settings[self.current_category][setting]["config_key"]
if setting_type == "option":
self.modified_settings[config_key] = button_state
elif setting_type == "bool":
self.modified_settings[config_key] = button_state
if button_state:
self.set_highlighted_style(self.on_radiobuttons[setting])
self.set_normal_style(self.off_radiobuttons[setting])
else:
self.set_highlighted_style(self.off_radiobuttons[setting])
self.set_normal_style(self.on_radiobuttons[setting])
elif setting_type == "slider":
new_value = int(button_state)
self.modified_settings[config_key] = new_value
self.sliders[setting].value = new_value
if setting == "FPS Limit":
if new_value == 0:
label_text = "FPS Limit: Disabled"
else:
label_text = f"FPS Limit: {str(new_value).rjust(8)}"
else:
label_text = f"{setting}: {str(new_value).rjust(8)}"
self.slider_labels[setting].text = label_text
def credits(self):
if hasattr(self, 'apply_button'):
self.anchor.remove(self.apply_button)
del self.apply_button
if hasattr(self, 'credits_label'):
self.anchor.remove(self.credits_label)
del self.credits_label
self.key_layout.clear()
self.value_layout.clear()
with open('CREDITS', 'r') as file:
text = file.read()
if self.window.width == 3840:
font_size = 30
elif self.window.width == 2560:
font_size = 20
elif self.window.width == 1920:
font_size = 17
elif self.window.width >= 1440:
font_size = 14
else:
font_size = 12
self.credits_label = arcade.gui.UILabel(text=text, text_color=arcade.color.WHITE, font_name="Roboto", font_size=font_size, align="center", multiline=True)
self.key_layout.add(self.credits_label)
def set_highlighted_style(self, element):
element.texture = button_hovered_texture
element.texture_hovered = button_texture
def set_normal_style(self, element):
element.texture_hovered = button_hovered_texture
element.texture = button_texture
def main_exit(self):
from menus.main import Main
self.window.show_view(Main(self.pypresence_client, *self.args))
def ui_cleanup(self):
self.ui.clear()
del self.ui
import copy, pypresence, json, os
import arcade, arcade.gui
from utils.constants import button_style, dropdown_style, slider_style, settings, discord_presence_id, settings_start_category
from utils.utils import FakePyPresence
from utils.preload import button_texture, button_hovered_texture
from arcade.gui import UIBoxLayout, UIAnchorLayout
class Settings(arcade.gui.UIView):
def __init__(self, pypresence_client, *args):
super().__init__()
self.args = args
with open("settings.json", "r") as file:
self.settings_dict = json.load(file)
self.pypresence_client = pypresence_client
self.pypresence_client.update(state='In Settings', details='Modifying Settings', start=self.pypresence_client.start_time)
self.slider_labels = {}
self.sliders = {}
self.on_radiobuttons = {}
self.off_radiobuttons = {}
self.current_category = settings_start_category
self.modified_settings = {}
def create_layouts(self):
self.anchor = self.add_widget(UIAnchorLayout(size_hint=(1, 1)))
self.box = UIBoxLayout(space_between=50, align="center", vertical=False)
self.anchor.add(self.box, anchor_x="center", anchor_y="top", align_x=10, align_y=-75)
self.top_box = UIBoxLayout(space_between=self.window.width / 160, vertical=False)
self.anchor.add(self.top_box, anchor_x="left", anchor_y="top", align_x=10, align_y=-10)
self.key_layout = self.box.add(UIBoxLayout(space_between=20, align='left'))
self.value_layout = self.box.add(UIBoxLayout(space_between=13, align='left'))
def on_show_view(self):
super().on_show_view()
self.create_layouts()
self.ui.push_handlers(self)
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda event: self.main_exit()
self.top_box.add(self.back_button)
self.display_categories()
self.display_category(settings_start_category)
def display_categories(self):
for category in settings:
category_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=category, style=button_style, width=self.window.width / 10, height=50)
if not category == "Credits":
category_button.on_click = lambda event, category=category: self.display_category(category)
else:
category_button.on_click = lambda event: self.credits()
self.top_box.add(category_button)
def display_category(self, category):
if hasattr(self, 'apply_button'):
self.anchor.remove(self.apply_button)
del self.apply_button
if hasattr(self, 'credits_label'):
self.anchor.remove(self.credits_label)
del self.credits_label
self.current_category = category
self.key_layout.clear()
self.value_layout.clear()
for setting in settings[category]:
label = arcade.gui.UILabel(text=setting, font_name="Roboto", font_size=28, text_color=arcade.color.WHITE )
self.key_layout.add(label)
setting_dict = settings[category][setting]
if setting_dict['type'] == "option":
dropdown = arcade.gui.UIDropdown(options=setting_dict['options'], width=200, height=50, default=self.settings_dict.get(setting_dict["config_key"], setting_dict["options"][0]), active_style=dropdown_style, dropdown_style=dropdown_style, primary_style=dropdown_style)
dropdown.on_change = lambda _, setting=setting, dropdown=dropdown: self.update(setting, dropdown.value, "option")
self.value_layout.add(dropdown)
elif setting_dict['type'] == "bool":
button_layout = self.value_layout.add(arcade.gui.UIBoxLayout(space_between=50, vertical=False))
on_radiobutton = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="ON", style=button_style, width=150, height=50)
self.on_radiobuttons[setting] = on_radiobutton
on_radiobutton.on_click = lambda _, setting=setting: self.update(setting, True, "bool")
button_layout.add(on_radiobutton)
off_radiobutton = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="OFF", style=button_style, width=150, height=50)
self.off_radiobuttons[setting] = off_radiobutton
off_radiobutton.on_click = lambda _, setting=setting: self.update(setting, False, "bool")
button_layout.add(off_radiobutton)
if self.settings_dict.get(setting_dict["config_key"], setting_dict["default"]):
self.set_highlighted_style(on_radiobutton)
self.set_normal_style(off_radiobutton)
else:
self.set_highlighted_style(off_radiobutton)
self.set_normal_style(on_radiobutton)
elif setting_dict['type'] == "slider":
if setting == "FPS Limit":
if self.settings_dict.get(setting_dict["config_key"]) == 0:
label_text = "FPS Limit: Disabled"
else:
label_text = f"FPS Limit: {self.settings_dict.get(setting_dict['config_key'], setting_dict['default'])}"
else:
label_text = f"{setting}: {int(self.settings_dict.get(setting_dict['config_key'], setting_dict['default']))}"
label.text = label_text
self.slider_labels[setting] = label
slider = arcade.gui.UISlider(width=400, height=50, value=self.settings_dict.get(setting_dict["config_key"], setting_dict["default"]), min_value=setting_dict['min'], max_value=setting_dict['max'], style=slider_style)
slider.on_change = lambda _, setting=setting, slider=slider: self.update(setting, slider.value, "slider")
self.sliders[setting] = slider
self.value_layout.add(slider)
self.apply_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='Apply', style=button_style, width=200, height=100)
self.apply_button.on_click = lambda event: self.apply_settings()
self.anchor.add(self.apply_button, anchor_x="right", anchor_y="bottom", align_x=-10, align_y=10)
def apply_settings(self):
for config_key, value in self.modified_settings.items():
self.settings_dict[config_key] = value
if self.settings_dict['window_mode'] == "Fullscreen":
self.window.set_fullscreen(True)
else:
self.window.set_fullscreen(False)
width, height = map(int, self.settings_dict['resolution'].split('x'))
self.window.set_size(width, height)
if self.settings_dict['vsync']:
self.window.set_vsync(True)
display_mode = self.window.display.get_default_screen().get_mode()
refresh_rate = display_mode.rate
self.window.set_update_rate(1 / refresh_rate)
self.window.set_draw_rate(1 / refresh_rate)
elif not self.settings_dict['fps_limit'] == 0:
self.window.set_vsync(False)
self.window.set_update_rate(1 / self.settings_dict['fps_limit'])
self.window.set_draw_rate(1 / self.settings_dict['fps_limit'])
else:
self.window.set_vsync(False)
self.window.set_update_rate(1 / 99999999)
self.window.set_draw_rate(1 / 99999999)
if self.settings_dict['discord_rpc']:
if isinstance(self.pypresence_client, FakePyPresence): # the user has enabled RPC in the settings in this session.
start_time = copy.deepcopy(self.pypresence_client.start_time)
self.pypresence_client.close()
del self.pypresence_client
try:
self.pypresence_client = pypresence.Presence(discord_presence_id)
self.pypresence_client.connect()
self.pypresence_client.update(state='In Settings', details='Modifying Settings', start=start_time)
self.pypresence_client.start_time = start_time
except:
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = start_time
else:
if not isinstance(self.pypresence_client, FakePyPresence):
start_time = copy.deepcopy(self.pypresence_client.start_time)
self.pypresence_client.update()
self.pypresence_client.close()
del self.pypresence_client
self.pypresence_client = FakePyPresence()
self.pypresence_client.start_time = start_time
self.ui_cleanup()
self.ui = arcade.gui.UIManager()
self.ui.enable()
self.create_layouts()
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda event: self.main_exit()
self.top_box.add(self.back_button)
self.display_categories()
self.display_category(self.current_category)
with open("settings.json", "w") as file:
file.write(json.dumps(self.settings_dict, indent=4))
def update(self, setting=None, button_state=None, setting_type="bool"):
setting_dict = settings[self.current_category][setting]
config_key = settings[self.current_category][setting]["config_key"]
if setting_type == "option":
self.modified_settings[config_key] = button_state
elif setting_type == "bool":
self.modified_settings[config_key] = button_state
if button_state:
self.set_highlighted_style(self.on_radiobuttons[setting])
self.set_normal_style(self.off_radiobuttons[setting])
else:
self.set_highlighted_style(self.off_radiobuttons[setting])
self.set_normal_style(self.on_radiobuttons[setting])
elif setting_type == "slider":
new_value = int(button_state)
self.modified_settings[config_key] = new_value
self.sliders[setting].value = new_value
if setting == "FPS Limit":
if new_value == 0:
label_text = "FPS Limit: Disabled"
else:
label_text = f"FPS Limit: {str(new_value).rjust(8)}"
else:
label_text = f"{setting}: {str(new_value).rjust(8)}"
self.slider_labels[setting].text = label_text
def credits(self):
if hasattr(self, 'apply_button'):
self.anchor.remove(self.apply_button)
del self.apply_button
if hasattr(self, 'credits_label'):
self.anchor.remove(self.credits_label)
del self.credits_label
self.key_layout.clear()
self.value_layout.clear()
with open('CREDITS', 'r') as file:
text = file.read()
if self.window.width == 3840:
font_size = 30
elif self.window.width == 2560:
font_size = 20
elif self.window.width == 1920:
font_size = 17
elif self.window.width >= 1440:
font_size = 14
else:
font_size = 12
self.credits_label = arcade.gui.UILabel(text=text, text_color=arcade.color.WHITE, font_name="Roboto", font_size=font_size, align="center", multiline=True)
self.key_layout.add(self.credits_label)
def set_highlighted_style(self, element):
element.texture = button_hovered_texture
element.texture_hovered = button_texture
def set_normal_style(self, element):
element.texture_hovered = button_hovered_texture
element.texture = button_texture
def main_exit(self):
from menus.main import Main
self.window.show_view(Main(self.pypresence_client, *self.args))
def ui_cleanup(self):
self.ui.clear()
del self.ui

View File

@@ -1,37 +1,37 @@
import arcade, arcade.gui
from utils.preload import button_texture, button_hovered_texture
from utils.constants import button_style
TUTORIAL_TEXT = """
In Connect the Current, you have to rotate power lines so power reaches to all of the houses.
- Every line has to be connected on all of it's sides.
- When needed, you might have to create loops of power or branches with no house linked to them.
(This is also because it's randomly generated and i couldn't find a way to generate maps with no meaningless branches)
- To rotate a line, just click on it and it will change its rotation.
- Maps are randomly generated, difficulty(size, source count, house count) depends on what you pick and grows exponentially.
"""
class Tutorial(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.pypresence_client = pypresence_client
self.pypresence_client.update(state="Checking Tutorial")
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=20), anchor_x="center", anchor_y="top")
def main_exit(self):
from menus.main import Main
self.window.show_view(Main(self.pypresence_client))
def on_show_view(self):
super().on_show_view()
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda event: self.main_exit()
self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5)
self.box.add(arcade.gui.UILabel(text="CTC Tutorial", font_size=40))
import arcade, arcade.gui
from utils.preload import button_texture, button_hovered_texture
from utils.constants import button_style
TUTORIAL_TEXT = """
In Connect the Current, you have to rotate power lines so power reaches to all of the houses.
- Every line has to be connected on all of it's sides.
- When needed, you might have to create loops of power or branches with no house linked to them.
(This is also because it's randomly generated and i couldn't find a way to generate maps with no meaningless branches)
- To rotate a line, just click on it and it will change its rotation.
- Maps are randomly generated, difficulty(size, source count, house count) depends on what you pick and grows exponentially.
"""
class Tutorial(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.pypresence_client = pypresence_client
self.pypresence_client.update(state="Checking Tutorial")
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=20), anchor_x="center", anchor_y="top")
def main_exit(self):
from menus.main import Main
self.window.show_view(Main(self.pypresence_client))
def on_show_view(self):
super().on_show_view()
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50)
self.back_button.on_click = lambda event: self.main_exit()
self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5)
self.box.add(arcade.gui.UILabel(text="CTC Tutorial", font_size=40))
self.box.add(arcade.gui.UILabel(text=TUTORIAL_TEXT, font_size=20, multiline=True))