Esempio n. 1
0
    def __init__(self, parent: wx.Window, world: "World"):
        super().__init__(parent, world)
        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)

        canvas_sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(canvas_sizer)

        file_sizer = wx.BoxSizer(wx.HORIZONTAL)
        file_sizer.AddStretchSpacer(1)
        self._file_panel = FilePanel(self)
        file_sizer.Add(self._file_panel, 0, wx.EXPAND, 0)
        canvas_sizer.Add(file_sizer, 0, wx.EXPAND, 0)

        self._tool_sizer = Tool(self)
        canvas_sizer.Add(self._tool_sizer, 1, wx.EXPAND, 0)

        self.bind_events()
Esempio n. 2
0
 def key_binds(self) -> KeybindGroup:
     config_ = CONFIG.get(EDIT_CONFIG_ID, {})
     user_keybinds = config_.get("user_keybinds", {})
     group = config_.get("keybind_group", DefaultKeybindGroupId)
     if group in user_keybinds:
         return user_keybinds[group]
     elif group in PresetKeybinds:
         return PresetKeybinds[group]
     else:
         return DefaultKeys
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 def __init__(self, parent: wx.Window, world: "BaseLevel",
              close_callback: Callable):
     super().__init__(parent, world)
     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
     for action_id, (modifier_keys, trigger_key) in keybinds.items():
         self.buttons.register_action(action_id, trigger_key, modifier_keys)
from __future__ import annotations
from typing import Type, Tuple

import atexit

import wx

from amulet_map_editor import CONFIG

PRE_EXISTING_CONFIG = CONFIG.get("window_preferences", {})


def write_config():
    CONFIG.put("window_preferences", PRE_EXISTING_CONFIG)


atexit.register(write_config)


class ExtendedTLW(wx.TopLevelWindow):
    __resized: bool
    __size: Tuple[int, int]
    __position: Tuple[int, int]


def on_idle(self: ExtendedTLW):
    qualified_name = ".".join((self.__module__, self.__class__.__name__))

    def wrapper(evt):
        if self.__resized:
            self.__resized = False
Esempio n. 7
0
    def enable(self):
        if self._canvas is None:
            self.Update()

            self._canvas = ControllableEditCanvas(self, self._world)

            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._canvas.set_key_binds(keybinds)

            self._file_panel = FilePanel(
                self._canvas,
                self._world,
                self._undo,
                self._redo,
                self._save_world,
                self._close_world,
            )
            self._select_options = SelectOptions(self._canvas)
            self._operation_options = OperationUI(self._canvas, self._world,
                                                  self._run_operation_event,
                                                  self._run_main_operation)
            self._tool_panel = ToolSelect(self._canvas)

            self._canvas.Bind(EVT_CAMERA_MOVE, self._file_panel.move_event)
            self._tool_panel.Bind(EVT_SELECT_TOOL_ENABLED,
                                  self.show_select_options)
            self._tool_panel.Bind(EVT_OPERATION_TOOL_ENABLED,
                                  self.show_operation_options)
            self._tool_panel.Bind(EVT_IMPORT_TOOL_ENABLED,
                                  self.show_import_options)
            self._tool_panel.Bind(EVT_EXPORT_TOOL_ENABLED,
                                  self.show_export_options)

            self._file_panel.Hide()
            self._select_options.Hide()
            self._operation_options.Hide()
            self._tool_panel.Hide()

            self._sizer.Add(self._canvas, 1, wx.EXPAND)

            canvas_sizer = wx.BoxSizer(wx.VERTICAL)
            self._canvas.SetSizer(canvas_sizer)
            bottom_sizer0 = wx.BoxSizer(wx.HORIZONTAL)
            middle_sizer0 = wx.BoxSizer(wx.VERTICAL)
            top_sizer0 = wx.BoxSizer(wx.HORIZONTAL)
            top_sizer0.AddStretchSpacer(1)
            top_sizer0.Add(self._file_panel, 0, wx.EXPAND, 0)
            canvas_sizer.Add(top_sizer0, 0, wx.EXPAND, 0)
            middle_sizer0.AddStretchSpacer(1)
            middle_sizer0.Add(self._select_options, 0, 0, 0)
            middle_sizer0.Add(self._operation_options, 0, 0, 0)
            middle_sizer0.AddStretchSpacer(1)
            canvas_sizer.Add(middle_sizer0, 1, wx.EXPAND, 0)
            bottom_sizer0.AddStretchSpacer(1)
            bottom_sizer0.Add(self._tool_panel, 0, wx.EXPAND, 0)
            bottom_sizer0.AddStretchSpacer(1)
            canvas_sizer.Add(bottom_sizer0, 0, wx.EXPAND, 0)

            self._temp.Destroy()
            self._file_panel.Show()
            self._select_options.Show()
            self._tool_panel.Show()

            self.Layout()
        self._canvas.Update()
        self._canvas.enable()
        self._canvas.set_size(self.GetSize()[0], self.GetSize()[1])
        self._canvas.draw()
        self._file_panel.change_dimension()
Esempio n. 8
0
_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)