//=============================================================================
// XueYu Plugins - Gif
// AXY_Gif.js
// Version: 1.0
// License: BSD
//=============================================================================
/*:
* @plugindesc v1.00 动图显示 This plugin show gif, jpg, and many formats img from website or local.
* @author XueYu Plugins
*
* @param 锚点
* @param Anchor
* @desc The Img Anchor point. topleft/center
* @default center
*
* @param X
* @desc The x position of img. this is a eval param, so you can use Variables.
* img的x位置。这是一个eval参数,所以可以使用变量
* @default Graphics.width/2
*
* @param Y
* @desc The y position of img. this is a eval param, so you can use Variables.
* @default Graphics.height/2-90
*
* @param Width
* @desc The img width with % percent or px. img宽度的百分比或px。
* @default 100%
*
* @param Height
* @desc The img height with % percent or px.
* @default 100%
*
* @param opacity
* @desc The css opacity. 0-1 css的不透明度。0 - 1
* @default 1
*
* @param zIndex
* @desc The css zIndex.
* @default 10000
*
* @param 改变(一般用于旋转)
* @param transform
* @desc 可用脚本 $gameTemp._DXXtransform = "rotate(0deg)"; 修改。
* @default rotate(0deg)
*
* @param 延时
* @param delay
* @desc The Img life time. set to 0 to disable. unit is microseconds.
* Img的使用寿命。设置为0禁用。单位是微秒。
* @default 0
*
* @param path
* @desc The gif file you save.
* @default img/gif/
*
* @help
* Introduction
* This plugin support rmmv show gif, jpg, and many formats img from website or local.
* Easy to use and powerful.
*
* Example:
* show:
* AXY_Gif.show({filename:'1.gif'});
* AXY_Gif.show({filename:'1.jpg'});
* AXY_Gif.show({filename:'url=img/faces/Actor1.png'});
* AXY_Gif.show({filename:'1.gif',id:2});
* AXY_Gif.show({id:3,filename:'1.gif',delay:3000});
* AXY_Gif.show({x:0, y:0, align:'topleft', filename:'url=http://www.yourdomain.com/gif.jpg'});
* AXY_Gif.show({x:0, y:0, align:'topleft', filename:'url=http://www.yourdomain.com/gif.gif'});
* all args with default:
* AXY_Gif.show({x:'Graphics.width/2', y:'Graphics.height/2-90', align:'center', filename:'1.gif',id:1,delay:0,width:'100%',height:'100%',opacity:1});
*
* move:
* AXY_Gif.move(id,x,y);
*
* remove with id:
* AXY_Gif.remove(1);
* AXY_Gif.remove(2);
* remove all:
* AXY_Gif.removeall();
*
*
* showtext
* AXY_Gif.showtext({x:500, y:500, id:50, content:'你好吗', color:'#000000', size:10});
*
* movetext
* AXY_Gif.movetext(id,x,y);
*/
// Imported
var Imported = Imported || {};
Imported.AXY_Gif = true;
// Parameter Variables
var AXY = AXY || {};
AXY.Gif = AXY.Gif || {};
AXY.Gif.Parameters = PluginManager.parameters('AXY_Gif');
AXY.Gif.Param = AXY.Gif.Param || {};
//
AXY.Gif.Param.Anchor = String(AXY.Gif.Parameters['Anchor']);
AXY.Gif.Param.X = String(AXY.Gif.Parameters['X']);
AXY.Gif.Param.Y = String(AXY.Gif.Parameters['Y']);
AXY.Gif.Param.Width = String(AXY.Gif.Parameters['Width']);
AXY.Gif.Param.Height = String(AXY.Gif.Parameters['Height']);
AXY.Gif.Param.opacity = parseFloat(AXY.Gif.Parameters['opacity']);
AXY.Gif.Param.zIndex = parseInt(AXY.Gif.Parameters['zIndex']);
AXY.Gif.Param.delay = parseInt(AXY.Gif.Parameters['delay']);
AXY.Gif.Param.path = String(AXY.Gif.Parameters['path']);
AXY.Gif.Param.transform = String(AXY.Gif.Parameters['transform']);
//main
//gif
AXY_Gif = {
show: function () {
//console.log(arguments[3]);
var AXYGifArgs = arguments[0] ? arguments[0] : {};
var filename = AXYGifArgs['filename'] ? AXYGifArgs['filename'] : "";
var delay = AXYGifArgs['delay'] ? AXYGifArgs['delay'] : AXY.Gif.Param.delay;
var id = AXYGifArgs['id'] ? AXYGifArgs['id'] : 1;
var x = AXYGifArgs['x'] != undefined ? AXYGifArgs['x'] : eval(AXY.Gif.Param.X);
var y = AXYGifArgs['y'] != undefined ? AXYGifArgs['y'] : eval(AXY.Gif.Param.Y);
var width = AXYGifArgs['width'] ? AXYGifArgs['width'] : AXY.Gif.Param.Width;
var height = AXYGifArgs['height'] ? AXYGifArgs['height'] : AXY.Gif.Param.Height;
var opacity = AXYGifArgs['opacity'] ? AXYGifArgs['opacity'] : AXY.Gif.Param.opacity;
var align = AXYGifArgs['align'] ? AXYGifArgs['align'] : AXY.Gif.Param.Anchor;
var transform = $gameTemp._DXXtransform ? $gameTemp._DXXtransform : AXY.Gif.Param.transform;
if(filename.indexOf('url=') != -1){
filename = filename.replace('url=', '');
}
else{
filename = AXY.Gif.Param.path + filename;
}
var AXYGifEntity;
var AXYGifTemplate = '<div id="AXYGif'+id+'" class="AXYGif" width=1600 height=900 style="visibility:hidden;position:fixed;left:0px;top:0px;transform:'+transform+';z-index:'+
AXY.Gif.Param.zIndex+';"><img src="'+filename+'" style="width:'+width+';height:'+height+';opacity:'+opacity+';" /></div>';
AXYGifEntity = $('body').append(AXYGifTemplate);
$("#AXYGif"+id+" img")[0].onload = function(){
if(align == 'center'){
if(width.indexOf("px") != -1){
var widthpx = width;
var widthint = parseFloat(width);
}
else{
var widthint = $("#AXYGif"+id+" img")[0].naturalWidth*parseFloat(width)/100;
if(widthint == 0){console.log("必须提前加载图片 否则naturalWidth为0");}
var Wadj = AXY_Gif.AdjustWidth(widthint);
var widthpx = Wadj+'px';
}
if(height.indexOf("px") != -1){
var heightpx = height;
var heightint = parseFloat(height);
}
else{
var heightint = $("#AXYGif"+id+" img")[0].naturalHeight*parseFloat(height)/100;
var Hadj = AXY_Gif.AdjustHeight(heightint);
var heightpx = Hadj+'px';
}
var imgx = widthint/2;
var imgy = heightint/2;
var divx = x-imgx;//*parseFloat(width)/100;
var divy = y-imgy;//*parseFloat(height)/100;
divx = AXY_Gif.AdjustX(divx);
divy = AXY_Gif.AdjustY(divy);
// console.log("x:" + divx + " y:" + divy);
$("#AXYGif"+id+" img").css({'width':widthpx,'height':heightpx});
$("#AXYGif"+id).css({left:divx+'px', top:divy+'px', visibility:'visible'});
}
else{
var wint = $("#AXYGif"+id+" img")[0].naturalWidth * parseFloat(width)/100;
var hint = $("#AXYGif"+id+" img")[0].naturalHeight * parseFloat(height)/100;
if(wint == 0){console.log("必须提前加载图片 否则naturalWidth为0");}
// console.log("w:" + wint + " h:" + hint);
var w = AXY_Gif.AdjustWidth(wint) + 'px';
var h = AXY_Gif.AdjustHeight(hint) + 'px';
x = AXY_Gif.AdjustX(x);
y = AXY_Gif.AdjustY(y);
$("#AXYGif"+id+" img").css({'width':w,'height':h});
$("#AXYGif"+id).css({left:x, top:y, visibility:'visible'});
// console.log($("#AXYGif"+id));
}
}
// console.log($("#AXYGif"+id));
if(delay>=1){
setTimeout(function()
{
$('#AXYGif'+id).remove();
}, delay);
}
},
remove: function () {
var id = arguments[0] ? arguments[0] : 1;
// console.log($('#AXYGif'+id));
// console.log($('#AXYGif'+id).stop());
$('#AXYGif'+id).stop().animate({"opacity": "0"},500, function() {
$(this).remove();
});
},
removeall: function () {
$('.AXYGif').stop().animate({"opacity": "0"}, 500, function() {
$(this).remove();
});
},
move: function () {
var id = arguments[0] ? arguments[0] : 1;
var x1 = arguments[1] ? arguments[1] : 1;
var y1 = arguments[2] ? arguments[2] : 1;
x1 = AXY_Gif.AdjustX(x1);
y1 = AXY_Gif.AdjustY(y1);
x1 = x1 + "px";
y1 = y1 + "px";
$('#AXYGif'+id).animate({left: x1, top: y1},"fast");
},
// removeall: function () {
// $('.AXYGif').stop().animate({"width": "0","height": "0"}, "normal", function() {
// $(this).remove();
// });
// }
showtext: function () {
var AXYGifArgs = arguments[0] ? arguments[0] : {};
var delay = AXYGifArgs['delay'] ? AXYGifArgs['delay'] : AXY.Gif.Param.delay;
var id = AXYGifArgs['id'] ? AXYGifArgs['id'] : 1;
var x = AXYGifArgs['x'] != undefined ? AXYGifArgs['x'] : 0;
var y = AXYGifArgs['y'] != undefined ? AXYGifArgs['y'] : 0;
var opacity = AXYGifArgs['opacity'] ? AXYGifArgs['opacity'] : AXY.Gif.Param.opacity;
var content = AXYGifArgs['content'] ? AXYGifArgs['content'] : 0;
var color = AXYGifArgs['color'] ? AXYGifArgs['color'] : 'white';
var size = AXYGifArgs['size'] ? AXYGifArgs['size'] : 5;
var zIndex = AXYGifArgs['zIndex'] ? AXYGifArgs['zIndex'] : 10001;
var AXYGifEntity;
var AXYGifTemplate = '<div id="AXYGiftext'+id+'" class="AXYGiftext" style="visibility:hidden;position:fixed;left:0px;top:0px;z-index:'+zIndex+';font-weight: 700;"><p><font size="'+size+'" face="arial" color="'+color+'">'+content+'</font></p></div>';
AXYGifEntity = $('body').append(AXYGifTemplate);
x = AXY_Gif.AdjustX(x);
y = AXY_Gif.AdjustY(y);
$("#AXYGiftext"+id).css({left:x, top:y, visibility:'visible'});
// console.log($("#AXYGif"+id));
if(delay>=1){
setTimeout(function()
{
$('#AXYGiftext'+id).remove();
}, delay);
}
},
removetext: function () {
var id = arguments[0] ? arguments[0] : 1;
$('#AXYGiftext'+id).stop().animate({"opacity": "0"},10, function() {
$(this).remove();
});
},
movetext: function () {
var id = arguments[0] ? arguments[0] : 1;
var x1 = arguments[1] ? arguments[1] : 1;
var y1 = arguments[2] ? arguments[2] : 1;
x1 = AXY_Gif.AdjustX(x1);
y1 = AXY_Gif.AdjustY(y1);
x1 = x1 + "px";
y1 = y1 + "px";
$('#AXYGiftext'+id).animate({left: x1, top: y1},300);
},
removealltext: function () {
$('.AXYGiftext').stop().animate({"opacity": "0"}, "fast", function() {
$(this).remove();
});
},
AdjustWidth: function () {
var Wself = arguments[0] ? arguments[0] : 1;
var Wnow = parseInt(Graphics._canvas.style.width);
var Wadjust = Wnow / 1600 * Wself ;
Wadjust = Math.round(Wadjust);
return Wadjust;
},
AdjustHeight: function () {
var Hself = arguments[0] ? arguments[0] : 1;
var Hnow = parseInt(Graphics._canvas.style.height);
var Hadjust = Hnow / 900 * Hself ;
Hadjust = Math.round(Hadjust);
return Hadjust;
},
AdjustX: function () {
var Xself = arguments[0] ? arguments[0] : 1;
var Wnow = parseInt(Graphics._canvas.style.width);
var Winner = window.innerWidth;
var Xadjust = Wnow / 1600 * Xself ;
if(Wnow != Winner){
var Xpy = (Winner - Wnow) / 2;
Xadjust = Xadjust + Xpy;
}
Xadjust = Math.round(Xadjust);
return Xadjust;
},
AdjustY: function () {
var Yself = arguments[0] ? arguments[0] : 1;
var Hnow = parseInt(Graphics._canvas.style.height);
var Hinner = window.innerHeight;
var Yadjust = Hnow / 900 * Yself ;
if(Hnow != Hinner){
var Ypy = (Hinner - Hnow) / 2 ;
Yadjust = Yadjust + Ypy;
}
Yadjust = Math.round(Yadjust);
return Yadjust;
}
};