module EventFlags (eventMState) where import Graphics.Rendering.OpenGL import Graphics.UI.GLUT import States import VectorMaps import ResionMap import Control.Applicative import qualified Data.Map as Map import General ------クリックに対してボタンフラグを認めるかの判定 buttonClickFlag :: MState -> DState -> KState -> ButtonName -> Bool buttonClickFlag mst dst kst eBN = let rButton = (Map.lookup eBN (eButtons dst)) in case rButton of Nothing -> False Just x -> if (buttonClickConti x kst) then buttonClick x kst else False -------クリックによるボタンイベント buttonClickEvent :: ButtonName -> MState -> DState -> KState -> MState buttonClickEvent eBN mst dst kst = let sGMode = switchGameMode mst newGMode = switchGMode sGMode (gameMode mst) (ButtonEvent eBN) in mStateChangeGMode mst newGMode -----インプットイベントの実行 inputEventp :: DState -> KState -> MState -> MState inputEventp dst kst mst = let ies = getInputEvent mst dst kst in iesChangeMState ies mst dst kst -------イベんとの実行 eventMState :: DState -> KState -> MState -> MState eventMState dst kst mst = inputEventp dst kst mst -------インプットイベントによるMStateの変更 inputEventChangeMState :: InputEvent -> MState -> MState inputEventChangeMState ie mst = let sGMode = switchGameMode mst newGMode = switchGMode sGMode (gameMode mst) ie in mStateChangeGMode mst newGMode ------イベントの実行(再帰) iesChangeMState :: [InputEvent] -> MState -> DState -> KState -> MState iesChangeMState [] mst dst kst = mst iesChangeMState (ie:ies) mst dst kst = inputEventChangeMState ie (iesChangeMState ies mst dst kst ) ------インプットイベントリストを作る getInputEvent :: MState -> DState -> KState -> [InputEvent] getInputEvent mst dst kst = case (downKey kst) of Nothing -> [] Just k -> case k of Char y -> [KeyPushEvent k] MouseButton y -> case (clickPos kst) of Nothing -> [] Just x -> map ButtonEvent (getClilckActiveButtons mst dst kst) ------クリックした位置にある有効なボタンのリストの取得 getClilckActiveButtons :: MState -> DState -> KState -> [ButtonName] getClilckActiveButtons mst dst kst = let cPos = (clickPos kst) gMode = gameMode mst sGMode = switchGameMode mst sGModeKey = Map.keys sGMode sGInputEventPair = filter ((== gMode) . fst) sGModeKey sGInputEvent = map snd sGInputEventPair sGButtonName = map ((\(Just x) -> x) . buttonEventBName) (filter dInputEventButton sGInputEvent) in case cPos of Nothing -> [] Just x -> filter (buttonClickFlag mst dst kst) sGButtonName ------ボタンをクリックしたかの判定 buttonClick :: EButton -> KState -> Bool buttonClick eB kst = let bContainer = buttonContainer eB cPos = (clickPos kst) in case cPos of Nothing -> False Just cPos' -> dContainerResionPoint' bContainer cPos' -------ボタン連続入力の可否 buttonClickConti :: EButton -> KState -> Bool buttonClickConti eB kst = if (buttonConti eB) then True else case (kStateCompareKeys kst) of Nothing -> False Just b -> b