﻿from tcaxPy import *
from pixLibs.ImageStone.pixStone import *

def tcaxPy_Init():
    global _FD          # 一帧的时间
    global _Fs
    global _TextLength
    global Font
    global FontOut
    global PIX_tex
    global PIX_tex2
    _FD = 1000 / GetVal(val_FXFPS)
    _Fs = GetVal(val_FontSize)
    _TextLength = GetVal(val_TextLength)
    _FontFileName = GetVal(val_FontFileName)
    _FaceID       = GetVal(val_FaceID)
    Font    = InitFont(_FontFileName, _FaceID, _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), MakeRGB(0, 0, 0), 0, 0)  #文字主體
    FontOut = InitFont(_FontFileName, _FaceID, _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), MakeRGB(0, 0, 0), 2, 0)  #文字邊框
    PIX_tex = ImagePix(abspath('fire_texture.png'), _Fs, 0)   #文字主體圖片
    PIX_tex2 = ImagePix(abspath('tex2.png'))     #文字邊框圖片
    


def tcaxPy_Fin():
    FinFont(Font)
    FinFont(FontOut)

def tcaxPy_Main(_i, _j, _n, _BT, _ET, _SK, _KT, _x, _y, _a, _txt):

    ASS_BUF  = []        # 保存ASS特效
    TCAS_BUF = []        # 保存TCAS特效

    ##### 主要特效编写操作 #####

    dx = _x - int(_a / 2 + 0.5)         # 一个固定操作, 将an5的坐标转换为an7
    dy = _y - int(_Fs / 2 + 0.5)        # ASS特效默认采用an5坐标, TCAS特效则采用an7坐标


    PIX_t = TextPix(Font, _txt)             # 获取文字
    
    dx = _x - int(_a / 2 + 0.5) + PIX_t[0][0]
    dy = _y - int(_Fs / 2 + 0.5) + PIX_t[0][1]
    dur = _KT * 10
    ts1 = _BT
    te1 = _BT + _SK
    
    PIX_t = PixTexture(PIX_t, PIX_tex)      # 增加主體纹理
    PIX_out = TextPix(FontOut, _txt)        # 获取边框
    PIX_out = PixTexture(PIX_out, PIX_tex2)      #增加邊框紋理
    PIX_out = PixColorMul(PIX_out, 1, 1, 1, 1)    # 增加邊框透明度 第四個數字不用邊框紋理的話可以設置為0 這樣能節省ASS體積
    PIX_out = PixBlur(PIX_out, 0)           # 增加邊框模糊
    PIX_ori = CombinePixs(PIX_out, PIX_t)   # 混合文字主体和边框 (边框作底)
    points = PixPoints(PIX_ori)
    pt_num = len(points)

    center = _n / 2 - 0.5      # center index of 5 texts is 2, center index of 6 is 2.5
    x = dx + 50 * (_j - center) / center
    y = dy + 10
    
    for i in range(pt_num):
        w = points[i][0]
        h = points[i][1]
        idx  = 4 * (h * PIX_ori[1][0] + w)                # 脚标
        PixR = PIX_ori[2][idx + 0]                        # 当前像素的红色分量
        PixG = PIX_ori[2][idx + 1]                        # 当前像素的绿色分量
        PixB = PIX_ori[2][idx + 2]                        # 当前像素的蓝色分量
        PixA = PIX_ori[2][idx + 3]                        # 当前像素的透明度
        
        x = dx + points[i][0]
        y = dy + points[i][1]

        EFT1 = an(7)+shad(0)+bord(0)+pos(x,y)+alpha(255-PixA)+color1(FmtRGB(PixR,PixG,PixB))  #這裡的顏色就不要去設置什麽COLOR1 COLOR3了
        ass_main(ASS_BUF, SubL(ts1,te1,3,Pix_Style), EFT1, PixPt())
        

    ##### 将结果返回给tcax进行处理 #####

    return (ASS_BUF, TCAS_BUF)



