master
a327ex 2021-03-10 23:49:16 -03:00
parent 45b29dc137
commit 01c2e2af1b
3 changed files with 195 additions and 28 deletions

View File

@ -9,6 +9,7 @@ end
function BuyScreen:on_enter(from, level, units)
self.level = level
self.units = units
self.main = Group()
self.top = Group()
@ -31,11 +32,6 @@ function BuyScreen:on_enter(from, level, units)
self.title = Text({{text = '[wavy_mid, fg]choose your initial party', font = pixul_font, alignment = 'center'}}, global_text_tags)
else
local tier_to_units = {
[1] = {'vagrant', 'swordsman', 'wizard', 'archer', 'cleric', 'scout'},
[2] = {'saboteur', 'hunter', 'cannoneer', 'stormweaver', 'squire', 'dual_gunner', 'chronomancer', 'sage', 'cannoneer'},
[3] = {'blade', 'outlaw', 'elementor', 'psykeeper', 'spellblade'},
}
local level_to_tier_weights = {
[1] = {100, 0, 0},
[2] = {95, 5, 0},
@ -65,11 +61,12 @@ function BuyScreen:on_enter(from, level, units)
}
self.cards = {}
self.selected_card_index = 1
self.cards[1] = ShopCard{group = self.main, x = gw/2 - 120, y = gh/4, w = 100, h = 90, unit = random:table(tier_to_units[random:weighted_pick(unpack(level_to_tier_weights[self.level]))]), parent = self}
self.cards[2] = ShopCard{group = self.main, x = gw/2, y = gh/4, w = 100, h = 90, unit = random:table(tier_to_units[random:weighted_pick(unpack(level_to_tier_weights[self.level]))]), parent = self}
self.cards[3] = ShopCard{group = self.main, x = gw/2 + 120, y = gh/4, w = 100, h = 90, unit = random:table(tier_to_units[random:weighted_pick(unpack(level_to_tier_weights[self.level]))]), parent = self}
self.cards[1] = ShopCard{group = self.main, x = 60, y = 75, w = 80, h = 90, unit = random:table(tier_to_characters[random:weighted_pick(unpack(level_to_tier_weights[self.level]))]), parent = self}
self.cards[2] = ShopCard{group = self.main, x = 155, y = 75, w = 80, h = 90, unit = random:table(tier_to_characters[random:weighted_pick(unpack(level_to_tier_weights[self.level]))]), parent = self}
self.cards[3] = ShopCard{group = self.main, x = 250, y = 75, w = 80, h = 90, unit = random:table(tier_to_characters[random:weighted_pick(unpack(level_to_tier_weights[self.level]))]), parent = self}
self.shop_text_sy = 1
self.shop_text = Text({{text = '[wavy_mid, fg]shop', font = pixul_font, alignment = 'center'}}, global_text_tags)
self.party_text = Text({{text = '[wavy_mid, fg]your party', font = pixul_font, alignment = 'center'}}, global_text_tags)
end
end
@ -129,7 +126,7 @@ function BuyScreen:update(dt)
else
if self.shop_text then self.shop_text:update(dt) end
if self.party_text then self.party_text:update(dt) end
end
end
@ -140,33 +137,75 @@ function BuyScreen:draw()
self.ui:draw()
if self.level == 0 then
if self.title then self.title:draw(3.25*gw/4, 25, 0, 1, self.title_sy) end
if self.unit_info_text then self.unit_info_text:draw(gw/2, gh/2) end
if self.title then self.title:draw(3.25*gw/4, 32, 0, 1, self.title_sy) end
else
if self.shop_text then self.shop_text:draw(gw/2, 15, 0, 1, self.shop_text_sy) end
if self.shop_text then self.shop_text:draw(32, 20, 0, 1, self.shop_text_sy) end
if self.party_text then self.party_text:draw(48, 190) end
end
end
CharacterPart = Object:extend()
CharacterPart:implement(GameObject)
function CharacterPart:init(args)
self:init_game_object(args)
end
function CharacterPart:update(dt)
self:update_game_object(dt)
end
function CharacterPart:draw()
graphics.push(self.x, self.y, 0, self.spring.x, self.spring.x)
graphics.rectangle(self.x, self.y, 14, 14, 3, 3, character_colors[self.character])
graphics.print_centered(self.level, pixul_font, self.x + 0.5, self.y + 2, 0, 1, 1, 0, 0, _G[character_color_strings[self.character]][-5])
graphics.pop()
end
function CharacterPart:on_mouse_enter()
self.spring:pull(0.2, 200, 10)
self.info_text = InfoText{group = main.current.ui}
self.info_text:activate({
{text = '[' .. character_color_strings[self.character] .. ']' .. self.character:capitalize() .. '[fg] - cost: [yellow]' .. self.parent.cost, font = pixul_font, alignment = 'center', height_multiplier = 1.25},
{text = character_descriptions[self.character](get_character_stat(self.character, 1, 'dmg')), font = pixul_font, alignment = 'center'},
}, nil, nil, nil, nil, 16, 4, nil, 2)
self.info_text.x, self.info_text.y = gw/2, gh/2 + 10
end
function CharacterPart:on_mouse_exit()
self.info_text:deactivate()
self.info_text = nil
end
ShopCard = Object:extend()
ShopCard:implement(GameObject)
function ShopCard:init(args)
self:init_game_object(args)
self.character_icon = CharacterIcon{group = main.current.top, x = self.x, y = self.y, character = self.unit}
self.shape = Rectangle(self.x, self.y, self.w, self.h)
self.interact_with_mouse = true
self.character_icon = CharacterIcon{group = main.current.top, x = self.x, y = self.y - 26, character = self.unit, parent = self}
self.class_icons = {}
for i, class in ipairs(character_classes[self.unit]) do
local x = self.x
if #character_classes[self.unit] == 2 then x = self.x - 10
elseif #character_classes[self.unit] == 3 then x = self.x - 20 end
table.insert(self.class_icons, ClassIcon{group = main.current.top, x = x + (i-1)*20, y = self.y + 10, class = class})
table.insert(self.class_icons, ClassIcon{group = main.current.top, x = x + (i-1)*20, y = self.y + 6, class = class, parent = self})
end
self.cost = character_tiers[self.unit]
end
function ShopCard:update(dt)
self:update_game_object(dt)
if self.unit_text then self.unit_text:update(dt) end
end
@ -193,7 +232,28 @@ end
function ShopCard:draw()
graphics.push(self.x, self.y, 0, self.spring.x, self.spring.x)
if self.selected then
graphics.rectangle(self.x, self.y, self.w, self.h, 6, 6, bg[-1])
end
graphics.pop()
end
function ShopCard:on_mouse_enter()
self.selected = true
self.spring:pull(0.1)
self.character_icon.spring:pull(0.1, 200, 10)
for _, class_icon in ipairs(self.class_icons) do
class_icon.selected = true
class_icon.spring:pull(0.1, 200, 10)
end
end
function ShopCard:on_mouse_exit()
self.selected = false
for _, class_icon in ipairs(self.class_icons) do class_icon.selected = false end
end
@ -203,6 +263,8 @@ CharacterIcon = Object:extend()
CharacterIcon:implement(GameObject)
function CharacterIcon:init(args)
self:init_game_object(args)
self.shape = Rectangle(self.x, self.y, 40, 20)
self.interact_with_mouse = true
self.character_text = Text({{text = '[' .. character_color_strings[self.character] .. ']' .. self.character, font = pixul_font, alignment = 'center'}}, global_text_tags)
end
@ -215,18 +277,36 @@ end
function CharacterIcon:draw()
graphics.push(self.x, self.y, 0, self.spring.x, self.spring.x)
graphics.rectangle(self.x, self.y - 25, 12, 12, 3, 3, character_colors[self.character])
self.character_text:draw(self.x, self.y - 10)
graphics.rectangle(self.x, self.y - 7, 14, 14, 3, 3, character_colors[self.character])
graphics.print_centered(self.parent.cost, pixul_font, self.x + 0.5, self.y - 5, 0, 1, 1, 0, 0, _G[character_color_strings[self.character]][-5])
self.character_text:draw(self.x, self.y + 10)
graphics.pop()
end
function CharacterIcon:on_mouse_enter()
self.spring:pull(0.2, 200, 10)
self.info_text = InfoText{group = main.current.ui}
self.info_text:activate({
{text = '[' .. character_color_strings[self.character] .. ']' .. self.character:capitalize() .. '[fg] - cost: [yellow]' .. self.parent.cost, font = pixul_font, alignment = 'center', height_multiplier = 1.25},
{text = character_descriptions[self.character](get_character_stat(self.character, 1, 'dmg')), font = pixul_font, alignment = 'center'},
}, nil, nil, nil, nil, 16, 4, nil, 2)
self.info_text.x, self.info_text.y = gw/2, gh/2 + 10
end
function CharacterIcon:on_mouse_exit()
self.info_text:deactivate()
self.info_text = nil
end
ClassIcon = Object:extend()
ClassIcon:implement(GameObject)
function ClassIcon:init(args)
self:init_game_object(args)
self.shape = Rectangle(self.x, self.y, 20, 30)
self.shape = Rectangle(self.x, self.y + 11, 20, 40)
self.interact_with_mouse = true
end
@ -238,19 +318,36 @@ end
function ClassIcon:draw()
graphics.push(self.x, self.y, 0, self.spring.x, self.spring.x)
_G[self.class]:draw(self.x, self.y, 0, 0.4, 0.4, 0, 0, class_colors[self.class])
local i, j, n = class_set_numbers[self.class](self.parent.parent.units)
graphics.rectangle(self.x, self.y, 16, 24, 4, 4, (n >= i) and class_colors[self.class] or bg[3])
_G[self.class]:draw(self.x, self.y, 0, 0.3, 0.3, 0, 0, (n >= i) and _G[class_color_strings[self.class]][-5] or bg[10])
graphics.rectangle(self.x, self.y + 26, 16, 16, 3, 3, bg[3])
if i == 2 then
graphics.line(self.x - 3, self.y + 20, self.x - 3, self.y + 25, (n >= 1) and class_colors[self.class] or bg[10], 3)
graphics.line(self.x - 3, self.y + 27, self.x - 3, self.y + 32, (n >= 2) and class_colors[self.class] or bg[10], 3)
graphics.line(self.x + 4, self.y + 20, self.x + 4, self.y + 25, (n >= 3) and class_colors[self.class] or bg[10], 3)
graphics.line(self.x + 4, self.y + 27, self.x + 4, self.y + 32, (n >= 4) and class_colors[self.class] or bg[10], 3)
elseif i == 3 then
graphics.line(self.x - 4, self.y + 22, self.x - 4, self.y + 30, (n >= 1) and class_colors[self.class] or bg[10], 2)
graphics.line(self.x, self.y + 22, self.x, self.y + 30, (n >= 2) and class_colors[self.class] or bg[10], 2)
graphics.line(self.x + 4, self.y + 22, self.x + 4, self.y + 30, (n >= 3) and class_colors[self.class] or bg[10], 2)
elseif i == 1 then
graphics.line(self.x - 3, self.y + 22, self.x - 3, self.y + 30, (n >= 1) and class_colors[self.class] or bg[10], 3)
graphics.line(self.x + 4, self.y + 22, self.x + 4, self.y + 30, (n >= 2) and class_colors[self.class] or bg[10], 3)
end
graphics.pop()
end
function ClassIcon:on_mouse_enter()
self.spring:pull(0.2, 200, 10)
local i, j, owned = class_set_numbers[self.class](self.parent.parent.units)
self.info_text = InfoText{group = main.current.ui}
self.info_text:activate({
{text = '[' .. class_color_strings[self.class] .. ']' .. self.class:capitalize(), font = pixul_font, alignment = 'center', height_multiplier = 1.25},
{text = class_descriptions[self.class](0), font = pixul_font, alignment = 'center'},
{text = '[' .. class_color_strings[self.class] .. ']' .. self.class:capitalize() .. '[fg] - owned: [yellow]' .. owned, font = pixul_font, alignment = 'center', height_multiplier = 1.25},
{text = class_descriptions[self.class]((owned >= j and 2) or (owned >= i and 1) or 0), font = pixul_font, alignment = 'center'},
}, nil, nil, nil, nil, 16, 4, nil, 2)
self.info_text.x, self.info_text.y = gw/2, self.y + 60
self.info_text.x, self.info_text.y = gw/2, gh/2 + 10
end

