From ca9aded3df74485d398c96c280104101f3a696af Mon Sep 17 00:00:00 2001 From: gplane Date: Wed, 26 Apr 2017 23:39:10 +0800 Subject: [PATCH] Add option for choosing types of textures to be cleared --- app/Http/Controllers/PlayerController.php | 8 ++- app/Models/Player.php | 21 ++++--- resources/assets/src/scripts/user.js | 69 ++++++++++++++--------- resources/lang/en/locale.js | 2 + resources/lang/zh_CN/locale.js | 2 + 5 files changed, 66 insertions(+), 36 deletions(-) diff --git a/app/Http/Controllers/PlayerController.php b/app/Http/Controllers/PlayerController.php index 6f639d3a..5b91d11a 100644 --- a/app/Http/Controllers/PlayerController.php +++ b/app/Http/Controllers/PlayerController.php @@ -138,9 +138,13 @@ class PlayerController extends Controller return json(trans('user.player.set.success', ['name' => $this->player->player_name]), 0); } - public function clearTexture() + public function clearTexture(Request $request) { - $this->player->clearTexture(); + $types = array_filter(['steve', 'alex', 'cape'], function ($type) use ($request) { + return $request->input($type); + }); + + $this->player->clearTexture($types); return json(trans('user.player.clear.success', ['name' => $this->player->player_name]), 0); } diff --git a/app/Models/Player.php b/app/Models/Player.php index 4aab2113..acbe5107 100644 --- a/app/Models/Player.php +++ b/app/Models/Player.php @@ -97,17 +97,22 @@ class Player extends Model /** * Clear the textures of player. * - * @return mixed + * @param array|string $types + * @return $this */ - public function clearTexture() + public function clearTexture($types) { - $this->setPreference('default'); + $types = (array) $types; - return $this->setTexture([ - 'tid_steve' => 0, - 'tid_alex' => 0, - 'tid_cape' => 0 - ]); + $map = []; + + foreach ($types as $type) { + $map["tid_$type"] = 0; + } + + $this->setTexture($map); + + return $this; } /** diff --git a/resources/assets/src/scripts/user.js b/resources/assets/src/scripts/user.js index 43c44664..d7ffff99 100644 --- a/resources/assets/src/scripts/user.js +++ b/resources/assets/src/scripts/user.js @@ -2,7 +2,7 @@ * @Author: printempw * @Date: 2016-07-16 10:02:24 * @Last Modified by: g-plane - * @Last Modified time: 2017-04-26 17:46:28 + * @Last Modified time: 2017-04-26 23:37:56 */ 'use strict'; @@ -393,32 +393,49 @@ function changePlayerName(pid, current_player_name) { } function clearTexture(pid) { - swal({ - text: trans('user.clearTexture'), - type: 'warning', - showCancelButton: true - }).then(function() { - $.ajax({ - type: "POST", - url: "./player/texture/clear", - dataType: "json", - data: { 'pid' : pid }, - success: function(json) { - if (json.errno == 0) { - swal({ - type: 'success', - html: json.msg - }); - } else { - swal({ - type: 'error', - html: json.msg - }); - } - }, - error: showAjaxError - }); + let dom = ` +
+ Default (Steve) +
+
+ Slim (Alex) +
+
+ ${trans('general.cape')} +
+ + `; + showModal(dom, trans('user.chooseClearTexture'), 'default', { callback: `ajaxClearTexture(${pid})` }); + return; +} + +function ajaxClearTexture(pid) { + $('.modal').each(function () { + if ($(this).css('display') == "none") + $(this).remove(); }); + + let data = { pid: pid }; + ['steve', 'alex', 'cape'].forEach(type => { + data[type] = $(`#clear-${type}`).prop('checked') ? 1 : 0; + }); + + if (data['steve'] == data['alex'] == data['cape'] == 0) { + toastr.warning(trans('user.noClearChoice')); + return; + } + + Promise.resolve($.ajax({ + type: 'POST', + url: './player/texture/clear', + dataType: 'json', + data: data + })).then(json => { + swal({ type: json.errno == 0 ? 'success' : 'error', html: json.msg }); + $('.modal').modal('hide'); + }).catch(error => showAjaxError); } function deletePlayer(pid) { diff --git a/resources/lang/en/locale.js b/resources/lang/en/locale.js index f4f0bff6..70c7693c 100644 --- a/resources/lang/en/locale.js +++ b/resources/lang/en/locale.js @@ -86,6 +86,8 @@ clearTexture: 'Sure to clear the skins & cape of this player?', deletePlayer: 'Sure to delete this player?', deletePlayerNotice: 'It\'s permanent. No backups.', + chooseClearTexture: 'Choose texture types you want to clear', + noClearChoice: 'You haven\'t choose any types', // Profile setAvatar: 'Sure to set this as your avatar?', diff --git a/resources/lang/zh_CN/locale.js b/resources/lang/zh_CN/locale.js index 4994c04c..547bcc11 100644 --- a/resources/lang/zh_CN/locale.js +++ b/resources/lang/zh_CN/locale.js @@ -86,6 +86,8 @@ clearTexture: '确定要重置该用户的皮肤/披风吗?', deletePlayer: '真的要删除该玩家吗?', deletePlayerNotice: '这将是永久性的删除', + chooseClearTexture: '选择要删除的材质类型', + noClearChoice: '您还没选择要删除的材质类型', // Profile setAvatar: '确定要将此材质设置为用户头像吗?',