Moins d'items dans la todolist:
Suppression de pas mal de messages polluant le sysout, notamment des dumps de games. Les layouts sont mieux gérés, notamment avec plus de miniels, pré-compatible avec la configuration. Ajout des menus clic-droit des actions et des inventaires, permettant de reset/supprimer/créer ... Ajout du line wrapping de blocs «notes» qui manquait.
This commit is contained in:
parent
2fe6235869
commit
2fdaf82782
@ -1,6 +1,7 @@
|
||||
package com.bernard.murder;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.util.HashMap;
|
||||
@ -20,4 +21,9 @@ public class Parametres {
|
||||
public static Color textPanMinielBackgroundColor = new Color(0xFFE085);
|
||||
public static Color textPanMinielTextColor = new Color(0x274290);
|
||||
|
||||
|
||||
public static Dimension minielMinSize = new Dimension(200, 300);
|
||||
public static int minielParLigne = 2;
|
||||
public static int lignesDeMinielAvantScroll = 2;
|
||||
|
||||
}
|
||||
|
||||
@ -124,9 +124,29 @@ public class GameManager {
|
||||
inventaires.addAll(partie.personnages());
|
||||
partie.personnagesStream().forEach(p -> inventaires.addAll(p.espacePersos()));
|
||||
return inventaires.stream().filter(i -> name.equalsIgnoreCase(i.getInventoryName())).findAny().orElseGet(()->{
|
||||
System.out.println("JE n'ai pas trouvé l'inventaire "+name+" dans la liste "+inventaires.stream().map(Inventaire::getInventoryName).collect(Collectors.joining(",")));
|
||||
System.err.println("JE n'ai pas trouvé l'inventaire "+name+" dans la liste "+inventaires.stream().map(Inventaire::getInventoryName).collect(Collectors.joining(",")));
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public void createObjet(String newName, Inventaire inv) {
|
||||
Objet o = new Objet(newName);
|
||||
System.out.println("Création de l'objet "+o+" dans "+inv);
|
||||
inv.addObjet(o);
|
||||
inventoryUpdate(inv);
|
||||
}
|
||||
public void deleteObjet(Objet o, Inventaire inv) {
|
||||
System.out.println("Destruction de l'objet "+o+" dans "+inv);
|
||||
inv.removeObjet(o);
|
||||
inventoryUpdate(inv);
|
||||
}
|
||||
public void renameObjet(Objet o, String newName, Inventaire inv) {
|
||||
System.out.println("Renommage de l'objet "+o+" en "+newName+" dans "+inv);
|
||||
Objet newObjet = new Objet(newName);
|
||||
inv.removeObjet(o);
|
||||
inv.addObjet(newObjet);
|
||||
inventoryUpdate(inv);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -44,6 +44,10 @@ public class Action implements Cloneable{
|
||||
triggertime=System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
triggertime=0;
|
||||
}
|
||||
|
||||
public boolean hasFinished() {
|
||||
return triggertime + basetime - System.currentTimeMillis()<0;
|
||||
}
|
||||
|
||||
@ -61,9 +61,7 @@ public class Personnage implements Inventaire{
|
||||
|
||||
@Override
|
||||
public void removeObjet(Objet o) {
|
||||
System.out.println("Avant :"+inventaire);
|
||||
this.inventaire.remove(o);
|
||||
System.out.println("Après :"+inventaire);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -36,7 +36,6 @@ public class MouseReactiveTabbedPane extends JTabbedPane {
|
||||
@Override
|
||||
public void dragOver(DropTargetDragEvent dtde) {
|
||||
int tab = getTab(dtde);
|
||||
System.out.println(">"+tab+"/"+hoverIndex+"-"+enteredTime);
|
||||
if(tab==-1) {
|
||||
enteredTime=-1;
|
||||
hoverIndex=-1;
|
||||
|
||||
315
src/main/java/com/bernard/murder/util/view/ScrollablePanel.java
Normal file
315
src/main/java/com/bernard/murder/util/view/ScrollablePanel.java
Normal file
@ -0,0 +1,315 @@
|
||||
package com.bernard.murder.util.view;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
//Honteusement volé de https://tips4java.wordpress.com/2009/12/20/scrollable-panel/
|
||||
|
||||
/**
|
||||
* A panel that implements the Scrollable interface. This class allows you to
|
||||
* customize the scrollable features by using newly provided setter methods so
|
||||
* you don't have to extend this class every time.
|
||||
*
|
||||
* Scrollable amounts can be specifed as a percentage of the viewport size or as
|
||||
* an actual pixel value. The amount can be changed for both unit and block
|
||||
* scrolling for both horizontal and vertical scrollbars.
|
||||
*
|
||||
* The Scrollable interface only provides a boolean value for determining
|
||||
* whether or not the viewport size (width or height) should be used by the
|
||||
* scrollpane when determining if scrollbars should be made visible. This class
|
||||
* supports the concept of dynamically changing this value based on the size of
|
||||
* the viewport. In this case the viewport size will only be used when it is
|
||||
* larger than the panels size. This has the effect of ensuring the viewport is
|
||||
* always full as components added to the panel will be size to fill the area
|
||||
* available, based on the rules of the applicable layout manager of course.
|
||||
*/
|
||||
public class ScrollablePanel extends JPanel implements Scrollable, SwingConstants {
|
||||
|
||||
private static final long serialVersionUID = -6250434641501235247L;
|
||||
|
||||
public enum ScrollableSizeHint {
|
||||
NONE, FIT, STRETCH;
|
||||
}
|
||||
|
||||
public enum IncrementType {
|
||||
PERCENT, PIXELS;
|
||||
}
|
||||
|
||||
private ScrollableSizeHint scrollableHeight = ScrollableSizeHint.NONE;
|
||||
private ScrollableSizeHint scrollableWidth = ScrollableSizeHint.NONE;
|
||||
|
||||
private IncrementInfo horizontalBlock;
|
||||
private IncrementInfo horizontalUnit;
|
||||
private IncrementInfo verticalBlock;
|
||||
private IncrementInfo verticalUnit;
|
||||
|
||||
/**
|
||||
* Default constructor that uses a FlowLayout
|
||||
*/
|
||||
public ScrollablePanel() {
|
||||
this(new FlowLayout());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constuctor for specifying the LayoutManager of the panel.
|
||||
*
|
||||
* @param layout the LayoutManger for the panel
|
||||
*/
|
||||
public ScrollablePanel(LayoutManager layout) {
|
||||
super(layout);
|
||||
|
||||
IncrementInfo block = new IncrementInfo(IncrementType.PERCENT, 100);
|
||||
IncrementInfo unit = new IncrementInfo(IncrementType.PERCENT, 10);
|
||||
|
||||
setScrollableBlockIncrement(HORIZONTAL, block);
|
||||
setScrollableBlockIncrement(VERTICAL, block);
|
||||
setScrollableUnitIncrement(HORIZONTAL, unit);
|
||||
setScrollableUnitIncrement(VERTICAL, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height ScrollableSizeHint enum
|
||||
*
|
||||
* @return the ScrollableSizeHint enum for the height
|
||||
*/
|
||||
public ScrollableSizeHint getScrollableHeight() {
|
||||
return scrollableHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ScrollableSizeHint enum for the height. The enum is used to determine
|
||||
* the boolean value that is returned by the getScrollableTracksViewportHeight()
|
||||
* method. The valid values are:
|
||||
*
|
||||
* ScrollableSizeHint.NONE - return "false", which causes the height of the
|
||||
* panel to be used when laying out the children ScrollableSizeHint.FIT - return
|
||||
* "true", which causes the height of the viewport to be used when laying out
|
||||
* the children ScrollableSizeHint.STRETCH - return "true" when the viewport
|
||||
* height is greater than the height of the panel, "false" otherwise.
|
||||
*
|
||||
* @param scrollableHeight as represented by the ScrollableSizeHint enum.
|
||||
*/
|
||||
public void setScrollableHeight(ScrollableSizeHint scrollableHeight) {
|
||||
this.scrollableHeight = scrollableHeight;
|
||||
revalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width ScrollableSizeHint enum
|
||||
*
|
||||
* @return the ScrollableSizeHint enum for the width
|
||||
*/
|
||||
public ScrollableSizeHint getScrollableWidth() {
|
||||
return scrollableWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ScrollableSizeHint enum for the width. The enum is used to determine
|
||||
* the boolean value that is returned by the getScrollableTracksViewportWidth()
|
||||
* method. The valid values are:
|
||||
*
|
||||
* ScrollableSizeHint.NONE - return "false", which causes the width of the panel
|
||||
* to be used when laying out the children ScrollableSizeHint.FIT - return
|
||||
* "true", which causes the width of the viewport to be used when laying out the
|
||||
* children ScrollableSizeHint.STRETCH - return "true" when the viewport width
|
||||
* is greater than the width of the panel, "false" otherwise.
|
||||
*
|
||||
* @param scrollableWidth as represented by the ScrollableSizeHint enum.
|
||||
*/
|
||||
public void setScrollableWidth(ScrollableSizeHint scrollableWidth) {
|
||||
this.scrollableWidth = scrollableWidth;
|
||||
revalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block IncrementInfo for the specified orientation
|
||||
*
|
||||
* @return the block IncrementInfo for the specified orientation
|
||||
*/
|
||||
public IncrementInfo getScrollableBlockIncrement(int orientation) {
|
||||
return orientation == SwingConstants.HORIZONTAL ? horizontalBlock : verticalBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the information needed to do block scrolling.
|
||||
*
|
||||
* @param orientation specify the scrolling orientation. Must be either:
|
||||
* SwingContants.HORIZONTAL or SwingContants.VERTICAL.
|
||||
* @paran type specify how the amount parameter in the calculation of the
|
||||
* scrollable amount. Valid values are: IncrementType.PERCENT - treat the
|
||||
* amount as a % of the viewport size IncrementType.PIXEL - treat the
|
||||
* amount as the scrollable amount
|
||||
* @param amount a value used with the IncrementType to determine the scrollable
|
||||
* amount
|
||||
*/
|
||||
public void setScrollableBlockIncrement(int orientation, IncrementType type, int amount) {
|
||||
IncrementInfo info = new IncrementInfo(type, amount);
|
||||
setScrollableBlockIncrement(orientation, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the information needed to do block scrolling.
|
||||
*
|
||||
* @param orientation specify the scrolling orientation. Must be either:
|
||||
* SwingContants.HORIZONTAL or SwingContants.VERTICAL.
|
||||
* @param info An IncrementInfo object containing information of how to
|
||||
* calculate the scrollable amount.
|
||||
*/
|
||||
public void setScrollableBlockIncrement(int orientation, IncrementInfo info) {
|
||||
switch (orientation) {
|
||||
case SwingConstants.HORIZONTAL:
|
||||
horizontalBlock = info;
|
||||
break;
|
||||
case SwingConstants.VERTICAL:
|
||||
verticalBlock = info;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid orientation: " + orientation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unit IncrementInfo for the specified orientation
|
||||
*
|
||||
* @return the unit IncrementInfo for the specified orientation
|
||||
*/
|
||||
public IncrementInfo getScrollableUnitIncrement(int orientation) {
|
||||
return orientation == SwingConstants.HORIZONTAL ? horizontalUnit : verticalUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the information needed to do unit scrolling.
|
||||
*
|
||||
* @param orientation specify the scrolling orientation. Must be either:
|
||||
* SwingContants.HORIZONTAL or SwingContants.VERTICAL.
|
||||
* @paran type specify how the amount parameter in the calculation of the
|
||||
* scrollable amount. Valid values are: IncrementType.PERCENT - treat the
|
||||
* amount as a % of the viewport size IncrementType.PIXEL - treat the
|
||||
* amount as the scrollable amount
|
||||
* @param amount a value used with the IncrementType to determine the scrollable
|
||||
* amount
|
||||
*/
|
||||
public void setScrollableUnitIncrement(int orientation, IncrementType type, int amount) {
|
||||
IncrementInfo info = new IncrementInfo(type, amount);
|
||||
setScrollableUnitIncrement(orientation, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the information needed to do unit scrolling.
|
||||
*
|
||||
* @param orientation specify the scrolling orientation. Must be either:
|
||||
* SwingContants.HORIZONTAL or SwingContants.VERTICAL.
|
||||
* @param info An IncrementInfo object containing information of how to
|
||||
* calculate the scrollable amount.
|
||||
*/
|
||||
public void setScrollableUnitIncrement(int orientation, IncrementInfo info) {
|
||||
switch (orientation) {
|
||||
case SwingConstants.HORIZONTAL:
|
||||
horizontalUnit = info;
|
||||
break;
|
||||
case SwingConstants.VERTICAL:
|
||||
verticalUnit = info;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid orientation: " + orientation);
|
||||
}
|
||||
}
|
||||
|
||||
// Implement Scrollable interface
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredScrollableViewportSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScrollableUnitIncrement(Rectangle visible, int orientation, int direction) {
|
||||
switch (orientation) {
|
||||
case SwingConstants.HORIZONTAL:
|
||||
return getScrollableIncrement(horizontalUnit, visible.width);
|
||||
case SwingConstants.VERTICAL:
|
||||
return getScrollableIncrement(verticalUnit, visible.height);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid orientation: " + orientation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScrollableBlockIncrement(Rectangle visible, int orientation, int direction) {
|
||||
switch (orientation) {
|
||||
case SwingConstants.HORIZONTAL:
|
||||
return getScrollableIncrement(horizontalBlock, visible.width);
|
||||
case SwingConstants.VERTICAL:
|
||||
return getScrollableIncrement(verticalBlock, visible.height);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid orientation: " + orientation);
|
||||
}
|
||||
}
|
||||
|
||||
protected int getScrollableIncrement(IncrementInfo info, int distance) {
|
||||
if (info.getIncrement() == IncrementType.PIXELS)
|
||||
return info.getAmount();
|
||||
else
|
||||
return distance * info.getAmount() / 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportWidth() {
|
||||
if (scrollableWidth == ScrollableSizeHint.NONE)
|
||||
return false;
|
||||
|
||||
if (scrollableWidth == ScrollableSizeHint.FIT)
|
||||
return true;
|
||||
|
||||
// STRETCH sizing, use the greater of the panel or viewport width
|
||||
|
||||
if (getParent() instanceof JViewport) {
|
||||
return (((JViewport) getParent()).getWidth() > getPreferredSize().width);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportHeight() {
|
||||
if (scrollableHeight == ScrollableSizeHint.NONE)
|
||||
return false;
|
||||
|
||||
if (scrollableHeight == ScrollableSizeHint.FIT)
|
||||
return true;
|
||||
|
||||
// STRETCH sizing, use the greater of the panel or viewport height
|
||||
|
||||
if (getParent() instanceof JViewport) {
|
||||
return (((JViewport) getParent()).getHeight() > getPreferredSize().height);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to hold the information required to calculate the scroll amount.
|
||||
*/
|
||||
static class IncrementInfo {
|
||||
private IncrementType type;
|
||||
private int amount;
|
||||
|
||||
public IncrementInfo(IncrementType type, int amount) {
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public IncrementType getIncrement() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScrollablePanel[" + type + ", " + amount + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,7 +65,6 @@ public class HoverSelect implements DropTargetListener,Runnable{
|
||||
@Override
|
||||
public void dragEnter(DropTargetDragEvent e) {
|
||||
enteredTime = System.nanoTime();
|
||||
System.out.println("entré");
|
||||
plannedThread = new Thread(()-> {
|
||||
try {
|
||||
Thread.sleep(waitTime/1_000_000, (int)(waitTime%1_000_000));
|
||||
@ -91,7 +90,6 @@ public class HoverSelect implements DropTargetListener,Runnable{
|
||||
@Override
|
||||
public void run() {
|
||||
enteredTime = System.nanoTime();
|
||||
System.out.println("entré");
|
||||
plannedThread = new Thread(()-> {
|
||||
try {
|
||||
Thread.sleep(waitTime/1_000_000, (int)(waitTime%1_000_000));
|
||||
|
||||
@ -3,15 +3,10 @@ package com.bernard.murder.view;
|
||||
import java.awt.GridLayout;
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.DataLine;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.TargetDataLine;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
@ -20,7 +15,6 @@ import javax.swing.JPanel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
import com.bernard.murder.audio.AudioServer;
|
||||
import com.bernard.murder.game.GameCreator;
|
||||
import com.bernard.murder.game.GameCreator.QuicksavedPartie;
|
||||
import com.bernard.murder.game.GameManager;
|
||||
@ -32,24 +26,6 @@ public class LauncherFrame extends JFrame{
|
||||
|
||||
private static final long serialVersionUID = 5831232688024137883L;
|
||||
|
||||
public static void main2(String[] args) throws LineUnavailableException {
|
||||
DataLine.Info ifM = new DataLine.Info(TargetDataLine.class, AudioServer.formatAudio);
|
||||
TargetDataLine mic = (TargetDataLine) AudioSystem.getLine(ifM);
|
||||
//DataLine.Info ifS = new DataLine.Info(SourceDataLine.class, AudioServer.formatAudio);
|
||||
//SourceDataLine spk = (SourceDataLine) AudioSystem.getLine(ifS);
|
||||
|
||||
mic.open(AudioServer.formatAudio);
|
||||
byte[] thedata = new byte[3512];
|
||||
mic.start();
|
||||
for(int i=0;i<500;i++) {
|
||||
System.out.println("Read :"+mic.read(thedata, 0, thedata.length));
|
||||
System.out.println(Arrays.toString(thedata));
|
||||
}
|
||||
mic.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new LauncherFrame();
|
||||
}
|
||||
|
||||
@ -35,7 +35,6 @@ public class MinelsCreator {
|
||||
|
||||
List<Minel> piecesMinels = new ArrayList<>();
|
||||
qpartie.piecesStream().map(p -> new InventaireMinel(manager, p)).forEach(m -> piecesMinels.add(m));
|
||||
|
||||
generalMinels.add(new TextPanMinel(manager));
|
||||
generalMinels.add(new ObjetSearchMinel(manager, manager.getEveryInventaire()));
|
||||
generalMinels.add(new ServeurMinel(manager));
|
||||
|
||||
@ -15,12 +15,14 @@ import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
|
||||
import com.bernard.murder.Parametres;
|
||||
import com.bernard.murder.ParseUtils;
|
||||
import com.bernard.murder.game.GameCreator.QuicksavedPartie;
|
||||
import com.bernard.murder.game.GameManager;
|
||||
import com.bernard.murder.model.Partie;
|
||||
import com.bernard.murder.model.Personnage;
|
||||
import com.bernard.murder.util.view.MouseReactiveTabbedPane;
|
||||
import com.bernard.murder.util.view.ScrollablePanel;
|
||||
import com.bernard.murder.view.minel.Minel;
|
||||
|
||||
public class MurderatorGameFrame extends JFrame{
|
||||
@ -36,7 +38,7 @@ public class MurderatorGameFrame extends JFrame{
|
||||
public MurderatorGameFrame(String frameName, Partie partie, GameManager manager,Map<String,List<Minel>> minelsSup,Map<Personnage,List<Minel>> minels) {
|
||||
this.setSize(700, 500);
|
||||
this.setMinimumSize(new Dimension(200, 100));
|
||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
this.setTitle(frameName);
|
||||
this.minelsSup = minelsSup;
|
||||
this.minels = minels;
|
||||
@ -45,7 +47,7 @@ public class MurderatorGameFrame extends JFrame{
|
||||
|
||||
this.setContentPane(genGamePane(partie,manager,minelsSup,minels));
|
||||
this.addWindowListener(new WListener());
|
||||
this.pack();
|
||||
//this.pack();
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setVisible(true);
|
||||
}
|
||||
@ -59,64 +61,57 @@ public class MurderatorGameFrame extends JFrame{
|
||||
}
|
||||
|
||||
public JPanel genGamePane(Partie partie,GameManager manager,Map<String,List<Minel>> minelsSup,Map<Personnage,List<Minel>> minels) {
|
||||
|
||||
JPanel globalPan = new JPanel(new BorderLayout());
|
||||
|
||||
//Center Panel
|
||||
MouseReactiveTabbedPane centerPan = new MouseReactiveTabbedPane(JTabbedPane.TOP);
|
||||
|
||||
int j = 0;
|
||||
|
||||
for(String s : minelsSup.keySet()) {
|
||||
JPanel centralLocalBpanPan = new JPanel(new GridLayout(2,(minelsSup.get(s).size()+1)/2,-1,-1));
|
||||
minelsSup.get(s).stream().map(m -> m.genContentPane()).forEach(mpan -> {centralLocalBpanPan.add(mpan);mpan.setBorder(BorderFactory.createLineBorder(ParseUtils.randDarkBlueColor(),2));});
|
||||
JScrollPane centralLocalPan = new JScrollPane(centralLocalBpanPan);
|
||||
centerPan.insertTab(s,null,centralLocalPan,null,j++);
|
||||
System.out.println(j);
|
||||
//Calcul des dimensions max
|
||||
int minelCount = minelsSup.get(s).size();
|
||||
int lincount = (int) Math.ceil(((double)minelCount)/((double)Parametres.minielParLigne));
|
||||
ScrollablePanel centralLocalBpanPan = new ScrollablePanel(new GridLayout(lincount,Parametres.minielParLigne,-1,-1));
|
||||
centralLocalBpanPan.setScrollableWidth( ScrollablePanel.ScrollableSizeHint.FIT );
|
||||
minelsSup.get(s).stream()
|
||||
.map(m -> m.genContentPane())
|
||||
.forEach(mpan -> {
|
||||
centralLocalBpanPan.add(mpan);
|
||||
mpan.setBorder(BorderFactory.createLineBorder(ParseUtils.randDarkBlueColor(),3));
|
||||
mpan.setMinimumSize(Parametres.minielMinSize);
|
||||
}
|
||||
);
|
||||
if(lincount > Parametres.lignesDeMinielAvantScroll) {
|
||||
|
||||
JScrollPane jsp = new JScrollPane(centralLocalBpanPan,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
centerPan.insertTab(s,null,jsp,null,j++);
|
||||
} else
|
||||
centerPan.insertTab(s,null,centralLocalBpanPan,null,j++);
|
||||
}
|
||||
|
||||
for(Personnage p : minels.keySet()) {
|
||||
JPanel centralLocalBpanPan = new JPanel(new GridLayout(2, (minels.get(p).size()+1)/2,-1,-1));
|
||||
minels.get(p).stream().map(m -> m.genContentPane()).forEach(mpan -> {centralLocalBpanPan.add(mpan);mpan.setBorder(BorderFactory.createLineBorder(ParseUtils.randDarkBlueColor(),2));});
|
||||
JScrollPane centralLocalPan = new JScrollPane(centralLocalBpanPan);
|
||||
centerPan.insertTab(p.getNom(),null,centralLocalPan,null,j++);
|
||||
System.out.println(j);
|
||||
|
||||
//Calcul des dimensions max
|
||||
int minelCount = minels.get(p).size();
|
||||
int lincount = (int) Math.ceil(((double)minelCount)/((double)Parametres.minielParLigne));
|
||||
ScrollablePanel centralLocalBpanPan = new ScrollablePanel(new GridLayout(lincount,Parametres.minielParLigne,-1,-1));
|
||||
centralLocalBpanPan.setScrollableWidth( ScrollablePanel.ScrollableSizeHint.FIT );
|
||||
minels.get(p).stream()
|
||||
.map(m -> m.genContentPane())
|
||||
.forEach(mpan -> {
|
||||
centralLocalBpanPan.add(mpan);
|
||||
mpan.setBorder(BorderFactory.createLineBorder(ParseUtils.randDarkBlueColor(),3));
|
||||
mpan.setMinimumSize(Parametres.minielMinSize);
|
||||
}
|
||||
);
|
||||
|
||||
if(lincount > Parametres.lignesDeMinielAvantScroll) {
|
||||
JScrollPane jsp = new JScrollPane(centralLocalBpanPan,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
centerPan.insertTab(p.getNom(),null,jsp,null,j++);
|
||||
} else
|
||||
centerPan.insertTab(p.getNom(),null,centralLocalBpanPan,null,j++);
|
||||
}
|
||||
|
||||
for (int i = 0; i < centerPan.getTabCount(); i++) {
|
||||
System.out.println(i);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
//Left Panel
|
||||
JPanel leftPan = new JPanel(new GridLayout(minels.size() + minelsSup.size(), 1));
|
||||
|
||||
for(String s : minelsSup.keySet()) {
|
||||
JButton localButton = new JButton(s);
|
||||
localButton.addActionListener(e -> centerLayout.show(centerPan, s));
|
||||
try {
|
||||
localButton.setDropTarget(new NotADropTarget());
|
||||
localButton.getDropTarget().addDropTargetListener(new HoverSelect(centerLayout, centerPan, s));
|
||||
} catch (TooManyListenersException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
leftPan.add(localButton);
|
||||
}
|
||||
for(Personnage p : minels.keySet()) {
|
||||
JButton localButton = new JButton(p.getNom());
|
||||
localButton.addActionListener(e -> centerLayout.show(centerPan, personnageIdentifier(p)));
|
||||
try {
|
||||
localButton.setDropTarget(new ObjetDropTarget(manager, p, ()->manager.inventoryUpdate(p)));
|
||||
localButton.getDropTarget().addDropTargetListener(new HoverSelect(centerLayout, centerPan, personnageIdentifier(p),DnDConstants.ACTION_MOVE));
|
||||
} catch (TooManyListenersException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
leftPan.add(localButton);
|
||||
}
|
||||
|
||||
globalPan.add(leftPan, BorderLayout.WEST);
|
||||
*/
|
||||
globalPan.add(centerPan, BorderLayout.CENTER);
|
||||
return globalPan;
|
||||
}
|
||||
@ -143,6 +138,8 @@ public class MurderatorGameFrame extends JFrame{
|
||||
|
||||
MurderatorGameFrame.this.setVisible(false);
|
||||
MurderatorGameFrame.this.dispose();
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
package com.bernard.murder.view.minel;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -11,7 +15,9 @@ import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.Timer;
|
||||
@ -35,6 +41,7 @@ public class ActionsMinel extends Minel {
|
||||
Collection<Action> updatingActions;
|
||||
Map<Action,JLabel> actionStatusTexts = new HashMap<>();
|
||||
Map<Action,JButton> actionButtons = new HashMap<>();
|
||||
Map<Action,JPopupMenu> jpmMenus = new HashMap<>();
|
||||
|
||||
public ActionsMinel(GameManager manager, Personnage perso) {
|
||||
super(manager);
|
||||
@ -55,17 +62,33 @@ public class ActionsMinel extends Minel {
|
||||
actionsListPan.setLayout(new BoxLayout(actionsListPan, BoxLayout.PAGE_AXIS));
|
||||
for(Action a : personnage.getActions()) {
|
||||
JPanel actionControlPanel = new JPanel(new BorderLayout());
|
||||
JPanel leftPan = new JPanel(new BorderLayout());
|
||||
JLabel actionName = new JLabel(a.getName());
|
||||
|
||||
JPanel outerButton = new JPanel(new GridBagLayout());
|
||||
|
||||
JButton actionButton = new JButton("GO");
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.anchor = GridBagConstraints.CENTER;
|
||||
outerButton.add(actionButton,gbc);
|
||||
|
||||
JLabel actionStatusText = new JLabel(availableText);
|
||||
|
||||
actionButton.addActionListener(e->launchAction(a));
|
||||
actionButtons.put(a, actionButton);
|
||||
actionStatusTexts.put(a, actionStatusText);
|
||||
|
||||
actionControlPanel.add(actionButton, BorderLayout.EAST);
|
||||
actionControlPanel.add(actionName, BorderLayout.NORTH);
|
||||
actionControlPanel.add(actionStatusText, BorderLayout.SOUTH);
|
||||
leftPan.add(actionName, BorderLayout.NORTH);
|
||||
leftPan.add(actionStatusText, BorderLayout.SOUTH);
|
||||
actionControlPanel.add(outerButton, BorderLayout.EAST);
|
||||
actionControlPanel.add(leftPan,BorderLayout.CENTER);
|
||||
|
||||
ActionPopupListener apl = new ActionPopupListener(a);
|
||||
jpmMenus.put(a, apl.makePopup());
|
||||
actionControlPanel.addMouseListener(apl);
|
||||
|
||||
actionsListPan.add(actionControlPanel);
|
||||
actionsListPan.add(new JSeparator());
|
||||
@ -96,6 +119,13 @@ public class ActionsMinel extends Minel {
|
||||
updatingActions.add(a);
|
||||
}
|
||||
|
||||
private void resetAction(Action a) {
|
||||
a.reset();
|
||||
actionButtons.get(a).setEnabled(true);
|
||||
updateTexts();
|
||||
updatingActions.remove(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlMappingBuilder saveToYaml() {
|
||||
return Yaml.createYamlMappingBuilder().add("personnage", personnage.getNom());
|
||||
@ -115,6 +145,37 @@ public class ActionsMinel extends Minel {
|
||||
actionStatusTexts.get(a).setText(String.format(waitingTimeText, ParseUtils.dumpTimeLength(a.timeToWaitLeft()), ParseUtils.dumpHourDate(a.dateReset())));
|
||||
}
|
||||
|
||||
public class ActionPopupListener extends MouseAdapter {
|
||||
|
||||
Action theAction;
|
||||
|
||||
public ActionPopupListener(Action theAction) {
|
||||
this.theAction = theAction;
|
||||
}
|
||||
|
||||
public final JPopupMenu makePopup() {
|
||||
JPopupMenu popup = new JPopupMenu();
|
||||
|
||||
JMenuItem jmi = new JMenuItem("Réinitialiser");
|
||||
jmi.addActionListener(e -> resetAction(theAction));
|
||||
popup.add(jmi);
|
||||
return popup;
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
maybeShowPopup(e);
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
maybeShowPopup(e);
|
||||
}
|
||||
|
||||
private void maybeShowPopup(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
jpmMenus.get(theAction).show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -3,12 +3,19 @@ package com.bernard.murder.view.minel;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListCellRenderer;
|
||||
|
||||
import com.amihaiemil.eoyaml.Yaml;
|
||||
@ -34,6 +41,8 @@ public class InventaireMinel extends Minel {
|
||||
|
||||
JList<Objet> objets;
|
||||
Inventaire inv;
|
||||
|
||||
JPopupMenu invPopup;
|
||||
|
||||
@Override
|
||||
public JPanel genContentPane() {
|
||||
@ -51,7 +60,7 @@ public class InventaireMinel extends Minel {
|
||||
|
||||
JPanel inventaire = new JPanel();
|
||||
|
||||
JButton voler = new JButton("RandomItem");
|
||||
JButton voler = new JButton("Objet au pif");
|
||||
voler.addActionListener(e -> {
|
||||
objets.setSelectedIndex((int) (Math.random() * objets.getModel().getSize()));
|
||||
});
|
||||
@ -60,6 +69,8 @@ public class InventaireMinel extends Minel {
|
||||
objets.setCellRenderer(new ObjetListCellRenderer());
|
||||
objets.setDragEnabled(true);
|
||||
objets.setTransferHandler(new ObjetTransferHandler());
|
||||
objets.setOpaque(false);
|
||||
objets.addMouseListener(new InvPopupListener());
|
||||
updateObjets();
|
||||
final ObjetDropTarget odt = new ObjetDropTarget(manager, inv, this::updateObjets);
|
||||
objets.setDropTarget(odt);
|
||||
@ -69,15 +80,15 @@ public class InventaireMinel extends Minel {
|
||||
|
||||
inventaire.add(objets);
|
||||
|
||||
JScrollPane textsp = new JScrollPane(inventaire);
|
||||
|
||||
globalpan.add(voler, BorderLayout.SOUTH);
|
||||
globalpan.add(inventaire, BorderLayout.CENTER);
|
||||
globalpan.add(textsp, BorderLayout.CENTER);
|
||||
|
||||
return globalpan;
|
||||
}
|
||||
|
||||
private void updateObjets() {
|
||||
System.out.print("Updating "+inv+" with");
|
||||
manager.dumpCurrentState();
|
||||
Objet[] objz = new Objet[inv.getObjects().size()];
|
||||
objz = inv.getObjects().toArray(objz);
|
||||
objets.setListData(objz);
|
||||
@ -92,18 +103,21 @@ public class InventaireMinel extends Minel {
|
||||
|
||||
private static final long serialVersionUID = -7176962839330435585L;
|
||||
|
||||
Font origFont = null;
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<? extends Objet> list, Objet objet, int index,
|
||||
boolean isSelected, boolean cellHasFocus) {
|
||||
|
||||
setText(objet.getNom());
|
||||
|
||||
if(origFont==null)origFont = getFont();
|
||||
if (isSelected) {
|
||||
setFont(getFont().deriveFont(Font.BOLD));
|
||||
setBackground(list.getSelectionBackground());
|
||||
double ratio = 0.9;
|
||||
setFont(origFont.deriveFont(AffineTransform.getScaleInstance(ratio, 1.0)));
|
||||
setBackground(list.getSelectionBackground());
|
||||
setForeground(list.getSelectionForeground());
|
||||
} else {
|
||||
setFont(getFont().deriveFont(Font.PLAIN));
|
||||
setFont(origFont.deriveFont(Font.PLAIN));
|
||||
setBackground(list.getBackground());
|
||||
setForeground(list.getForeground());
|
||||
}
|
||||
@ -112,4 +126,70 @@ public class InventaireMinel extends Minel {
|
||||
}
|
||||
}
|
||||
|
||||
public class InvPopupListener extends MouseAdapter{
|
||||
|
||||
JPopupMenu jpm;
|
||||
JMenuItem renameOpt;
|
||||
JMenuItem deleteOpt;
|
||||
|
||||
public InvPopupListener() {
|
||||
|
||||
jpm = new JPopupMenu();
|
||||
|
||||
JMenuItem createOpt = new JMenuItem("Créer");
|
||||
createOpt.addActionListener(e -> {
|
||||
String newName = JOptionPane.showInputDialog(
|
||||
objets,
|
||||
"Nom du nouvel objet",
|
||||
"Création d'objet",
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
if(newName != null)
|
||||
manager.createObjet(newName,inv);
|
||||
});
|
||||
jpm.add(createOpt);
|
||||
renameOpt = new JMenuItem("Renommer");
|
||||
renameOpt.addActionListener(e -> {
|
||||
String newName = JOptionPane.showInputDialog(
|
||||
objets,
|
||||
"Nouveau nom",
|
||||
"Renommage d'objet",
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
if(newName != null)
|
||||
manager.renameObjet(objets.getSelectedValue(),newName,inv);
|
||||
});
|
||||
jpm.add(renameOpt);
|
||||
deleteOpt = new JMenuItem("Supprimer");
|
||||
deleteOpt.addActionListener(e -> {
|
||||
int res = JOptionPane.showConfirmDialog(
|
||||
objets,
|
||||
"Voulez-vous vraiment détruire cet objet ?",
|
||||
"Destruction d'objet",
|
||||
JOptionPane.WARNING_MESSAGE,
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if(res == JOptionPane.OK_OPTION)
|
||||
manager.deleteObjet(objets.getSelectedValue(),inv);
|
||||
});
|
||||
jpm.add(deleteOpt);
|
||||
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
maybeShowPopup(e);
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
maybeShowPopup(e);
|
||||
}
|
||||
|
||||
private void maybeShowPopup(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
objets.setSelectedIndex(objets.locationToIndex(e.getPoint()));
|
||||
renameOpt.setEnabled(!objets.isSelectionEmpty());
|
||||
deleteOpt.setEnabled(!objets.isSelectionEmpty());
|
||||
jpm.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import javax.swing.BorderFactory;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
@ -114,7 +115,7 @@ public class ObjetSearchMinel extends Minel {
|
||||
|
||||
|
||||
panel.add(searchField, BorderLayout.NORTH);
|
||||
panel.add(searchResults,BorderLayout.CENTER);
|
||||
panel.add(new JScrollPane(searchResults),BorderLayout.CENTER);
|
||||
|
||||
globalPan.add(titre,BorderLayout.NORTH);
|
||||
globalPan.add(panel,BorderLayout.CENTER);
|
||||
|
||||
@ -142,7 +142,7 @@ public class EnceintePopupListener extends MouseAdapter{
|
||||
JLabel idText = new JLabel();
|
||||
idText.setFont(idText.getFont().deriveFont(Font.ITALIC));
|
||||
idText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
micListe.getSelectionModel().addListSelectionListener(e ->
|
||||
micListe.getSelectionModel().addListSelectionListener(e -> //XXX: Tester si l'affichage se met bien à jour ici
|
||||
idText.setText("Id: "+ (micListe.getSelectedValue()!=null?micListe.getSelectedValue():-1))
|
||||
);
|
||||
popup.add(idText);
|
||||
|
||||
@ -40,6 +40,7 @@ public class TextPanMinel extends Minel {
|
||||
textArea = new JTextArea();
|
||||
textArea.setBorder(new EmptyBorder(23,23,23,23));
|
||||
textArea.setText("");
|
||||
textArea.setLineWrap(true);
|
||||
|
||||
textArea.setBackground(Parametres.textPanMinielBackgroundColor);
|
||||
textArea.setForeground(Parametres.textPanMinielTextColor);
|
||||
|
||||
@ -36,7 +36,6 @@ public class ObjetDropTarget extends DropTarget {
|
||||
}
|
||||
for(Runnable runnable : toUpdate)
|
||||
runnable.run();
|
||||
manager.dumpCurrentState();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user