

//
// Core Program for TETDM 
// PopUpForAssist.java Version 1.00
// Copyright(C) 2017-2018 TETDM CORE MEMBER ALL RIGHTS RESERVED.
// This program is provided under the license.
//


package source.Tutorial;

import source.*;
import source.GameMode.*;
import source.TextData.*;
import source.Utility.*;


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.*;
import javax.imageio.ImageIO;

import java.awt.geom.RoundRectangle2D;

import java.applet.* ;
import static java.lang.Math.* ;

import static java.awt.BorderLayout.* ;


public class PopUpForAssist extends JFrame implements MouseListener,MouseMotionListener  ////////////////////////
{
    Image image;
    Control control;
    
    Container pane;
	AssistPanel assistPanel;
    PopUpForPause popForPause;

    public static String chara[] = new String[2];



    public PopUpForAssist(int X,int Y,int width,int height,boolean decolation,Control control,String face)
    {
        this.control=control;
        String tutorialPath = control.absolutePath + "source" + File.separator + "Tutorial" + File.separator;
        
        try{
            File file = new File(tutorialPath+"serif"+ File.separator +"coslog.txt");
            BufferedReader br = new BufferedReader(new FileReader(file));
            chara[0] = br.readLine();
            chara[1] = br.readLine();
            br.close();
        }catch(FileNotFoundException e){
            System.out.println(e);
            chara[0]="0";
            chara[1]="0";
        }catch(IOException e){
            System.out.println(e);
            chara[0]="0";
            chara[1]="0";
        }
        
        
        String imagePath = tutorialPath+"image"+File.separator+"character"+File.separator+chara[0]+File.separator+chara[0]+chara[1];

        if(face.equals("normal"))
        {
            ImageIcon icon = new ImageIcon(imagePath + "1.png");
            image = icon.getImage();
        }
        if(face.equals("smile"))
        {
            ImageIcon icon = new ImageIcon(imagePath + "2.png");
            image = icon.getImage();
        }
        if(face.equals("sad"))
        {
            ImageIcon icon = new ImageIcon(imagePath + "3.png");
            image = icon.getImage();
        }
        
        pane = getContentPane();
        pane.setLayout(new BorderLayout());
        assistPanel = new AssistPanel();
        pane.add(assistPanel);
        
        /////////////////////
        pane.addMouseListener(this);
        pane.addMouseMotionListener(this);
        /////////////////////
        
        setAlwaysOnTop(true);
        setUndecorated(decolation);
        setVisible(true);
        
        JFrame.setDefaultLookAndFeelDecorated(true);
        setBackground(new Color(0,0,0,0));
        
        setBounds(X, Y, width, height);
        StoryControl.CharaStanding(X,Y);
    }

	
	///////////////////////////////////////////
	int mousex ,mousey;
    int positionx, positiony;
	int incompox,incompoy;
	
	public void mouseEntered(MouseEvent e){}
	public void mouseExited(MouseEvent e){}

    public void mouseClicked(MouseEvent e)
    {
        if(popForPause==null)
            popForPause = new PopUpForPause(control, this);
    }
	
	public void mousePressed(MouseEvent e){		
		incompox = 0;
		incompoy = 0;
		incompox = e.getPoint().x;
		incompoy = e.getPoint().y;
	}
	
	public void mouseReleased(MouseEvent e){
         //StoryControl.SerihuControl(1);
    }

	public void mouseDragged(MouseEvent e){
		mousex = e.getLocationOnScreen().x;
		mousey = e.getLocationOnScreen().y;
				
		positionx = mousex - incompox;
		positiony = mousey - incompoy;
	
		positionx -= getInsets().left;
		positiony -= getInsets().top;

		setLocation(positionx, positiony);
        
        StoryControl.CharaStanding(positionx,positiony);
        
	}	
	public void mouseMoved(MouseEvent e){}
	/////////////////////////////////////////////////////
	

    public void closeWindow()
    {
        if(popForPause != null)
        {
            popForPause.dispose();
            popForPause = null;
        }
    }
		
	class AssistPanel extends JPanel
	{
        int sizeX,sizeY;
        
		AssistPanel(){}
		
        public void getLocalSize()
        {
            sizeX = getWidth();
            sizeY = getHeight();
        }
        
		public void update(Graphics g)		//Avoid from blinking
		{
			paintComponent(g);
		}
		
		public void paintComponent(Graphics g)
		{
			Graphics2D g2 = (Graphics2D)g;
			
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// Anti aliasing
			g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);			
			
			getLocalSize();
			
			g2.drawImage(image,0,0,sizeX,sizeY,this);
		}	
		
	}	
}


