Package editor.model

Source Code of editor.model.GUIModel

package editor.model;

import beans.core.GeneralConstant;
import beans.serializable.MapConfig;
import beans.serializable.Monster;
import beans.serializable.Objet;
import beans.serializable.Spell;
import beans.serializable.StatsPerso;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.util.Map;
import editor.core.PopUpGenerator;
import java.util.Observable;
import javax.swing.JPanel;
import beans.core.Core;
import beans.core.db.ObjetControl;
import beans.core.db.PersoControl;
import beans.core.db.SkillControl;
import beans.core.db.SpellControl;
import beans.serializable.Skill;
import editor.core.ConstantEditor.Frame;

/**
* Model de gestion des interfaces IHM
* @author mastersnes
*/
public class GUIModel extends Observable {

    private boolean launched = false;
    private JPanel leftPanel;
    private JPanel rightPanel;
    private Frame currentFrame = null;
    private EditorModel editorModel;

    /**
     * Constructeur par defaut du model
     */
    public GUIModel() {
        super();
        leftPanel = new JPanel();
        rightPanel = new JPanel();
    }

    /**
     * Retourne l'element gauche qui constitue la vue de l'editeur de map
     * @return Panneau de gauche
     */
    public JPanel getLeftPanel() {
        return leftPanel;
    }

    /**
     * Retourne l'element de droite qui constitue la vue de la liste des tileSets
     * @return Panneau de droite
     */
    public JPanel getRightPanel() {
        return rightPanel;
    }

    /**
     * Definie la vue de gauche
     * @param leftPanel panneau gauche
     * @param dimension dimension du panneau
     */
    public void setLeftPanel(final JPanel leftPanel, final Dimension dimension) {
        this.leftPanel = leftPanel;
        leftPanel.setPreferredSize(dimension);
        leftPanel.setSize(dimension);
        setChanged();
        notifyObservers();
    }

    /**
     * Definie la vue de droite
     * @param rightPanel panneau de droite
     */
    public void setRightPanel(final JPanel rightPanel) {
        this.rightPanel = rightPanel;
        setChanged();
        notifyObservers();
    }

    /**
     * Initialise la creation d'une nouvelle map
     */
    public void initNewMap() {
        this.currentFrame = Frame.MAP;
        if (launched) {
            PopUpGenerator.showAcceptScreenPopUp(this);
        } else {
            acceptPopUpResponse(true);
        }
    }

    /**
     * Initialise la creation d'un nouvel objet
     */
    public void initNewObjet() {
        this.currentFrame = Frame.OBJECT;
        if (launched) {
            PopUpGenerator.showAcceptScreenPopUp(this);
        } else {
            acceptPopUpResponse(true);
        }
    }

    /**
     * Reponse de la fenêtre de validation d'une action
     * @param accept
     */
    public void acceptPopUpResponse(final boolean accept) {
        if (accept) {
            switch (this.currentFrame) {
                case MAP:
                    PopUpGenerator.showInitMapPopUp(this);
                    break;
                case OBJECT:
                    PopUpGenerator.showInitObjectPopUp(this);
                    break;
                case EQUIPMENT:
                    break;
                case LOAD:
                    PopUpGenerator.showInitChargerPopUp(this);
                    break;
                case MONSTER:
                    PopUpGenerator.showInitMonsterPopUp(this);
                    break;
                case SPELL:
                    PopUpGenerator.showInitSpellPopUp(this);
                    break;
                case SKILL:
                    PopUpGenerator.showInitSkillPopUp(this);
                    break;
                case HERO:
                    PopUpGenerator.showInitHeroPopUp(this);
                    break;
                default:
                    return;
            }
        }
    }

    /**
     * Reponse de la fenêtre d'initialisation de la map
     * @param fields
     */
    public void initMapPopUpResponse(final Map<String, String> fields) {
        this.launched = true;
        editorModel = new EditorModel(fields, this);
    }

    /**
     * Reponse de la fenêtre d'initialisation d'un objet
     * @param fields
     */
    public void initObjectPopUpResponse(final Objet objet) {
        final ObjetControl objetControl = new ObjetControl();
        objetControl.saveObjet(objet);
    }

    /**
     * Appel de la fenêtre de sauvegarde de la map
     */
    public void sauverMap() {
        if (editorModel != null) {
            PopUpGenerator.showSauverMapPopUp(this);
        }
    }

