def _setup_ui(self): self._x: wx.SpinCtrl = self._add_row( "x", wx.SpinCtrl, min=-30000000, max=30000000 ) self._y: wx.SpinCtrl = self._add_row( "y", wx.SpinCtrl, min=-30000000, max=30000000 ) self._z: wx.SpinCtrl = self._add_row( "z", wx.SpinCtrl, min=-30000000, max=30000000 ) for ui in (self._x, self._y, self._z): ui.SetValidator(IntValidator()) self._copy_air: wx.CheckBox = self._add_row("Copy Air", wx.CheckBox) copy_air = config.get("edit_select_location", {}).get("copy_air", False) self._copy_air.SetValue(copy_air) self._copy_air.Bind(wx.EVT_CHECKBOX, self._save_config) self._copy_water: wx.CheckBox = self._add_row("Copy Water", wx.CheckBox) copy_water = config.get("edit_select_location", {}).get("copy_water", True) self._copy_water.SetValue(copy_water) self._copy_water.Bind(wx.EVT_CHECKBOX, self._save_config) self._copy_lava: wx.CheckBox = self._add_row("Copy Lava", wx.CheckBox) copy_lava = config.get("edit_select_location", {}).get("copy_lava", True) self._copy_lava.SetValue(copy_lava) self._copy_lava.Bind(wx.EVT_CHECKBOX, self._save_config) self._x.Bind(wx.EVT_SPINCTRL, self._on_transform_change) self._y.Bind(wx.EVT_SPINCTRL, self._on_transform_change) self._z.Bind(wx.EVT_SPINCTRL, self._on_transform_change)
def enable(self): if self._canvas is None: self.Update() self._canvas = EditCanvas(self, self._world, self._close_self_callback) for arg in self._canvas.setup(): if isinstance(arg, (int, float)): self._temp_loading_bar.SetValue(min(arg, 1) * 10000) elif (isinstance(arg, tuple) and isinstance(arg[0], (int, float)) and isinstance(arg[1], str)): self._temp_loading_bar.SetValue(min(arg[0], 1) * 10000) self._temp_msg.SetLabel(arg[1]) self.Layout() self.Update() wx.Yield() edit_config: dict = config.get(EDIT_CONFIG_ID, {}) self._canvas.camera.perspective_fov = edit_config.get( "options", {}).get("fov", 70.0) if self._canvas.camera.perspective_fov > 180: self._canvas.camera.perspective_fov = 70.0 self._canvas.renderer.render_distance = edit_config.get( "options", {}).get("render_distance", 5) self._canvas.camera.rotate_speed = edit_config.get( "options", {}).get("camera_sensitivity", 2.0) self._sizer.Clear(True) self._sizer.Add(self._canvas, 1, wx.EXPAND) self._canvas.Show() self.Layout() self._canvas.Update() self._canvas.enable()
def _edit_controls(self): edit_config = config.get(EDIT_CONFIG_ID, {}) keybind_id = edit_config.get("keybind_group", DefaultKeybindGroupId) user_keybinds = edit_config.get("user_keybinds", {}) key_config = KeyConfigDialog(self, keybind_id, KeybindKeys, PresetKeybinds, user_keybinds) if key_config.ShowModal() == wx.ID_OK: user_keybinds, keybind_id, keybinds = key_config.options edit_config["user_keybinds"] = user_keybinds edit_config["keybind_group"] = keybind_id config.put(EDIT_CONFIG_ID, edit_config) self._canvas.set_key_binds(keybinds)
def _edit_controls(self): edit_config = config.get(EDIT_CONFIG_ID, {}) keybind_id = edit_config.get("keybind_group", DefaultKeybindGroupId) user_keybinds = edit_config.get("user_keybinds", {}) key_config = KeyConfigDialog(self, keybind_id, KeybindKeys, PresetKeybinds, user_keybinds) if key_config.ShowModal() == wx.ID_OK: user_keybinds, keybind_id, keybinds = key_config.options edit_config["user_keybinds"] = user_keybinds edit_config["keybind_group"] = keybind_id config.put(EDIT_CONFIG_ID, edit_config) self._canvas.buttons.clear_registered_actions() for action, (modifier_keys, trigger_key) in keybinds.items(): self._canvas.buttons.register_action(action, trigger_key, modifier_keys)
def __init__(self, parent: wx.Window, world: "World", close_callback: Callable, **kwargs): super().__init__(parent, world, **kwargs) self._close_callback = close_callback self._file_panel: Optional[FilePanel] = None self._tool_sizer: Optional[ToolManagerSizer] = None config_ = config.get(EDIT_CONFIG_ID, {}) user_keybinds = config_.get("user_keybinds", {}) group = config_.get("keybind_group", DefaultKeybindGroupId) if group in user_keybinds: keybinds = user_keybinds[group] elif group in PresetKeybinds: keybinds = PresetKeybinds[group] else: keybinds = DefaultKeys self.set_key_binds(keybinds)
def rebuild(self, new_world: str = None): meta: dict = config.get("amulet_meta", {}) recent_worlds: list = meta.setdefault("recent_worlds", []) if new_world is not None: while new_world in recent_worlds: recent_worlds.remove(new_world) recent_worlds.insert(0, new_world) while len(recent_worlds) > 5: recent_worlds.pop(5) if self._world_list is not None: self._world_list.Destroy() self._world_list = WorldList(self, recent_worlds, self._open_world_callback, sort=False) self.add_object(self._world_list, 1, wx.EXPAND) self.Layout() config.put("amulet_meta", meta)
def _edit_options(self): if self._canvas is not None: fov = self._canvas.fov render_distance = self._canvas.render_distance camera_sensitivity = self._canvas.camera_rotate_speed dialog = SimpleDialog(self, "Options") sizer = wx.FlexGridSizer(3, 2, 0, 0) dialog.sizer.Add(sizer, flag=wx.ALL, border=5) fov_ui = wx.SpinCtrlDouble(dialog, min=0, max=180, initial=fov) def set_fov(evt): self._canvas.fov = fov_ui.GetValue() fov_ui.Bind(wx.EVT_SPINCTRLDOUBLE, set_fov) sizer.Add( wx.StaticText(dialog, label="Field of View"), flag=wx.LEFT | wx.TOP | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=5, ) sizer.Add( fov_ui, flag=wx.LEFT | wx.TOP | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=5, ) render_distance_ui = wx.SpinCtrl(dialog, min=0, max=50, initial=render_distance) def set_render_distance(evt): self._canvas.render_distance = render_distance_ui.GetValue() render_distance_ui.Bind(wx.EVT_SPINCTRL, set_render_distance) sizer.Add( wx.StaticText(dialog, label="Render Distance"), flag=wx.LEFT | wx.TOP | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=5, ) sizer.Add( render_distance_ui, flag=wx.LEFT | wx.TOP | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=5, ) camera_sensitivity_ui = wx.SpinCtrlDouble( dialog, min=0, max=10, initial=camera_sensitivity) def set_camera_sensitivity(evt): self._canvas.camera_rotate_speed = camera_sensitivity_ui.GetValue( ) camera_sensitivity_ui.Bind(wx.EVT_SPINCTRLDOUBLE, set_camera_sensitivity) sizer.Add( wx.StaticText(dialog, label="Camera Sensitivity"), flag=wx.LEFT | wx.TOP | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=5, ) sizer.Add( camera_sensitivity_ui, flag=wx.LEFT | wx.TOP | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=5, ) dialog.Fit() response = dialog.ShowModal() if response == wx.ID_OK: edit_config: dict = config.get(EDIT_CONFIG_ID, {}) edit_config.setdefault("options", {}) edit_config["options"]["fov"] = fov_ui.GetValue() edit_config["options"][ "render_distance"] = render_distance_ui.GetValue() edit_config["options"][ "camera_sensitivity"] = camera_sensitivity_ui.GetValue() config.put(EDIT_CONFIG_ID, edit_config) elif response == wx.ID_CANCEL: self._canvas.fov = fov self._canvas.render_distance = render_distance self._canvas.camera_rotate_speed = camera_sensitivity
_lang = {} lang_dir = os.path.dirname(__file__) default_lang = "english" def _load_langauge(lang: str): lang_path = os.path.join(lang_dir, lang + ".lang") if os.path.isfile(lang_path): with open(lang_path) as f: for line in f.readlines(): line = line.split("=", 1) if len(line) != 2: continue _lang[line[0].strip()] = line[1].strip() def load_language(lang: str): """Load the contents of a language file from lang over """ _lang.clear() _load_langauge(default_lang) if lang != default_lang: _load_langauge(lang) load_language(config.get("amulet_meta", {}).get("lang", default_lang)) def get(key): return _lang.get(key, key)
def _save_config(self, evt): select_config = config.get("edit_select_location", {}) select_config["copy_air"] = self.copy_air select_config["copy_water"] = self.copy_water select_config["copy_lava"] = self.copy_lava config.put("edit_select_location", select_config)
from __future__ import annotations import atexit import wx import amulet_map_editor.api.config as config PRE_EXISTING_CONFIG = config.get("window_preferences", {}) def write_config(): config.put("window_preferences", PRE_EXISTING_CONFIG) atexit.register(write_config) def on_idle(self): global PRE_EXISTING_CONFIG qualified_name = ".".join((self.__module__, self.__class__.__name__)) def wrapper(evt): update_cfg = False if self.__resized: self.__resized = False update_cfg = True if self.__moved: self.__moved = False update_cfg = True
_lang_dirs: Set[str] = set() # the language directories _lang: Dict[str, str] = { } # a storage for the language strings. unique_identifier: language_string _default_language = "en" # find out what language the user is using. try: # try getting the OS language _language = locale.getdefaultlocale()[0] except: # if that fails use the default language _language = _default_language # if a language is set in the config use that _language = CONFIG.get("amulet_meta", {}).get("lang", _language) def register_lang_directory(lang_dir: str): """Register a new language directory. Use this, if you are a third party program, to register new translations for your program. :param lang_dir: The directory containing language files to register. Files must be of the format <language_code>.lang eg en_US.lang :return: """ if os.path.isdir(lang_dir): if lang_dir in _lang_dirs: log.warning( f"The language directory {lang_dir} has already been registered." ) else: