Skip to content

Commit

Permalink
Area viewer: Bugfixes and updates
Browse files Browse the repository at this point in the history
- bugfix in popup menu on ambient sound items 
- options to set frame rate for overlays and animations
- added "Update map" option to toolbar
  • Loading branch information
Argent77 committed Mar 6, 2014
1 parent 4163df2 commit b019a5e
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 66 deletions.
106 changes: 70 additions & 36 deletions src/infinity/resource/are/viewer/AreaViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ public void actionPerformed(ActionEvent event)
} finally {
WindowBlocker.blockWindow(this, false);
}
WindowBlocker.blockWindow(this, false);
} else if (cb == cbDrawClosed) {
WindowBlocker.blockWindow(this, true);
try {
Expand Down Expand Up @@ -306,8 +305,12 @@ public void actionPerformed(ActionEvent event)
} else if (event.getSource() == tbSettings) {
viewSettings();
} else if (event.getSource() == tbRefresh) {
// TODO: add "Refresh map structures" functionality
JOptionPane.showMessageDialog(this, "Not yet implemented...", "Reload map structures", JOptionPane.INFORMATION_MESSAGE);
WindowBlocker.blockWindow(this, true);
try {
reloadLayers();
} finally {
WindowBlocker.blockWindow(this, false);
}
} else if (ArrayUtil.indexOf(tbAddLayerItem, event.getSource()) >= 0) {
// TODO: include "Add layer item" functionality
int index = ArrayUtil.indexOf(tbAddLayerItem, event.getSource());
Expand Down Expand Up @@ -912,7 +915,7 @@ private void init()
tbRefresh = new JButton(Icons.getIcon("icn_refresh.png"));
tbRefresh.setToolTipText("Update map");
tbRefresh.addActionListener(this);
// toolBar.add(tbRefresh);
toolBar.add(tbRefresh);

updateToolBarButtons();

Expand Down Expand Up @@ -991,7 +994,7 @@ private void initGuiSettings()
// initializing layers
layerManager = new LayerManager(getCurrentAre(), getCurrentWed(), this);
layerManager.setDoorState(Settings.DrawClosed ? ViewerConstants.DOOR_CLOSED : ViewerConstants.DOOR_OPEN);
layerManager.setScheduleEnabled(true);
layerManager.setScheduleEnabled(Settings.EnableSchedules);
layerManager.setSchedule(LayerManager.toSchedule(getHour()));
addLayerItems();
updateScheduledItems();
Expand Down Expand Up @@ -1047,6 +1050,8 @@ private void updateWindowTitle()
dayNight = "day";
}

String scheduleState = Settings.EnableSchedules ? "enabled" : "disabled";

String doorState = isDoorStateClosed() ? "closed" : "open";

String overlayState;
Expand All @@ -1060,8 +1065,8 @@ private void updateWindowTitle()

String gridState = isTileGridEnabled() ? "enabled" : "disabled";

setTitle(String.format("%1$s (Time: %2$02d:00 (%3$s), Doors: %4$s, Overlays: %5$s, Grid: %6$s, Zoom: %7$d%%)",
windowTitle, getHour(), dayNight, doorState, overlayState, gridState, zoom));
setTitle(String.format("%1$s (Time: %2$02d:00 (%3$s), Schedules: %4$s, Doors: %5$s, Overlays: %6$s, Grid: %7$s, Zoom: %8$d%%)",
windowTitle, getHour(), dayNight, scheduleState, doorState, overlayState, gridState, zoom));
}