    /**
     * Sauvegarde de la map
     * @param name
     */
    public void sauverMap(final String name) {
        if (editorModel != null) {
            final MapConfig mapConfig = editorModel.getConfig();
            GeneralConstant.serialize(GeneralConstant.SAVE_MAPCONFIG_PATH + name, editorModel.getConfig());
            Core.sauverCouches(editorModel.getLayers(), name);
            PopUpGenerator.showSucces();
        }
    }

    /**
     * Redefinie la couche courante
     * @param layer
     */
    public void setCouche(final int layer) {
        if (editorModel != null) {
            editorModel.setLayer(layer);
        }
    }

    /**
     * Appel la fenêtre de chargement d'une map
     */
    public void loadMap() {
        this.currentFrame = Frame.LOAD;
        if (launched) {
            PopUpGenerator.showAcceptScreenPopUp(this);
        } else {
            acceptPopUpResponse(true);
        }
    }

    /**
     * Charge la map passé en parametre
     * @param configPath
     */
    public void loadMapResponse(final String configPath) {
        MapConfig config = null;
        Map<Integer, BufferedImage> couches = null;
        if (!configPath.equals("")) {
            config = (MapConfig) GeneralConstant.deSerialize(GeneralConstant.SAVE_MAPCONFIG_PATH + configPath);
            couches = Core.loadCouche(configPath);
            editorModel = new EditorModel(couches, config, this);
        }

    }

    /**
     * Initialise la fenetre de creation d'un nouveau monstre
     */
    public void initNewMonster() {
        this.currentFrame = Frame.MONSTER;
        if (launched) {
            PopUpGenerator.showAcceptScreenPopUp(this);
        } else {
            acceptPopUpResponse(true);
        }
    }

    /**
     * Reponse de la fenêtre d'initialisation d'un nouveau monstre
     * @param fields
     */
    public void initMonsterPopUpResponse(final Map<String, String> fields) {
        final String name = fields.get("name");
        final String imagePath = fields.get("image");
        final int lifeMax = Integer.parseInt(fields.get("life"));
        final int manaMax = Integer.parseInt(fields.get("mana"));
        final int attaque = Integer.parseInt(fields.get("attaque"));
        final int defense = Integer.parseInt(fields.get("defense"));
        final Objet loot = (Objet) GeneralConstant.deSerialize(GeneralConstant.SAVE_OBJECT_PATH + fields.get("loot"));
        final Monster monster = new Monster(name, 10, imagePath, lifeMax, manaMax, attaque, defense, loot);
        GeneralConstant.serialize(GeneralConstant.SAVE_MONSTER_PATH + name, monster);
    }

    /**
     * Appel de la fenêtre de redimensionnement de la map
     */
    public void redimensionner() {
        if (editorModel != null) {
            PopUpGenerator.showRedimensionPopUp(this);
        }
    }

    /**
     * Redimensionne la map
     * @param widthString
     * @param heightString
     */
    public void redimensionnerResponse(final String widthString, final String heightString) {
        int width = 0;
        int height = 0;
        try {
            width = Integer.parseInt(widthString);
            height = Integer.parseInt(heightString);
        } catch (final NumberFormatException numberFormatException) {
        }

        editorModel.redimensionner(width, height);
        setLeftPanel(leftPanel, new Dimension(width * GeneralConstant.BLOC_WIDTH, height * GeneralConstant.BLOC_HEIGHT));
    }

    public void initNewSpell() {
         this.currentFrame = Frame.SPELL;
        if (launched) {
            PopUpGenerator.showAcceptScreenPopUp(this);
        } else {
            acceptPopUpResponse(true);
        }
    }
    public void initNewSkill() {
         this.currentFrame = Frame.SKILL;
        if (launched) {
            PopUpGenerator.showAcceptScreenPopUp(this);
        } else {
            acceptPopUpResponse(true);
        }
    }

    public void initSpellPopUpResponse(final Spell spell) {
        final SpellControl spellControl = new SpellControl();
        spellControl.saveSpell(spell);
    }
    public void initSkillPopUpResponse(final Skill skill) {
        final SkillControl skillControl = new SkillControl();
        skillControl.saveSkill(skill);
    }

    public void initNewHero() {
         this.currentFrame = Frame.HERO;
        if (launched) {
            PopUpGenerator.showAcceptScreenPopUp(this);
        } else {
            acceptPopUpResponse(true);
        }
    }

    public void initHeroPopUpResponse(final StatsPerso statPerso) {
        final PersoControl persoControl = new PersoControl();
        persoControl.saveChangeStatut(statPerso);
    }
}
TOP

Related Classes of editor.model.GUIModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.