Skip to content

Commit 272efb3

Browse files
author
Darrell Root
committed
Resizing windows now works for local and galactic maps.
That said, images are still 20 pixels across and dont resize. But targetting, direction, and scaling of the screens works.
1 parent fe92af8 commit 272efb3

File tree

4 files changed

+239
-12
lines changed

4 files changed

+239
-12
lines changed

src/jtrek/visual/BasePanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public void setBounds(int x, int y, int width, int height) {
6363
else {
6464
super.setBounds(x, y, width, height);
6565
}
66-
view_size.width = width - TWO_BORDERS;
67-
view_size.height = height - TWO_BORDERS;
66+
view_size.width = width;// - TWO_BORDERS;
67+
view_size.height = height;// - TWO_BORDERS;
6868
setup();
6969
}
7070

src/jtrek/visual/GalacticPanel.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import jtrek.config.*;
88

99
public class GalacticPanel extends BaseMapPanel {
10-
final static float SCALE = (float)500 / (float)Universe.PIXEL_SIZE;
10+
static float SCALE = (float)500 / (float)Universe.PIXEL_SIZE;
1111

1212
GalacticBitmaps bitmaps;
1313

@@ -30,17 +30,31 @@ void setup() {
3030

3131
/** getCourse */
3232
byte getCourse() {
33+
int xclick = mx * Universe.PIXEL_SIZE / this.getWidth();
34+
int yclick = my * Universe.PIXEL_SIZE / this.getHeight();
3335
return (byte)Math.rint(
34-
Math.atan2((double)mx - data.me.x * 0.005d, data.me.y * 0.005d - (double)my) / Math.PI * 128);
36+
Math.atan2(xclick - data.me.x, data.me.y - yclick) / Math.PI * 128);
3537
}
3638

3739
/** getTarget */
3840
Object getTarget(int target_type) {
39-
return data.getTarget((mx * Universe.PIXEL_SIZE) / 500, (my * Universe.PIXEL_SIZE) / 500, target_type);
41+
return data.getTarget((mx * Universe.PIXEL_SIZE) / this.getWidth(), (my * Universe.PIXEL_SIZE) / this.getHeight(), target_type);
4042
}
4143

44+
/**
45+
* Added support to rescale galactic window based on resizing
46+
*/
47+
private void updateScale() {
48+
if (this.getWidth() < 100) { // abort recalculation if window too small
49+
return;
50+
}
51+
GalacticPanel.SCALE = (float)this.getWidth() / (float)Universe.PIXEL_SIZE;
52+
}
4253
/** update */
4354
public void update(Graphics g) {
55+
this.updateScale();
56+
redraw_all_planets = true;
57+
4458
Graphics og = offscreen.getGraphics();
4559
og.setFont(getFont());
4660
Graphics pg = planet_offscreen.getGraphics();

src/jtrek/visual/LocalPanel.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ public class LocalPanel extends BaseMapPanel {
1111
final static Color PRESSOR_COLOR = new Color(0x888800);
1212
final static int ALERT_FILTER = (Player.GREEN | Player.YELLOW | Player.RED);
1313

14-
final static int SCALE = 40;
15-
final static int VIEW = SCALE * 250;
14+
final static int TARGET_VIEW_WIDTH = 20000;
15+
static int SCALE = 40;
16+
static int VIEW = SCALE * 250;
1617

1718
LocalBitmaps bitmaps;
1819
int alert = 0;
@@ -59,6 +60,22 @@ public void newShip() {
5960
}
6061
}
6162

63+
/**
64+
* Recalculates scale. Tactical screen should cover 20,000 netrek units
65+
* and (by default) is 500 pixels wide
66+
* That's 20% across the universe.
67+
*/
68+
private void recalculateScale() {
69+
int viewWidth = this.getWidth();
70+
if (viewWidth < 100) {
71+
// giving up, view too small
72+
return;
73+
}
74+
LocalPanel.VIEW = TARGET_VIEW_WIDTH / 2;
75+
LocalPanel.SCALE = TARGET_VIEW_WIDTH / viewWidth;
76+
77+
}
78+
6279
public void goneToOutfit() {
6380
alert = 0;
6481
tractor_count = 0;
@@ -72,17 +89,22 @@ public void goneToOutfit() {
7289

7390
/** getCourse */
7491
byte getCourse() {
92+
int centerX = this.getWidth() / 2;
93+
int centerY = this.getHeight() / 2;
7594
return (byte)Math.rint(
76-
Math.atan2((double)(mx - 250), (double)(250 - my)) / Math.PI * 128);
95+
Math.atan2((double)(mx - centerX), (double)(centerY - my)) / Math.PI * 128);
7796
}
7897

7998
/** getTarget */
8099
Object getTarget(int target_sype) {
81-
return data.getTarget(data.me.x + ((mx - 250) * SCALE), data.me.y + ((my - 250) * SCALE), target_sype);
100+
int centerX = this.getWidth() / 2;
101+
int centerY = this.getHeight() / 2;
102+
return data.getTarget(data.me.x + ((mx - centerX) * SCALE), data.me.y + ((my - centerY) * SCALE), target_sype);
82103
}
83104

84105
/** update */
85106
public void update(Graphics g) {
107+
recalculateScale(); // added to support changing view size
86108
Graphics og = offscreen.getGraphics();
87109
og.setFont(getFont());
88110

@@ -211,7 +233,7 @@ else if((planet.flags & Planet.AGRI) != 0) {
211233
} // end draw planets
212234

213235
// draw the players
214-
for(int p = players.length; --p >= 0;) {
236+
for(int p = players.length - 1; p >= 0; p--) {
215237
Player player = players[p];
216238

217239
// see if this player is active
@@ -263,7 +285,14 @@ else if (player.cloakphase > 0) {
263285
}
264286

265287
if (player.status == Player.ALIVE) {
288+
289+
// if my ship image is null, create it
290+
if (player.me && bitmaps.myship == null) {
291+
newShip();
292+
}
266293
Image ship = player.me ? bitmaps.myship : bitmaps.ships[player.team.no][player.ship.type];
294+
//Image ship = bitmaps.ships[player.team.no][player.ship.type];
295+
267296
source_y = bitmaps.rosette[player.dir];
268297

269298
og.drawImage(ship,

src/jtrek/visual/NetrekFrame.java

Lines changed: 186 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class NetrekFrame extends Frame {
2222
public InfoPanel server_info;
2323
public LocalPanel local;
2424
public GalacticPanel galactic;
25-
public Dashboard dashboard;
25+
public Dashboard dashboard; // also known as tstat i think
2626
public WarningPanel warning;
2727
public MessagePanel message;
2828
public PlayerListPanel player_list;
@@ -56,6 +56,7 @@ public class NetrekFrame extends Frame {
5656
public FeatureList feature_list;
5757
public Beeplite beeplite;
5858
public boolean quit = false;
59+
private NetrekFrame netrekFrame;
5960

6061
public NetrekFrame(Communications comm, Universe data) {
6162
super("Netrek");
@@ -65,6 +66,8 @@ public NetrekFrame(Communications comm, Universe data) {
6566
setBackground(Color.black);
6667
setIconImage(ICON_IMAGE);
6768

69+
netrekFrame = this;
70+
6871
// install the message handlers
6972
dmessage = new IncomingMessageHandler(this, data, comm);
7073
smessage = new SendMessage(this, data, comm);
@@ -216,6 +219,80 @@ public void windowClosing(WindowEvent e) {
216219
detached_motd.addKeyListener(key_handler);
217220
detached_motd.detachWindow(null).addKeyListener(key_handler);
218221
setupBasePanel(detached_motd);
222+
223+
this.addComponentListener(new ComponentAdapter() {
224+
public void componentResized(ComponentEvent e) {
225+
// This is only called when the user releases the mouse button.
226+
System.out.println("componentResized");
227+
netrekFrame.resizeWindows();
228+
}
229+
});
230+
231+
}
232+
233+
void resizeWindows() {
234+
int windowWidth = this.getWidth();
235+
int windowHeight = this.getHeight();
236+
237+
int leftYPosition = 0;
238+
int rightYPosition = 0;
239+
int halfWidth = windowWidth / 2;
240+
241+
int mapDimension = Math.min(halfWidth, windowHeight * 742 / 1008); //keep maps square
242+
243+
// overlapping front windows
244+
245+
entry.setBounds(0, 0, mapDimension, mapDimension);
246+
if (login != null) {
247+
login.setBounds(0, 0, mapDimension, mapDimension);
248+
}
249+
information.setBounds(0, 0, mapDimension, mapDimension);
250+
attached_motd.setBounds(halfWidth, 0, mapDimension, mapDimension);
251+
options.setBounds(halfWidth, 0, mapDimension, mapDimension);
252+
253+
// left column
254+
255+
local.setBounds(0,0,mapDimension, mapDimension);
256+
leftYPosition += mapDimension;
257+
258+
dashboard.setBounds(0, leftYPosition, halfWidth, 51);;
259+
leftYPosition += 51;
260+
261+
// reviews seem to overlap
262+
review.setBounds(0,leftYPosition, halfWidth, windowHeight / 4);
263+
leftYPosition += windowHeight / 4;
264+
265+
review_all.setBounds(0,leftYPosition, halfWidth, windowHeight / 8);
266+
leftYPosition += windowHeight / 8;
267+
268+
review_team.setBounds(0,leftYPosition, halfWidth, windowHeight / 8);
269+
leftYPosition += windowHeight / 8;
270+
271+
review_your.setBounds(0, leftYPosition, halfWidth, windowHeight / 8);
272+
leftYPosition += windowHeight / 8;
273+
274+
review_kill.setBounds(0, leftYPosition, halfWidth, windowHeight / 8);
275+
leftYPosition += windowHeight / 8;
276+
277+
review_phaser.setBounds(0, leftYPosition, halfWidth, windowHeight / 8);
278+
leftYPosition += windowHeight / 8;
279+
280+
// right column
281+
282+
galactic.setBounds(halfWidth, 0, mapDimension, mapDimension);
283+
rightYPosition += mapDimension;
284+
285+
warning.setBounds(halfWidth, rightYPosition, halfWidth, windowHeight / 28);
286+
rightYPosition += windowHeight / 28;
287+
288+
message.setBounds(halfWidth, rightYPosition, windowWidth/2, windowHeight / 28);
289+
rightYPosition += windowHeight / 28;
290+
291+
player_list.setBounds(halfWidth, rightYPosition, windowWidth / 2, windowHeight /4);
292+
rightYPosition += windowHeight / 4;
293+
294+
295+
219296
}
220297

221298
void shutDown() {
@@ -268,6 +345,7 @@ public void slotFound() {
268345
// z-order of dialogs don't stay over this frame correctly
269346
addNotify();
270347
addWindows();
348+
//newWindowSetup();
271349
Insets insets = getInsets();
272350
Rectangle rect = Defaults.getWindowGeometry("netrek");
273351
rect.width += insets.left + insets.right;
@@ -278,6 +356,43 @@ public void slotFound() {
278356
requestFocus();
279357
}
280358

359+
/*public void newWindowSetup() {
360+
361+
this.setBounds(0,0,1008,742);
362+
363+
add(information);
364+
365+
BasePanel login = (BasePanel) getWindow("login");
366+
login.setVisible(false);
367+
Container netrekWindow = getWindow("netrek");
368+
GridBagConstraints constraints = new GridBagConstraints();
369+
370+
constraints.gridx = 0;
371+
constraints.gridy = 0;
372+
constraints.anchor = GridBagConstraints.NORTHWEST;
373+
netrekWindow.add(login,constraints);
374+
375+
BasePanel local = (BasePanel) getWindow("local");
376+
local.setMinimumSize(new Dimension(508,508));
377+
local.setBounds(0, 0, 500, 500);
378+
constraints.gridx = 0;
379+
constraints.gridy = 0;
380+
constraints.anchor = GridBagConstraints.NORTHWEST;
381+
netrekWindow.add(local,constraints);
382+
local.setVisible(true);
383+
384+
385+
BasePanel entry = (BasePanel) getWindow("entry");
386+
entry.setVisible(false);
387+
388+
constraints.gridx = 0;
389+
constraints.gridy = 0;
390+
constraints.anchor = GridBagConstraints.NORTHWEST;
391+
netrekWindow.add(entry,constraints);
392+
393+
}
394+
*/
395+
281396
public void showLogin() {
282397
local.setVisible(true);
283398
galactic.setVisible(true);
@@ -312,7 +427,14 @@ else if(parent_name.equalsIgnoreCase("none")) {
312427
parent = this;
313428
}
314429
try {
315-
parent.add(panel);
430+
//GridBagConstraints constraints = getConstraints(panel);
431+
setSize(panel);
432+
//if (constraints != null) {
433+
// parent.add(panel,constraints);
434+
//} else {
435+
parent.add(panel);
436+
//}
437+
panel.setVisible(Defaults.getWindowVisible(panel.name));
316438
}
317439
catch(IllegalArgumentException e) {
318440
System.err.println("Error adding window \"" + panel.getName() + "\" to parent, " + e.getMessage());
@@ -328,6 +450,7 @@ void setupWindows() {
328450
setupBasePanel(windows[w]);
329451
}
330452
}
453+
331454

332455
/** setupBasePanel */
333456
void setupBasePanel(BasePanel panel) {
@@ -342,6 +465,67 @@ void setupBasePanel(BasePanel panel) {
342465
panel.setVisible(Defaults.getWindowVisible(panel.name));
343466
}
344467

468+
/*private GridBagConstraints getConstraints(BasePanel panel) {
469+
GridBagConstraints constraints = new GridBagConstraints();
470+
if (panel.name.equals("local")) {
471+
constraints.gridx = 0;
472+
constraints.gridy = 0;
473+
constraints.anchor = GridBagConstraints.NORTHWEST;
474+
return constraints;
475+
} else if (panel.name.equals("map")) {
476+
constraints.gridx = 0;
477+
constraints.gridy = 1;
478+
constraints.anchor = GridBagConstraints.NORTHEAST;
479+
return constraints;
480+
} else {
481+
return null;
482+
}
483+
}*/
484+
485+
void setSize(BasePanel panel) {
486+
if(panel.getParent() != null) {
487+
Rectangle geometry = Defaults.getWindowGeometry(panel.name);
488+
if (geometry.x < 0) {
489+
geometry.x = 0;
490+
}
491+
if (geometry.y < 0) {
492+
geometry.y = 0;
493+
}
494+
panel.setBounds(geometry);
495+
}
496+
}
497+
/**
498+
* New attempt to setup windows for netrek 0.9.7 to allow resizing
499+
* @param panel
500+
*/
501+
/*void setupBasePanel2(BasePanel panel) {
502+
GridBagConstraints constraints = new GridBagConstraints();
503+
504+
if (panel.name.equals("local")) {
505+
constraints.gridx = 0;
506+
constraints.gridy = 0;
507+
constraints.anchor = GridBagConstraints.NORTHWEST;
508+
panel.setSize(508, 508);
509+
panel.setVisible(true);
510+
} else if (panel.name.equals("map")) {
511+
constraints.gridx = 0;
512+
constraints.gridy = 1;
513+
constraints.anchor = GridBagConstraints.NORTHEAST;
514+
panel.setSize(508, 508);
515+
panel.setVisible(true);
516+
} else {
517+
if(panel.getParent() != null) {
518+
Rectangle geometry = Defaults.getWindowGeometry(panel.name);
519+
if(panel.getParent() == this) {
520+
Insets i = getInsets();
521+
geometry.translate(i.left, i.top);
522+
}
523+
panel.setBounds(geometry);
524+
}
525+
panel.setVisible(Defaults.getWindowVisible(panel.name));
526+
}
527+
}*/
528+
345529
/** loginComplete */
346530
public void loginComplete() {
347531
login.getParent().remove(login);

0 commit comments

Comments
 (0)