//=============================================================================
// MenuSetting.js
//=============================================================================

/*:
 * @plugindesc MenuSettion.
 * @author MilkForce
 *
 * @help This plugin does not provide plugin commands.
 */

/*:ja
 * @plugindesc Menu screen settings
 * @author MilkForce
 *
 * @help このプラグインには、プラグインコマンドはありません。
 */

(function() {




//***オプション画面

	Window_Options.prototype.addGeneralOptions = function() {
		//コマンド記憶？を表示しない
		this.addCommand(TextManager.alwaysDash, 'alwaysDash');
	};

//***メインメニュー

	//メニューの余計なwindowを画面外へ
	var _Scene_Menu_create = Scene_Menu.prototype.create;
    Scene_Menu.prototype.create = function() {
        _Scene_Menu_create.call(this);
		this._commandWindow.x = (Graphics.boxWidth/2)-(this._commandWindow.width/2);
		this._commandWindow.y = (Graphics.boxHeight/2)-(this._commandWindow.height/2);
		this._statusWindow.x = Graphics.boxWidth;
        this._statusWindow.y = Graphics.boxHeight;
        this._goldWindow.x = Graphics.boxWidth;
	};

//*** タイトルメニュー位置
	var _Window_TitleCommand_updatePlacement = Window_TitleCommand.prototype.updatePlacement;
    Window_TitleCommand.prototype.updatePlacement = function() {
        _Window_TitleCommand_updatePlacement.call(this);
        this.x += 150;
        this.y += -110;
        this.setBackgroundType(1);
    };
    Window_TitleCommand.prototype.windowWidth = function() {
        return 200;
    };
//***タイトルメニューに終了を追加
	var _Window_TitleCommand_makeCommandList = Window_TitleCommand.prototype.makeCommandList;
	Window_TitleCommand.prototype.makeCommandList = function() {
		_Window_TitleCommand_makeCommandList.call(this);
		this.addCommand('Shut Down', 'endGame');
	};
	var _Scene_Title_createCommandWindow =Scene_Title.prototype.createCommandWindow;
	Scene_Title.prototype.createCommandWindow = function() {
		_Scene_Title_createCommandWindow.call(this);
		this._commandWindow.setHandler('endGame', this.endGame.bind(this));
	};
	Scene_Title.prototype.endGame = function() {
		this._commandWindow.close();
		this.fadeOutAll();
		SceneManager.exit();
	};
	
//***アイテムメニュー全体
	
	//カテゴリウィンドウは表示しない
	Scene_Item.prototype.create = function() {
		Scene_ItemBase.prototype.create.call(this);
		this.createHelpWindow();
		//this.createCategoryWindow();
		this._categoryWindow = new Window_ItemCategory();
		this.createItemWindow();
		//this.createActorWindow();
	};
	
	//アイテムウィンドウの位置調整とアウティブ化
	Scene_Item.prototype.createItemWindow = function() {
		var width=Graphics.boxWidth/2;
		var x=(Graphics.boxWidth/2)-(width/2);
		var height=Graphics.boxHeight/2;
		var y=Graphics.boxHeight-height-this._helpWindow.height;
		
		this._itemWindow = new Window_ItemList(x, y, width, height);
		this._itemWindow.setHelpWindow(this._helpWindow);
		this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
		this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
		this.addWindow(this._itemWindow);
		this._categoryWindow.setItemWindow(this._itemWindow);
		
		this._itemWindow.activate();
   		this._itemWindow.selectLast();
		this._itemWindow.updateHelp();
		
	};

	//キャンセルでメインメニューに戻す
	Scene_Item.prototype.onItemCancel = function() {
		this._itemWindow.deselect();
		SceneManager.pop();
	};
	//アイテムヘルプウィンドウ生成時に位置を調整する
	Scene_Item.prototype.createHelpWindow = function() {
		this._helpWindow = new Window_Help();
		this._helpWindow.y=Graphics.boxHeight-this._helpWindow.height;
		this.addWindow(this._helpWindow);
	};
	
//***アイテムウィンドウ
	
	//アイテムを選択して決定しても何もしないようにする
    Window_ItemList.prototype.processOk = function() {};
	
	
	//全てのアイテムを常にグレーアウトしない
	Window_ItemList.prototype.isEnabled = function(item) { return true;};
	
	//常に普通のアイテムを表示
	Window_ItemList.prototype.includes = function(item) {
		return DataManager.isItem(item) && item.itypeId === 1;
		//return DataManager.isItem(item) && item.itypeId === 2;//大事なもの
	};
	
	//アイテム一列表示
	Window_ItemList.prototype.maxCols = function() {return 1;};
			
	
	Window_ItemList.prototype.drawItem = function(index) {
		var item = this._data[index];
		if (item) {
			var numberWidth = this.numberWidth();
			var rect = this.itemRect(index);
			rect.width -= this.textPadding();
			this.changePaintOpacity(this.isEnabled(item));
			this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth);
			//this.drawItemNumber(item, rect.x, rect.y, rect.width);
			this.changePaintOpacity(1);
		}
	};
	
	//アイテムウィンドウ更新時に余計な事をしない
	Window_ItemList.prototype.refresh = function() {
		this.makeItemList();
		this.drawAllItems();
	};

//*** セーブ・ロード メニュー
//※アプリケーションの用語でセーブとロードのメッセージをシンプルにしておく

	//ウィンドウ位置調整	
	Scene_File.prototype.createListWindow = function() {
		var width = 470;//Graphics.boxWidth/2;
		var x = (Graphics.boxWidth/2)-(width/2);
		
		this._helpWindow.x=x;
		this._helpWindow.width=width;
		
		var height=Graphics.boxHeight/2;
		var y=(Graphics.boxHeight/2)-(height/2);
		
		this._helpWindow.y=y-this._helpWindow.height;
		
		this._listWindow = new Window_SavefileList(x, y, width, height);
		this._listWindow.setHandler('ok',     this.onSavefileOk.bind(this));
		this._listWindow.setHandler('cancel', this.popScene.bind(this));
		this._listWindow.select(this.firstSavefileIndex());
		this._listWindow.setTopRow(this.firstSavefileIndex() - 2);
		this._listWindow.setMode(this.mode());
		this._listWindow.refresh();
		this.addWindow(this._listWindow);
	};


	
	//セーブファイルの表示行数
	Window_SavefileList.prototype.maxVisibleItems = function() {return 6;};
	
	//Window_SavefileList
	
	Window_SavefileList.prototype.drawPlaytime = function(info, x, y, width) {
		var drow_text="";
		if(info.progress_day){
			drow_text="Day "+info.progress_day;
		}
		if(Number(info.progress_time)==1){
			drow_text+=" Night ";
		}else{
			drow_text+=" Noon ";	
		}
				
		if (info.timestamp) {
			drow_text+=timestampToUnixtime(info.timestamp);
		}
		
		if(drow_text!=""){
			this.drawText(drow_text, x, y, width, 'right');	
		}
		
	};
	
	Window_SavefileList.prototype.drawFileId = function(id, x, y) {
		this.drawText(id+".", x, y, 180);
	};

	Window_SavefileList.prototype.drawContents = function(info, rect, valid) {
		var y = rect.y + rect.height - (rect.height/2)-(this.lineHeight()/2);
		this.drawPlaytime(info, rect.x, rect.y, rect.width);
	};
	
	//保持するセーブファイルインフォに経過日数と時間帯を記録
	DataManager.makeSavefileInfo = function() {
		var info = {};
		info.globalId   = this._globalId;
		info.title      = $dataSystem.gameTitle;
		info.characters = $gameParty.charactersForSavefile();
		info.faces      = $gameParty.facesForSavefile();
		info.playtime   = $gameSystem.playtimeText();
		info.timestamp  = Date.now();
		
		info.progress_day=$gameVariables.value(100);
		info.progress_time=$gameVariables.value(99);
		return info;
	};


})();



