| summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/View')
| -rw-r--r-- | src/View/PlayerInput.elm | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/src/View/PlayerInput.elm b/src/View/PlayerInput.elm new file mode 100644 index 0000000..01d926c --- /dev/null +++ b/src/View/PlayerInput.elm @@ -0,0 +1,152 @@ +module View.PlayerInput exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import List +import Html +import Html.Attributes +import Html.Events + +-- Local Module ---------------------------------------------------------------- +import Struct.Event +import Struct.Model +import Struct.UI + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_choice_html : ( + (Int, (Html.Html Struct.Event.Type)) -> + (Html.Html Struct.Event.Type) + ) +get_choice_html data = + let (ix, html) = data in + (Html.div + [ + (Html.Attributes.class "tonkadur-choice"), + (Html.Events.onClick (Struct.Event.ChoiceSelected ix)) + ] + [html] + ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type) +get_html model = + if (List.isEmpty model.ui.displayed_choices) + then + case model.ui.input of + Struct.UI.NoInput -> (Html.div [] []) + Struct.UI.IntegerInput -> + (Html.div + [ + (Html.Attributes.class "tonkadur-input") + ] + [ + (Html.div + [ + (Html.Attributes.class "tonkadur-input-instruction") + ] + [ + (Html.text + ( + "A number between " + ++ (String.fromInt model.ui.min) + ++ " and " + ++ (String.fromInt model.ui.max) + ++ " is expected:" + ) + ) + ] + ), + (Html.input + [ + (Html.Attributes.class "tonkadur-input-field"), + (Html.Attributes.min (String.fromInt model.ui.min)), + (Html.Attributes.max (String.fromInt model.ui.max)) + ] + [ + ] + ) + ] + ) + + Struct.UI.StringInput -> + (Html.div + [ + (Html.Attributes.class "tonkadur-input") + ] + [ + (Html.div + [ + (Html.Attributes.class "tonkadur-input-instruction") + ] + [ + (Html.text + ( + "A string of size between " + ++ (String.fromInt model.ui.min) + ++ " and " + ++ (String.fromInt model.ui.max) + ++ " characters is expected:" + ) + ) + ] + ), + (Html.input + [ + (Html.Attributes.class "tonkadur-input-field"), + (Html.Attributes.minlength model.ui.min), + (Html.Attributes.maxlength model.ui.max) + ] + [ + ] + ) + ] + ) + + Struct.UI.CommandInput -> + (Html.div + [ + (Html.Attributes.class "tonkadur-input") + ] + [ + (Html.div + [ + (Html.Attributes.class "tonkadur-input-instruction") + ] + [ + (Html.text + ( + "A space-separated list of strings (total size " + ++ " between " + ++ (String.fromInt model.ui.min) + ++ " and " + ++ (String.fromInt model.ui.max) + ++ " characters) is expected:" + ) + ) + ] + ), + (Html.input + [ + (Html.Attributes.class "tonkadur-input-field"), + (Html.Attributes.minlength model.ui.min), + (Html.Attributes.maxlength model.ui.max) + ] + [ + ] + ) + ] + ) + else + (Html.div + [ + (Html.Attributes.class "tonkadur-choice-list") + ] + (List.map (get_choice_html) model.ui.displayed_choices) + ) |


