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

Progress info enhancements #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/

#Eclipse files
.project
.classpath

#generated maps
/maps

# IntelliJ project files
.idea
*.iml
out
2 changes: 0 additions & 2 deletions src/com/wurmonline/wurmapi/api/WurmAPI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.wurmonline.wurmapi.api;

import com.wurmonline.wurmapi.api.map.dump.Colorist;

import java.io.File;
import java.io.IOException;

Expand Down
14 changes: 7 additions & 7 deletions src/net/buddat/wgenerator/HeightMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.awt.image.BufferedImage;
import java.awt.image.DataBufferUShort;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -83,18 +84,17 @@ private void importHeightImage() {
}

long startTime = System.currentTimeMillis();

try {
DataBufferUShort buffer = (DataBufferUShort) heightImage.getRaster().getDataBuffer();
Raster data = heightImage.getData();

int[][] array = new int[mapSize][mapSize];
for (int x = 0; x < mapSize; x++) {
for (int y = 0; y < mapSize; y++) {

for (int x = 0; x < mapSize; x++) {
for (int y = 0; y < mapSize; y++) {
double[] dArray = null;

array[x][y] = buffer.getElem(x + y * mapSize);
dArray = data.getPixel(x,y, dArray);

setHeight(x, y, getHeight(x, y) + (array[x][y] / 65536f), false);
setHeight(x, y, getHeight(x, y) + (dArray[0] / 65536f), false);
}
}

Expand Down
38 changes: 27 additions & 11 deletions src/net/buddat/wgenerator/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.*;
import java.awt.Taskbar.State;

import javax.imageio.ImageIO;
import java.io.*;
Expand All @@ -43,6 +44,8 @@ public class MainWindow extends JFrame {
private Constants.VIEW_TYPE defaultView = Constants.VIEW_TYPE.HEIGHT;
private ProgressHandler progress;

private Taskbar taskbar = Taskbar.getTaskbar();

private JProgressBar progressBar;
private JLabel lblMemory;
private JPanel contentPane;
Expand Down Expand Up @@ -219,12 +222,14 @@ public MainWindow() {
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setLocationRelativeTo(null);
setContentPane(contentPane);


taskbar.setWindowProgressState(this, State.NORMAL);

JTabbedPane optionsPane = new JTabbedPane(JTabbedPane.TOP);

progressBar = new JProgressBar();
progressBar.setStringPainted(true);
progressBar.setString("");
progressBar.setString(Constants.READY);
progressBar.setEnabled(true);
progressBar.setValue(100);

Expand Down Expand Up @@ -1368,7 +1373,7 @@ private void init() {
setupButtonActions();
setRockTotal();
updateMapCoords(0,0,false);
progress = new ProgressHandler(progressBar,lblMemory);
progress = new ProgressHandler(progressBar,lblMemory, taskbar, this);
progress.update(100);
System.setErr(new PrintStream(new StreamCapturer(System.err,this)));

Expand Down Expand Up @@ -1712,7 +1717,8 @@ private void startLoading(String task) {
}

private void stopLoading() {
progress.update(100,"");
progress.update(100, Constants.READY);
taskbar.setWindowProgressValue(this, 0);
}

boolean actionReady() {
Expand Down Expand Up @@ -2014,11 +2020,13 @@ void actionResetBiomes () {

for (int i = 0; i < heightMap.getMapSize(); i++) {
for (int j = 0; j < heightMap.getMapSize(); j++) {
progress.update((int)((float)(i*heightMap.getMapSize()+j)/(heightMap.getMapSize()*heightMap.getMapSize())*100f));
int prog = (int)((float)(i*heightMap.getMapSize()+j)/(heightMap.getMapSize()*heightMap.getMapSize())*100f);
taskbar.setWindowProgressValue(this, prog);
progress.update(prog);
tileMap.addDirt(i, j, 0);
}
}

updateMapView();

genHistory.add("RESETBIOMES:null");
Expand Down Expand Up @@ -2472,7 +2480,9 @@ private void updateMapView() {
Graphics g = mapPanel.getMapImage().getGraphics();

for (int i = 0; i < heightMap.getMapSize(); i++) {
progress.update((int)((float)i/heightMap.getMapSize()*98f));
int prog = (int)((float)i/heightMap.getMapSize()*98f);
taskbar.setWindowProgressValue(this, prog);
progress.update(prog);
for (int j = 0; j < heightMap.getMapSize(); j++) {
g.setColor(new Color((float) heightMap.getHeight(i, j), (float) heightMap.getHeight(i, j), (float) heightMap.getHeight(i, j)));
g.fillRect(i, j, 1, 1);
Expand Down Expand Up @@ -2504,7 +2514,9 @@ private void updateAPIMap() {

try {
for (int i = 0; i < heightMap.getMapSize(); i++) {
progress.update((int)((float)i/heightMap.getMapSize()*100f/3));
int prog = (int)((float)i/heightMap.getMapSize()*100f/3);
taskbar.setWindowProgressValue(this, prog);
progress.update(prog);
for (int j = 0; j < heightMap.getMapSize(); j++) {
map.setSurfaceHeight(i, j, tileMap.getSurfaceHeight(i, j));
map.setRockHeight(i, j, tileMap.getRockHeight(i, j));
Expand All @@ -2516,7 +2528,9 @@ private void updateAPIMap() {
}
}
for (int i = 0; i < heightMap.getMapSize(); i++) {
progress.update((int)((float)i/heightMap.getMapSize()*100f/3)+33);
int prog = (int)((float)i/heightMap.getMapSize()*100f/3)+33;
taskbar.setWindowProgressValue(this, prog);
progress.update(prog);
for (int j = 0; j < heightMap.getMapSize(); j++) {
if(tileMap.getType(i, j) != Tile.TILE_ROCK && !tileMap.getType(i, j).isTree() && !tileMap.getType(i, j).isBush()) {
for(int x = i - 1; x <= i + 1; x++) {
Expand All @@ -2531,7 +2545,9 @@ private void updateAPIMap() {
}
}
for (int i = 0; i < heightMap.getMapSize(); i++) {
progress.update((int)((float)i/heightMap.getMapSize()*100f/3)+66);
int prog = (int)((float)i/heightMap.getMapSize()*100f/3)+66;
taskbar.setWindowProgressValue(this, prog);
progress.update(prog);
for (int j = 0; j < heightMap.getMapSize(); j++) {
if (tileMap.getType(i, j).isTree()) {
map.setTree(i, j, tileMap.getType(i, j).getTreeType((byte) 0), FoliageAge.values()[treeRand.nextInt(FoliageAge.values().length)], GrowthTreeStage.MEDIUM);
Expand Down Expand Up @@ -2906,4 +2922,4 @@ public void submitError(String err) {
public static void log (String s) {
System.out.println(s);
}
}
}
3 changes: 2 additions & 1 deletion src/net/buddat/wgenerator/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/
public class Constants {

public static final String version = "2.9.0";
public static final String version = "2.9.1";
public static final String WINDOW_TITLE = "Map Generator for Wurm Unlimited";
public static final String READY = "Ready";

public static final int MAP_SIZE = 2048;
public static final int MAP_HEIGHT = 4096;
Expand Down
26 changes: 21 additions & 5 deletions src/net/buddat/wgenerator/util/ProgressHandler.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package net.buddat.wgenerator.util;

import java.awt.Taskbar;

import javax.swing.*;

import net.buddat.wgenerator.MainWindow;

public class ProgressHandler {

JProgressBar progressBar;
JLabel lblMemory;
private JProgressBar progressBar;
private JLabel lblMemory;

private Taskbar taskbar;
private MainWindow mainWindow;

public ProgressHandler(JProgressBar progress, JLabel memory) {
progressBar = progress;
lblMemory = memory;
public ProgressHandler(JProgressBar progress, JLabel memory, Taskbar taskbar, MainWindow mainWindow) {
this.progressBar = progress;
this.lblMemory = memory;
this.taskbar = taskbar;
this.mainWindow = mainWindow;
}

private void setMemoryUsage() {
Expand All @@ -25,6 +34,13 @@ public void update(int value) {
public void update(int value, String text) {
progressBar.setValue(value);
progressBar.setString(text);
taskbar.setWindowProgressValue(mainWindow, value);
if(value == 100) {
mainWindow.setTitle(Constants.WINDOW_TITLE + " - v " + Constants.version + " - " + "Ready");
}else {
mainWindow.setTitle(Constants.WINDOW_TITLE + " - v " + Constants.version + " - " + text + ": " + value + "%");
}

setMemoryUsage();
}

Expand Down