// Returns the general day time (day/twilight/night)
Expand Down Expand Up @@ -1146,7 +1151,7 @@ private synchronized void setVisualState(int hour)
}
if (!rcCanvas.isMapLoaded() || rcCanvas.getWed() != map.getWed(Map.MAP_DAY)) {
rcCanvas.loadMap(map.getWed(Map.MAP_DAY));
reloadWedLayers();
reloadWedLayers(true);
}
rcCanvas.setLighting(index);
break;
Expand All @@ -1156,7 +1161,7 @@ private synchronized void setVisualState(int hour)
}
if (!rcCanvas.isMapLoaded() || rcCanvas.getWed() != map.getWed(Map.MAP_DAY)) {
rcCanvas.loadMap(map.getWed(Map.MAP_DAY));
reloadWedLayers();
reloadWedLayers(true);
}
rcCanvas.setLighting(index);
break;
Expand All @@ -1167,7 +1172,7 @@ private synchronized void setVisualState(int hour)
if (!rcCanvas.isMapLoaded() || map.hasExtendedNight()) {
if (rcCanvas.getWed() != map.getWed(Map.MAP_NIGHT)) {
rcCanvas.loadMap(map.getWed(Map.MAP_NIGHT));
reloadWedLayers();
reloadWedLayers(true);
}
}
if (!map.hasExtendedNight()) {
Expand Down Expand Up @@ -1548,18 +1553,22 @@ private boolean updateItemPopup(Point canvasCoords)
AbstractLayerItem[] items = itemList.get(j).getLayerItems();
// for each layer item...
for (int k = 0; k < items.length; k++) {
// special case: Ambient/Ambient range (avoid duplicates)
// special case: Ambient/Ambient range (avoiding duplicates)
if (stacking == LayerStackingType.Ambient &&
isLayerEnabled(LayerStackingType.AmbientRange) &&
cbLayerAmbientRange.isSelected() &&
((LayerObjectAmbient)itemList.get(j)).isLocal()) {
// skipped: will be handled in AmbientRange layer
break;
}
if (stacking == LayerStackingType.AmbientRange &&
((LayerObjectAmbient)itemList.get(j)).isLocal() &&
k == ViewerConstants.AMBIENT_ITEM_ICON) {
// considering ranged item only
continue;
if (stacking == LayerStackingType.AmbientRange) {
if (((LayerObjectAmbient)itemList.get(j)).isLocal() &&
k == ViewerConstants.AMBIENT_ITEM_ICON) {
// considering ranged item only
continue;
} else if (!((LayerObjectAmbient)itemList.get(j)).isLocal()) {
// global sounds don't have ambient ranges
break;
}
}
itemLocation.x = canvasCoords.x - items[k].getX();
itemLocation.y = canvasCoords.y - items[k].getY();
Expand Down Expand Up @@ -1631,45 +1640,61 @@ private void showItemPopup(MouseEvent event)
// Updates all available layer items
private void reloadLayers()
{
reloadAreLayers();
reloadWedLayers();
reloadAreLayers(false);
reloadWedLayers(false);
orderLayerItems();
}

// Updates ARE-related layer items
private void reloadAreLayers()
private void reloadAreLayers(boolean order)
{
if (layerManager != null) {
for (int i = 0; i < LayerStackingType.values().length; i++) {
LayerStackingType layer = LayerStackingType.values()[i];
if (layer != LayerStackingType.DoorPoly && layer != LayerStackingType.WallPoly) {
removeLayerItems(layer);
layerManager.setAreResource(getCurrentAre());
updateLayerItems(layer);
addLayerItems(layer);
if (layer != LayerStackingType.AmbientRange) {
showLayer(Settings.stackingToLayer(layer), cbLayers[i].isSelected());
// layerManager.setAreResource(getCurrentAre());
for (int i = 0; i < LayerManager.getLayerTypeCount(); i++) {
LayerType layer = LayerManager.getLayerType(i);
LayerStackingType layer2 = Settings.layerToStacking(layer);
if (layer != LayerType.DoorPoly && layer != LayerType.WallPoly) {
removeLayerItems(layer2);
if (layer == LayerType.Ambient) {
removeLayerItems(LayerStackingType.AmbientRange);
}
layerManager.reload(layer);
updateLayerItems(layer2);
addLayerItems(layer2);
if (layer == LayerType.Ambient) {
updateLayerItems(LayerStackingType.AmbientRange);
addLayerItems(LayerStackingType.AmbientRange);
}
showLayer(layer, cbLayers[i].isSelected());
}
}
updateAmbientRange();
updateRealAnimation();
}
updateAmbientRange();
updateRealAnimation();
if (order) {
orderLayerItems();
}
rcCanvas.repaint();
}

// Updates WED-related layer items
private void reloadWedLayers()
private void reloadWedLayers(boolean order)
{
if (layerManager != null) {
removeLayerItems(LayerStackingType.DoorPoly);
removeLayerItems(LayerStackingType.WallPoly);
layerManager.setWedResource(getCurrentWed());
updateLayerItems(LayerStackingType.DoorPoly);
addLayerItems(LayerStackingType.DoorPoly);
showLayer(LayerType.DoorPoly, cbLayers[LayerManager.getLayerTypeIndex(LayerType.DoorPoly)].isSelected());
updateLayerItems(LayerStackingType.WallPoly);
addLayerItems(LayerStackingType.WallPoly);
showLayer(LayerType.DoorPoly, cbLayers[LayerManager.getLayerTypeIndex(LayerType.DoorPoly)].isSelected());
showLayer(LayerType.WallPoly, cbLayers[LayerManager.getLayerTypeIndex(LayerType.WallPoly)].isSelected());
}
if (order) {
orderLayerItems();
}
rcCanvas.repaint();
}


Expand Down Expand Up @@ -1769,11 +1794,11 @@ private Window getViewerWindow(AbstractStruct as)
return NearInfinity.getInstance();
}


// Applying time schedule settings to layer items
private void updateTimeSchedules()
{
layerManager.setScheduleEnabled(Settings.EnableSchedules);
updateWindowTitle();
}

// Updates the state of the ambient sound range checkbox and associated functionality
Expand Down Expand Up @@ -1953,14 +1978,16 @@ private void orderLayerItems()
for (int j = 0; j < list.size(); j++) {
if (Settings.ListLayerOrder.get(i) == LayerStackingType.AmbientRange) {
// Special: process ambient ranges only
AbstractLayerItem item = list.get(j).getLayerItem(ViewerConstants.AMBIENT_ITEM_RANGE);
LayerObjectAmbient obj = (LayerObjectAmbient)list.get(j);
AbstractLayerItem item = obj.getLayerItem(ViewerConstants.AMBIENT_ITEM_RANGE);
if (item != null) {
rcCanvas.setComponentZOrder(item, index);
index++;
}
} else if (Settings.ListLayerOrder.get(i) == LayerStackingType.Ambient) {
// Special: process ambient icons only
AbstractLayerItem item = list.get(j).getLayerItem(ViewerConstants.AMBIENT_ITEM_ICON);
LayerObjectAmbient obj = (LayerObjectAmbient)list.get(j);
AbstractLayerItem item = obj.getLayerItem(ViewerConstants.AMBIENT_ITEM_ICON);
rcCanvas.setComponentZOrder(item, index);
index++;
} else {
Expand Down Expand Up @@ -2096,6 +2123,13 @@ private void applySettings()
layerManager.setRealAnimationInterpolation(ViewerConstants.TYPE_NEAREST_NEIGHBOR);
break;
}
// applying frame rate to animated overlays
int interval = (int)(1000.0 / Settings.FrameRateOverlays);
if (interval != timerOverlays.getDelay()) {
timerOverlays.setDelay(interval);
}
// applying frame rate to background animations
layerManager.setRealAnimationFrameRate(Settings.FrameRateAnimations);
}
}

Expand Down
31 changes: 31 additions & 0 deletions src/infinity/resource/are/viewer/LayerAnimation.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class LayerAnimation extends BasicLayer<LayerObjectAnimation>

private boolean realEnabled, realPlaying, forcedInterpolation;
private int frameState, interpolationType;
private double frameRate;

public LayerAnimation(AreResource are, AreaViewer viewer)
{
Expand Down Expand Up @@ -238,6 +239,36 @@ public void setRealAnimationFrameState(int state)
}
}

/**
* Returns the frame rate used for playing back background animations.
* @return Frame rate in frames/second.
*/
public double getRealAnimationFrameRate()
{
return frameRate;
}

/**
* Specify a new frame rate for real animations.
* @param frameRate Frame rate in frames/second.
*/
public void setRealAnimationFrameRate(double frameRate)
{
frameRate = Math.min(Math.max(frameRate, 1.0), 30.0);
if (frameRate != this.frameRate) {
this.frameRate = frameRate;
List<LayerObjectAnimation> list = getLayerObjects();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
AnimatedLayerItem item = (AnimatedLayerItem)list.get(i).getLayerItem(ViewerConstants.ANIM_ITEM_REAL);
if (item != null) {
item.setFrameRate(this.frameRate);
}
}
}
}
}

private void updateFrameState()
{
List<LayerObjectAnimation> list = getLayerObjects();
Expand Down
50 changes: 36 additions & 14 deletions src/infinity/resource/are/viewer/LayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
* Manages all layer objects of a single ARE map.
* @author argent77
*/
/*
* TODO: add interpolation type support for animations
* TODO: add update layer item methods for all layers
*/
public final class LayerManager
{
// Defines order of drawing
Expand Down Expand Up @@ -66,8 +62,9 @@ public final class LayerManager

private AreResource are;
private WedResource wed;
private boolean scheduleEnabled, forcedInterpolation;
private int schedule, interpolationType;
private boolean scheduleEnabled, animForcedInterpolation;
private int schedule, animInterpolationType;
private double animFrameRate;

/**
* Returns the number of supported layer types.
Expand Down Expand Up @@ -463,7 +460,7 @@ public void setRealAnimationPlaying(boolean play)
*/
public int getRealAnimationInterpolation()
{
return interpolationType;
return animInterpolationType;
}

/**
Expand All @@ -477,11 +474,11 @@ public void setRealAnimationInterpolation(int interpolationType)
case ViewerConstants.TYPE_NEAREST_NEIGHBOR:
case ViewerConstants.TYPE_BILINEAR:
case ViewerConstants.TYPE_BICUBIC:
if (interpolationType != this.interpolationType) {
this.interpolationType = interpolationType;
if (interpolationType != animInterpolationType) {
animInterpolationType = interpolationType;
LayerAnimation layer = (LayerAnimation)getLayer(LayerType.Animation);
if (layer != null) {
layer.setRealAnimationInterpolation(this.interpolationType);
layer.setRealAnimationInterpolation(animInterpolationType);
}
}
}
Expand All @@ -493,7 +490,7 @@ public void setRealAnimationInterpolation(int interpolationType)
*/
public boolean isRealAnimationForcedInterpolation()
{
return forcedInterpolation;
return animForcedInterpolation;
}

/**
Expand All @@ -502,11 +499,36 @@ public boolean isRealAnimationForcedInterpolation()
*/
public void setRealAnimationForcedInterpolation(boolean forced)
{
if (forced != forcedInterpolation) {
forcedInterpolation = forced;
if (forced != animForcedInterpolation) {
animForcedInterpolation = forced;
LayerAnimation layer = (LayerAnimation)getLayer(LayerType.Animation);
if (layer != null) {
layer.setRealAnimationForcedInterpolation(animForcedInterpolation);
}
}
}

/**
* Returns the frame rate used for playing back background animations.
* @return Frame rate in frames/second.
*/
public double getRealAnimationFrameRate()
{
return animFrameRate;
}

/**
* Specify a new frame rate for background animations.
* @param frameRate Frame rate in frames/second.
*/
public void setRealAnimationFrameRate(double frameRate)
{
frameRate = Math.min(Math.max(frameRate, 1.0), 30.0);
if (frameRate != this.animFrameRate) {
animFrameRate = frameRate;
LayerAnimation layer = (LayerAnimation)getLayer(LayerType.Animation);
if (layer != null) {
layer.setRealAnimationForcedInterpolation(forcedInterpolation);
layer.setRealAnimationFrameRate(animFrameRate);
}
}
}
Expand Down
Loading

0 comments on commit b019a5e

Please sign in to comment.