diff --git a/source/GM-TE/GMTEEditor.class.st b/source/GM-TE/GMTEEditor.class.st index c4e2db17..7173b72c 100644 --- a/source/GM-TE/GMTEEditor.class.st +++ b/source/GM-TE/GMTEEditor.class.st @@ -6,19 +6,23 @@ Class { { #category : #'as yet unclassified', - #'squeak_changestamp' : 'TW 5/19/2024 17:18' + #'squeak_changestamp' : 'Alex M 5/20/2024 15:46' } GMTEEditor class >> createCommandBarWithBuilder: aBuilder [ ^aBuilder pluggablePanelSpec new name: 'command bar'; children: {aBuilder pluggableButtonSpec new + name: 'export'; label: 'Export'; frame: (LayoutFrame fractions: (0 @ 0 corner: 0.3 @ 1) offsets: nil). aBuilder pluggableButtonSpec new frame: (LayoutFrame fractions: (0.3 @ 0 corner: 0.6 @ 1) offsets: nil); + action: [GMTEEditor loadTileSetWithDimensions: 16@16]; + name: 'import'; label: 'Import'. aBuilder pluggableButtonSpec new frame: (LayoutFrame fractions: (0.6 @ 0 corner: 0.9 @ 1) offsets: nil); + name: 'openInWorld'; label: 'Open in World'}; frame: (LayoutFrame fractions: (0 @ 0 corner: 1 @ 0.1) offsets: nil); yourself @@ -37,11 +41,11 @@ GMTEEditor class >> createLayersWithBuilder: aBuilder [ { #category : #'as yet unclassified', - #'squeak_changestamp' : 'JS 5/19/2024 17:12' + #'squeak_changestamp' : 'Alex M 5/20/2024 15:44' } GMTEEditor class >> createTileViewerWithBuilder: aBuilder [ ^aBuilder pluggablePanelSpec new - name: 'Tile Viewer'; + name: 'tile viewer'; layout: #horizontal; frame: (LayoutFrame fractions: (0.2 @ 0.1 corner: 0.8 @ 0.8) offsets: nil); yourself @@ -49,11 +53,11 @@ GMTEEditor class >> createTileViewerWithBuilder: aBuilder [ { #category : #'as yet unclassified', - #'squeak_changestamp' : 'TW 5/19/2024 17:28' + #'squeak_changestamp' : 'Alex M 5/20/2024 16:46' } GMTEEditor class >> createTilestoreWithBuilder: aBuilder [ - ^aBuilder pluggablePanelSpec new + ^aBuilder pluggableScrollPaneSpec new frame: ((0 @ 0.1) corner: 0.2 @ 1); name: 'tile store'; layout: #vertical; @@ -79,11 +83,48 @@ GMTEEditor class >> createTrayWithBuilder: aBuilder [ { #category : #'as yet unclassified', - #'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:57' + #'squeak_changestamp' : 'Alex M 5/20/2024 17:44' +} +GMTEEditor class >> loadTileSetWithDimensions: aPoint [ + + "Do we really leaves this here or do we create an extra class for" + + | fc stream form tile tile_width tile_height image morphs| + + fc := FileChooser new. + fc initializeAsSystemWindowWithCaptionPane. + fc setCaption: 'Select a picture file' translated. + fc setSuffixes: {'png' . 'gif' . 'bmp' . 'jpg' . 'jpeg' }. + stream := fc open. + + stream ifNil: [^ nil]. + + form := Form fromBinaryStream: stream. + + morphs := OrderedCollection new. + + tile_width := aPoint x. + tile_height := aPoint y. + "TODO: refactor into non C-like code" + 0 to: (form height - tile_height) by: tile_height do:[:y| + 0 to: (form width - tile_width) by: tile_width do: [:x| + tile := form contentsOfArea: (Rectangle origin: x@y extent: tile_width@tile_height). + image := GMTETileSelector new + image: (tile scaledToWidth: 50). + morphs add: image. + ]. + ]. + + ^ morphs. +] + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Alex M 5/20/2024 17:43' } GMTEEditor class >> new [ - |builder spec morph tileMatrixMorph tileStore tileViewer| + |builder spec morph tileMatrixMorph tileStore tileViewer commandBar| super new. builder := ToolBuilder default. spec := builder pluggableWindowSpec new @@ -97,15 +138,18 @@ GMTEEditor class >> new [ self createLayersWithBuilder: builder}; yourself. morph := builder build: spec. + commandBar := morph submorphNamed: 'command bar'. tileStore := morph submorphNamed: 'tile store'. - tileViewer := (morph submorphNamed: 'Tile Viewer'). - - tileStore addMorph: Morph new. - tileStore addMorph: (Morph new - color: Color red; - yourself). + tileViewer := morph submorphNamed: 'tile viewer'. + + "TODO 16 by 16 is a magic number. Where do we store tile dimensions?" + (commandBar submorphNamed: 'import') action: [ + "TODO make multiple sprite sets available?" + tileStore morph removeAllMorphs; + addAllMorphs: (GMTEEditor loadTileSetWithDimensions: 16@16). + ]. - tileMatrixMorph := GMTETileMap tileWidth: 20 tileHeight: 20 padding: 0.15 sizeRatio: 1. + tileMatrixMorph := GMTETileMap tileWidth: 10 tileHeight: 10 padding: 0.0 sizeRatio: 2. tileViewer addMorph: tileMatrixMorph. diff --git a/source/GM-TE/GMTETileMap.class.st b/source/GM-TE/GMTETileMap.class.st index 2d2e5a59..8ff557dd 100644 --- a/source/GM-TE/GMTETileMap.class.st +++ b/source/GM-TE/GMTETileMap.class.st @@ -111,21 +111,29 @@ GMTETileMap >> borderTileWidth: anObject [ { #category : #updating, - #'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:49' + #'squeak_changestamp' : 'Valentin Teutschbein 5/20/2024 20:30' } GMTETileMap >> clearTiles [ - self gridTileMatrix do: [:aTile | aTile delete]. + self gridTileMatrix do: [:aTile | aTile delete] ] { - #category : #updating, - #'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:55' + #category : #'import/export', + #'squeak_changestamp' : 'Alex M 5/20/2024 13:15' +} +GMTETileMap >> exportAsImage [ + "Add further options in the future like choosing file format?" + self exportAsPNG +] + +{ + #category : #accessing, + #'squeak_changestamp' : 'Valentin Teutschbein 5/20/2024 20:10' } GMTETileMap >> extent: aPoint [ self gridTileMatrix ifNotNil: [self rescaleMap]. - super extent: aPoint. ] @@ -334,17 +342,16 @@ GMTETileMap >> processTiles [ { #category : #updating, - #'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:50' + #'squeak_changestamp' : 'Valentin Teutschbein 5/20/2024 20:30' } GMTETileMap >> rescaleMap [ - "comment stating purpose of message" self rescaleMapWidth: self tileWidth height: self tileHeight padding: self mapPadding ] { #category : #updating, - #'squeak_changestamp' : 'Ivo Zilkenat 5/20/2024 19:50' + #'squeak_changestamp' : 'Valentin Teutschbein 5/20/2024 20:18' } GMTETileMap >> rescaleMapWidth: aWidth height: aHeigth padding: aPadding [ "Rescale map & trigger update" @@ -353,8 +360,7 @@ GMTETileMap >> rescaleMapWidth: aWidth height: aHeigth padding: aPadding [ self clearTiles. self setDimensionsWidth: aWidth height: aHeigth padding: aPadding. - self updateMap. - + self updateMap ] { diff --git a/source/GM-TE/GMTETileSelector.class.st b/source/GM-TE/GMTETileSelector.class.st new file mode 100644 index 00000000..26327c85 --- /dev/null +++ b/source/GM-TE/GMTETileSelector.class.st @@ -0,0 +1,15 @@ +Class { + #name : #GMTETileSelector, + #superclass : #ImageMorph, + #category : #'GM-TE' +} + +{ + #category : #'as yet unclassified', + #'squeak_changestamp' : 'Alex M 5/20/2024 18:29' +} +GMTETileSelector >> handlesMouseDown: evt [ + "handlesMouseStillDown: for tiles" + Transcript show: 'test'. + ^ true. +]