diff --git a/src/Dodge/Data/SelectionList.hs b/src/Dodge/Data/SelectionList.hs index c564daf40..21acdad4b 100644 --- a/src/Dodge/Data/SelectionList.hs +++ b/src/Dodge/Data/SelectionList.hs @@ -52,14 +52,6 @@ data SelectionSection a = SelectionSection , _ssDescriptor :: String } -data SelectionIntMap a = SelectionIntMap - { _smItems :: [SelectionItem a] - , _smSelPos :: Maybe Int - , _smRegex :: Maybe String - , _smShownItems :: IntMap (SelectionItem a) - } - --deriving (Eq, Ord, Show, Read) --Generic, Flat) - data SelectionWidth = FixedSelectionWidth Int | VariableSelectionWidth (Int -> Int) | UseMaxSelectionItemWidth @@ -94,7 +86,6 @@ data SelectionItem a = SelectionItem makeLenses ''ListDisplayParams makeLenses ''SelectionList makeLenses ''SelectionItem -makeLenses ''SelectionIntMap makeLenses ''SelectionSection makeLenses ''SelectionSections makeLenses ''SectionCursor diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index 17d42796b..bab012e9c 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -6,7 +6,6 @@ module Dodge.Render.HUD ( ) where import Dodge.Inventory -import SelectionIntMap import Dodge.Data.Combine import Dodge.Default.SelectionList import Dodge.Creature.Info diff --git a/src/Dodge/Render/List.hs b/src/Dodge/Render/List.hs index c97d157eb..5b5acc999 100644 --- a/src/Dodge/Render/List.hs +++ b/src/Dodge/Render/List.hs @@ -2,7 +2,6 @@ module Dodge.Render.List where --import Picture.Text import Dodge.Inventory -import SelectionIntMap import qualified Data.IntMap.Strict as IM --import Data.Foldable import Dodge.SelectionList @@ -29,29 +28,12 @@ drawSelectionList ldps cfig sl = (makeSelectionListPictures sl) <> drawSelectionCursor ldps cfig sl -drawSelectionMap :: ListDisplayParams -> Configuration -> SelectionIntMap a -> Picture -drawSelectionMap ldps cfig sl = - listPicturesAtScaleOff - (_ldpVerticalGap ldps) - (_ldpScale ldps) - (_ldpPosX ldps) - (_ldpPosY ldps) - cfig - 0 --(_slOffset sl) - (makeSelectionMapPictures sl) - <> drawSelectionMapCursor ldps cfig sl - makeSelectionListPictures :: SelectionList a -> [Picture] makeSelectionListPictures sl = concatMap f $ getShownItems sl where f si = map (color (_siColor si) . text) $ _siPictures si --f si = map (textGrad (_siColor si) (withAlpha 0 (_siColor si))) $ _siPictures si -makeSelectionMapPictures :: SelectionIntMap a -> [Picture] -makeSelectionMapPictures sl = foldMap f $ _smShownItems sl - where - f si = map (color (_siColor si) . text) $ _siPictures si - drawCursorAt :: ListDisplayParams -> Configuration -> Maybe Int -> [SelectionItem a] -> Picture drawCursorAt ldps cfig mi lis = fromMaybe mempty $ do i <- mi @@ -67,23 +49,6 @@ drawCursorAt ldps cfig mi lis = fromMaybe mempty $ do FixedSelectionWidth x -> x _ -> 1 -drawCursorAt' :: ListDisplayParams -> Configuration -> Int -> IM.IntMap (SelectionItem a) -> Picture -drawCursorAt' ldps cfig i lis = fromMaybe mempty $ do - selit <- lis IM.!? i - f <- case _ldpCursorType ldps of - BorderCursor cps -> Just $ listCursorChooseBorderScale (_ldpVerticalGap ldps) (_ldpScale ldps) cps - NoCursor -> Nothing - let j = getIthPos i lis - col = _siColor selit - return $ f (_ldpPosX ldps + (9 * fromIntegral (_siOffX selit))) (_ldpPosY ldps) cfig j 0 col wdth (_siHeight selit) - where - wdth = case _ldpWidth ldps of - FixedSelectionWidth x -> x - _ -> 1 - -drawSelectionMapCursor :: ListDisplayParams -> Configuration -> SelectionIntMap a -> Picture -drawSelectionMapCursor ldps cfig sl = drawCursorAt ldps cfig (sl ^. smSelPos) (IM.elems $ _smShownItems sl) - drawSelectionCursor :: ListDisplayParams -> Configuration -> SelectionList a -> Picture drawSelectionCursor ldps cfig sl = drawCursorAt ldps cfig (f $ sl ^. slSelPos) (getShownItems sl) where diff --git a/src/Dodge/SelectionSections.hs b/src/Dodge/SelectionSections.hs index 9bb536346..baf14f14b 100644 --- a/src/Dodge/SelectionSections.hs +++ b/src/Dodge/SelectionSections.hs @@ -119,3 +119,6 @@ ssLookupGE' i sss = do case IM.lookupMin (ss ^. ssItems) of Just (j', si) -> return (i', j', si) Nothing -> ssLookupGT' i' sss + +getIthPos :: Int -> IM.IntMap (SelectionItem a) -> Int +getIthPos i sm = sum . fmap _siHeight . fst $ IM.split i sm diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 0ec46ee5f..05d8c931a 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -151,12 +151,6 @@ updateUseInput u = case u ^? uvScreenLayers . _head of _ | inCloseRegex (u ^. uvWorld) -> doRegexInput 2 closeRegex closeRegex u _ -> M.foldlWithKey' updateKeyInGame u pkeys where - inregex sm = fromMaybe False $ do - i <- sm ^? smSelPos . _Just - si <- sm ^? smShownItems . ix i - case si of - SelectionRegex {} -> return True - _ -> return False pkeys = u ^. uvWorld . input . pressedKeys optionScreenUpdate :: diff --git a/src/Dodge/Update/Scroll.hs b/src/Dodge/Update/Scroll.hs index 0a7323d13..608bf7f6c 100644 --- a/src/Dodge/Update/Scroll.hs +++ b/src/Dodge/Update/Scroll.hs @@ -3,7 +3,6 @@ module Dodge.Update.Scroll ( ) where import Dodge.SelectionSections -import SelectionIntMap import qualified Data.Map.Strict as M import Data.Maybe import Dodge.Base diff --git a/src/Dodge/Update/UsingInput.hs b/src/Dodge/Update/UsingInput.hs index 34ec2e439..9ca809467 100644 --- a/src/Dodge/Update/UsingInput.hs +++ b/src/Dodge/Update/UsingInput.hs @@ -6,19 +6,17 @@ module Dodge.Update.UsingInput ( import Control.Lens import qualified Data.Map.Strict as M import Dodge.Base.You -import Dodge.Combine +--import Dodge.Combine import Dodge.Creature.Impulse.UseItem import Dodge.Data.Combine import Dodge.Data.SelectionList import Dodge.Data.World import Dodge.InputFocus -import Dodge.Inventory -import Dodge.Inventory.Add +--import Dodge.Inventory +--import Dodge.Inventory.Add import Dodge.Terminal.LeftButton import Geometry -import ListHelp import SDL -import SelectionIntMap updateUsingInput :: World -> World updateUsingInput w = case w ^. hud . hudElement of diff --git a/src/SelectionIntMap.hs b/src/SelectionIntMap.hs deleted file mode 100644 index 251c33532..000000000 --- a/src/SelectionIntMap.hs +++ /dev/null @@ -1,61 +0,0 @@ -module SelectionIntMap where - -import Data.Foldable -import Data.Maybe -import Color -import Regex -import qualified Data.IntMap.Strict as IM -import Dodge.Data.SelectionList -import LensHelp - -setShownIntMap :: SelectionIntMap a -> SelectionIntMap a -setShownIntMap sm = case sm ^. smRegex of - Nothing -> sm & smShownItems .~ IM.fromAscList (zip [0..] allitms) - Just str -> sm & smShownItems - .~ IM.fromAscList (zip [0..] (f str : filter (regexList str . _siPictures) allitms)) - where - allitms = sm ^. smItems - f str = SelectionRegex - { _siPictures = ["FILTER: " ++ str] - , _siHeight = 1 - , _siIsSelectable = True - , _siColor = white - , _siOffX = 0 - } - -initialSelPos :: SelectionIntMap a -> SelectionIntMap a -initialSelPos sm = sm & smSelPos .~ mi - where - mi = case sm ^? smShownItems . ix 0 of - Nothing -> Nothing - Just SelectionRegex {} -> case sm ^? smShownItems . ix 1 of - Nothing -> Just 0 - Just _ -> Just 1 - _ -> Just 0 - --- assumes that at least one item is selectable! --- also assumes that the integer is 1 or -1 -moveSelectionMapStep :: Int -> SelectionIntMap a -> SelectionIntMap a -moveSelectionMapStep x sm = fromMaybe sm $ do - i <- _smSelPos sm - (n,_) <- IM.lookupMax (sm ^. smShownItems) - let j = (i - x) `mod` (n + 1) - case sm ^? smShownItems . ix j . siIsSelectable of - Just True -> Just $ sm & smSelPos ?~ j - _ -> Just $ moveSelectionMapStep x (sm & smSelPos ?~ j) - -moveSelectionMapSelection :: Int -> SelectionIntMap a -> SelectionIntMap a -moveSelectionMapSelection i sm - | any _siIsSelectable (sm ^. smShownItems) = foldl' - (&) - sm - (replicate (abs i) (moveSelectionMapStep (signum i))) - | otherwise = sm & smSelPos .~ Nothing - -getIthPos :: Int -> IM.IntMap (SelectionItem a) -> Int -getIthPos i sm = sum . fmap _siHeight . fst $ IM.split i sm - -getIthYOffset :: Float -> Float -> SelectionIntMap a -> Int -> Float -getIthYOffset ygap scale sm i = (scale * 10 + ygap) * (fromIntegral yint + 1) - where - yint = getIthPos i (sm ^. smShownItems)