All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ace.ui.components.panels.sub.GeneralPanel Maven / Gradle / Ivy

The newest version!
package ace.ui.components.panels.sub;

import ace.data.player.IPlayerData;
import ace.ui.components.partial.text.field.TextFormattedDataPanel;
import ace.ui.components.partial.text.field.TextReadOnlyDataPanel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

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

/**
 * Sub-panel for {@link ace.ui.components.panels.CharacterPanel} related to general information about the player
 */
@Component
@ConditionalOnProperty(name = "editor.live.boot")
public class GeneralPanel extends JPanel {
    @Autowired
    private IPlayerData playerData;

    private TextFormattedDataPanel playerName;
    private TextReadOnlyDataPanel playerLevel;
    private TextReadOnlyDataPanel money;
    private TextReadOnlyDataPanel unspentSkillPoints;

    @PostConstruct
    private void init() {
        setLayout(new GridLayout(0, 1));
    }

    /**
     * @throws NoSuchMethodException reflection exception from trying to create invalid method
     */
    public void renderData() throws NoSuchMethodException {
        removeAll();
        createGeneralPanel();
    }

    private void createGeneralPanel() throws NoSuchMethodException {
        Class clazz = playerData.getClass();

        playerName = new TextFormattedDataPanel<>("Character name", playerData.getPlayerName());
        playerName.setDataGetter(playerData, clazz.getMethod("getPlayerName"));
        playerName.createListener(playerData, clazz.getMethod("setPlayerName", String.class));
        add(playerName);

        playerLevel = new TextReadOnlyDataPanel<>("Player level", playerData.getPlayerLevel());
        playerLevel.setDataGetter(playerData, clazz.getMethod("getPlayerLevel"));
        add(playerLevel);

        money = new TextReadOnlyDataPanel<>("Money", playerData.getMoney());
        money.setDataGetter(playerData, clazz.getMethod("getMoney"));
        add(money);

        unspentSkillPoints = new TextReadOnlyDataPanel<>("Unspent skill points", playerData.getUnspentSkillPoints());
        unspentSkillPoints.setDataGetter(playerData, clazz.getMethod("getUnspentSkillPoints"));
        add(unspentSkillPoints);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy