Allow for equip/unequip with single left click
This commit is contained in:
@@ -4,6 +4,7 @@ module Dodge.Inventory.RBList (
|
|||||||
equipSiteToPositions,
|
equipSiteToPositions,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Control.Applicative
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Data.List (elemIndex, findIndex)
|
import Data.List (elemIndex, findIndex)
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
@@ -30,11 +31,25 @@ updateRBList w
|
|||||||
where
|
where
|
||||||
cr = you w
|
cr = you w
|
||||||
|
|
||||||
|
-- want to choose the current position if the item is equipped, otherwise try to
|
||||||
|
-- find a free equipment slot
|
||||||
|
chooseEquipmentPosition :: Creature -> [EquipPosition] -> Int
|
||||||
|
chooseEquipmentPosition cr eps = fromMaybe (chooseFreeSite cr eps) $ do
|
||||||
|
i <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||||
|
ep <- cr ^? crInvEquipped . ix i
|
||||||
|
elemIndex ep eps
|
||||||
|
|
||||||
|
chooseFreeSite :: Creature -> [EquipPosition] -> Int
|
||||||
|
chooseFreeSite cr = fromMaybe 0 . findIndex hasnoequipment
|
||||||
|
where
|
||||||
|
hasnoequipment ep = isNothing $ cr ^? crEquipment . ix ep
|
||||||
|
|
||||||
getEquipmentAllocation :: World -> EquipmentAllocation
|
getEquipmentAllocation :: World -> EquipmentAllocation
|
||||||
getEquipmentAllocation w = fromMaybe DoNotMoveEquipment $ do
|
getEquipmentAllocation w = fromMaybe DoNotMoveEquipment $ do
|
||||||
curpos <- you w ^? crManipulation . manObject . inInventory . ispItem
|
curpos <- you w ^? crManipulation . manObject . inInventory . ispItem
|
||||||
esite <- you w ^? crInv . ix curpos . itUse . equipEffect . eeSite
|
esite <- you w ^? crInv . ix curpos . itUse . equipEffect . eeSite
|
||||||
i <- w ^? rbOptions . opSel
|
i <- w ^? rbOptions . opSel
|
||||||
|
<|> Just (chooseEquipmentPosition (you w) (equipSiteToPositions esite))
|
||||||
es <- equipSiteToPositions esite ^? ix i
|
es <- equipSiteToPositions esite ^? ix i
|
||||||
return $ case you w ^? crInvEquipped . ix curpos of
|
return $ case you w ^? crInvEquipped . ix curpos of
|
||||||
Just epos
|
Just epos
|
||||||
@@ -67,13 +82,3 @@ equipSiteToPositions es = case es of
|
|||||||
GoesOnWrist -> [OnLeftWrist, OnRightWrist]
|
GoesOnWrist -> [OnLeftWrist, OnRightWrist]
|
||||||
GoesOnLegs -> [OnLegs]
|
GoesOnLegs -> [OnLegs]
|
||||||
|
|
||||||
chooseEquipmentPosition :: Creature -> [EquipPosition] -> Int
|
|
||||||
chooseEquipmentPosition cr eps = fromMaybe (chooseFreeSite cr eps) $ do
|
|
||||||
i <- cr ^? crManipulation . manObject . inInventory . ispItem
|
|
||||||
ep <- cr ^? crInvEquipped . ix i
|
|
||||||
elemIndex ep eps
|
|
||||||
|
|
||||||
chooseFreeSite :: Creature -> [EquipPosition] -> Int
|
|
||||||
chooseFreeSite cr = fromMaybe 0 . findIndex hasnoequipment
|
|
||||||
where
|
|
||||||
hasnoequipment ep = isNothing $ cr ^? crEquipment . ix ep
|
|
||||||
|
|||||||
@@ -163,8 +163,7 @@ drawRBOptions cfig w = fromMaybe mempty $ do
|
|||||||
maybetopborder 0 curpos = listCursorChooseBorderScale 0 1 [North] curpos 0 white 7 1
|
maybetopborder 0 curpos = listCursorChooseBorderScale 0 1 [North] curpos 0 white 7 1
|
||||||
maybetopborder _ _ = mempty
|
maybetopborder _ _ = mempty
|
||||||
maybebottomborder a b curpos
|
maybebottomborder a b curpos
|
||||||
| a == b - 1 =
|
| a == b - 1 = listCursorChooseBorderScale 0 1 [South] curpos 0 white 7 1
|
||||||
listCursorChooseBorderScale 0 1 [South] curpos 0 white 7 1
|
|
||||||
| otherwise = mempty
|
| otherwise = mempty
|
||||||
otheritem j = fromMaybe "" $ do
|
otheritem j = fromMaybe "" $ do
|
||||||
itm <- you w ^? crInv . ix j
|
itm <- you w ^? crInv . ix j
|
||||||
|
|||||||
Reference in New Issue
Block a user