【RPG Maker MV 仿新仙剑 战斗场景UI (七)】

RPG Maker MV 仿新仙剑 战斗场景UI 七

法术物品窗口

继续水点内容

现在发出及确认物品窗口显示及操作。

代码

javascript 复制代码
function Window_BattleItem() {
    this.initialize.apply(this, arguments);
}

Window_BattleItem.prototype = Object.create(Pal_Window_ItemList.prototype);
Window_BattleItem.prototype.constructor = Window_BattleItem;

Window_BattleItem.prototype.initialize = function(x, y, width, height) {
    Pal_Window_ItemList.prototype.initialize.call(this, x, y, width, height);
    this.hide();
};

Window_BattleItem.prototype.includes = function(item) {
    return $gameParty.canUse(item);
};

Window_BattleItem.prototype.show = function() {
    this.selectLast();
    this.showHelpWindow();
    Pal_Window_ItemList.prototype.show.call(this);
};

Window_BattleItem.prototype.hide = function() {
    this.hideHelpWindow();
    Pal_Window_ItemList.prototype.hide.call(this);
};

这里和法术窗口是一样的继承了之前的窗口。

javascript 复制代码
Pal_Scene_Battle.prototype.createItemWindow = function() {
    this._itemWindow = new Window_BattleItem(39, 169, 561, 213);
    this._itemWindow.setHelpWindow(this._helpWindow);
    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
    this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
    this.addChild(this._itemWindow);
};

创建物品战斗窗口。

javascript 复制代码
Pal_Scene_Battle.prototype.commandItem = function() {
	this._skillBackgroundSprite.visible=true;
	this._skillHelpBackgroundSprite.visible=true;
	this._itemWindow.refresh();
	this._itemWindow.show();
	this._itemWindow.activate();
};

打开物品窗口,并显示背景。

javascript 复制代码
Pal_Scene_Battle.prototype.onActorCancel = function() {
    this._actorWindow.hide();
	if(this._actorCommandWindow.currentSymbol()==='skill'){
		this._skillBackgroundSprite.visible=true;
		this._skillHelpBackgroundSprite.visible=true;
		this._skillWindow.show();
		this._skillWindow.activate();
	}
	if(this._itemCommandWindow.currentSymbol()==='use'){
		this._skillBackgroundSprite.visible=true;
		this._skillHelpBackgroundSprite.visible=true;
		this._itemWindow.show();
		this._itemWindow.activate();
	}
	
};
Pal_Scene_Battle.prototype.onEnemyCancel = function() {
    this._enemyWindow.hide();
	if(this._actorCommandWindow.currentSymbol()==='attack'){
		this._actorCommandWindow.activate();
	}
	if(this._actorCommandWindow.currentSymbol()==='skill'){
		this._skillBackgroundSprite.visible=true;
		his._skillHelpBackgroundSprite.visible=true;
		this._skillWindow.show();
		this._skillWindow.activate();
	}
	if(this._itemCommandWindow.currentSymbol()==='use'){
		this._skillBackgroundSprite.visible=true;
		this._skillHelpBackgroundSprite.visible=true;
		this._itemWindow.show();
		this._itemWindow.activate();
	}
};
Pal_Scene_Battle.prototype.onSelectAction = function() {
    var action = BattleManager.inputtingAction();
    this._skillWindow.hide();
    this._itemWindow.hide();
    if (!action.needsSelection()) {
        this.selectNextCommand();
    } else if (action.isForOpponent()) {
        this.selectEnemySelection();
    } else {
        this.selectActorSelection();
    }
};

这三个方法是在使用物品或使用法术时调用的。
onSelectAction 方法中判断了目标对象的操作,因此在判断前,将法术及物品的战斗窗口均进行隐藏。
onActorCancelonEnemyCancel 角色和敌人选择的取消方法法术及物品使用上之前是switch语句进行判断的,但为了仿仙剑的一致性,因此将处理了这些方法操作,开启对应的背景,但麻烦来了,每个操作的标志默认判断是传入的角色的战斗指令操作,这样就会导致能使用法术的,但物品的就判断不了,因此将switch语句改成多个if判断,这样就能根据需要的内容进行处理了。

javascript 复制代码
Pal_Scene_Battle.prototype.onItemOk = function() {
	this._skillBackgroundSprite.visible=false;
	this._skillHelpBackgroundSprite.visible=false;
	this._itemCommandWindow.hide();
	this._otherCommandWindow.hide();
    var item = this._itemWindow.item();
    var action = BattleManager.inputtingAction();
    action.setItem(item.id);
    $gameParty.setLastItem(item);
    this.onSelectAction();
};
Pal_Scene_Battle.prototype.onItemCancel = function() {
	this._skillBackgroundSprite.visible=false;
	this._skillHelpBackgroundSprite.visible=false;
	this._itemCommandWindow.show();
	this._otherCommandWindow.show();
	this.startItemCommandSelection();
    this._itemWindow.hide();
};

物品的使用及取消物品战斗菜单,这里着重说下取消的,里面调用了开始物品命令选择的方法,这是为了能够正常的跳转回物品战斗的指令窗口,和原版游戏的操作保持一致。

仿新仙剑效果

这样的基本的UI效果和操作的效果就出来了!

相关推荐
火山灿火山7 分钟前
初识Qt(使用不同中方式创建helloworld)
开发语言·qt
华仔啊12 分钟前
还在用 WebSocket 做实时通信?SSE 可能更简单
前端·javascript
BD_Marathon36 分钟前
sbt 编译打包 scala
开发语言·后端·scala
雾岛听蓝44 分钟前
C++ 入门核心知识点(从 C 过渡到 C++ 基础)
开发语言·c++·经验分享·visual studio
7***37451 小时前
Java设计模式之工厂
java·开发语言·设计模式
木易士心1 小时前
深入剖析:按下 F5 后,浏览器前端究竟发生了什么?
前端·javascript
上不如老下不如小1 小时前
2025年第七届全国高校计算机能力挑战赛初赛 Python组 编程题汇总
开发语言·python·算法
程序员小白条1 小时前
你面试时吹过最大的牛是什么?
java·开发语言·数据库·阿里云·面试·职场和发展·毕设
xump2 小时前
如何在DevTools选中调试一个实时交互才能显示的元素样式
前端·javascript·css
Front_Yue2 小时前
深入探究跨域请求及其解决方案
前端·javascript