Skip to content

Commit

Permalink
edited preview before importing
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksander Morgensterns committed May 22, 2024
1 parent 805e0dc commit 31ac11e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 15 deletions.
105 changes: 92 additions & 13 deletions source/GM-TE/GMTEEditor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,70 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 5/22/2024 14:32'
}
GMTEEditor class >> confirmPreviewOf: morphArray withDimensions: aPoint [
"TODO: Could break with too big tilesets. Maybe filter only first 100 tiles?"
|img dialog|

img := Morph new
beTransparent;
extent:(aPoint);
yourself.
(img layoutPolicy: TableLayout new)
listDirection: #leftToRight;
wrapDirection: #leftToRight.

(morphArray reversed) do: [:morph|
img addMorph: (ImageMorph new image: (morph image scaledToWidth: 50); borderColor: (Color red); borderWidth:1;yourself).
].

dialog := DialogWindow new
title: 'Preview';
message: 'Import Tileset?';
addPaneMorph: img;
createButton: 'Yes' translated value: true;
createCancelButton: 'No' translated value: false;
selectedButtonIndex: 1; "YES"
registerKeyboardShortcuts.
dialog paneMorph extent: img extent.
^ dialog getUserResponseAtHand.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 5/22/2024 14:42'
}
GMTEEditor class >> confirmPreviewOf: morphArray withDimensions: aPoint withTileSize: aNumber [
"TODO: Could break with too big tilesets. Maybe filter only first 100 tiles?"
|img dialog|

img := Morph new
beTransparent;
extent:(aPoint);
yourself.
(img layoutPolicy: TableLayout new)
listDirection: #leftToRight;
wrapDirection: #leftToRight.

(morphArray reversed) do: [:morph|
img addMorph: (ImageMorph new image: (morph image scaledToWidth: aNumber); borderColor: (Color red); borderWidth:1;yourself).
].

dialog := DialogWindow new
title: 'Preview';
message: 'Import Tileset?';
addPaneMorph: img;
createButton: 'Yes' translated value: true;
createCancelButton: 'No' translated value: false;
selectedButtonIndex: 1; "YES"
registerKeyboardShortcuts.
dialog paneMorph extent: img extent.
^ dialog getUserResponseAtHand.
]

{
#category : #construction,
#'squeak_changestamp' : 'TW 5/22/2024 11:41'
}
GMTEEditor class >> createCommandBarWithBuilder: aBuilder for: aModel [
Expand Down Expand Up @@ -51,7 +115,7 @@ GMTEEditor class >> createCommandBarWithBuilder: aBuilder for: aModel [
]

{
#category : #'as yet unclassified',
#category : #construction,
#'squeak_changestamp' : 'TW 5/22/2024 01:15'
}
GMTEEditor class >> createLayersWithBuilder: aBuilder for: aModel [
Expand All @@ -71,7 +135,7 @@ GMTEEditor class >> createLayersWithBuilder: aBuilder for: aModel [
]

{
#category : #'as yet unclassified',
#category : #construction,
#'squeak_changestamp' : 'Alex M 5/21/2024 15:49'
}
GMTEEditor class >> createTileViewerWithBuilder: aBuilder [
Expand All @@ -84,7 +148,7 @@ GMTEEditor class >> createTileViewerWithBuilder: aBuilder [
]

{
#category : #'as yet unclassified',
#category : #construction,
#'squeak_changestamp' : 'Alex M 5/21/2024 14:08'
}
GMTEEditor class >> createTilestoreWithBuilder: aBuilder [
Expand All @@ -105,7 +169,7 @@ GMTEEditor class >> createTilestoreWithBuilder: aBuilder [
]

{
#category : #'as yet unclassified',
#category : #construction,
#'squeak_changestamp' : 'TW 5/22/2024 11:50'
}
GMTEEditor class >> createTrayWithBuilder: aBuilder [
Expand Down Expand Up @@ -197,13 +261,13 @@ GMTEEditor class >> layerList [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'TW 5/22/2024 12:08'
#'squeak_changestamp' : 'Alex M 5/22/2024 14:50'
}
GMTEEditor class >> loadTileSetWithDimensions: aPoint model: aModel [
"The source argument is mostly for debugging. Make it nicer with objects"
"Do we really leaves this here or do we create an extra class for"

| fc stream form tile tileWidth tileHeight image morphs |
| fc stream form tile tileWidth tileHeight image morphs previewDimensions previewTileSize |

fc := FileChooser new.
fc initializeAsSystemWindowWithCaptionPane.
Expand All @@ -229,13 +293,18 @@ GMTEEditor class >> loadTileSetWithDimensions: aPoint model: aModel [
morphs add: image.
].
].

"TODO: This is maybe not the nicest way to write it. Maybe put more of it into confirmPreview?"
previewTileSize := (form width max: 500) / (form width / tileWidth).
previewDimensions := (form extent / aPoint * previewTileSize) + (2*((form width / tileWidth + 1)@(form height / tileHeight + 1))).
(GMTEEditor confirmPreviewOf: morphs withDimensions: previewDimensions withTileSize: previewTileSize) ifFalse:[^ nil].

^ morphs.
]

{
#category : #initialisation,
#'squeak_changestamp' : 'TW 5/22/2024 12:35'
#'squeak_changestamp' : 'Alex M 5/22/2024 13:29'
}
GMTEEditor >> buildWith: builder [
"called it builder instead of aBuilder since every other implementation does that"
Expand All @@ -262,8 +331,6 @@ GMTEEditor >> buildWith: builder [
panel := GMTETileContainer withParent: self tileStore.

self tileStore morph: panel.

self tileStore on: #mouseMove send: [Transcript show: 'hello'] to: self.

selectedTile := ImageMorph new.
"TODO: Make this nicer."
Expand Down Expand Up @@ -309,15 +376,27 @@ GMTEEditor >> exportAsImage [

{
#category : #'button functions',
#'squeak_changestamp' : 'TW 5/22/2024 12:10'
#'squeak_changestamp' : 'Alex M 5/22/2024 14:24'
}
GMTEEditor >> import [

"TODO 16 by 16 is a magic number. Where do we store tile dimensions?"
"TODO make multiple sprite sets available?"
| tiles tile_height dimensions ratio|
ratio := 1. "TODO: Where is ratio stored? When do we enter it?"
tile_height := FillInTheBlankMorph request: 'Enter tile height (width is calculated by ratio)'.

(tile_height = '')
ifTrue: [^ nil]
ifFalse:[tile_height := tile_height asInteger].

dimensions := (tile_height @ (tile_height * ratio)).
tiles := GMTEEditor loadTileSetWithDimensions: dimensions model: self.

tiles
ifNil: [^ nil].

self tileStore morph
removeAllMorphs;
addAllMorphs: (GMTEEditor loadTileSetWithDimensions: 16@16 model: self).
addAllMorphs: tiles.
]

{
Expand Down
4 changes: 2 additions & 2 deletions source/GM-TE/GMTETileContainer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ GMTETileContainer >> parent: anObject [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Alex M 5/21/2024 16:50'
#'squeak_changestamp' : 'Alex M 5/22/2024 13:15'
}
GMTETileContainer >> step [
self parent ifNotNil:[self extent: parent extent]
self parent ifNotNil:[self extent: parent extent ]
]

{
Expand Down

0 comments on commit 31ac11e

Please sign in to comment.