Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the views preview #126

Merged
merged 32 commits into from Jul 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
23dc195
Views : starting to implement the function which shows the selected
egofree71 Jul 3, 2014
8c7bccd
Views : center the selected view in the viewport.
egofree71 Jul 3, 2014
0a098da
Views : calculate the offsets between the room and the editor
egofree71 Jul 3, 2014
4457d60
Views : use method visualToComponent in Visual Panel to take into
egofree71 Jul 5, 2014
2a5a046
Views : test if the new position of the viewport is above the origin
egofree71 Jul 5, 2014
7960951
Views: debugging when testing the new position of the viewport.
egofree71 Jul 6, 2014
e8172b0
Views : if the view is not visible or if the views are not enabled,
egofree71 Jul 6, 2014
d94d188
Views : get the first instance in room of the 'Object following' object.
egofree71 Jul 6, 2014
5aaa07e
Views : center the window on the 'object following' first instance.
egofree71 Jul 6, 2014
a21e0f1
Views : display the view with 'object following' in the center of the
egofree71 Jul 6, 2014
90ba6b9
Views : if the view object has been changed, update the view's display.
egofree71 Jul 6, 2014
30cbe32
Views : clean-up.
egofree71 Jul 7, 2014
f4fe2db
Views : testing.
egofree71 Jul 7, 2014
72becce
Views : clean-up.
egofree71 Jul 8, 2014
cb84722
Views : if we are modifying the dimension of a view with an 'object
egofree71 Jul 8, 2014
709ea75
Views : views are centered correctly when zoome scale is two.
egofree71 Jul 9, 2014
8486f6e
Views : use the instance left upper location to center view.
egofree71 Jul 9, 2014
6f725de
Views : if the visible property of a view is changed, update the
egofree71 Jul 10, 2014
3a27a17
Views : clean-up.
egofree71 Jul 10, 2014
d427874
Views : Take into the zoom scale when there is an 'object to follow'.
egofree71 Jul 10, 2014
b0212e3
Views : if the view position is above the viewport coordinates, use the
egofree71 Jul 10, 2014
d9de8c7
Views : testing when zoom scale < 1
egofree71 Jul 10, 2014
9d3b3e8
Views : correctly centering views when zoom level < 1, and renaming a
egofree71 Jul 11, 2014
6dd737c
Views : Centering views with 'object following' when zoomscale < 1.
egofree71 Jul 11, 2014
996546d
Views : When there is an 'object to follow',no need to use zoomLevel
egofree71 Jul 12, 2014
e8deda2
Views : when then 'shows views' menu is called, get the 'object to
egofree71 Jul 12, 2014
c590582
Views : When the 'show views' menu is called, reset the 'object to
egofree71 Jul 12, 2014
65e997e
Views : clean-up.
egofree71 Jul 12, 2014
8b860b2
Views : clean-up.
egofree71 Jul 12, 2014
ae4065a
Views : display the border zone.
egofree71 Jul 16, 2014
dae0331
Views : don't draw the border zone when it's empty.
egofree71 Jul 16, 2014
ab90846
Undo : added the 'undo history size' in preference settings.
egofree71 Jul 17, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 73 additions & 0 deletions org/lateralgm/components/visual/RoomEditor.java
Expand Up @@ -47,6 +47,8 @@
import org.lateralgm.resources.sub.Tile;
import org.lateralgm.resources.sub.Instance.PInstance;
import org.lateralgm.resources.sub.Tile.PTile;
import org.lateralgm.resources.sub.View.PView;
import org.lateralgm.resources.sub.View;
import org.lateralgm.subframes.RoomFrame;
import org.lateralgm.subframes.CodeFrame;
import org.lateralgm.ui.swing.visuals.RoomVisual;
Expand Down Expand Up @@ -587,6 +589,7 @@ public Object validate(PRoomEditor k, Object v)
case SHOW_OBJECTS:
case SHOW_TILES:
case SHOW_VIEWS:
updateViewsObjectFollowingProperty();
roomVisual.setVisible(k.rvBinding,(Boolean) v);
break;
case DELETE_UNDERLYING_OBJECTS:
Expand All @@ -608,5 +611,75 @@ public Object validate(PRoomEditor k, Object v)
}
return v;
}

