refactors rowControls

This commit is contained in:
2019-11-03 22:01:45 +01:00
parent d415a92d41
commit c79b95e1d7
2 changed files with 456 additions and 319 deletions

615
main.js
View File

@@ -6472,6 +6472,15 @@ var $elm$core$Set$Set_elm_builtin = function (a) {
return {$: 'Set_elm_builtin', a: a}; return {$: 'Set_elm_builtin', a: a};
}; };
var $elm$core$Set$empty = $elm$core$Set$Set_elm_builtin($elm$core$Dict$empty); var $elm$core$Set$empty = $elm$core$Set$Set_elm_builtin($elm$core$Dict$empty);
var $elm$core$Set$insert = F2(
function (key, _v0) {
var dict = _v0.a;
return $elm$core$Set$Set_elm_builtin(
A3($elm$core$Dict$insert, key, _Utils_Tuple0, dict));
});
var $elm$core$Set$fromList = function (list) {
return A3($elm$core$List$foldl, $elm$core$Set$insert, $elm$core$Set$empty, list);
};
var $elm$core$Debug$log = _Debug_log; var $elm$core$Debug$log = _Debug_log;
var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil); var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil);
var $author$project$Main$printError = function (error) { var $author$project$Main$printError = function (error) {
@@ -6493,12 +6502,6 @@ var $author$project$Main$setError = F2(
{error: error}) {error: error})
}); });
}); });
var $elm$core$Set$insert = F2(
function (key, _v0) {
var dict = _v0.a;
return $elm$core$Set$Set_elm_builtin(
A3($elm$core$Dict$insert, key, _Utils_Tuple0, dict));
});
var $elm$core$Dict$member = F2( var $elm$core$Dict$member = F2(
function (key, dict) { function (key, dict) {
var _v0 = A2($elm$core$Dict$get, key, dict); var _v0 = A2($elm$core$Dict$get, key, dict);
@@ -6739,8 +6742,17 @@ var $author$project$Main$update = F2(
if (nextMode.$ === 'Nothing') { if (nextMode.$ === 'Nothing') {
return $elm$core$Maybe$Nothing; return $elm$core$Maybe$Nothing;
} else { } else {
if (nextMode.a.$ === 'Grab') {
var _v12 = nextMode.a;
return $elm$core$Maybe$Just(
$elm$core$Set$fromList(
_List_fromArray(
[34, 38])));
} else {
var others = nextMode.a;
return $elm$core$Maybe$Just($elm$core$Set$empty); return $elm$core$Maybe$Just($elm$core$Set$empty);
} }
}
}() }()
}) })
}), }),
@@ -6780,14 +6792,17 @@ var $elm$html$Html$Events$onClick = function (msg) {
'click', 'click',
$elm$json$Json$Decode$succeed(msg)); $elm$json$Json$Decode$succeed(msg));
}; };
var $elm$html$Html$p = _VirtualDom_node('p');
var $elm$html$Html$span = _VirtualDom_node('span'); var $elm$html$Html$span = _VirtualDom_node('span');
var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text;
var $elm$html$Html$text = $elm$virtual_dom$VirtualDom$text;
var $author$project$Main$actionButton = F4( var $author$project$Main$actionButton = F4(
function (mode, t, icon, color) { function (mode, t, icon, color) {
return A2( return A2(
$elm$html$Html$button, $elm$html$Html$button,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$Attributes$class('button is-rounded is-' + color), $elm$html$Html$Attributes$class('button is-' + color),
$elm$html$Html$Events$onClick( $elm$html$Html$Events$onClick(
$author$project$Main$ModeSwitched(mode)) $author$project$Main$ModeSwitched(mode))
]), ]),
@@ -6808,16 +6823,296 @@ var $author$project$Main$actionButton = F4(
$elm$svg$Svg$Attributes$class('fas fa-' + icon) $elm$svg$Svg$Attributes$class('fas fa-' + icon)
]), ]),
_List_Nil) _List_Nil)
])),
A2(
$elm$html$Html$p,
_List_Nil,
_List_fromArray(
[
$elm$html$Html$text(t)
])) ]))
])); ]));
}); });
var $elm$html$Html$article = _VirtualDom_node('article'); var $elm$html$Html$article = _VirtualDom_node('article');
var $elm$html$Html$div = _VirtualDom_node('div'); var $elm$html$Html$div = _VirtualDom_node('div');
var $elm$html$Html$hr = _VirtualDom_node('hr'); var $elm$html$Html$hr = _VirtualDom_node('hr');
var $elm$html$Html$p = _VirtualDom_node('p');
var $elm$html$Html$section = _VirtualDom_node('section'); var $elm$html$Html$section = _VirtualDom_node('section');
var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text; var $author$project$Main$isSelected = F2(
var $elm$html$Html$text = $elm$virtual_dom$VirtualDom$text; function (selection, item) {
if (selection.$ === 'Just') {
var s = selection.a;
return A2($elm$core$Set$member, item.id, s);
} else {
return false;
}
});
var $author$project$Main$renderName = function (item) {
return A2(
$elm$html$Html$p,
_List_Nil,
_List_fromArray(
[
$elm$html$Html$text(item.name)
]));
};
var $author$project$Main$LootViewItemSwitched = function (a) {
return {$: 'LootViewItemSwitched', a: a};
};
var $elm$core$String$fromFloat = _String_fromNumber;
var $elm$html$Html$input = _VirtualDom_node('input');
var $elm$json$Json$Decode$at = F2(
function (fields, decoder) {
return A3($elm$core$List$foldr, $elm$json$Json$Decode$field, decoder, fields);
});
var $elm$json$Json$Decode$bool = _Json_decodeBool;
var $elm$html$Html$Events$targetChecked = A2(
$elm$json$Json$Decode$at,
_List_fromArray(
['target', 'checked']),
$elm$json$Json$Decode$bool);
var $elm$html$Html$Events$onCheck = function (tagger) {
return A2(
$elm$html$Html$Events$on,
'change',
A2($elm$json$Json$Decode$map, tagger, $elm$html$Html$Events$targetChecked));
};
var $elm$html$Html$Attributes$type_ = $elm$html$Html$Attributes$stringProperty('type');
var $author$project$Main$rowModeControlsRenderer = F2(
function (mode, item) {
var _v0 = function () {
switch (mode.$) {
case 'Buy':
return _Utils_Tuple2(
A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text(
$elm$core$String$fromInt(item.base_price) + 'po')
])),
true);
case 'Sell':
return _Utils_Tuple2(
A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text(
$elm$core$String$fromFloat(item.base_price / 2) + 'po')
])),
true);
case 'Grab':
return _Utils_Tuple2(
A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text('Grab')
])),
true);
case 'Add':
return _Utils_Tuple2(
A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text('New !')
])),
false);
default:
return _Utils_Tuple2(
$elm$html$Html$text(''),
false);
}
}();
var itemInfo = _v0.a;
var canSelect = _v0.b;
return A2(
$elm$html$Html$div,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-right')
]),
A2(
$elm$core$List$cons,
itemInfo,
canSelect ? _List_fromArray(
[
A2(
$elm$html$Html$input,
_List_fromArray(
[
$elm$html$Html$Attributes$class('checkbox level-item'),
$elm$html$Html$Attributes$type_('checkbox'),
$elm$html$Html$Events$onCheck(
function (v) {
return $author$project$Main$LootViewItemSwitched(item.id);
})
]),
_List_Nil)
]) : _List_Nil));
});
var $elm$html$Html$table = _VirtualDom_node('table');
var $elm$html$Html$th = _VirtualDom_node('th');
var $elm$html$Html$thead = _VirtualDom_node('thead');
var $elm$core$List$filter = F2(
function (isGood, list) {
return A3(
$elm$core$List$foldr,
F2(
function (x, xs) {
return isGood(x) ? A2($elm$core$List$cons, x, xs) : xs;
}),
_List_Nil,
list);
});
var $elm$core$Tuple$second = function (_v0) {
var y = _v0.b;
return y;
};
var $elm$html$Html$Attributes$classList = function (classes) {
return $elm$html$Html$Attributes$class(
A2(
$elm$core$String$join,
' ',
A2(
$elm$core$List$map,
$elm$core$Tuple$first,
A2($elm$core$List$filter, $elm$core$Tuple$second, classes))));
};
var $elm$html$Html$label = _VirtualDom_node('label');
var $elm$core$List$singleton = function (value) {
return _List_fromArray(
[value]);
};
var $elm$html$Html$td = _VirtualDom_node('td');
var $elm$html$Html$tr = _VirtualDom_node('tr');
var $author$project$Main$viewItemTableRow = F3(
function (selected, rowControls, item) {
return A2(
$elm$html$Html$tr,
_List_fromArray(
[
$elm$html$Html$Attributes$classList(
_List_fromArray(
[
_Utils_Tuple2(
'is-selected',
selected(item))
]))
]),
_List_fromArray(
[
A2(
$elm$html$Html$td,
_List_Nil,
_List_fromArray(
[
A2(
$elm$html$Html$label,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level checkbox')
]),
A2(
$elm$core$List$cons,
A2(
$elm$html$Html$div,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-left')
]),
_List_fromArray(
[
A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text(item.name)
]))
])),
function () {
if (rowControls.$ === 'Just') {
var render = rowControls.a;
return $elm$core$List$singleton(
render(item));
} else {
return _List_Nil;
}
}()))
]))
]));
});
var $author$project$Main$viewChest = F2(
function (items, model) {
var rowControls = function () {
var _v0 = model.state.activeMode;
if (_v0.$ === 'Just') {
var mode = _v0.a;
return $elm$core$Maybe$Just(
$author$project$Main$rowModeControlsRenderer(mode));
} else {
var _v1 = model.state.route;
if (_v1.$ === 'GroupLoot') {
return $elm$core$Maybe$Just($author$project$Main$renderName);
} else {
var others = _v1;
return $elm$core$Maybe$Nothing;
}
}
}();
return A2(
$elm$html$Html$table,
_List_fromArray(
[
$elm$html$Html$Attributes$class('table is-fullwidth is-striped is-light')
]),
A2(
$elm$core$List$cons,
A2(
$elm$html$Html$thead,
_List_fromArray(
[
$elm$html$Html$Attributes$class('table-header')
]),
_List_fromArray(
[
A2(
$elm$html$Html$th,
_List_Nil,
_List_fromArray(
[
$elm$html$Html$text('Nom')
]))
])),
A2(
$elm$core$List$map,
A2(
$author$project$Main$viewItemTableRow,
$author$project$Main$isSelected(model.state.selection),
rowControls),
items)));
});
var $author$project$Main$stackedIcon = function (name) { var $author$project$Main$stackedIcon = function (name) {
return A2( return A2(
$elm$html$Html$span, $elm$html$Html$span,
@@ -6996,6 +7291,25 @@ var $elm$html$Html$Attributes$href = function (url) {
_VirtualDom_noJavaScriptUri(url)); _VirtualDom_noJavaScriptUri(url));
}; };
var $elm$html$Html$nav = _VirtualDom_node('nav'); var $elm$html$Html$nav = _VirtualDom_node('nav');
var $author$project$Main$renderIcon = F2(
function (name, size) {
return A2(
$elm$html$Html$span,
_List_fromArray(
[
$elm$html$Html$Attributes$class('icon is-medium')
]),
_List_fromArray(
[
A2(
$elm$html$Html$i,
_List_fromArray(
[
$elm$html$Html$Attributes$class(name + (' fa-' + size))
]),
_List_Nil)
]));
});
var $author$project$Main$viewHeaderBar = function (model) { var $author$project$Main$viewHeaderBar = function (model) {
return A2( return A2(
$elm$html$Html$nav, $elm$html$Html$nav,
@@ -7021,9 +7335,16 @@ var $author$project$Main$viewHeaderBar = function (model) {
$elm$html$Html$Attributes$class('navbar-item'), $elm$html$Html$Attributes$class('navbar-item'),
$elm$html$Html$Attributes$href('/') $elm$html$Html$Attributes$href('/')
]), ]),
_List_fromArray(
[
A2($author$project$Main$renderIcon, 'fab fa-d-and-d', '2x'),
A2(
$elm$html$Html$span,
_List_Nil,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$text(model.player.name) $elm$html$Html$text(model.player.name)
]))
])), ])),
A2( A2(
$elm$html$Html$a, $elm$html$Html$a,
@@ -7079,9 +7400,16 @@ var $author$project$Main$viewHeaderBar = function (model) {
$elm$html$Html$Attributes$class('navbar-item'), $elm$html$Html$Attributes$class('navbar-item'),
$elm$html$Html$Attributes$href('/marchand') $elm$html$Html$Attributes$href('/marchand')
]), ]),
_List_fromArray(
[
A2($author$project$Main$renderIcon, 'fas fa-store-alt', '1x'),
A2(
$elm$html$Html$span,
_List_Nil,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$text('Marchand') $elm$html$Html$text('Marchand')
]))
])), ])),
A2( A2(
$elm$html$Html$a, $elm$html$Html$a,
@@ -7091,6 +7419,12 @@ var $author$project$Main$viewHeaderBar = function (model) {
$elm$html$Html$Attributes$href( $elm$html$Html$Attributes$href(
(!model.player.id) ? '/nouveau-tresor' : '/coffre') (!model.player.id) ? '/nouveau-tresor' : '/coffre')
]), ]),
_List_fromArray(
[
A2($author$project$Main$renderIcon, 'fas fa-gem', '1x'),
A2(
$elm$html$Html$span,
_List_Nil,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$text( $elm$html$Html$text(
@@ -7098,248 +7432,9 @@ var $author$project$Main$viewHeaderBar = function (model) {
])) ]))
])) ]))
])) ]))
]));
};
var $elm$html$Html$table = _VirtualDom_node('table');
var $elm$html$Html$th = _VirtualDom_node('th');
var $elm$html$Html$thead = _VirtualDom_node('thead');
var $author$project$Main$LootViewItemSwitched = function (a) {
return {$: 'LootViewItemSwitched', a: a};
};
var $elm$core$List$filter = F2(
function (isGood, list) {
return A3(
$elm$core$List$foldr,
F2(
function (x, xs) {
return isGood(x) ? A2($elm$core$List$cons, x, xs) : xs;
}),
_List_Nil,
list);
});
var $elm$core$Tuple$second = function (_v0) {
var y = _v0.b;
return y;
};
var $elm$html$Html$Attributes$classList = function (classes) {
return $elm$html$Html$Attributes$class(
A2(
$elm$core$String$join,
' ',
A2(
$elm$core$List$map,
$elm$core$Tuple$first,
A2($elm$core$List$filter, $elm$core$Tuple$second, classes))));
};
var $elm$core$String$fromFloat = _String_fromNumber;
var $author$project$Main$controlsRenderer = F2(
function (mode, item) {
switch (mode.$) {
case 'Buy':
return A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text(
$elm$core$String$fromInt(item.base_price) + 'po')
]));
case 'Sell':
return A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text(
$elm$core$String$fromFloat(item.base_price / 2) + 'po')
]));
case 'Grab':
return A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text('Grab')
]));
case 'Add':
return A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text('New !')
]));
default:
return $elm$html$Html$text('');
}
});
var $elm$html$Html$input = _VirtualDom_node('input');
var $author$project$Main$isSelected = F2(
function (id, selection) {
return A2($elm$core$Set$member, id, selection);
});
var $elm$html$Html$label = _VirtualDom_node('label');
var $elm$json$Json$Decode$at = F2(
function (fields, decoder) {
return A3($elm$core$List$foldr, $elm$json$Json$Decode$field, decoder, fields);
});
var $elm$json$Json$Decode$bool = _Json_decodeBool;
var $elm$html$Html$Events$targetChecked = A2(
$elm$json$Json$Decode$at,
_List_fromArray(
['target', 'checked']),
$elm$json$Json$Decode$bool);
var $elm$html$Html$Events$onCheck = function (tagger) {
return A2(
$elm$html$Html$Events$on,
'change',
A2($elm$json$Json$Decode$map, tagger, $elm$html$Html$Events$targetChecked));
};
var $elm$core$List$singleton = function (value) {
return _List_fromArray(
[value]);
};
var $elm$html$Html$td = _VirtualDom_node('td');
var $elm$html$Html$tr = _VirtualDom_node('tr');
var $elm$html$Html$Attributes$type_ = $elm$html$Html$Attributes$stringProperty('type');
var $author$project$Main$viewItemTableRow = F3(
function (selection, activeMode, item) {
var selected = function () {
if (selection.$ === 'Just') {
var s = selection.a;
return A2($author$project$Main$isSelected, item.id, s);
} else {
return false;
}
}();
var levelRight = function () {
if (activeMode.$ === 'Nothing') {
return _List_Nil;
} else {
var mode = activeMode.a;
return $elm$core$List$singleton(
A2(
$elm$html$Html$div,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-right')
]),
_List_fromArray(
[
A2($author$project$Main$controlsRenderer, mode, item),
A2(
$elm$html$Html$input,
_List_fromArray(
[
$elm$html$Html$Attributes$class('checkbox level-item'),
$elm$html$Html$Attributes$type_('checkbox'),
$elm$html$Html$Events$onCheck(
function (v) {
return $author$project$Main$LootViewItemSwitched(item.id);
})
]),
_List_Nil)
])));
}
}();
return A2(
$elm$html$Html$tr,
_List_fromArray(
[
$elm$html$Html$Attributes$classList(
_List_fromArray(
[
_Utils_Tuple2('is-selected', selected)
]))
]),
_List_fromArray(
[
A2(
$elm$html$Html$td,
_List_Nil,
_List_fromArray(
[
A2(
$elm$html$Html$label,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level checkbox')
]),
$elm$core$List$concat(
_List_fromArray(
[
_List_fromArray(
[
A2(
$elm$html$Html$div,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-left')
]),
_List_fromArray(
[
A2(
$elm$html$Html$p,
_List_fromArray(
[
$elm$html$Html$Attributes$class('level-item')
]),
_List_fromArray(
[
$elm$html$Html$text(item.name)
]))
]))
]),
levelRight
])))
])) ]))
])); ]));
}); };
var $author$project$Main$viewLoot = F3(
function (items, selection, activeMode) {
return A2(
$elm$html$Html$table,
_List_fromArray(
[
$elm$html$Html$Attributes$class('table is-fullwidth is-striped is-light')
]),
_Utils_ap(
_List_fromArray(
[
A2(
$elm$html$Html$thead,
_List_fromArray(
[
$elm$html$Html$Attributes$class('table-header')
]),
_List_fromArray(
[
A2(
$elm$html$Html$th,
_List_Nil,
_List_fromArray(
[
$elm$html$Html$text('Nom')
]))
]))
]),
A2(
$elm$core$List$map,
A2($author$project$Main$viewItemTableRow, selection, activeMode),
items)));
});
var $author$project$Main$showWealthField = F2( var $author$project$Main$showWealthField = F2(
function (name, value) { function (name, value) {
return A2( return A2(
@@ -7488,7 +7583,7 @@ var $author$project$Main$view = function (model) {
$elm$html$Html$div, $elm$html$Html$div,
_List_fromArray( _List_fromArray(
[ [
$elm$html$Html$Attributes$class('buttons') $elm$html$Html$Attributes$class('buttons has-addons')
]), ]),
_List_fromArray( _List_fromArray(
[ [
@@ -7498,7 +7593,7 @@ var $author$project$Main$view = function (model) {
'Valider', 'Valider',
'plus', 'plus',
'primary'), 'primary'),
A4($author$project$Main$actionButton, $elm$core$Maybe$Nothing, 'Annuler', 'coins', 'danger') A4($author$project$Main$actionButton, $elm$core$Maybe$Nothing, 'Annuler', 'times', 'danger')
])) ]))
]); ]);
} else { } else {
@@ -7510,7 +7605,7 @@ var $author$project$Main$view = function (model) {
A4( A4(
$author$project$Main$actionButton, $author$project$Main$actionButton,
$elm$core$Maybe$Just($author$project$Main$Sell), $elm$core$Maybe$Just($author$project$Main$Sell),
'', 'Vendre',
'coins', 'coins',
'danger') 'danger')
]); ]);
@@ -7530,12 +7625,20 @@ var $author$project$Main$view = function (model) {
A4( A4(
$author$project$Main$actionButton, $author$project$Main$actionButton,
$elm$core$Maybe$Just($author$project$Main$Buy), $elm$core$Maybe$Just($author$project$Main$Buy),
'', 'Acheter',
'coins', 'coins',
'success') 'success')
]); ]);
default: default:
return _List_Nil; return _List_fromArray(
[
A4(
$author$project$Main$actionButton,
$elm$core$Maybe$Just($author$project$Main$Add),
'Nouveau loot',
'plus',
'primary')
]);
} }
} }
}(); }();
@@ -7584,7 +7687,7 @@ var $author$project$Main$view = function (model) {
$elm$html$Html$text(header) $elm$html$Html$text(header)
])), ])),
$author$project$Main$viewSearchBar, $author$project$Main$viewSearchBar,
A3($author$project$Main$viewLoot, shownLoot, model.state.selection, model.state.activeMode) A2($author$project$Main$viewChest, shownLoot, model)
])), ])),
A2($elm$html$Html$hr, _List_Nil, _List_Nil), A2($elm$html$Html$hr, _List_Nil, _List_Nil),
A2( A2(

View File

@@ -252,7 +252,8 @@ update msg model =
{ state | activeMode = nextMode { state | activeMode = nextMode
, selection = case nextMode of , selection = case nextMode of
Nothing -> Nothing Nothing -> Nothing
Just _ -> Just Set.empty Just Grab -> Just (Set.fromList [34, 38])
Just others -> Just Set.empty
}} }}
, cmd) , cmd)
@@ -303,9 +304,10 @@ type ViewMode
| Confirm -- Confirm action and exit mode | Confirm -- Confirm action and exit mode
actionButton mode t icon color = actionButton mode t icon color =
button [ class <| "button is-rounded is-" ++ color button [ class <| "button is-" ++ color
, onClick (ModeSwitched mode) ] , onClick (ModeSwitched mode) ]
[ span [ class "icon" ] [ i [ Svg.Attributes.class <| "fas fa-" ++ icon ] [] ] [ span [ class "icon" ] [ i [ Svg.Attributes.class <| "fas fa-" ++ icon ] [] ]
, p [] [text t]
] ]
view : Model -> Browser.Document Msg view : Model -> Browser.Document Msg
@@ -324,16 +326,17 @@ view model =
actionControls = actionControls =
case model.state.activeMode of case model.state.activeMode of
Just mode -> -- When a mode is active Just mode -> -- When a mode is active
[ div [class "buttons"] [ div [ class "buttons has-addons"]
[ actionButton (Just Confirm) "Valider" "plus" "primary" [ actionButton (Just Confirm) "Valider" "plus" "primary"
, actionButton Nothing "Annuler" "coins" "danger"] , actionButton Nothing "Annuler" "times" "danger"
]
] ]
Nothing -> -- Buttons to enter mode Nothing -> -- Buttons to enter mode
case model.state.route of case model.state.route of
PlayerChest -> [actionButton (Just Sell) "" "coins" "danger"] PlayerChest -> [actionButton (Just Sell) "Vendre" "coins" "danger"]
GroupLoot -> [actionButton (Just Grab) "Demander" "coins" "primary"] GroupLoot -> [actionButton (Just Grab) "Demander" "coins" "primary"]
Merchant -> [actionButton (Just Buy) "" "coins" "success"] Merchant -> [actionButton (Just Buy) "Acheter" "coins" "success"]
NewLoot -> [] NewLoot -> [actionButton (Just Add) "Nouveau loot" "plus" "primary"]
in in
{ title = "Loot-a-lot in ELM" { title = "Loot-a-lot in ELM"
@@ -343,7 +346,7 @@ view model =
, article [class "section container"] , article [class "section container"]
[ p [class "heading"] [text header] [ p [class "heading"] [text header]
, viewSearchBar , viewSearchBar
, viewLoot shownLoot model.state.selection model.state.activeMode , viewChest shownLoot model
] ]
, hr [] [] , hr [] []
, section [class "container"] [viewDebugSection model] , section [class "container"] [viewDebugSection model]
@@ -352,58 +355,76 @@ view model =
-- LOOT Views -- LOOT Views
isSelected id selection = isSelected : Maybe Selection -> Item -> Bool
Set.member id selection isSelected selection item =
viewLoot : Loot -> Maybe Selection -> Maybe ViewMode -> Html Msg
viewLoot items selection activeMode =
table [ class "table is-fullwidth is-striped is-light"]
([ thead [class "table-header"]
[ th [] [text "Nom"] ]
]
++ List.map (viewItemTableRow selection activeMode) items
)
controlsRenderer : ViewMode -> Item -> Html Msg
controlsRenderer mode item =
case mode of
Buy -> p [class "level-item"] [ text (String.fromInt item.base_price ++ "po")]
Sell -> p [class "level-item"] [ text (String.fromFloat (toFloat item.base_price / 2) ++ "po")]
Grab -> p [class "level-item"] [ text "Grab" ]
Add -> p [class "level-item"] [ text "New !" ]
Confirm -> text ""
viewItemTableRow : Maybe Selection -> Maybe ViewMode -> Item -> Html Msg
viewItemTableRow selection activeMode item =
let
selected =
case selection of case selection of
Just s -> Just s ->
isSelected item.id s Set.member item.id s
Nothing -> Nothing ->
False False
levelRight = renderName item =
case activeMode of p [] [text item.name]
Nothing -> []
Just mode -> List.singleton ( viewChest : Loot -> Model -> Html Msg
viewChest items model =
let
-- If a mode is active, render its controls
-- Otherwise, controls may be rendered depending on current route
rowControls = case model.state.activeMode of
Just mode -> Just (rowModeControlsRenderer mode)
Nothing ->
case model.state.route of
GroupLoot -> Just renderName
others -> Nothing
in
table [ class "table is-fullwidth is-striped is-light"]
<| thead [ class "table-header" ]
[ th [] [ text "Nom" ] ]
:: List.map (viewItemTableRow (isSelected model.state.selection) rowControls) items
-- Renders controls for a specific mode
rowModeControlsRenderer : ViewMode -> Item -> Html Msg
rowModeControlsRenderer mode item =
let
(itemInfo, canSelect) = case mode of
Buy ->
( p [class "level-item"] [ text (String.fromInt item.base_price ++ "po")]
, True )
Sell ->
( p [class "level-item"] [ text (String.fromFloat (toFloat item.base_price / 2) ++ "po")]
, True )
Grab ->
( p [class "level-item"] [ text "Grab" ]
, True )
Add ->
( p [class "level-item"] [ text "New !" ]
, False )
Confirm ->
(text ""
, False )
in
div [ class "level-right" ] div [ class "level-right" ]
[ controlsRenderer mode item <| itemInfo
, input [ class "checkbox level-item" :: if canSelect then
[input [ class "checkbox level-item"
, type_ "checkbox" , type_ "checkbox"
, onCheck (\v -> LootViewItemSwitched item.id) , onCheck (\v -> LootViewItemSwitched item.id)
] [] ] [] ]
]) else
in []
tr [ classList [ ("is-selected", selected) ] ]
viewItemTableRow : (Item -> Bool) -> Maybe (Item -> Html Msg) -> Item -> Html Msg
viewItemTableRow selected rowControls item =
tr [ classList [ ("is-selected", selected item) ] ]
[ td [] [ td []
[ label [ class "level checkbox" ] [ label [ class "level checkbox" ]
(List.concat [[ <| div [ class "level-left" ]
div [ class "level-left" ]
[ p [class "level-item"] [ text item.name ]] [ p [class "level-item"] [ text item.name ]]
] :: case rowControls of
, levelRight Just render -> List.singleton (render item)
]) Nothing -> []
] ]
] ]
@@ -452,6 +473,12 @@ debugSwitchPlayers =
, a [ onClick (PlayerChanged 2) ] [text "Fefi"] , a [ onClick (PlayerChanged 2) ] [text "Fefi"]
] ]
renderIcon name size =
span [ class <| "icon is-medium"]
[ i [ class <| name ++ " fa-" ++ size] [] ]
-- HEADER SECTION -- HEADER SECTION
viewHeaderBar : Model -> Html Msg viewHeaderBar : Model -> Html Msg
@@ -459,7 +486,9 @@ viewHeaderBar model =
nav [ class "navbar container", class "is-info" ] nav [ class "navbar container", class "is-info" ]
[ div [ class "navbar-brand" ] [ div [ class "navbar-brand" ]
[ a [ class "navbar-item", href "/"] [ a [ class "navbar-item", href "/"]
[ text model.player.name ] [ renderIcon "fab fa-d-and-d" "2x"
, span [] [ text model.player.name ]
]
, a [class "navbar-burger is-active"] , a [class "navbar-burger is-active"]
[ span [attribute "aria-hidden" "true"] [] [ span [attribute "aria-hidden" "true"] []
, span [attribute "aria-hidden" "true"] [] , span [attribute "aria-hidden" "true"] []
@@ -468,7 +497,10 @@ viewHeaderBar model =
] ]
, div [ class "navbar-menu is-active" ] , div [ class "navbar-menu is-active" ]
[ div [class "navbar-end"] [ div [class "navbar-end"]
[ a [class "navbar-item", href "/marchand"] [text "Marchand"] [ a [class "navbar-item", href "/marchand"]
[ renderIcon "fas fa-store-alt" "1x"
, span [] [text "Marchand"]
]
, a , a
[ class "navbar-item" [ class "navbar-item"
, href (if model.player.id == 0 , href (if model.player.id == 0
@@ -477,7 +509,9 @@ viewHeaderBar model =
else else
"/coffre") "/coffre")
] ]
[text (if model.player.id == 0 then "Nouveau loot" else "Coffre de groupe")] [ renderIcon "fas fa-gem" "1x"
, span [] [text (if model.player.id == 0 then "Nouveau loot" else "Coffre de groupe")]
]
] ]
] ]