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/Frame.java
| a9b2a64 | 1 | package gdxstudio; |
| a9b2a64 | 2 | |
| a9b2a64 | 3 | import gdxstudio.panel.ActorPanel; |
| a9b2a64 | 4 | import gdxstudio.panel.BaseList; |
| a9b2a64 | 5 | import gdxstudio.panel.BaseTable; |
| a9b2a64 | 6 | import gdxstudio.panel.ConsolePanel; |
| a9b2a64 | 7 | import gdxstudio.panel.DashPanel; |
| a9b2a64 | 8 | import gdxstudio.panel.EffectPanel; |
| a9b2a64 | 9 | import gdxstudio.panel.EventPanel; |
| a9b2a64 | 10 | import gdxstudio.panel.ProjectPanel; |
| a9b2a64 | 11 | import gdxstudio.panel.ProjectSettingsPanel; |
| a9b2a64 | 12 | import gdxstudio.panel.PropertyPanel; |
| a9b2a64 | 13 | import gdxstudio.panel.SceneEffectPanel; |
| a9b2a64 | 14 | import gdxstudio.panel.ScenePanel; |
| a9b2a64 | 15 | import gdxstudio.panel.StudioPanel; |
| a9b2a64 | 16 | |
| a62d533 | 17 | import java.awt.BorderLayout; |
| a62d533 | 18 | import java.awt.Component; |
| a62d533 | 19 | import java.awt.event.WindowEvent; |
| a62d533 | 20 | import java.awt.event.WindowListener; |
| a62d533 | 21 | |
| a62d533 | 22 | import javax.swing.JButton; |
| a62d533 | 23 | import javax.swing.JFrame; |
| a62d533 | 24 | import javax.swing.JLabel; |
| a62d533 | 25 | import javax.swing.JList; |
| a62d533 | 26 | import javax.swing.JPanel; |
| a62d533 | 27 | |
| a9b2a64 | 28 | import scene2d.Asset; |
| a9b2a64 | 29 | import scene2d.Scene; |
| a62d533 | 30 | import web.laf.lite.layout.VerticalFlowLayout; |
| 7c84877 | 31 | import web.laf.lite.utils.UIUtils; |
| a62d533 | 32 | |
| a62d533 | 33 | final public class Frame extends JFrame implements WindowListener{
|
| a62d533 | 34 | private static final long serialVersionUID = 1L; |
| a62d533 | 35 | private static Frame frame; |
| a62d533 | 36 | private static ToolBar toolBar; |
| a62d533 | 37 | private static JPanel rightSideBar; |
| a62d533 | 38 | private static JPanel leftSideBar; |
| a62d533 | 39 | private static StatusBar statusBar; |
| a62d533 | 40 | public static Content content; |
| a62d533 | 41 | |
| a62d533 | 42 | public static ProjectPanel projectPanel; |
| a62d533 | 43 | public static ProjectSettingsPanel projectSettingsPanel; |
| a62d533 | 44 | public static ScenePanel scenePanel; |
| a62d533 | 45 | public static SceneEffectPanel sceneEffectPanel; |
| a62d533 | 46 | public static ActorPanel actorPanel; |
| a62d533 | 47 | |
| a62d533 | 48 | public static DashPanel dashPanel; |
| a62d533 | 49 | public static PropertyPanel propertyPanel; |
| a62d533 | 50 | public static EffectPanel effectPanel; |
| a62d533 | 51 | public static EventPanel eventPanel; |
| a62d533 | 52 | |
| a62d533 | 53 | public static boolean projectEnabled = true; |
| a62d533 | 54 | |
| a62d533 | 55 | |
| a62d533 | 56 | private Frame() {
|
| a62d533 | 57 | setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); |
| a62d533 | 58 | addWindowListener(this); |
| 7c84877 | 59 | //styleProject(); |
| a62d533 | 60 | } |
| a62d533 | 61 | |
| a62d533 | 62 | public static Frame getInstance(){
|
| a62d533 | 63 | if(frame == null) |
| a62d533 | 64 | frame = new Frame(); |
| a62d533 | 65 | return frame; |
| a62d533 | 66 | } |
| a62d533 | 67 | |
| a62d533 | 68 | public void initToolBar(){
|
| a62d533 | 69 | toolBar = new ToolBar(); |
| a62d533 | 70 | add(toolBar, BorderLayout.NORTH); |
| a62d533 | 71 | } |
| a62d533 | 72 | |
| a62d533 | 73 | public void initSideBar(){
|
| 7c84877 | 74 | rightSideBar = new JPanel(new VerticalFlowLayout(0, 10)); |
| 7c84877 | 75 | UIUtils.setUndecorated(rightSideBar, true); |
| a62d533 | 76 | dashPanel = new DashPanel(); |
| a62d533 | 77 | propertyPanel = new PropertyPanel(); |
| a62d533 | 78 | effectPanel = new EffectPanel(); |
| a62d533 | 79 | eventPanel = new EventPanel(); |
| a62d533 | 80 | rightSideBar.add(dashPanel); |
| a62d533 | 81 | rightSideBar.add(propertyPanel); |
| a62d533 | 82 | //rightSideBar.add(new TablePanel("TT"));
|
| a62d533 | 83 | rightSideBar.add(effectPanel); |
| a62d533 | 84 | rightSideBar.add(eventPanel); |
| a62d533 | 85 | |
| 7c84877 | 86 | leftSideBar = new JPanel(new VerticalFlowLayout(0, 10)); |
| 7c84877 | 87 | UIUtils.setUndecorated(leftSideBar, true); |
| a62d533 | 88 | projectPanel = new ProjectPanel(); |
| a62d533 | 89 | projectSettingsPanel = new ProjectSettingsPanel(); |
| a62d533 | 90 | projectSettingsPanel.setVisible(false); |
| a62d533 | 91 | scenePanel = new ScenePanel(); |
| a62d533 | 92 | sceneEffectPanel = new SceneEffectPanel(); |
| a62d533 | 93 | actorPanel = new ActorPanel(); |
| a62d533 | 94 | leftSideBar.add(projectPanel); |
| a62d533 | 95 | leftSideBar.add(projectSettingsPanel); |
| a62d533 | 96 | leftSideBar.add(scenePanel); |
| a62d533 | 97 | leftSideBar.add(sceneEffectPanel); |
| a62d533 | 98 | leftSideBar.add(actorPanel); |
| a62d533 | 99 | |
| a62d533 | 100 | add(rightSideBar, BorderLayout.EAST); |
| a62d533 | 101 | add(leftSideBar, BorderLayout.WEST); |
| a62d533 | 102 | } |
| a62d533 | 103 | |
| a62d533 | 104 | public void initStatusBar(){
|
| a62d533 | 105 | statusBar = new StatusBar(); |
| a62d533 | 106 | add(statusBar, BorderLayout.SOUTH); |
| a62d533 | 107 | } |
| a62d533 | 108 | |
| a62d533 | 109 | public void initContent(){
|
| a62d533 | 110 | content = new Content(); |
| a62d533 | 111 | add(content, BorderLayout.CENTER); |
| a62d533 | 112 | } |
| a62d533 | 113 | |
| a62d533 | 114 | public static void toggleToolBar(){
|
| a62d533 | 115 | toolBar.setVisible(!toolBar.isVisible()); |
| a62d533 | 116 | } |
| a62d533 | 117 | |
| a62d533 | 118 | public static void toggleStatusBar(){
|
| a62d533 | 119 | statusBar.setVisible(!statusBar.isVisible()); |
| a62d533 | 120 | } |
| a62d533 | 121 | |
| a62d533 | 122 | public static void toggleLeftSideBar(){
|
| a62d533 | 123 | leftSideBar.setVisible(!leftSideBar.isVisible()); |
| a9b2a64 | 124 | if(Content.studioPanel != null) |
| a9b2a64 | 125 | Content.studioPanel.revalidateScreenPosition(); |
| a62d533 | 126 | } |
| a62d533 | 127 | |
| a62d533 | 128 | public static void toggleRightSideBar(){
|
| a62d533 | 129 | rightSideBar.setVisible(!rightSideBar.isVisible()); |
| a9b2a64 | 130 | if(Content.studioPanel != null) |
| a9b2a64 | 131 | Content.studioPanel.revalidateScreenPosition(); |
| a62d533 | 132 | } |
| a62d533 | 133 | |
| a62d533 | 134 | private static void updateProject(){
|
| a62d533 | 135 | Asset.loadAsynchronous = false; |
| a62d533 | 136 | Asset.setBasePath(Content.getProject()); |
| a62d533 | 137 | SceneEditor.reloadAssets = true; // to load assets of new project |
| a62d533 | 138 | StudioPanel.updateAssets(); |
| a62d533 | 139 | Content.toggleView(2); |
| a62d533 | 140 | sceneEffectPanel.clear(); |
| a62d533 | 141 | scenePanel.clear(); |
| a62d533 | 142 | projectSettingsPanel.clear(); |
| a62d533 | 143 | propertyPanel.clear(); |
| a62d533 | 144 | eventPanel.clear(); |
| a62d533 | 145 | |
| 9b56888 | 146 | //sceneEffectPanel.update(); |
| a62d533 | 147 | projectPanel.update(); |
| a62d533 | 148 | projectSettingsPanel.update(); |
| a62d533 | 149 | eventPanel.update(); |
| a62d533 | 150 | //Content.studioPanel.createStudioCanvas(); |
| a62d533 | 151 | ConsolePanel.updateCompiler(); |
| a62d533 | 152 | } |
| a62d533 | 153 | |
| a62d533 | 154 | public static void setEnabledProject(){
|
| a62d533 | 155 | if(!projectEnabled){
|
| a62d533 | 156 | enableProject(); |
| a62d533 | 157 | updateProject(); |
| a62d533 | 158 | } |
| a62d533 | 159 | } |
| a62d533 | 160 | |
| a62d533 | 161 | public static void setDisabledProject(){
|
| a62d533 | 162 | if(projectEnabled) |
| a62d533 | 163 | if(!Content.projectExists()) |
| a62d533 | 164 | Frame.disableProject(); |
| a62d533 | 165 | } |
| a62d533 | 166 | |
| a62d533 | 167 | private static void enableProject(){
|
| 9b56888 | 168 | //enablePanel(toolBar); |
| a62d533 | 169 | enablePanel(content); |
| a62d533 | 170 | enablePanel(rightSideBar); |
| a62d533 | 171 | enablePanel(leftSideBar); |
| a62d533 | 172 | enablePanel(statusBar); |
| a62d533 | 173 | for(JButton btn : Style.viewGroup) |
| a62d533 | 174 | btn.setEnabled(true); |
| a62d533 | 175 | projectEnabled = true; |
| a62d533 | 176 | } |
| a62d533 | 177 | |
| a62d533 | 178 | private static void disableProject(){
|
| 9b56888 | 179 | //disablePanel(toolBar); |
| a62d533 | 180 | disablePanel(content); |
| a62d533 | 181 | disablePanel(rightSideBar); |
| a62d533 | 182 | disablePanel(leftSideBar); |
| a62d533 | 183 | disablePanel(statusBar); |
| a62d533 | 184 | for(JButton btn : Style.viewGroup) |
| a62d533 | 185 | btn.setEnabled(false); |
| a62d533 | 186 | projectEnabled = false; |
| a62d533 | 187 | } |
| a62d533 | 188 | |
| a62d533 | 189 | public static void styleProject(){
|
| a62d533 | 190 | stylePanel(toolBar); |
| a62d533 | 191 | stylePanel(content); |
| a62d533 | 192 | stylePanel(rightSideBar); |
| a62d533 | 193 | stylePanel(leftSideBar); |
| a62d533 | 194 | stylePanel(statusBar); |
| a62d533 | 195 | for(JButton btn : Style.viewGroup){
|
| a62d533 | 196 | btn.setForeground(Style.font); |
| a62d533 | 197 | btn.setBackground(Style.topColor); |
| a62d533 | 198 | } |
| 7c84877 | 199 | toolBar.searchBar.setBackground(Style.listBg); |
| a62d533 | 200 | } |
| a62d533 | 201 | |
| a62d533 | 202 | private static void stylePanel(JPanel panel){
|
| a62d533 | 203 | panel.setForeground(Style.font); |
| a62d533 | 204 | panel.setBackground(Style.botColor); |
| a62d533 | 205 | for(Component c: panel.getComponents()){
|
| a62d533 | 206 | c.setForeground(Style.font); |
| 7c84877 | 207 | c.setBackground(Style.botColor); |
| a62d533 | 208 | if(c instanceof BaseList){
|
| a62d533 | 209 | ((BaseList)c).list.setBackground(Style.listBg); |
| a62d533 | 210 | ((BaseList)c).list.setForeground(Style.font); |
| 7c84877 | 211 | ((BaseList)c).list.setSelectionBackground(Style.listSelect); |
| a62d533 | 212 | ((BaseList)c).list.setSelectionForeground(Style.headerFg); |
| a62d533 | 213 | } |
| a62d533 | 214 | else if(c instanceof BaseTable){
|
| a62d533 | 215 | ((BaseTable)c).table.setBackground(Style.listBg); |
| a62d533 | 216 | ((BaseTable)c).table.setForeground(Style.font); |
| 7c84877 | 217 | ((BaseTable)c).table.setSelectionBackground(Style.listSelect); |
| a62d533 | 218 | ((BaseTable)c).table.setSelectionForeground(Style.headerFg); |
| a62d533 | 219 | } |
| a62d533 | 220 | else if(c instanceof Style.TitleLabel) |
| a62d533 | 221 | ((Style.TitleLabel)c).setForeground(Style.headerFg); |
| a62d533 | 222 | else if(c instanceof Style.TitleButton) |
| a62d533 | 223 | ((Style.TitleButton)c).setForeground(Style.headerFg); |
| a62d533 | 224 | else if(c instanceof JPanel) |
| a62d533 | 225 | enablePanel((JPanel)c); |
| a62d533 | 226 | } |
| a62d533 | 227 | } |
| a62d533 | 228 | |
| a62d533 | 229 | private static void enablePanel(JPanel panel){
|
| a62d533 | 230 | panel.setForeground(Style.font); |
| a62d533 | 231 | panel.setBackground(Style.topColor); |
| a62d533 | 232 | for(Component c: panel.getComponents()){
|
| a62d533 | 233 | c.setEnabled(true); |
| a62d533 | 234 | c.setForeground(Style.font); |
| a62d533 | 235 | c.setBackground(Style.topColor); |
| a62d533 | 236 | if(c instanceof JPanel) |
| a62d533 | 237 | enablePanel((JPanel)c); |
| a62d533 | 238 | else if(c instanceof JList) |
| a62d533 | 239 | ((JList<?>)c).setEnabled(true); |
| a62d533 | 240 | else if(c instanceof JLabel) |
| a62d533 | 241 | ((JLabel)c).setEnabled(true); |
| a62d533 | 242 | else if(c instanceof Style.TitleLabel) |
| a62d533 | 243 | ((Style.TitleLabel)c).setForeground(Style.headerFg); |
| a62d533 | 244 | else if(c instanceof Style.TitleButton) |
| a62d533 | 245 | ((Style.TitleButton)c).setForeground(Style.headerFg); |
| a62d533 | 246 | } |
| a62d533 | 247 | } |
| a62d533 | 248 | |
| a62d533 | 249 | private static void disablePanel(JPanel panel){
|
| a62d533 | 250 | for(Component c: panel.getComponents()){
|
| a62d533 | 251 | c.setEnabled(false); |
| a62d533 | 252 | if(c instanceof JPanel) |
| a62d533 | 253 | disablePanel((JPanel)c); |
| a62d533 | 254 | else if(c instanceof JList) |
| a62d533 | 255 | ((JList<?>)c).setEnabled(false); |
| a62d533 | 256 | else if(c instanceof JLabel) |
| a62d533 | 257 | ((JLabel)c).setEnabled(false); |
| a62d533 | 258 | } |
| a62d533 | 259 | } |
| a62d533 | 260 | |
| a62d533 | 261 | @Override |
| a62d533 | 262 | public void windowActivated(WindowEvent arg0) {
|
| a62d533 | 263 | } |
| a62d533 | 264 | |
| a62d533 | 265 | @Override |
| a62d533 | 266 | public void windowClosed(WindowEvent arg0) {
|
| a62d533 | 267 | } |
| a62d533 | 268 | |
| a62d533 | 269 | @Override |
| a62d533 | 270 | public void windowClosing(WindowEvent arg0) {
|
| a62d533 | 271 | Content.editor.save(); |
| a9b2a64 | 272 | Scene.getCurrentScene().save(scenePanel.getSelectedValue()); |
| a62d533 | 273 | if(Content.studioPanel.canvas != null) |
| a9b2a64 | 274 | Scene.getRoot().clear(); |
| a62d533 | 275 | //Stage.exit(); |
| a62d533 | 276 | //Content.studioPanel.destroyCanvas(); |
| a62d533 | 277 | dispose(); |
| a62d533 | 278 | System.exit(0); |
| a62d533 | 279 | } |
| a62d533 | 280 | |
| a62d533 | 281 | @Override |
| a62d533 | 282 | public void windowDeactivated(WindowEvent arg0) {
|
| a62d533 | 283 | } |
| a62d533 | 284 | |
| a62d533 | 285 | @Override |
| a62d533 | 286 | public void windowDeiconified(WindowEvent arg0) {
|
| a62d533 | 287 | } |
| a62d533 | 288 | |
| a62d533 | 289 | @Override |
| a62d533 | 290 | public void windowIconified(WindowEvent arg0) {
|
| a62d533 | 291 | } |
| a62d533 | 292 | |
| a62d533 | 293 | @Override |
| a62d533 | 294 | public void windowOpened(WindowEvent arg0) {
|
| a62d533 | 295 | } |
| a62d533 | 296 | } |