// Set the 'object to follow' coordinates for each view in the room
private void updateViewsObjectFollowingProperty()
{
// If the views are not enabled
if ((Boolean) room.get(PRoom.VIEWS_ENABLED) == false)
return;

for (View view : room.views)
{
// If the view is not visible, don't show it
if ((Boolean) view.properties.get(PView.VISIBLE) == false)
return;

// Get the reference to the 'Object following' object
ResourceReference<GmObject> objectToFollowReference = null;

// If there is 'Object following' object for the selected view
if (view.properties.get(PView.OBJECT) != null)
objectToFollowReference = view.properties.get(PView.OBJECT);

// If there is no object to follow, reset the corresponding view properties
if (objectToFollowReference == null)
{
view.properties.put(PView.OBJECT_FOLLOWING_X,-1);
view.properties.put(PView.OBJECT_FOLLOWING_Y,-1);
continue;
}

Instance instanceToFollow = null;

// get the first instance in the room
for (Instance instance : room.instances)
{
ResourceReference<GmObject> instanceObject = instance.properties.get(PInstance.OBJECT);

if (instanceObject == objectToFollowReference)
{
instanceToFollow = instance;
break;
}
}

// If there is an instance to follow
if (instanceToFollow != null)
{
// Properties of the view
Point viewPosition = new Point(0,0);
int viewWidth = (Integer) view.properties.get(PView.VIEW_W);
int viewHeight = (Integer) view.properties.get(PView.VIEW_H);

// Get the instance position
Point instancePosition = new Point(0,0);
instancePosition.x = (Integer) instanceToFollow.properties.get(PInstance.X);
instancePosition.y = (Integer) instanceToFollow.properties.get(PInstance.Y);

viewPosition.x = instancePosition.x - viewWidth / 2;
viewPosition.y = instancePosition.y - viewHeight / 2;

// Set this new location into the view properties
view.properties.put(PView.OBJECT_FOLLOWING_X, viewPosition.x);
view.properties.put(PView.OBJECT_FOLLOWING_Y, viewPosition.y);
}
else
{
view.properties.put(PView.OBJECT_FOLLOWING_X,-1);
view.properties.put(PView.OBJECT_FOLLOWING_Y,-1);
}
}
}
}
}
8 changes: 6 additions & 2 deletions org/lateralgm/components/visual/VisualPanel.java
Expand Up @@ -64,12 +64,12 @@ protected void componentToVisual(Rectangle r, int z)
r.height = zoom(r.height,2 - z);
}

protected void visualToComponent(Point p)
public void visualToComponent(Point p)
{
visualToComponent(p,zoom);
}

protected void visualToComponent(Point p, int z)
public void visualToComponent(Point p, int z)
{
p.x = zoom(p.x - overallBounds.x,z) + visualOffsetX(z);
p.y = zoom(p.y - overallBounds.y,z) + visualOffsetY(z);
Expand All @@ -84,6 +84,10 @@ protected void visualToComponent(Rectangle r, int z)
r.height = zoom(r.height,z);
}

public Rectangle getOverallBounds()
{
return overallBounds;
}
protected static double zoom(double d, int z)
{
return z > 0 ? z * d : d / (2 - z);
Expand Down
4 changes: 4 additions & 0 deletions org/lateralgm/main/Prefs.java
Expand Up @@ -139,6 +139,8 @@ public static void loadPrefs()
str = getString("externalSoundEditorCommand","null");
useExternalSoundEditor = !str.isEmpty() && !str.toLowerCase().equals("null");
externalSoundEditorCommand = str.toLowerCase().equals("system") ? null : str;

undoHistorySize = getInt("undoHistorySize", 100);
}

public static String iconPack;
Expand Down Expand Up @@ -183,4 +185,6 @@ public static void loadPrefs()
public static boolean useExternalSoundEditor;
public static String externalSoundEditorCommand;

public static int undoHistorySize;

}
7 changes: 7 additions & 0 deletions org/lateralgm/main/PrefsStore.java
Expand Up @@ -174,6 +174,13 @@ public static void setDockEventPanel(boolean selected)
Prefs.dockEventPanel = selected;
}

public static void setUndoHistorySize(int undoHistorySize)
{
PREFS.putInt("undoHistorySize",undoHistorySize);
Prefs.undoHistorySize = undoHistorySize;
}


