Skip to content

Commit

Permalink
Draw held items in the Pokémon widget
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Jan 11, 2016
1 parent 5948268 commit 5331e66
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
11 changes: 11 additions & 0 deletions battle/scripts/objects/general/bag.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ function bag (items) {
self.items.remove(index);
};

self.give = function (index, poke) {
var item = self.items[index], taken = null;
self.items.remove(index);
if (poke.item !== null) {
taken = self.add(poke.item);
poke.item = null;
}
poke.item = item.item;
return taken;
};

self.has = function (item) {
return foreach(self.items, function (which) {
if (which.item === item || (Items._(which.item + " => category?") && Items._(which.item + " => category") === item)) // Whether the exact item was in possession, or an item in the same category
Expand Down
14 changes: 8 additions & 6 deletions battle/scripts/objects/general/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,14 @@ function pokemon (data, validate) {
self.mega = form;
if (self.trainer !== null)
self.trainer.megaEvolution = true;
var display = Display.state.save();
Textbox.effect(function () {
Display.state.load(display);
self.cry();
});
if (!self.battler.battle.process) Textbox.state(self.name() + " Mega Evolved!");
if (!self.battler.battle.process) {
var display = Display.state.save();
Textbox.effect(function () {
Display.state.load(display);
self.cry();
});
Textbox.state(self.name() + " Mega Evolved!");
}
}
};

Expand Down
28 changes: 21 additions & 7 deletions battle/scripts/objects/unique/Widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,33 @@ Widgets.FlowGrid = {
context.fill();
}
// Icon
var icon = Sprite.load(poke.paths.icon(true));
var redrawOnceLoaded = path => {
Sprite.load(path, function () {
if (Widgets.Party.interface.cells.indexOf(poke) !== -1) {
Widgets.Party.interface.redrawCell(poke);
}
});
};
var icon;
icon = Sprite.load(poke.paths.icon(true));
if (icon) {
context.imageSmoothingEnabled = false;
context.copyImageHD(icon.image, false, true, position.x + (size.width - icon.width) / 2, position.y + (size.height - icon.height) / 2);
context.imageSmoothingEnabled = true;
} else {
Sprite.load(poke.paths.icon(true), function () {
if (Widgets.Party.interface.cells.indexOf(poke) !== -1) {
Widgets.Party.interface.redrawCell(poke);
}
});
redrawOnceLoaded(poke.paths.icon(true));
}
var drawBanner = (text) => {
// Item
if (poke.item !== null) {
var item = Items._(poke.item);
icon = Sprite.load(item.paths.icon(true));
if (icon) {
context.copyImageHD(icon.image, false, true, position.x + (size.width - icon.width / 2) / 2 + 8, position.y + (size.height - icon.height / 2) / 2 + 8, icon.width / 2, icon.height / 2);
} else {
redrawOnceLoaded(item.paths.icon(true));
}
}
var drawBanner = text => {
var bannerHeight = 32;
context.fillStyle = "hsl(0, 60%, 40%)";
context.fillRectHD(position.x, position.y + (size.height - bannerHeight) / 2, size.width, bannerHeight);
Expand Down

0 comments on commit 5331e66

Please sign in to comment.