Skip to content

Commit

Permalink
Merge branch 'gentlegiantJGC' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlegiantJGC committed Apr 17, 2020
2 parents b000094 + 7a5c5e0 commit 2ef57d0
Show file tree
Hide file tree
Showing 21 changed files with 801 additions and 435 deletions.
17 changes: 13 additions & 4 deletions amulet_map_editor/amulet_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, parent):
| wx.CLIP_CHILDREN
| wx.RESIZE_BORDER,
)
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH) # TODO: work out proper localisation
icon = wx.Icon()
icon.CopyFromBitmap(wx.Bitmap(os.path.join(os.path.dirname(__file__), 'img', 'icon64.png'), wx.BITMAP_TYPE_ANY))
self.SetIcon(icon)
Expand Down Expand Up @@ -113,8 +114,8 @@ def _add_world_tab(self, obj, obj_name):
self._disable_enable()

def _show_open_world(self):
self.Disable()
WorldSelectWindow(self._open_world, self.Enable)
select_world = WorldSelectWindow(self, self._open_world)
select_world.ShowModal()

def _open_world(self, path: str):
"""Open a world panel add add it to the notebook"""
Expand Down Expand Up @@ -208,12 +209,20 @@ def __init__(self, parent, open_world):
self._help_button.Bind(wx.EVT_BUTTON, self._documentation)
self.add_object(self._help_button, 0, wx.ALL | wx.CENTER)

self._help_button = wx.Button(self, label='Amulet Discord', size=(400, 70))
self._help_button.SetFont(button_font)
self._help_button.Bind(wx.EVT_BUTTON, self._discord)
self.add_object(self._help_button, 0, wx.ALL | wx.CENTER)

def _show_world_select(self, evt):
self.Disable()
WorldSelectWindow(self._open_world_callback, self.Enable)
select_world = WorldSelectWindow(self, self._open_world_callback)
select_world.ShowModal()

def _documentation(self, evt):
webbrowser.open('https://github.com/Amulet-Team/Amulet-Map-Editor/tree/master/amulet_map_editor/readme.md')

def _discord(self, evt):
webbrowser.open('https://discord.gg/BTm6jnf')

def enable(self):
self.GetGrandParent().create_menu()
30 changes: 15 additions & 15 deletions amulet_map_editor/amulet_wx/world_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,17 @@ def _update_recent(self, path):
self._open_world_callback(path)


