package cn.forevermc.launcher.ctrl.pane;

import cn.forevermc.launcher.bean.Game;
import cn.forevermc.launcher.bean.LaunchGame;
import cn.forevermc.launcher.bean.Page;
import cn.forevermc.launcher.service.GameService;
import cn.forevermc.launcher.service.PageService;
import cn.forevermc.launcher.util.Resources;
import cn.forevermc.launcher.view.pages.AboutPane;
import com.imyeyu.inject.annotation.Controller;
import com.imyeyu.inject.annotation.Inject;
import com.imyeyu.inject.annotation.InvokeForInjected;
import com.imyeyu.inject.annotation.SuperInject;

/**
 * 关于
 *
 * @author 夜雨
 * @since 2022-11-25 15:02
 */
@Controller
@SuperInject
public class About extends AboutPane {

	@Inject
	private PageService pageService;

	@Inject
	private GameService gameService;

	@Inject
	private LaunchGame launchGame;

	public About() {
		close.setOnAction(e -> pageService.to(Page.MENU));
	}

	@InvokeForInjected
	private void injected() {
		launchGame.addListener((obs, o, newLaunchGame) -> {
			if (newLaunchGame == null) {
				title.setImage(Resources.TITLE);
			} else {
				Game.MetaData.RealVersion realVersion = gameService.getRealVersion(newLaunchGame);
				if (realVersion.isModernStyle()) {
					title.setImage(Resources.TITLE_NEW);
				} else {
					title.setImage(Resources.TITLE);
				}
			}
		});
	}
}