1
0
mirror of https://github.com/exane/not-gwent-online synced 2025-11-05 00:58:26 +00:00

add card redraw at battle begin

This commit is contained in:
exane
2015-06-23 18:12:11 +02:00
parent dbe76f7038
commit ee1b0e0eda
9 changed files with 114 additions and 72 deletions

View File

@@ -226,6 +226,8 @@ var BattleView = Backbone.View.extend({
this.listenTo(user, "change:openDiscard", this.render);
this.listenTo(user, "change:setAgile", this.render);
this.listenTo(user, "change:setHorn", this.render);
this.listenTo(user, "change:isReDrawing", this.render);
/*this.listenTo(user, "change:handCards", this.render);*/
this.$hand = this.$el.find(".field-hand");
this.$preview = this.$el.find(".card-preview");
@@ -378,6 +380,12 @@ var BattleView = Backbone.View.extend({
calculateCardMargin(this.$el.find(".field-hand .card"), 538, 70, this.handCards.length);
}
if(this.user.get("isReDrawing")) {
this.user.set("handCards", this.handCards);
var modal = new ReDrawModal({model: this.user});
this.$el.prepend(modal.render().el);
}
if(this.user.get("openDiscard")){
var modal = new Modal({model: this.user});
this.$el.prepend(modal.render().el);
@@ -488,6 +496,28 @@ var MedicModal = Modal.extend({
}
});
var ReDrawModal = Modal.extend({
template: require("../templates/modal.redraw.handlebars"),
initialize: function(){
this.listenTo(this.model, "change:isReDrawing", this.cancel);
},
events: {
"click .card": "onCardClick"
},
onCardClick: function(e){
console.log($(e.target).closest(".card"));
var id = $(e.target).closest(".card").data().id;
this.model.get("app").send("redraw:reDrawCard", {
cardID: id
})
},
cancel: function(){
if(!this.model.get("isReDrawing")) return;
this.model.get("app").send("redraw:close_client");
this.model.set("isReDrawing", false);
}
});
var User = Backbone.Model.extend({
defaults: {
name: "",
@@ -554,6 +584,14 @@ var User = Backbone.Model.extend({
self.set("setHorn", data.cardID);
})
app.receive("redraw:cards", function() {
self.set("isReDrawing", true);
})
app.receive("redraw:close", function() {
self.set("isReDrawing", false);
})
app.on("createRoom", this.createRoom, this);
app.on("joinRoom", this.joinRoom, this);
app.on("setName", this.setName, this);