class WorldSelectWindow(wx.Frame):
def __init__(self, open_world_callback: Callable[[str], None], close_callback: Callable[[], None]):
wx.Frame.__init__(
self,
None,
id=wx.ID_ANY,
class WorldSelectWindow(wx.Dialog):
def __init__(self, parent: wx.Window, open_world_callback: Callable[[str], None]):
super().__init__(
parent,
title="World Select",
pos=wx.DefaultPosition,
size=wx.Size(560, 400),
pos=wx.Point(0, 0),
size=wx.Size(*[int(s*0.99) for s in parent.GetSize()]),
style=wx.CAPTION
| wx.CLOSE_BOX
| wx.MAXIMIZE_BOX
| wx.MAXIMIZE
# | wx.MAXIMIZE
| wx.SYSTEM_MENU
| wx.TAB_TRAVERSAL
| wx.CLIP_CHILDREN
Expand All @@ -298,16 +296,18 @@ def __init__(self, open_world_callback: Callable[[str], None], close_callback: C
self.Bind(wx.EVT_CLOSE, self._hide_event)

self._open_world_callback = open_world_callback
self._close_callback = close_callback
self.world_select = WorldSelectAndRecentUI(self, self._run_callback)
self.Show()

def _run_callback(self, path):
self.Hide()
self._close()
self._open_world_callback(path)
self._close_callback()
self.Destroy()

def _hide_event(self, evt):
self._close_callback()
self._close()
evt.Skip()

def _close(self):
if self.IsModal():
self.EndModal(0)
else:
self.Close()
2 changes: 1 addition & 1 deletion amulet_map_editor/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _load_langauge(lang: str):
line = line.split('=', 1)
if len(line) != 2:
continue
_lang[line[0]] = line[1]
_lang[line[0].strip()] = line[1].strip()


def load_language(lang: str):
Expand Down
21 changes: 13 additions & 8 deletions amulet_map_editor/opengl/mesh/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def __init__(self,
self._bounds_: Optional[numpy.ndarray] = None # The min and max locations
self.verts = numpy.zeros((6*2*3*3, self._vert_len), dtype=numpy.float32)

self.verts[:36, 5:9] = texture_bounds.get(('amulet', 'ui/selection'), ('minecraft', 'missing_no'))
self.verts[36:72, 5:9] = texture_bounds.get(('amulet', 'ui/selection_green'), ('minecraft', 'missing_no'))
self.verts[72:, 5:9] = texture_bounds.get(('amulet', 'ui/selection_blue'), ('minecraft', 'missing_no'))
missing_no = texture_bounds.get(('minecraft', 'missing_no'), (0, 0, 0, 0))
self.verts[:36, 5:9] = texture_bounds.get(('amulet', 'ui/selection'), missing_no)
self.verts[36:72, 5:9] = texture_bounds.get(('amulet', 'ui/selection_green'), missing_no)
self.verts[72:, 5:9] = texture_bounds.get(('amulet', 'ui/selection_blue'), missing_no)
self.verts[:, 9:12] = 1
self.draw_count = 36
self._draw_mode = GL_TRIANGLES
Expand Down Expand Up @@ -124,17 +125,21 @@ def _setup(self):
super()._setup()
self.create_geometry()

def draw(self, transformation_matrix: numpy.ndarray):
def draw(self, transformation_matrix: numpy.ndarray, draw_corners=True):
self._draw_mode = GL_TRIANGLES
self.draw_start = 0
draw_count = self.draw_count
if not draw_corners:
self.draw_count = 36
super().draw(transformation_matrix)

glDisable(GL_DEPTH_TEST)
self._draw_mode = GL_LINE_STRIP
draw_count = self.draw_count
self.draw_count = 36
for start in range(0, draw_count, 36):
self.draw_start = start
super().draw(transformation_matrix)
super().draw(transformation_matrix)
if draw_corners:
for start in range(36, draw_count, 36):
self.draw_start = start
super().draw(transformation_matrix)
self.draw_count = draw_count
glEnable(GL_DEPTH_TEST)
19 changes: 11 additions & 8 deletions amulet_map_editor/opengl/mesh/world_renderer/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, identifier: str, region_size=16):
# which causes issues due to dictionaries resizing
self._chunk_temp: queue.Queue = queue.Queue()
self._chunk_temp_set = set()
self.chunk_rebuilds = set()
self._rebuild_regions = []

def add_render_chunk(self, render_chunk: RenderChunk):
"""Add a RenderChunk to the database.
Expand Down Expand Up @@ -73,20 +73,23 @@ def unload(self, safe_area: Tuple[int, int, int, int] = None):
max_rx, max_rz = self.region_coords(*safe_area[2:])
delete_regions = []
for region in self._regions.values():
if min_rx <= region.rx <= max_rx and min_rz <= region.rz <= max_rz:
region.rebuild()
else:
if not (min_rx <= region.rx <= max_rx and min_rz <= region.rz <= max_rz):
region.unload()
delete_regions.append((region.rx, region.rz))

for region in delete_regions:
del self._regions[region]

def rebuild(self):
"""Force a rebuild of the region geometry from the chunk geometry
Useful to force an update rather than wait for the next unload call."""
for region in self._regions.values():
region.rebuild()
"""Rebuild a single region which was last rebuild the longest ago.
Put this on a semi-fast clock to rebuild all regions."""
if not self._rebuild_regions:
self._rebuild_regions = list(self._regions.keys())

if self._rebuild_regions:
region = self._rebuild_regions.pop(0)
if region in self._regions:
self._regions[region].rebuild()


class RenderRegion(TriMesh):
Expand Down
13 changes: 7 additions & 6 deletions amulet_map_editor/opengl/mesh/world_renderer/world.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy
from typing import TYPE_CHECKING, Tuple, Generator, Union, Optional, Dict, Any, List
from typing import TYPE_CHECKING, Tuple, Generator, Union, Optional, Dict, Any, List, Set
import math
from concurrent.futures import ThreadPoolExecutor, Future
import time
Expand Down Expand Up @@ -49,6 +49,7 @@ def __init__(self, render_world: 'RenderWorld'):
self._region_size = render_world.chunk_manager.region_size
self._enabled = False
self._generator: Optional[Future] = None
self._chunk_rebuilds: Set[Tuple[int, int]] = set()

@property
def render_world(self) -> "RenderWorld":
Expand Down Expand Up @@ -81,11 +82,11 @@ def _generate_chunks(self):
for offset in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
chunk_coords_ = (chunk_coords[0] + offset[0], chunk_coords[1] + offset[1])
if chunk_coords_ in self.render_world.chunk_manager:
self.render_world.chunk_manager.chunk_rebuilds.add(chunk_coords_)
elif self.render_world.chunk_manager.chunk_rebuilds:
self._chunk_rebuilds.add(chunk_coords_)
elif self._chunk_rebuilds:
# if a chunk was not found that needs rebuilding due to it changing but a previously
# identified neighbour chunk needs rebuilding do that.
chunk_coords = self.render_world.chunk_manager.chunk_rebuilds.pop()
chunk_coords = self._chunk_rebuilds.pop()
else:
# if no chunks need rebuilding then find a new chunk to load.
chunk_coords = next(
Expand All @@ -97,8 +98,8 @@ def _generate_chunks(self):
)
if chunk_coords is not None:
# if chunk coords is in here then remove it so it doesn't get generated twice.
if chunk_coords in self.render_world.chunk_manager.chunk_rebuilds:
self.render_world.chunk_manager.chunk_rebuilds.remove(chunk_coords)
if chunk_coords in self._chunk_rebuilds:
self._chunk_rebuilds.remove(chunk_coords)

# generate the chunk
chunk = RenderChunk(
Expand Down
5 changes: 3 additions & 2 deletions amulet_map_editor/plugins/operations/fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from amulet.operations.fill import fill
from amulet.api.selection import Selection
from amulet.api.block import Block
from amulet.api.data_types import Dimension
from amulet_map_editor.amulet_wx.block_select import BlockDefine
from amulet_map_editor.amulet_wx.simple import SimpleDialog

Expand All @@ -13,12 +14,12 @@

def fill_(
world: "World",
dimension: int,
dimension: Dimension,
selection_box: Selection,
options: dict
):
if isinstance(options.get('fill_block'), Block):
fill(world, dimension, selection_box, options)
yield from fill(world, dimension, selection_box, options)
else:
wx.MessageBox('Please specify a block before running the fill operation')

Expand Down
9 changes: 8 additions & 1 deletion amulet_map_editor/plugins/operations/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from amulet.api.block import Block
from amulet.api.selection import Selection
from amulet.api.data_types import Dimension
from amulet_map_editor.amulet_wx.block_select import BlockDefine
from amulet_map_editor.amulet_wx.simple import SimpleDialog, SimplePanel

Expand All @@ -13,7 +14,7 @@

def replace(
world: "World",
dimension: int,
dimension: Dimension,
selection: Selection,
options: dict
):
Expand All @@ -30,6 +31,9 @@ def replace(
original_block_matches = []
universal_block_count = 0

iter_count = len(list(world.get_chunk_slices(selection, dimension)))
count = 0

for chunk, slices, _ in world.get_chunk_slices(selection, dimension):
if universal_block_count < len(world.palette):
for universal_block_id in range(universal_block_count, len(world.palette)):
Expand All @@ -51,6 +55,9 @@ def replace(
chunk.blocks[slices] = blocks
chunk.changed = True

count += 1
yield 100 * count / iter_count


def show_ui(parent, world: "World", options: dict) -> dict:
dialog = SimpleDialog(parent, 'Replace')
Expand Down
4 changes: 1 addition & 3 deletions amulet_map_editor/plugins/programs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def __init__(self, parent, path):
self._finished = True

def menu(self, menu: MenuData) -> MenuData:
menu.setdefault('&File', {}).setdefault('system', {}).setdefault('Save\tCtrl+s', lambda evt: self.world.save())
# menu.setdefault('&File', {}).setdefault('system', {}).setdefault('Save As', lambda evt: self.GetGrandParent().close_world(self.world.world_path))
menu.setdefault('&File', {}).setdefault('exit', {}).setdefault('Close World\tCtrl+w', lambda evt: self.GetGrandParent().close_world(self.world.world_path))
menu.setdefault('&File', {}).setdefault('exit', {}).setdefault('Close World', lambda evt: self.GetGrandParent().close_world(self.world.world_path))
return self._extensions[self.GetSelection()].menu(menu)

def _load_extensions(self):
Expand Down
4 changes: 2 additions & 2 deletions amulet_map_editor/plugins/programs/convert/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def _help_controls(self):
webbrowser.open("https://github.com/Amulet-Team/Amulet-Map-Editor/tree/master/amulet_map_editor/plugins/programs/convert/readme.md")

def _show_world_select(self, evt):
self.Disable()
WorldSelectWindow(self._output_world_callback, self.Enable)
select_world = WorldSelectWindow(self, self._output_world_callback)
select_world.ShowModal()

def _output_world_callback(self, path):
if path == self.world.world_path:
Expand Down
Empty file.
Loading

0 comments on commit 2ef57d0

Please sign in to comment.