gdx-studio
git clone https://git.pyrossh.dev/gdx-studio
An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop
src/gdxstudio/panel/ActorPanel.java
| a9b2a64 | 1 | package gdxstudio.panel; |
| a9b2a64 | 2 | import gdxstudio.Content; |
| a9b2a64 | 3 | import gdxstudio.Frame; |
| a9b2a64 | 4 | import gdxstudio.SceneEditor; |
| a9b2a64 | 5 | import gdxstudio.StatusBar; |
| a9b2a64 | 6 | import gdxstudio.Style; |
| a9b2a64 | 7 | |
| a9b2a64 | 8 | import java.awt.Component; |
| 7c84877 | 9 | import java.awt.Dimension; |
| a62d533 | 10 | import java.awt.event.ActionEvent; |
| a62d533 | 11 | |
| a62d533 | 12 | import javax.swing.JButton; |
| 7c84877 | 13 | import javax.swing.JComboBox; |
| 7c84877 | 14 | import javax.swing.JPanel; |
| a62d533 | 15 | import javax.swing.event.ListSelectionEvent; |
| a62d533 | 16 | |
| a9b2a64 | 17 | import scene2d.Scene; |
| 7c84877 | 18 | import web.laf.lite.widget.CenterPanel; |
| 7c84877 | 19 | |
| a62d533 | 20 | import com.badlogic.gdx.scenes.scene2d.Actor; |
| a62d533 | 21 | |
| a62d533 | 22 | public class ActorPanel extends BaseList {
|
| a62d533 | 23 | private static final long serialVersionUID = 1L; |
| a62d533 | 24 | |
| a62d533 | 25 | String[] btns = new String[]{
|
| a62d533 | 26 | "Cut", "cut", "Copy", "copy", "Paste", "paste", "Delete", "trash" |
| a62d533 | 27 | }; |
| 7c84877 | 28 | private JComboBox<String> groupCombo = BaseTable.createComboBox(); |
| a62d533 | 29 | |
| a62d533 | 30 | public static Actor copiedActor = null; |
| 7c84877 | 31 | public static Actor cutActor = null; |
| a9b2a64 | 32 | public Component paste; |
| a9b2a64 | 33 | |
| a62d533 | 34 | |
| a62d533 | 35 | public ActorPanel(){
|
| a62d533 | 36 | super("Actors", "");
|
| 7c84877 | 37 | JPanel tools = Style.createButtonToolBar(this, btns); |
| 7c84877 | 38 | groupCombo.addItem("Root");
|
| 7c84877 | 39 | groupCombo.setPreferredSize(new Dimension(90, 17)); |
| 7c84877 | 40 | tools.add(new CenterPanel(groupCombo, false, true)); |
| 7c84877 | 41 | add(tools); |
| a62d533 | 42 | add(scrollPane); |
| a9b2a64 | 43 | if(Frame.scenePanel.selectedValueExists()) |
| a9b2a64 | 44 | setHeaderText(Frame.scenePanel.getSelectedValue()); |
| a9b2a64 | 45 | paste = tools.getComponent(2); |
| a9b2a64 | 46 | paste.setEnabled(false); |
| a62d533 | 47 | } |
| a62d533 | 48 | |
| a62d533 | 49 | public void addActor(String actorName){
|
| a62d533 | 50 | lock(); |
| a62d533 | 51 | listModel2.addElement(actorName); |
| a62d533 | 52 | unlock(); |
| a62d533 | 53 | } |
| a62d533 | 54 | |
| a62d533 | 55 | public void renameActor(String actorName, String newName){
|
| a62d533 | 56 | lock(); |
| a62d533 | 57 | listModel2.removeElement(actorName); |
| a62d533 | 58 | listModel2.addElement(newName); |
| a62d533 | 59 | unlock(); |
| a62d533 | 60 | } |
| a62d533 | 61 | |
| 7c84877 | 62 | public void addGroup(String groupName){
|
| 7c84877 | 63 | groupCombo.addItem(groupName); |
| 7c84877 | 64 | } |
| 7c84877 | 65 | |
| 7c84877 | 66 | public void removeGroup(String groupName){
|
| 7c84877 | 67 | // must check for root |
| 7c84877 | 68 | for(int i=0;i<groupCombo.getItemCount();i++) |
| 7c84877 | 69 | if(groupCombo.getItemAt(i).equals(groupCombo.getSelectedItem())){
|
| 7c84877 | 70 | groupCombo.removeItem(groupName); |
| 7c84877 | 71 | break; |
| 7c84877 | 72 | } |
| 7c84877 | 73 | } |
| 7c84877 | 74 | |
| a62d533 | 75 | @Override |
| a62d533 | 76 | public void clear(){
|
| a62d533 | 77 | lock(); |
| a62d533 | 78 | listModel2.model.clear(); |
| a62d533 | 79 | unlock(); |
| a62d533 | 80 | StatusBar.updateSelected("None");
|
| a62d533 | 81 | } |
| a62d533 | 82 | |
| a62d533 | 83 | public boolean contains(String name){
|
| a62d533 | 84 | return listModel2.contains(name); |
| a62d533 | 85 | } |
| a62d533 | 86 | |
| a62d533 | 87 | public int indexOf(String element){
|
| a62d533 | 88 | return listModel2.indexOf(element); |
| a62d533 | 89 | } |
| a62d533 | 90 | |
| a62d533 | 91 | @Override |
| a62d533 | 92 | public void valueChanged(ListSelectionEvent e) {
|
| a62d533 | 93 | if (e.getValueIsAdjusting() == false) {
|
| a9b2a64 | 94 | SceneEditor.doClick(Scene.getCurrentScene().findActor(list.getSelectedValue())); |
| a62d533 | 95 | } |
| a62d533 | 96 | } |
| a62d533 | 97 | |
| a62d533 | 98 | @Override |
| a62d533 | 99 | public void actionPerformed(ActionEvent e) {
|
| a62d533 | 100 | lock(); |
| a62d533 | 101 | switch(((JButton)e.getSource()).getToolTipText()){
|
| a62d533 | 102 | case "Cut": |
| a9b2a64 | 103 | if(list.getSelectedIndex() != -1){
|
| a9b2a64 | 104 | cutActor = SceneEditor.selectedActor; |
| a9b2a64 | 105 | copiedActor = null; |
| a9b2a64 | 106 | listModel2.removeElement(SceneEditor.selectedActor.getName()); |
| a9b2a64 | 107 | Scene.getCurrentScene().removeActor(SceneEditor.selectedActor); |
| a9b2a64 | 108 | paste.setEnabled(true); |
| a9b2a64 | 109 | } |
| a62d533 | 110 | break; |
| a62d533 | 111 | |
| a62d533 | 112 | case "Copy": |
| a9b2a64 | 113 | if(list.getSelectedIndex() != -1){
|
| a9b2a64 | 114 | String line = Scene.json.toJson(SceneEditor.selectedActor); |
| a9b2a64 | 115 | copiedActor = Scene.json.fromJson(Actor.class, line); |
| a9b2a64 | 116 | cutActor = null; |
| a9b2a64 | 117 | paste.setEnabled(true); |
| a9b2a64 | 118 | } |
| a62d533 | 119 | break; |
| a62d533 | 120 | |
| a62d533 | 121 | case "Paste": |
| 7c84877 | 122 | if(cutActor != null){
|
| 7c84877 | 123 | Content.studioPanel.setName(cutActor); |
| 7c84877 | 124 | cutActor = null; |
| a9b2a64 | 125 | paste.setEnabled(false); |
| 7c84877 | 126 | } |
| a62d533 | 127 | if(copiedActor != null){
|
| a9b2a64 | 128 | copiedActor = Scene.json.fromJson(Actor.class, Scene.json.toJson(SceneEditor.selectedActor)); |
| 7c84877 | 129 | Content.studioPanel.setName(copiedActor); |
| a62d533 | 130 | } |
| a9b2a64 | 131 | Scene.isDirty = true; |
| a62d533 | 132 | break; |
| a62d533 | 133 | |
| a62d533 | 134 | case "Delete": |
| a9b2a64 | 135 | if(list.getSelectedIndex() != -1){
|
| a9b2a64 | 136 | Scene.getCurrentScene().removeActor(SceneEditor.selectedActor); |
| a9b2a64 | 137 | StatusBar.updateSelected("None");
|
| a9b2a64 | 138 | if(contains(SceneEditor.selectedActor.getName())) |
| a9b2a64 | 139 | listModel2.removeElement(SceneEditor.selectedActor.getName()); |
| a9b2a64 | 140 | Scene.isDirty = true; |
| a9b2a64 | 141 | } |
| a62d533 | 142 | break; |
| a62d533 | 143 | } |
| a62d533 | 144 | unlock(); |
| a62d533 | 145 | } |
| 7c84877 | 146 | |
| 7c84877 | 147 | public void setHeaderText(String text){
|
| 7c84877 | 148 | header.setText(text); |
| 7c84877 | 149 | } |
| a62d533 | 150 | } |