Dialog fix

This commit is contained in:
iryupnik 2020-06-10 15:02:05 +02:00
parent 3a2b14cee8
commit 22d6595797
13 changed files with 119 additions and 18 deletions

View File

@ -7,6 +7,9 @@ import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import java.awt.*; import java.awt.*;
public class Person extends Cell { public class Person extends Cell {
private final int WALKING_SPEED = 3;
private Map map; private Map map;
private ImagePerson imagePerson; private ImagePerson imagePerson;
private int directionMove; private int directionMove;
@ -189,7 +192,7 @@ public class Person extends Cell {
@Override @Override
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
super.paint(g); super.paint(g);
if (distanceOfAnimation == 0) { if (distanceOfAnimation <= WALKING_SPEED - 1) {
isMoving = false; isMoving = false;
} }
if (isMoving) { if (isMoving) {
@ -208,7 +211,7 @@ public class Person extends Cell {
break; break;
} }
if (distanceOfAnimation > 0 && isMoving) { if (distanceOfAnimation > 0 && isMoving) {
distanceOfAnimation -= 2; distanceOfAnimation -= WALKING_SPEED;
} }
else { else {
isMoving = false; isMoving = false;

View File

@ -46,7 +46,7 @@ public class Dialog {
text.setBounds(cellSize, cellSize / 2, size.width, size.height); text.setBounds(cellSize, cellSize / 2, size.width, size.height);
dialogBar.unsetImageDialog(); dialogBar.unsetImageDialog();
} }
dialogBar.repaint();
return text; return text;
} }
@ -59,6 +59,7 @@ public class Dialog {
if (dialogBar.getComponentCount() != 0) if (dialogBar.getComponentCount() != 0)
dialogBar.remove(0); dialogBar.remove(0);
dialogBar.add(textToShow); dialogBar.add(textToShow);
dialogBar.repaint();
charNumber++; charNumber++;
if (charNumber == textLength) { if (charNumber == textLength) {
timer.stop(); timer.stop();
@ -70,7 +71,8 @@ public class Dialog {
if (text.contains("<html>")) if (text.contains("<html>"))
charNumber = 6; charNumber = 6;
dialogBar.setVisible(true); dialogBar.setVisible(true);
timer = new Timer(30, e -> { dialogBar.repaint();
timer = new Timer(40, e -> {
if (voiceover) if (voiceover)
soundManager.playSound(voice + ".wav", -20.0f); soundManager.playSound(voice + ".wav", -20.0f);
showByChar(); showByChar();
@ -84,6 +86,7 @@ public class Dialog {
if (text.contains("<html>")) if (text.contains("<html>"))
charNumber = 6; charNumber = 6;
dialogBar.setVisible(true); dialogBar.setVisible(true);
dialogBar.repaint();
while (charNumber <= text.length()) { while (charNumber <= text.length()) {
if (voiceover) if (voiceover)
soundManager.playSound(voice + ".wav", -20.0f); soundManager.playSound(voice + ".wav", -20.0f);

View File

@ -2,9 +2,16 @@ package ruscz.game.gameOfProd.Inventory;
import java.util.LinkedList; import java.util.LinkedList;
/**
* Class for working with Inventory (fully static)
*/
public class InventoryManager { public class InventoryManager {
private static LinkedList<Item> inventory = new LinkedList<Item>(); private static LinkedList<Item> inventory = new LinkedList<>();
/**
* Increase multiplicity of items, if exists in Inventory, or add to List
* @param item Item to add to inventory
*/
public static void addItem(Item item) { public static void addItem(Item item) {
for(Item item1: inventory){ for(Item item1: inventory){
if(item1.equals(item)) { if(item1.equals(item)) {
@ -15,10 +22,18 @@ public class InventoryManager {
inventory.add(item); inventory.add(item);
} }
/**
* Deletes all items from Inventory
*/
public static void flushInventory() { public static void flushInventory() {
inventory = new LinkedList<>(); inventory = new LinkedList<>();
} }
/**
* Checks, if item in Inventory
* @param item Item to check
* @return true if is in List, false if not
*/
public static boolean isInInventory(Item item) { public static boolean isInInventory(Item item) {
for (Item inventoryItem : inventory) { for (Item inventoryItem : inventory) {
if (inventoryItem.equals(item)) return true; if (inventoryItem.equals(item)) return true;
@ -26,9 +41,16 @@ public class InventoryManager {
return false; return false;
} }
/**
* Removes count of Item, if it possible
* @param item Item to remove
* @param count Count of this Item
* @return true if successful, false if not
*/
public static boolean removeItem(Item item, int count) { public static boolean removeItem(Item item, int count) {
if (isInInventory(item)) { if (isInInventory(item)) {
Item itemIn = findItemByName(item.getName()); Item itemIn = findItemByName(item.getName());
if (itemIn == null) return false;
if (itemIn.getMultiplicity() > count) if (itemIn.getMultiplicity() > count)
itemIn.setMultiplicity(itemIn.getMultiplicity() - count); itemIn.setMultiplicity(itemIn.getMultiplicity() - count);
else if (itemIn.getMultiplicity() == count) else if (itemIn.getMultiplicity() == count)
@ -41,6 +63,11 @@ public class InventoryManager {
public static LinkedList<Item> getInventory() { return inventory; } public static LinkedList<Item> getInventory() { return inventory; }
/**
* Return Item, if exists in List with this Name
* @param name Name of Item
* @return Item if exists, null if not
*/
public static Item findItemByName(String name) { public static Item findItemByName(String name) {
for (Item item : inventory) { for (Item item : inventory) {
if (item.getName().equals(name)) return item; if (item.getName().equals(name)) return item;

View File

@ -5,13 +5,15 @@ import ruscz.game.gameOfProd.Image.ImageCell;
import javax.swing.*; import javax.swing.*;
import java.util.Objects; import java.util.Objects;
/**
* Class, describing Item in Game
*/
public class Item { public class Item {
private ItemAction itemAction; private ItemAction itemAction;
private final String name; private final String name;
private int multiplicity; private int multiplicity;
private final int image; private final int image;
public Item(String name, int multiplicity, int image, String itemAction) { public Item(String name, int multiplicity, int image, String itemAction) {
this.name = parseName(name); this.name = parseName(name);
this.image = image; this.image = image;
@ -26,12 +28,21 @@ public class Item {
setItemActionByName(itemAction); setItemActionByName(itemAction);
} }
/**
* Removes all "-" in text
* @param name Name of Item
* @return Name with whitespaces
*/
private String parseName(String name) { private String parseName(String name) {
name = name.replace("-", " "); name = name.replace("-", " ");
name = name.substring(0, 1).toUpperCase() + name.substring(1); name = name.substring(0, 1).toUpperCase() + name.substring(1);
return name; return name;
} }
/**
* Choose enumeration by String you provide
* @param action Name of action
*/
private void setItemActionByName(String action) { private void setItemActionByName(String action) {
switch (action) { switch (action) {
case "heal": case "heal":

View File

@ -1,5 +1,8 @@
package ruscz.game.gameOfProd.Inventory; package ruscz.game.gameOfProd.Inventory;
/**
* Enumerations for Item, describing what action provide
*/
public enum ItemAction { public enum ItemAction {
HEAL, MANA, DEFENCE, STRENGTH, KEY; HEAL, MANA, DEFENCE, STRENGTH, KEY;
} }

View File

@ -5,9 +5,12 @@ import ruscz.game.gameOfProd.Image.ImageCell;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
/**
* Graphic representation of Item for Battle
*/
public class ItemPanel extends JPanel { public class ItemPanel extends JPanel {
ImageCell imageCell; private final ImageCell imageCell;
int item; private final int item;
public ItemPanel(ImageCell imageCell, int item){ public ItemPanel(ImageCell imageCell, int item){
this.imageCell = imageCell; this.imageCell = imageCell;

View File

@ -22,7 +22,7 @@ import java.util.LinkedList;
* It also holds references to all major classes * It also holds references to all major classes
*/ */
public class WindowOfFreeMove extends JLayeredPane { public class WindowOfFreeMove extends JLayeredPane {
public static final int CELL_SIZE = 70; public static final int CELL_SIZE = 69;
public static int CANVAS_WIDTH = 50; public static int CANVAS_WIDTH = 50;
public static int CANVAS_HEIGHT = 50; public static int CANVAS_HEIGHT = 50;
public static final int WINDOW_WIDTH = 13; public static final int WINDOW_WIDTH = 13;
@ -211,8 +211,7 @@ public class WindowOfFreeMove extends JLayeredPane {
mapManager.getActualMap().getPerson().move(); mapManager.getActualMap().getPerson().move();
camera.moveCamera(); camera.moveCamera();
canvas.repaint(); canvas.repaint();
foreground.repaint(); if (foreground.isVisible()) foreground.repaint();
dialogBar.repaint();
}); });
timer.start(); timer.start();
} }

View File

@ -0,0 +1,12 @@
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0

View File

@ -0,0 +1,21 @@
<tileset> A2_Ground.png
<tileset> A5_Tiles.png
<cellmap> CHEST 0
<cellmap> TRIGGER 0
<cellmap> BLOCK 0
<cellmap> MOVETO 0
<cellmap> EVENT 0
<cellmap> DOOR/DOORTO 0
<soundmap> DOOR qubodup-DoorOpen01-changed.wav qubodup-DoorClose02-changed.wav doorLocked.wav
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194
194 194 194 194 194 194 194 194 194 194 194 194

View File

@ -0,0 +1,13 @@
12 12
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY

View File

@ -14,7 +14,7 @@
<trigger> <trigger>
<x>6</x> <x>6</x>
<y>4</y> <y>4</y>
<active>true</active> <active>false</active>
</trigger> </trigger>
<trigger> <trigger>
<x>14</x> <x>14</x>
@ -24,7 +24,7 @@
<chest> <chest>
<x>1</x> <x>1</x>
<y>2</y> <y>2</y>
<active>true</active> <active>false</active>
</chest> </chest>
<chest> <chest>
<x>15</x> <x>15</x>
@ -35,7 +35,7 @@
<x>8</x> <x>8</x>
<y>4</y> <y>4</y>
<locked>false</locked> <locked>false</locked>
<open>false</open> <open>true</open>
</dooŕ> </dooŕ>
<door> <door>
<x>2</x> <x>2</x>
@ -110,7 +110,7 @@
<x>2</x> <x>2</x>
<y>12</y> <y>12</y>
<locked>false</locked> <locked>false</locked>
<open>false</open> <open>true</open>
</dooŕ> </dooŕ>
<door> <door>
<x>17</x> <x>17</x>
@ -152,13 +152,13 @@
<trigger> <trigger>
<x>6</x> <x>6</x>
<y>2</y> <y>2</y>
<active>true</active> <active>false</active>
</trigger> </trigger>
<door> <door>
<x>6</x> <x>6</x>
<y>1</y> <y>1</y>
<locked>false</locked> <locked>false</locked>
<open>false</open> <open>true</open>
</dooŕ> </dooŕ>
</events> </events>
</map> </map>

View File

@ -0,0 +1,6 @@
<item>
<name>cup-o'-coffee</name>
<multiplicity>1</multiplicity>
<image>295</image>
<action>heal</action>
</item>

View File

@ -1,6 +1,6 @@
<location> <location>
<map>openspace</map> <map>openspace</map>
<x>8</x> <x>8</x>
<y>16</y> <y>15</y>
<direction>3</direction> <direction>3</direction>
</location> </location>