Skip to content

Commit

Permalink
#56 Adds simple news logo and reader animation.
Browse files Browse the repository at this point in the history
Adds also JUnit for that. This animation is also
called when animation timer event occurs.
  • Loading branch information
tuomount committed Jul 26, 2017
1 parent 3729cd5 commit 78af725
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/openRealmOfStars/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,10 @@ public void actionPerformed(final ActionEvent arg0) {
// Ship Design View
shipDesignView.handleAction(arg0);
}
if (gameState == GameState.NEWS_CORP_VIEW && newsCorpView != null) {
// News Corp view
newsCorpView.handleAction(arg0);
}
if (gameState == GameState.VIEWSTATS && statView != null) {
// Stat View
statView.handleAction(arg0);
Expand Down
63 changes: 60 additions & 3 deletions src/main/java/org/openRealmOfStars/game/States/NewsCorpView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;

Expand All @@ -17,7 +19,6 @@
import org.openRealmOfStars.gui.panels.BlackPanel;
import org.openRealmOfStars.gui.panels.ImagePanel;
import org.openRealmOfStars.gui.panels.InvisiblePanel;
import org.openRealmOfStars.player.SpaceRace.SpaceRace;
import org.openRealmOfStars.starMap.newsCorp.ImageInstruction;
import org.openRealmOfStars.starMap.newsCorp.NewsData;

Expand Down Expand Up @@ -55,10 +56,24 @@ public class NewsCorpView extends BlackPanel {
*/
private ImagePanel newsImage;

/**
* Image of NewsReader
*/
private BufferedImage newsReader;
/**
* News text
*/
private InfoTextArea textArea;

/**
* Animation framing
*/
private int animation;

/**
* News reader image panel
*/
private ImagePanel newsReaderPanel;
/**
* Construtor for News Corp View.
* @param news News Data
Expand All @@ -70,8 +85,12 @@ public NewsCorpView(final NewsData news, final ActionListener listener) {
base.setLayout(new BorderLayout());
base.setTitle("Galactic Broadcasting News Company");
// TODO: This image needs to be changed
ImagePanel imagePanel = new ImagePanel(SpaceRace.HUMAN.getRaceImage());
base.add(imagePanel, BorderLayout.WEST);
newsReaderPanel = new ImagePanel(GuiStatics.IMAGE_HUMAN_RACE);
newsReader = new BufferedImage(196, 700,
BufferedImage.TYPE_4BYTE_ABGR);
animation = 0;
newsReaderPanel.setImage(newsReader);
base.add(newsReaderPanel, BorderLayout.WEST);
InfoPanel newsPanel = new InfoPanel();
newsPanel.setLayout(new BoxLayout(newsPanel, BoxLayout.Y_AXIS));
newsPanel.setTitle("News headline");
Expand Down Expand Up @@ -115,4 +134,42 @@ public NewsCorpView(final NewsData news, final ActionListener listener) {
// Add panels to base
this.add(bottomPanel, BorderLayout.SOUTH);
}

/**
* Handle events for NewsCorpView.
* @param arg0 ActionEvent
*/
public void handleAction(final ActionEvent arg0) {
if (arg0.getActionCommand().equals(GameCommands.COMMAND_ANIMATION_TIMER)
&& animation < 180) {
Graphics2D g = (Graphics2D) newsReader.getGraphics();
g.drawImage(GuiStatics.STAR_FIELD_IMAGE, -10 - animation,
-200 + animation, null);
if (animation < 64) {
g.drawImage(GuiStatics.IMAGE_GBNC,
newsReader.getWidth() / 2 - GuiStatics.IMAGE_GBNC.getWidth() / 2,
-16 + animation * 2, null);
animation++;
} else {
g.drawImage(GuiStatics.IMAGE_GBNC,
newsReader.getWidth() / 2 - GuiStatics.IMAGE_GBNC.getWidth() / 2,
-16 + 128, null);
if (animation < 162) {
g.drawImage(GuiStatics.IMAGE_ANDROID,
newsReader.getWidth() / 2
- GuiStatics.IMAGE_ANDROID.getWidth() / 2,
newsReader.getHeight() - (animation - 64) * 2, null);
animation++;
} else {
g.drawImage(GuiStatics.IMAGE_ANDROID,
newsReader.getWidth() / 2
- GuiStatics.IMAGE_ANDROID.getWidth() / 2,
newsReader.getHeight() - (162 - 64) * 2, null);
animation++;
}

}
newsReaderPanel.repaint();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.openRealmOfStars.game.States;

import java.awt.event.ActionEvent;

//import static org.junit.Assert.*;

import java.awt.event.ActionListener;

import org.junit.Test;
import org.mockito.Mockito;
import org.openRealmOfStars.game.GameCommands;
import org.openRealmOfStars.starMap.newsCorp.NewsData;

/**
Expand Down Expand Up @@ -46,4 +49,24 @@ public void testBasic() {
new NewsCorpView(newsData, listener);
}

@Test
public void testRepaintNewsReader() {
ActionListener listener = Mockito.mock(ActionListener.class);
NewsData newsData = Mockito.mock(NewsData.class);
Mockito.when(newsData.getImageInstructions()).thenReturn(
"background(nebulae)+planet(position center,rock1,full)"
+ "+text(WAR DECLARATION!)+text(Empire of Test)+relation_symbol(war)"
+ "+text(Democracy of Defender)");
Mockito.when(newsData.getNewsText()).thenReturn("Empire of Test"
+ " declares war against Democracy of Defender! This meeting"
+ " happened in Planet I");
NewsCorpView view = new NewsCorpView(newsData, listener);
ActionEvent arg0 = Mockito.mock(ActionEvent.class);
Mockito.when(arg0.getActionCommand()).thenReturn(
GameCommands.COMMAND_ANIMATION_TIMER);
for (int i = 0; i < 300; i++) {
view.handleAction(arg0);
}
}

}

0 comments on commit 78af725

Please sign in to comment.