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/Content.java
| a9b2a64 | 1 | package gdxstudio; |
| a9b2a64 | 2 | import gdxstudio.panel.AssetPanel; |
| a9b2a64 | 3 | import gdxstudio.panel.ConsolePanel; |
| a9b2a64 | 4 | import gdxstudio.panel.ReplacePanel; |
| a9b2a64 | 5 | import gdxstudio.panel.StudioPanel; |
| a9b2a64 | 6 | import gdxstudio.panel.WidgetPanel; |
| a9b2a64 | 7 | |
| a62d533 | 8 | import java.awt.BorderLayout; |
| a62d533 | 9 | import java.awt.CardLayout; |
| a62d533 | 10 | import java.awt.Insets; |
| a62d533 | 11 | import java.io.File; |
| a62d533 | 12 | |
| 7c84877 | 13 | import javax.swing.BorderFactory; |
| a62d533 | 14 | import javax.swing.JButton; |
| a62d533 | 15 | import javax.swing.JPanel; |
| a62d533 | 16 | import javax.swing.SwingUtilities; |
| a62d533 | 17 | |
| a62d533 | 18 | import org.fife.ui.rsyntaxtextarea.Theme; |
| a62d533 | 19 | import org.fife.ui.rtextarea.RTextScrollPane; |
| a62d533 | 20 | |
| a62d533 | 21 | import web.laf.lite.layout.VerticalFlowLayout; |
| a62d533 | 22 | import web.laf.lite.utils.UIUtils; |
| a62d533 | 23 | import web.laf.lite.widget.Register; |
| a62d533 | 24 | |
| a62d533 | 25 | final public class Content extends JPanel {
|
| a62d533 | 26 | private static final long serialVersionUID = 1L; |
| a62d533 | 27 | private static JPanel card; |
| a62d533 | 28 | public static String currentView = "Project"; |
| a62d533 | 29 | |
| a62d533 | 30 | private static String projectFile = null; |
| a62d533 | 31 | private static Register projectRegister; |
| a62d533 | 32 | |
| a62d533 | 33 | public static Theme theme = Icon.loadTheme(Register.getTheme()); |
| a62d533 | 34 | |
| a62d533 | 35 | public static Editor editor; |
| a62d533 | 36 | public static RTextScrollPane editorScroll; |
| a62d533 | 37 | public static StudioPanel studioPanel; |
| a62d533 | 38 | private static ReplacePanel replacePanel; |
| a62d533 | 39 | public static AssetPanel assetPanel; |
| a9b2a64 | 40 | public static WidgetPanel widgetPanel; |
| a62d533 | 41 | private static ConsolePanel consolePanel; |
| a62d533 | 42 | |
| a62d533 | 43 | public static void initProjects(){
|
| a62d533 | 44 | projectRegister = new Register(105); |
| a62d533 | 45 | projectFile = Register.getString(projectRegister); |
| a62d533 | 46 | } |
| a62d533 | 47 | |
| a62d533 | 48 | public Content(){
|
| a62d533 | 49 | super(new BorderLayout()); |
| a62d533 | 50 | UIUtils.setMargin(this, new Insets(1,2,0,2)); |
| a62d533 | 51 | UIUtils.setUndecorated(this, true); |
| a62d533 | 52 | editor = new Editor(); |
| a62d533 | 53 | theme.apply(editor); |
| a62d533 | 54 | editorScroll = new RTextScrollPane(editor); |
| a62d533 | 55 | editorScroll.getGutter().setBookmarkIcon(Icon.icon("bookmark"));
|
| a62d533 | 56 | editorScroll.getGutter().setBookmarkingEnabled(true); |
| a62d533 | 57 | editorScroll.setVerticalScrollBarPolicy(RTextScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
| a62d533 | 58 | UIUtils.setDrawBorder(editorScroll, false); |
| a62d533 | 59 | studioPanel = new StudioPanel(); |
| a62d533 | 60 | // CardLayout |
| a62d533 | 61 | card = new JPanel(new CardLayout()); |
| a62d533 | 62 | card.add(editorScroll, "Editor"); |
| a62d533 | 63 | card.add(studioPanel, "Studio"); |
| a62d533 | 64 | |
| a62d533 | 65 | JPanel north = new JPanel(new VerticalFlowLayout()); |
| a62d533 | 66 | replacePanel = new ReplacePanel(); |
| a62d533 | 67 | north.add(replacePanel); |
| a62d533 | 68 | add(north, BorderLayout.NORTH); |
| a62d533 | 69 | add(card, BorderLayout.CENTER); |
| a62d533 | 70 | |
| a62d533 | 71 | JPanel vert = new JPanel(new VerticalFlowLayout()); |
| a62d533 | 72 | assetPanel = new AssetPanel(); |
| a62d533 | 73 | consolePanel = new ConsolePanel(); |
| a62d533 | 74 | assetPanel.setVisible(false); |
| a9b2a64 | 75 | widgetPanel = new WidgetPanel(); |
| a9b2a64 | 76 | widgetPanel.setVisible(false); |
| a9b2a64 | 77 | |
| a9b2a64 | 78 | vert.add(widgetPanel); |
| a62d533 | 79 | vert.add(assetPanel); |
| a62d533 | 80 | vert.add(consolePanel); |
| a62d533 | 81 | add(vert, BorderLayout.SOUTH); |
| 7c84877 | 82 | setBorder(BorderFactory.createMatteBorder(0, 1, 0, 1, Style.border)); |
| a62d533 | 83 | } |
| a62d533 | 84 | |
| a62d533 | 85 | private static boolean canvasChanged = true; |
| a62d533 | 86 | public static void toggleView(int index) {
|
| a62d533 | 87 | for(JButton b: Style.viewGroup){
|
| a62d533 | 88 | if(index-1 == Style.viewGroup.indexOf(b)) |
| a62d533 | 89 | b.setSelected(true); |
| a62d533 | 90 | else |
| a62d533 | 91 | b.setSelected(false); |
| a62d533 | 92 | } |
| a62d533 | 93 | switch(index){
|
| a62d533 | 94 | case 1: showContent("Editor");
|
| a62d533 | 95 | break; |
| a62d533 | 96 | case 2: showContent("Studio");
|
| a62d533 | 97 | if(canvasChanged){
|
| a62d533 | 98 | SwingUtilities.invokeLater(new Runnable(){
|
| a62d533 | 99 | @Override |
| a62d533 | 100 | public void run() {
|
| a62d533 | 101 | studioPanel.createStudioCanvas(); |
| a62d533 | 102 | } |
| a62d533 | 103 | }); |
| a62d533 | 104 | canvasChanged = false; |
| a62d533 | 105 | } |
| a62d533 | 106 | break; |
| a62d533 | 107 | case 3: showContent("Studio");
|
| a62d533 | 108 | SwingUtilities.invokeLater(new Runnable(){
|
| a62d533 | 109 | @Override |
| a62d533 | 110 | public void run() {
|
| a62d533 | 111 | studioPanel.createHieroCanvas(); |
| a62d533 | 112 | } |
| a62d533 | 113 | }); |
| a62d533 | 114 | canvasChanged = true; |
| a62d533 | 115 | break; |
| a62d533 | 116 | case 4: showContent("Studio");
|
| a62d533 | 117 | SwingUtilities.invokeLater(new Runnable(){
|
| a62d533 | 118 | @Override |
| a62d533 | 119 | public void run() {
|
| a62d533 | 120 | studioPanel.createParticleCanvas(); |
| a62d533 | 121 | } |
| a62d533 | 122 | }); |
| a62d533 | 123 | canvasChanged = true; |
| a62d533 | 124 | break; |
| a62d533 | 125 | default: break; |
| a62d533 | 126 | } |
| a62d533 | 127 | } |
| a62d533 | 128 | |
| a62d533 | 129 | public static void toggleReplace(){
|
| a62d533 | 130 | replacePanel.setVisible(!replacePanel.isVisible()); |
| a62d533 | 131 | } |
| a62d533 | 132 | |
| a62d533 | 133 | public static void toggleAsset(){
|
| a62d533 | 134 | assetPanel.setVisible(!assetPanel.isVisible()); |
| a62d533 | 135 | } |
| a62d533 | 136 | |
| a62d533 | 137 | public static void toggleConsole(){
|
| a62d533 | 138 | consolePanel.setVisible(!consolePanel.isVisible()); |
| a62d533 | 139 | } |
| a62d533 | 140 | |
| a9b2a64 | 141 | public static void toggleWidget(){
|
| a9b2a64 | 142 | widgetPanel.setVisible(!widgetPanel.isVisible()); |
| a9b2a64 | 143 | } |
| a9b2a64 | 144 | |
| a62d533 | 145 | private static void showContent(String contentName){
|
| a62d533 | 146 | if(currentView.equals(contentName)) |
| a62d533 | 147 | return; |
| a62d533 | 148 | ((CardLayout) card.getLayout()).show(card, contentName); |
| a62d533 | 149 | currentView = contentName; |
| a62d533 | 150 | } |
| a62d533 | 151 | |
| a62d533 | 152 | public static boolean projectExists(){
|
| a62d533 | 153 | if(getProject() == null || getProject().isEmpty() || !(new File(getProject()).exists())) |
| a62d533 | 154 | return false; |
| a62d533 | 155 | return true; |
| a62d533 | 156 | } |
| a62d533 | 157 | |
| a62d533 | 158 | public static String getProject() {
|
| a62d533 | 159 | return projectFile; |
| a62d533 | 160 | } |
| a62d533 | 161 | |
| a62d533 | 162 | public static void setProject(String prjName) {
|
| a62d533 | 163 | prjName = prjName.replace("\\", "/");
|
| a62d533 | 164 | Register.putString(projectRegister, prjName); |
| a62d533 | 165 | projectFile = prjName; |
| a62d533 | 166 | } |
| a62d533 | 167 | } |