【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效果和操作的效果就出来了!

相关推荐
AAA大运重卡何师傅(专跑国道)43 分钟前
【无标题】
开发语言·c#
sugar__salt1 小时前
从栈队列数据结构到JS原型面向对象全解
前端·javascript·数据结构
XBodhi.1 小时前
Visual Studio C++ 语法错误: 缺少“;”(在“return”的前面)
开发语言·c++·visual studio
MageGojo1 小时前
随机文案模块怎么做?从接口封装到前端展示的完整实现思路
javascript·前端开发·api接口·后端开发·随机文案
独特的螺狮粉1 小时前
篮球集训班器具管理系统 - 鸿蒙PC Electron框架完整技术实现指南
前端·javascript·华为·electron·前端框架·开源·鸿蒙
小妖6661 小时前
js 生成随机数技巧 Math.random().toString(36)
javascript·随机数
LSssT.2 小时前
【01】Python 机器学习
开发语言·python
AI_零食2 小时前
番茄钟鸿蒙PC Electron框架完成:状态机、定时器管理与专注力工具设计
前端·javascript·华为·electron·开源·鸿蒙·鸿蒙系统
提子拌饭1332 小时前
逛三园游戏——基于鸿蒙PC Electron框架实现
前端·javascript·游戏·华为·electron·鸿蒙
l1t2 小时前
DeepSeek总结的使用实体-组件-系统和基于存在性处理进行Python编程39-40
开发语言·python