Commit before extending selection sections: overlapping elements
This commit is contained in:
+77
-64
@@ -1,41 +1,48 @@
|
||||
module Dodge.Item.Display (
|
||||
itemDisplay,
|
||||
selectedItemDisplay,
|
||||
-- selectedItemDisplay,
|
||||
itemString,
|
||||
itemBaseName,
|
||||
basicItemDisplay,
|
||||
) where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import Dodge.Item.Info
|
||||
import Data.Maybe
|
||||
import Data.Sequence
|
||||
import Dodge.Data.Creature
|
||||
import Dodge.Item.SlotsTaken
|
||||
import Dodge.Module
|
||||
import LensHelp
|
||||
import Padding
|
||||
|
||||
itemDisplay :: Item -> [String]
|
||||
itemDisplay it = itemDisplayWithNumber (showConsumption (_itUse it)) it
|
||||
itemDisplay :: Creature -> Item -> [String]
|
||||
itemDisplay cr itm = --itemDisplayWithNumber (showConsumption cr it) it
|
||||
zipWithDefaults id (leftPad 15 ' ') itemDisplayPad (basicItemDisplay itm) (itemNumberDisplay cr itm)
|
||||
|
||||
itemDisplayWithNumber :: String -> Item -> [String]
|
||||
itemDisplayWithNumber numberstr it =
|
||||
Prelude.take (itSlotsTaken it) $
|
||||
(midPadL 15 ' ' thename (' ' : numberstr) ++ theparam) :
|
||||
catMaybes [maybeWarmupStatus it, maybeRateStatus it]
|
||||
++ moduleStrings it
|
||||
++ repeat "\\"
|
||||
zipWithDefaults :: (a -> c) -> (b -> c) -> (a -> b -> c) -> [a] -> [b] -> [c]
|
||||
zipWithDefaults f g h xs ys = go xs ys
|
||||
where
|
||||
thename = itemBaseName it
|
||||
theparam =
|
||||
fromMaybe []
|
||||
. listToMaybe
|
||||
$ mapMaybe
|
||||
($ it)
|
||||
[ maybeModeStatus
|
||||
]
|
||||
go [] bs = map g bs
|
||||
go as [] = map f as
|
||||
go (a:as) (b:bs) = h a b : go as bs
|
||||
|
||||
|
||||
itemDisplayPad :: [Char] -> String -> [Char]
|
||||
itemDisplayPad ls rs
|
||||
| rs == "" = ls
|
||||
| otherwise = midPadL 15 ' ' ls (' ':rs)
|
||||
|
||||
basicItemDisplay :: Item -> [String]
|
||||
basicItemDisplay itm =
|
||||
Prelude.take (itSlotsTaken itm) $
|
||||
itemBaseName itm :
|
||||
catMaybes [maybeWarmupStatus itm, maybeRateStatus itm]
|
||||
++ moduleStrings itm
|
||||
++ repeat "\\"
|
||||
|
||||
itemString :: Item -> String
|
||||
itemString = head . itemDisplay
|
||||
itemString = head . basicItemDisplay
|
||||
|
||||
itemBaseName :: Item -> String
|
||||
itemBaseName it = case _iyBase $ _itType it of
|
||||
@@ -48,17 +55,6 @@ itemBaseName it = case _iyBase $ _itType it of
|
||||
EQUIP eit -> show eit
|
||||
Consumable cit -> show cit
|
||||
|
||||
selectedItemDisplay :: Creature -> Item -> [String]
|
||||
selectedItemDisplay cr it = itemDisplayWithNumber (showSelectedConsumption cr (_itUse it)) it
|
||||
|
||||
-- | Displays the item name, ammo if loaded, and any selected '_itCharMode'.
|
||||
showSelectedConsumption :: Creature -> ItemUse -> String
|
||||
showSelectedConsumption cr iu = case iu of
|
||||
HeldUse{} -> showReloadProgress cr (iu ^?! heldConsumption . laSource)
|
||||
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
|
||||
EquipUse{_equipEffect = ee} -> showEquipmentNumber ee
|
||||
_ -> show $ iu ^?! useAmount . getItAmount -- partial, be careful if adding new data constructors
|
||||
|
||||
showAutoRechargeProgress :: LeftConsumption -> String
|
||||
showAutoRechargeProgress lc = case lc of
|
||||
AutoRecharging{}
|
||||
@@ -66,43 +62,65 @@ showAutoRechargeProgress lc = case lc of
|
||||
| otherwise -> show (_arLoaded lc)
|
||||
ChargeableAmmo{} -> show (_wpCharge lc)
|
||||
|
||||
showReloadProgress :: Creature -> AmmoSource -> String
|
||||
showReloadProgress cr ic = case cr ^? crManipulation . manObject . inInventory . iselAction of
|
||||
Just (ReloadAction i la) -> show i ++ showLoadActionType la ic
|
||||
_ -> case ic of
|
||||
InternalSource ia -> case ia ^? iaProgress . _Just . ix 0 of
|
||||
Nothing -> show $ ia ^. iaLoaded
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la ic
|
||||
ExternalSource ea -> fromMaybe "X" $ do
|
||||
i <- ea ^? _Just
|
||||
itm <- cr ^? crInv . ix i
|
||||
return $ show $ itemBaseName itm
|
||||
--showReloadProgress :: Creature -> Item -> String
|
||||
--showReloadProgress cr itm = case cr ^? crManipulation . manObject . inInventory . iselAction of
|
||||
-- Just (ReloadAction i la) -> show i ++ showLoadActionType la ic
|
||||
-- _ -> case ic of
|
||||
-- InternalSource ia -> case ia ^? iaProgress . _Just . ix 0 of
|
||||
-- Nothing -> show $ ia ^. iaLoaded
|
||||
-- Just la -> show (_actionTime la) ++ showLoadActionType la ic
|
||||
-- AboveSource -> fromMaybe "XXXX" $ do
|
||||
-- i <- fmap (subtract 1) $ itm ^? itLocation . ipInvID
|
||||
-- x <- cr ^? crInv . ix i . itUse . equipEffect . eeUse . euseAmmoAmount
|
||||
-- return $ showIntKMG' x
|
||||
-- where
|
||||
-- ic = (itm ^?! itUse . heldConsumption . laSource)
|
||||
|
||||
showConsumption :: ItemUse -> String
|
||||
showConsumption iu = case iu of
|
||||
HeldUse{} -> showReloadProgress' (_heldConsumption iu)
|
||||
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
|
||||
EquipUse{_equipEffect = ee} -> showEquipmentNumber ee
|
||||
_ -> show $ iu ^?! useAmount . getItAmount
|
||||
itemNumberDisplay :: Creature -> Item -> [String]
|
||||
itemNumberDisplay cr itm = case iu of
|
||||
HeldUse{} -> [showReloadProgress' cr itm]
|
||||
LeftUse{} -> [showAutoRechargeProgress (_leftConsumption iu)]
|
||||
EquipUse{} -> showEquipmentNumber cr itm
|
||||
_ -> [show $ iu ^?! useAmount . getItAmount]
|
||||
where
|
||||
iu = itm ^?! itUse
|
||||
|
||||
showEquipmentNumber :: EquipEffect -> String
|
||||
showEquipmentNumber ee = case _eeUse ee of
|
||||
EFuelSource x _ -> show x
|
||||
EAmmoSource {_euseAmmoAmount = x} -> showIntKMG' x
|
||||
EBatterySource {_euseBatteryAmount = x} -> show x
|
||||
_ -> ""
|
||||
showEquipmentNumber :: Creature -> Item -> [String]
|
||||
showEquipmentNumber cr itm = case _eeUse ee of
|
||||
EFuelSource x _ -> [show x]
|
||||
EAmmoSource {} -> showAmmoSource cr itm
|
||||
EBatterySource {_euseBatteryAmount = x} -> [show x]
|
||||
_ -> [""]
|
||||
where
|
||||
ee = itm ^?! itUse . equipEffect
|
||||
|
||||
showReloadProgress' :: HeldConsumption -> String
|
||||
showReloadProgress' ic = case ic ^? laSource of
|
||||
showAmmoSource :: Creature -> Item -> [String]
|
||||
showAmmoSource cr itm = fromMaybe ["FAIL"] $ do
|
||||
eu <- itm ^? itUse . equipEffect . eeUse
|
||||
atype <- eu ^? euseAmmoSourceType
|
||||
x <- fmap showIntKMG' $ eu ^? euseAmmoAmount
|
||||
i <- itm ^? itLocation . ipInvID
|
||||
(do
|
||||
at' <- cr ^? crInv . ix (i + 1) . itUse . heldConsumption . laSourceType
|
||||
as <- cr ^? crInv . ix (i + 1) . itUse . heldConsumption . laSource
|
||||
guard (at' == atype && as == AboveSource)
|
||||
return ["vvvv",x] ) <|> Just [x]
|
||||
|
||||
showReloadProgress' :: Creature -> Item -> String
|
||||
showReloadProgress' cr itm = case ic ^? laSource of
|
||||
Just (InternalSource ia) -> case ia ^? iaProgress . _Just . ix 0 of
|
||||
Nothing -> fromMaybe "" $ do
|
||||
x <- ic ^? laSource . _InternalSource . iaLoaded
|
||||
return $ show x
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la (_laSource ic)
|
||||
Just (ExternalSource ea) -> fromMaybe "X" $ do
|
||||
i <- ea ^? _Just
|
||||
return $ show i
|
||||
Just AboveSource -> fromMaybe "XXXX" $ do
|
||||
i <- fmap (subtract 1) $ itm ^? itLocation . ipInvID
|
||||
_ <- cr ^? crInv . ix i . itUse . equipEffect . eeUse . euseAmmoAmount
|
||||
--return $ showIntKMG' x
|
||||
return ""
|
||||
_ -> ""
|
||||
where
|
||||
ic = itm ^?! itUse . heldConsumption
|
||||
|
||||
showLoadActionType :: LoadAction -> AmmoSource -> String
|
||||
showLoadActionType la as = case la of
|
||||
@@ -123,11 +141,6 @@ maybeWarmupStatus it = case it ^? itUse . heldDelay . warmMax of
|
||||
let n = show x
|
||||
in Just $ Prelude.take (5 - Prelude.length n) "*WARM" ++ n
|
||||
|
||||
maybeModeStatus :: Item -> Maybe String
|
||||
maybeModeStatus it = case it ^? itUse . heldScroll of
|
||||
Just HeldScrollCharMode{_hsCharMode = (c :<| _)} -> Just [' ', c]
|
||||
_ -> Nothing
|
||||
|
||||
maybeRateStatus :: Item -> Maybe String
|
||||
maybeRateStatus it = case it ^? itUse . heldDelay . rateMaxMax of
|
||||
Nothing -> Nothing
|
||||
|
||||
Reference in New Issue
Block a user