com.github.fauu.helix.editor.EditorFrame.java Source code

Java tutorial

Introduction

Here is the source code for com.github.fauu.helix.editor.EditorFrame.java

Source

/*
 * Copyright (C) 2014 Helix Engine Developers (http://github.com/fauu/HelixEngine)
 *
 * This software is licensed under the GNU General Public License
 * (version 3 or later). See the COPYING file in this distribution.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this software. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Piotr Grabowski <fau999@gmail.com>
 */

package com.github.fauu.helix.editor;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglCanvas;
import com.badlogic.gdx.math.Vector2;
import com.github.fauu.helix.core.Camera;
import com.github.fauu.helix.core.MapRegion;
import com.github.fauu.helix.editor.ui.MenuBar;
import com.github.fauu.helix.editor.ui.Sidebar;
import com.github.fauu.helix.editor.ui.StatusBar;
import com.github.fauu.helix.editor.ui.dialogs.NewMapRegionDialog;

import javax.swing.*;
import java.awt.*;

public class EditorFrame extends JFrame {

    private MapRegion mapRegion;
    private Camera camera;

    private Container mainContainer;
    private Sidebar sidebar;
    private StatusBar statusBar;

    public EditorFrame() {
        setTitle("helix");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        final MenuBar menuBar = new MenuBar(this);
        setJMenuBar(menuBar);

        mainContainer = getContentPane();
        mainContainer.setLayout(new BorderLayout());

        sidebar = new Sidebar(this);
        mainContainer.add(sidebar, BorderLayout.LINE_START);

        final LwjglCanvas canvas = new LwjglCanvas(new World(this));
        canvas.getCanvas().setPreferredSize(new Dimension(800, 600));
        mainContainer.add(canvas.getCanvas(), BorderLayout.CENTER);

        statusBar = new StatusBar();
        mainContainer.add(statusBar, BorderLayout.PAGE_END);

        pack();
        setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new EditorFrame();
            }
        });
    }

    public void receiveMapRegion(MapRegion mapRegion) {
        this.mapRegion = mapRegion;

        camera.moveTo(mapRegion.getCenterCoordinates());
        sidebar.updateModel(mapRegion);
    }

    public void receiveCamera(Camera camera) {
        this.camera = camera;
    }

    public void saveMapRegion() {
        MapRegionWriter.saveMapRegion(mapRegion, Gdx.files.internal("assets/mapregions/0.hmr"));
    }

    public void createMapRegion(int width, int height) {
        // FIXME: Needs to allow other texture sets and geometry sets
        mapRegion.create(new Vector2(width, height), null, null, mapRegion.getTextureAtlas(),
                mapRegion.getGeometrySet());

        camera.moveTo(mapRegion.getCenterCoordinates());
    }

    public void showNewMapRegionDialog() {
        final NewMapRegionDialog newMapRegionDialog = new NewMapRegionDialog(this);
    }

    public Sidebar getSidebar() {
        return sidebar;
    }

    public MapRegion getMapRegion() {
        return mapRegion;
    }

    public StatusBar getStatusBar() {
        return statusBar;
    }

}