Skip to content

Commit

Permalink
add fill and sell all buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
liqMix committed Jul 1, 2024
1 parent 5a7ed89 commit 5a268af
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 22 deletions.
65 changes: 52 additions & 13 deletions internal/game/gamebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (s *GameStateBuild) Begin(g *Game) {
g.ui.equipmentPanel.onBuyClick = func() {
s.BuyEquipment(g)
}

g.ui.equipmentPanel.onSortClick = func(sp SortProperty) {
if g.equipment == nil || len(g.equipment) == 0 {
return
Expand Down Expand Up @@ -136,10 +137,14 @@ func (s *GameStateBuild) Begin(g *Game) {
g.ui.equipmentPanel.SetEquipment(afterAuto)
}
}
g.ui.equipmentPanel.buyButton.text.SetText(fmt.Sprintf("Random Loot\n%dgp", s.EquipmentCost()))
g.ui.equipmentPanel.onSellAllClick = func() {
s.SellAllEquipment(g)
}
g.ui.equipmentPanel.buyButton.text.SetText(fmt.Sprintf("Buy Loot\n%dgp", s.EquipmentCost()))
g.ui.equipmentPanel.buyButton.Enable()
g.ui.equipmentPanel.sortButton.Enable()
g.ui.equipmentPanel.autoEquipButton.Enable()
g.ui.equipmentPanel.sellAllButton.Enable()
g.ui.equipmentPanel.onItemClick = func(which int) {
g.ui.equipmentPanel.list.selected = which
s.selectedEquipment = which
Expand Down Expand Up @@ -251,10 +256,13 @@ func (s *GameStateBuild) Begin(g *Game) {
g.UpdateInfo()
}

g.ui.dudePanel.buyButton.onClick = func() {
g.ui.dudePanel.onBuyClick = func() {
s.BuyDude(g)
}
g.ui.dudePanel.buyButton.text.SetText(fmt.Sprintf("Random Dude\n%dgp", s.DudeCost(len(g.dudes))))
g.ui.dudePanel.onFillClick = func() {
s.FillDudes(g)
}
g.ui.dudePanel.buyButton.text.SetText(fmt.Sprintf("Hire Dude\n%dgp", s.DudeCost(len(g.dudes))))
g.ui.dudePanel.buyButton.disabled = false

g.ui.roomPanel.buyButton.onClick = func() {
Expand Down Expand Up @@ -315,11 +323,12 @@ func (s *GameStateBuild) End(g *Game) {
}
g.ui.buttonPanel.hidden = true
g.ui.roomInfoPanel.hidden = true
g.ui.roomPanel.buyButton.disabled = true
g.ui.dudePanel.buyButton.disabled = true
g.ui.equipmentPanel.autoEquipButton.disabled = true
g.ui.equipmentPanel.buyButton.disabled = true
g.ui.equipmentPanel.sortButton.disabled = true
g.ui.roomPanel.buyButton.Disable()
g.ui.dudePanel.buyButton.Disable()
g.ui.equipmentPanel.autoEquipButton.Disable()
g.ui.equipmentPanel.buyButton.Disable()
g.ui.equipmentPanel.sortButton.Disable()
g.ui.equipmentPanel.sellAllButton.Disable()
g.ui.dudeInfoPanel.equipmentDetails.sellButton.hidden = true
g.ui.dudeInfoPanel.equipmentDetails.swapButton.hidden = true
}
Expand All @@ -333,10 +342,21 @@ func (s *GameStateBuild) Update(g *Game) GameState {

if g.autoplay {
if s.nextStory != nil {
if s.nextStory.level%3 == 0 {
s.BuyDude(g)
// Always dude-maxxin
s.FillDudes(g)

// Auto-equip the gear
if len(g.equipment) > 0 {
g.ui.equipmentPanel.autoEquipButton.onClick()
}
// Auto-sell the remaining gear
if len(g.equipment) > 0 {
for _, e := range g.equipment {
s.SellEquipment(g, e)
}
}
}

j := 0
attempts := 0
for i := 0; i < len(s.availableRooms); {
Expand Down Expand Up @@ -604,12 +624,12 @@ func (s *GameStateBuild) DudeCost(dudeCount int) int {
return int(cost)
}

func (s *GameStateBuild) BuyDude(g *Game) {
func (s *GameStateBuild) BuyDude(g *Game) bool {
// COST?
cost := s.DudeCost(len(g.dudes))
if g.gold < cost {
g.ui.feedback.Msg(FeedbackBad, fmt.Sprintf("need more gold to purchase a dude! (%d)", cost))
return
return false
}
g.gold -= cost

Expand All @@ -624,13 +644,14 @@ func (s *GameStateBuild) BuyDude(g *Game) {
profession := WeightedRandomProfessionKind(g.dudes)
dude := NewDude(profession, level)
g.dudes = append(g.dudes, dude)
g.ui.dudePanel.buyButton.text.SetText(fmt.Sprintf("Random Dude\n%dgp", s.DudeCost(len(g.dudes))))
g.ui.dudePanel.buyButton.text.SetText(fmt.Sprintf("Hire Dude\n%dgp", s.DudeCost(len(g.dudes))))
g.UpdateInfo()

AddMessage(
MessageNeutral,
fmt.Sprintf("Hired %s (Level %d %s) for %d gold.", dude.Name(), level, profession.String(), cost),
)
return true
}

func (s *GameStateBuild) EquipmentCost() int {
Expand Down Expand Up @@ -697,3 +718,21 @@ func (s *GameStateBuild) SellEquipment(g *Game, e *Equipment) {
e.Activate(EventSell{equipment: e, dudes: g.GetAliveDudes()})
g.UpdateInfo()
}

func (s *GameStateBuild) FillDudes(g *Game) {
for {
if !s.BuyDude(g) {
break
}
}
}

func (s *GameStateBuild) SellAllEquipment(g *Game) {
equipmentList := make([]*Equipment, len(g.equipment))
copy(equipmentList, g.equipment)
for _, e := range equipmentList {
s.SellEquipment(g, e)
}
g.equipment = make([]*Equipment, 0)
g.ui.equipmentPanel.SetEquipment(g.equipment)
}
62 changes: 53 additions & 9 deletions internal/game/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,11 @@ type DudePanel struct {
dudes []*Dude
title *UIText
buyButton *ButtonPanel
fillButton *ButtonPanel
onBuyClick func()
onFillClick func()
onItemClick func(index int)
onItemHover func(index int)
onBuyClick func()
}

func MakeDudePanel() DudePanel {
Expand All @@ -851,10 +853,16 @@ func MakeDudePanel() DudePanel {
list: NewUIItemList(DirectionVertical),
count: NewUIText("0", assets.BodyFont, assets.ColorHeading),
}
btn := MakeButtonPanel(assets.BodyFont, PanelStyleButtonAttached)
dp.buyButton = &btn

buy := MakeButtonPanel(assets.BodyFont, PanelStyleButtonAttached)
dp.buyButton = &buy
dp.buyButton.text.center = true
dp.buyButton.text.SetText("Buy\nRandom Dude")
dp.buyButton.text.SetText("Hire Dude")

fill := MakeButtonPanel(assets.BodyFont, PanelStyleButton)
dp.fillButton = &fill
dp.fillButton.text.center = true
dp.fillButton.text.SetText("Fill")

dp.panel.AddChild(dp.title)
dp.panel.AddChild(dp.list)
Expand Down Expand Up @@ -954,6 +962,12 @@ func (dp *DudePanel) Layout(o *UIOptions) {
dp.buyButton.Layout(nil, o)
dp.buyButton.text.SetPosition(dp.buyButton.text.X(), dp.buyButton.text.Y()+4*o.Scale)
dp.buyButton.SetPosition(dp.panel.X()+dp.panel.Width()/2-dp.buyButton.Width()/2, dp.panel.Y()+dp.panel.Height()-10*o.Scale)

dp.fillButton.SetSize(dp.panel.Width(), 48)
dp.fillButton.Layout(nil, o)
dp.fillButton.text.SetPosition(dp.fillButton.text.X(), dp.fillButton.text.Y()+4*o.Scale)
// Next to buy button
dp.fillButton.SetPosition(dp.buyButton.X()+dp.buyButton.Width()+4*o.Scale, dp.panel.Y()+dp.panel.Height()-5*o.Scale)
}

func (dp *DudePanel) Update(o *UIOptions) {
Expand All @@ -976,11 +990,18 @@ func (dp *DudePanel) Check(mx, my float64, kind UICheckKind) bool {
}
return true
}
if dp.fillButton.Check(mx, my, kind) {
if kind == UICheckClick && dp.onFillClick != nil {
dp.onFillClick()
}
return true
}
return false
}

func (dp *DudePanel) Draw(o *render.Options) {
dp.buyButton.Draw(o)
dp.fillButton.Draw(o)
dp.panel.Draw(o)
dp.count.Draw(o)
}
Expand Down Expand Up @@ -1289,12 +1310,14 @@ type EquipmentPanel struct {
autoEquipButton *ButtonPanel
buyButton *ButtonPanel
sortButton *ButtonPanel
sellAllButton *ButtonPanel
sortMethod SortProperty
showDetails bool
details *EquipmentDetailsPanel

onAutoEquipClick func()
onBuyClick func()
onSellAllClick func()
onSortClick func(sortMethod SortProperty)
onItemClick func(index int)
onItemHover func(index int)
Expand All @@ -1312,7 +1335,7 @@ func MakeEquipmentPanel() EquipmentPanel {
buy := MakeButtonPanel(assets.BodyFont, PanelStyleButtonAttached)
ep.buyButton = &buy
ep.buyButton.text.center = true
ep.buyButton.text.SetText("Buy\nRandom Loot")
ep.buyButton.text.SetText("Buy Loot")

// Sort
sort := MakeButtonPanel(assets.BodyFont, PanelStyleButton)
Expand All @@ -1326,7 +1349,12 @@ func MakeEquipmentPanel() EquipmentPanel {
ep.autoEquipButton.text.center = true
ep.autoEquipButton.text.SetText("Auto\nEquip")

// Sort button
// Sell All
sellAll := MakeButtonPanel(assets.BodyFont, PanelStyleButton)
ep.sellAllButton = &sellAll
ep.sellAllButton.text.center = true
ep.sellAllButton.text.SetText("Sell\nAll")

ep.list.spaceBetween = -2
ep.panel.AddChild(ep.title)
ep.panel.AddChild(ep.list)
Expand Down Expand Up @@ -1360,24 +1388,31 @@ func (ep *EquipmentPanel) Layout(o *UIOptions) {
ep.panel.padding = 6 * o.Scale
ep.list.SetSize(ep.panel.Width(), ep.panel.Height()-ep.panel.padding*2-ep.title.Height())

// Buy button (below)
// Buy button
ep.buyButton.SetSize(ep.panel.Width(), 48)
ep.buyButton.Layout(nil, o)
ep.buyButton.text.SetPosition(ep.buyButton.text.X(), ep.buyButton.text.Y()+1*o.Scale)
ep.buyButton.SetPosition(ep.panel.X()+ep.panel.Width()/2-ep.buyButton.Width()/2, ep.panel.Y()+ep.panel.Height()-5*o.Scale)

// Sort button (right top)
// Sort button
// ep.sortButton.SetSize(1, 1)
// ep.sortButton.Layout(nil, o)
// ep.sortButton.text.SetPosition(ep.sortButton.text.X(), ep.sortButton.text.Y()+0*o.Scale)
// ep.sortButton.SetPosition(ep.panel.X()+ep.panel.Width()-ep.sortButton.Width()/2, ep.panel.Y()+5*o.Scale)

// Auto equip button (right top)
// Auto equip button
ep.autoEquipButton.SetSize(ep.panel.Width(), 48)
ep.autoEquipButton.Layout(nil, o)
ep.autoEquipButton.text.SetPosition(ep.autoEquipButton.text.X(), ep.autoEquipButton.text.Y()+0*o.Scale)
ep.autoEquipButton.SetPosition(ep.panel.X()+ep.panel.Width()-ep.autoEquipButton.Width()/2+10*o.Scale, ep.panel.Y()+ep.panel.Height()-5*o.Scale)

// Sell all button
ep.sellAllButton.SetSize(ep.panel.Width(), 48)
ep.sellAllButton.Layout(nil, o)
ep.sellAllButton.text.SetPosition(ep.sellAllButton.text.X(), ep.sellAllButton.text.Y()+0*o.Scale)
// Right of auto equip button
ep.sellAllButton.SetPosition(ep.autoEquipButton.panel.X()+ep.autoEquipButton.panel.Width()+4*o.Scale, ep.autoEquipButton.panel.Y())

ep.panel.Layout(nil, o)
ep.details.Layout(o)
ep.details.panel.SetSize(128*o.Scale, 96*o.Scale)
Expand Down Expand Up @@ -1424,6 +1459,14 @@ func (ep *EquipmentPanel) Check(mx, my float64, kind UICheckKind) bool {
}
return true
}
if ep.sellAllButton.Check(mx, my, kind) {
if kind == UICheckClick {
if ep.onSellAllClick != nil {
ep.onSellAllClick()
}
}
return true
}

if ep.panel.Check(mx, my, kind) {
return true
Expand All @@ -1443,6 +1486,7 @@ func (ep *EquipmentPanel) Draw(o *render.Options) {
ep.buyButton.Draw(o)
if ep.equipment != nil && len(ep.equipment) != 0 {
ep.autoEquipButton.Draw(o)
ep.sellAllButton.Draw(o)
ep.sortButton.Draw(o)
}
}
Expand Down

0 comments on commit 5a268af

Please sign in to comment.