public static int getNumberOfBackups()
{
return PREFS.getInt("FILE_BACKUP_COUNT",1);
Expand Down
3 changes: 3 additions & 0 deletions org/lateralgm/messages/messages.properties
Expand Up @@ -547,6 +547,9 @@ PreferencesFrame.TAB_MIME_PREFIX=MIME Types and Prefixes
PreferencesFrame.HINT_MIME_PREFIX=Resource extension MIME types and prefixes
PreferencesFrame.TAB_CODE_EDITOR=Code Editor
PreferencesFrame.HINT_CODE_EDITOR=Code Editor
PreferencesFrame.TAB_ROOM_EDITOR=Room Editor
PreferencesFrame.HINT_ROOM_EDITOR=Room Editor
PreferencesFrame.UNDO_HISTORY_SIZE=Undo history size (-1 for unlimited)
PreferencesFrame.APPLY_CHANGES=Apply Changes
PreferencesFrame.CLOSE=Close
PreferencesFrame.APPLY_CHANGES_NOTICE=You may need to restart the program for some changes to take effect.
Expand Down
4 changes: 2 additions & 2 deletions org/lateralgm/resources/sub/View.java
Expand Up @@ -20,11 +20,11 @@ public class View
public enum PView
{
VISIBLE,VIEW_X,VIEW_Y,VIEW_W,VIEW_H,PORT_X,PORT_Y,PORT_W,PORT_H,BORDER_H,BORDER_V,SPEED_H,
SPEED_V,OBJECT
SPEED_V,OBJECT, OBJECT_FOLLOWING_X, OBJECT_FOLLOWING_Y
}

private static final EnumMap<PView,Object> DEFS = PropertyMap.makeDefaultMap(PView.class,false,0,
0,640,480,0,0,640,480,32,32,-1,-1,null);
0,640,480,0,0,640,480,32,32,-1,-1,null,-1,-1);

public View()
{
Expand Down
43 changes: 42 additions & 1 deletion org/lateralgm/subframes/PreferencesFrame.java
Expand Up @@ -10,6 +10,7 @@

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
Expand All @@ -30,6 +31,7 @@
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import org.lateralgm.components.NumberField;
import org.lateralgm.components.impl.DocumentUndoManager;
import org.lateralgm.main.LGM;
import org.lateralgm.main.Prefs;
Expand All @@ -51,6 +53,9 @@ public class PreferencesFrame extends JFrame implements ActionListener
JTextField soundEditorPath, backgroundEditorPath, spriteEditorPath, codeEditorPath, numberBackupsField;
// Sounds use their own stored filename/extension, which may vary from sound to sound.
JTextField backgroundMIME, spriteMIME, scriptMIME;

// Room editor fields
NumberField undoHistorySize;

private JPanel makeGeneralPrefs()
{
Expand Down Expand Up @@ -402,6 +407,38 @@ private JPanel makeCodeEditorPrefs()
return p;
}

// Create the room editor panel
private Component makeRoomEditorPrefs()
{
JPanel p = new JPanel();

JLabel undoHistorySizeLabel = new JLabel(Messages.getString("PreferencesFrame.UNDO_HISTORY_SIZE") + " : ");
undoHistorySize = new NumberField(-1, 999999, Prefs.undoHistorySize);

GroupLayout gl = new GroupLayout(p);
gl.setAutoCreateGaps(true);
gl.setAutoCreateContainerGaps(true);

gl.setHorizontalGroup(
gl.createSequentialGroup()
.addGroup(gl.createParallelGroup(Alignment.TRAILING)
.addComponent(undoHistorySizeLabel))
.addGroup(gl.createParallelGroup()
.addComponent(undoHistorySize, 100, 100, 100))
);

gl.setVerticalGroup(
gl.createSequentialGroup()
.addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(undoHistorySizeLabel)
.addComponent(undoHistorySize, 18, 18, 18))
);

p.setLayout(gl);

return p;
}

public PreferencesFrame()
{
setAlwaysOnTop(false);
Expand All @@ -424,6 +461,8 @@ public PreferencesFrame()
/**/null,makeMimePrefixPrefs(),Messages.getString("PreferencesFrame.HINT_MIME_PREFIX")); //$NON-NLS-1$
tabs.addTab(Messages.getString("PreferencesFrame.TAB_CODE_EDITOR"), //$NON-NLS-1$
/**/null,makeCodeEditorPrefs(),Messages.getString("PreferencesFrame.HINT_CODE_EDITOR")); //$NON-NLS-1$
tabs.addTab(Messages.getString("PreferencesFrame.TAB_ROOM_EDITOR"), //$NON-NLS-1$
/**/null,makeRoomEditorPrefs(),Messages.getString("PreferencesFrame.HINT_ROOM_EDITOR")); //$NON-NLS-1$

JPanel p = new JPanel();
GroupLayout gl = new GroupLayout(p);
Expand Down Expand Up @@ -451,7 +490,7 @@ public PreferencesFrame()

add(p,BorderLayout.SOUTH);
}

public void SavePreferences()
{
LGM.iconspack = (String)iconCombo.getSelectedItem();
Expand All @@ -472,6 +511,8 @@ public void SavePreferences()
PrefsStore.setSoundEditorCommand(soundEditorPath.getText());
PrefsStore.setScriptEditorCommand(codeEditorPath.getText());
PrefsStore.setDockEventPanel(dockEvent.isSelected());
PrefsStore.setDockEventPanel(dockEvent.isSelected());
PrefsStore.setUndoHistorySize(undoHistorySize.getIntValue());
}

public void ResetPreferences()
Expand Down