View File

@ -347,3 +347,7 @@ with which win condition it's happening... I'll fix it in time. Tomorrow I can g
Initial work done on the main buy screen. Fairly slow moving still. There's a sort of conceptual fuzziness that happens when writing UI code where there's a few different ways of doing it and this freedom seems fairly paralyzing.
I've been thinking really hard about what to do about that but it's still up in the air. The "dead simple layouts" thing is a good idea but layouting is not necessarily the main problem I have, it's more like relationships between
different objects and a UI coordination issue that seems to stop me.
# Day 22 - 10/03/21
More UI progress on buy screen.

View File

@ -208,7 +208,6 @@ function init()
end
get_character_stat = function(character, level, stat)
print(character)
local group = Group():set_as_physics_world(32, 0, 0, {'player', 'enemy', 'projectile', 'enemy_projectile'})
local mock = Player{group = group, leader = true, character = character, level = level}
mock:update(1/60)
@ -255,22 +254,89 @@ function init()
local ylb1 = function(lvl) return (lvl == 1 and 'yellow' or 'light_bg') end
local ylb2 = function(lvl) return (lvl == 2 and 'yellow' or 'light_bg') end
class_descriptions = {
['ranger'] = function(lvl) return '[' .. ylb1(lvl) .. ']2[' .. ylb2(lvl) .. ']/4 [fg]- [' .. ylb1(lvl) .. ']10%[' .. ylb2(lvl) .. ']/20% [fg]chance to release a barrage on attack' end,
['ranger'] = function(lvl) return '[' .. ylb1(lvl) .. ']2[' .. ylb2(lvl) .. ']/4 [fg]- [' .. ylb1(lvl) .. ']10%[' .. ylb2(lvl) .. ']/20% [fg]chance to release a barrage on attack to allied rangers' end,
['warrior'] = function(lvl) return '[' .. ylb1(lvl) .. ']2[' .. ylb2(lvl) .. ']/4 [fg]- [' .. ylb1(lvl) .. ']+25[' .. ylb2(lvl) .. ']/+50 [fg]defense to allied warriors' end,
['mage'] = function(lvl) return '[' .. ylb1(lvl) .. ']2[' .. ylb2(lvl) .. ']/4 [fg]- [' .. ylb1(lvl) .. ']-15[' .. ylb2(lvl) .. ']/-30 [fg]enemy defense' end,
['nuker'] = function(lvl) return '[' .. ylb1(lvl) .. ']2[' .. ylb2(lvl) .. ']/4 [fg]- [' .. ylb1(lvl) .. ']+15%[' .. ylb2(lvl) .. ']/+25% [fg]area damage and size' end,
['rogue'] = function(lvl) return '[' .. ylb1(lvl) .. ']2[' .. ylb2(lvl) .. ']/4 [fg]- [' .. ylb1(lvl) .. ']10%[' .. ylb2(lvl) .. ']/20% [fg]chance to crit, dealing [yellow]4x[] damage' end,
['nuker'] = function(lvl) return '[' .. ylb1(lvl) .. ']2[' .. ylb2(lvl) .. ']/4 [fg]- [' .. ylb1(lvl) .. ']+15%[' .. ylb2(lvl) .. ']/+25% [fg]area damage and size to allied nukers' end,
['rogue'] = function(lvl) return '[' .. ylb1(lvl) .. ']2[' .. ylb2(lvl) .. ']/4 [fg]- [' .. ylb1(lvl) .. ']10%[' .. ylb2(lvl) .. ']/20% [fg]chance to crit to allied rogues, dealing [yellow]4x[] damage' end,
['healer'] = function(lvl) return '[' .. ylb1(lvl) .. ']3 [fg]- [' .. ylb1(lvl) .. ']+25% [fg]healing effectiveness' end,
['conjurer'] = function(lvl) return '[' .. ylb1(lvl) .. ']2 [fg]- [' .. ylb1(lvl) .. ']+25% [fg]construct damage and duration' end,
['enchanter'] = function(lvl) return '[' .. ylb1(lvl) .. ']3 [fg]- [' .. ylb1(lvl) .. ']+25% [fg]damage to all allies' end,
['psy'] = function(lvl) return '[fg]damage taken by psy units is reflected to enemies at double its value' end,
['psy'] = function(lvl) return '[fg]damage taken by psy units is reflected to enemies at [yellow]2x[fg] its value' end,
}
tier_to_characters = {
[1] = {'vagrant', 'swordsman', 'wizard', 'archer', 'cleric', 'scout'},
[2] = {'saboteur', 'hunter', 'cannoneer', 'stormweaver', 'squire', 'dual_gunner', 'chronomancer', 'sage', 'cannoneer'},
[3] = {'blade', 'outlaw', 'elementor', 'psykeeper', 'spellblade', 'engineer'},
}
character_tiers = {
['vagrant'] = 1,
['swordsman'] = 1,
['wizard'] = 1,
['archer'] = 1,
['scout'] = 1,
['cleric'] = 1,
['outlaw'] = 3,
['blade'] = 3,
['elementor'] = 3,
['saboteur'] = 2,
['stormweaver'] = 2,
['sage'] = 2,
['squire'] = 2,
['cannoneer'] = 2,
['dual_gunner'] = 2,
['hunter'] = 2,
['chronomancer'] = 2,
['spellblade'] = 3,
['psykeeper'] = 3,
['engineer'] = 3,
}
get_number_of_units_per_class = function(units)
local rangers = 0
local warriors = 0
local healers = 0
local mages = 0
local nukers = 0
local conjurers = 0
local rogues = 0
local enchanters = 0
local psys = 0
for _, unit in ipairs(units) do
for _, unit_class in ipairs(character_classes[unit.character]) do
if unit_class == 'ranger' then rangers = rangers + 1 end
if unit_class == 'warrior' then warriors = warriors + 1 end
if unit_class == 'healer' then healers = healers + 1 end
if unit_class == 'mage' then mages = mages + 1 end
if unit_class == 'nuker' then nukers = nukers + 1 end
if unit_class == 'conjurer' then conjurers = conjurers + 1 end
if unit_class == 'rogue' then rogues = rogues + 1 end
if unit_class == 'enchanter' then enchanters = enchanters + 1 end
if unit_class == 'psy' then psys = psys + 1 end
end
end
return {ranger = rangers, warrior = warriors, healer = healers, mage = mages, nuker = nukers, conjurer = conjurers, rogue = rogues, enchanter = enchanters, psy = psys}
end
class_set_numbers = {
['ranger'] = function(units) return 2, 4, get_number_of_units_per_class(units).ranger end,
['warrior'] = function(units) return 2, 4, get_number_of_units_per_class(units).warrior end,
['mage'] = function(units) return 2, 4, get_number_of_units_per_class(units).mage end,
['nuker'] = function(units) return 2, 4, get_number_of_units_per_class(units).nuker end,
['rogue'] = function(units) return 2, 4, get_number_of_units_per_class(units).rogue end,
['healer'] = function(units) return 3, 3, get_number_of_units_per_class(units).healer end,
['conjurer'] = function(units) return 2, 2, get_number_of_units_per_class(units).conjurer end,
['enchanter'] = function(units) return 3, 3, get_number_of_units_per_class(units).enchanter end,
['psy'] = function(units) return 1, 2, get_number_of_units_per_class(units).psy end,
}
resource = 0
main = Main()
main:add(BuyScreen'buy_screen')
main:go_to('buy_screen', 1, {})
main:go_to('buy_screen', 1, {{character = 'vagrant'}, {character = 'swordsman'}, {character = 'wizard'}, {character = 'archer'}, {character = 'scout'}, {character = 'cleric'}})
end