Add option for choosing types of textures to be cleared

This commit is contained in:
gplane 2017-04-26 23:39:10 +08:00
parent e0fee86ea7
commit ca9aded3df
5 changed files with 66 additions and 36 deletions

View File

@ -138,9 +138,13 @@ class PlayerController extends Controller
return json(trans('user.player.set.success', ['name' => $this->player->player_name]), 0); 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); return json(trans('user.player.clear.success', ['name' => $this->player->player_name]), 0);
} }

View File

@ -97,17 +97,22 @@ class Player extends Model
/** /**
* Clear the textures of player. * 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([ $map = [];
'tid_steve' => 0,
'tid_alex' => 0, foreach ($types as $type) {
'tid_cape' => 0 $map["tid_$type"] = 0;
]); }
$this->setTexture($map);
return $this;
} }
/** /**

View File

@ -2,7 +2,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-07-16 10:02:24 * @Date: 2016-07-16 10:02:24
* @Last Modified by: g-plane * @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'; 'use strict';
@ -393,32 +393,49 @@ function changePlayerName(pid, current_player_name) {
} }
function clearTexture(pid) { function clearTexture(pid) {
swal({ let dom = `
text: trans('user.clearTexture'), <div class="form-group">
type: 'warning', <input type="checkbox" id="clear-steve"> Default (Steve)
showCancelButton: true </div>
}).then(function() { <div class="form-group">
$.ajax({ <input type="checkbox" id="clear-alex"> Slim (Alex)
type: "POST", </div>
url: "./player/texture/clear", <div class="form-group">
dataType: "json", <input type="checkbox" id="clear-cape"> ${trans('general.cape')}
data: { 'pid' : pid }, </div>
success: function(json) { <script>
if (json.errno == 0) { $('input[type=checkbox]').iCheck({ checkboxClass: 'icheckbox_square-blue' });
swal({ </script>
type: 'success', `;
html: json.msg showModal(dom, trans('user.chooseClearTexture'), 'default', { callback: `ajaxClearTexture(${pid})` });
return;
}
function ajaxClearTexture(pid) {
$('.modal').each(function () {
if ($(this).css('display') == "none")
$(this).remove();
}); });
} else {
swal({ let data = { pid: pid };
type: 'error', ['steve', 'alex', 'cape'].forEach(type => {
html: json.msg data[type] = $(`#clear-${type}`).prop('checked') ? 1 : 0;
}); });
if (data['steve'] == data['alex'] == data['cape'] == 0) {
toastr.warning(trans('user.noClearChoice'));
return;
} }
},
error: showAjaxError 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) { function deletePlayer(pid) {

View File

@ -86,6 +86,8 @@
clearTexture: 'Sure to clear the skins & cape of this player?', clearTexture: 'Sure to clear the skins & cape of this player?',
deletePlayer: 'Sure to delete this player?', deletePlayer: 'Sure to delete this player?',
deletePlayerNotice: 'It\'s permanent. No backups.', deletePlayerNotice: 'It\'s permanent. No backups.',
chooseClearTexture: 'Choose texture types you want to clear',
noClearChoice: 'You haven\'t choose any types',
// Profile // Profile
setAvatar: 'Sure to set this as your avatar?', setAvatar: 'Sure to set this as your avatar?',

View File

@ -86,6 +86,8 @@
clearTexture: '确定要重置该用户的皮肤/披风吗?', clearTexture: '确定要重置该用户的皮肤/披风吗?',
deletePlayer: '真的要删除该玩家吗?', deletePlayer: '真的要删除该玩家吗?',
deletePlayerNotice: '这将是永久性的删除', deletePlayerNotice: '这将是永久性的删除',
chooseClearTexture: '选择要删除的材质类型',
noClearChoice: '您还没选择要删除的材质类型',
// Profile // Profile
setAvatar: '确定要将此材质设置为用户头像吗?', setAvatar: '确定要将此材质设置为用户头像吗?',