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 = ` +