Skip to content

Commit

Permalink
Better biome picker
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Nov 30, 2023
1 parent 025e9e9 commit feaf0db
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 80 deletions.
2 changes: 1 addition & 1 deletion app/assets/css/app.min.css

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion app/assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,8 @@ ul.log {
.icon.autoLayer { background-image: url("../icons/autoLayer.png") }
.icon.bug { background-image: url("../icons/bug.svg"); }
.icon.checker { background-image: url("../icons/checker.svg"); }
.icon.checkboxOn { background-image: url("../icons/checkboxOn.svg"); }
.icon.checkboxOff { background-image: url("../icons/checkboxOff.svg"); }
.icon.clear { background-image: url("../icons/clear.svg"); }
.icon.close { background-image: url("../icons/close.png"); }
.icon.color { background-image: url("../icons/color.svg"); }
Expand Down Expand Up @@ -3740,7 +3742,13 @@ textarea {
.icon.selectionTick {
width: 24px;
height: 24px;
margin-left: 3px;
margin-right: 4px;
&.checkboxOn {
filter: brightness(1) sepia(1) hue-rotate(0.15rad) saturate(10);
}
&.checkboxOff {
opacity: 0.35;
}
}
&.selected {
background-color: $bgMed;
Expand Down
1 change: 1 addition & 0 deletions app/assets/icons/checkboxOff.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/icons/checkboxOn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 14 additions & 46 deletions src/electron.renderer/ui/modal/ContextMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ typedef ContextAction = {
var ?separatorAfter: Bool;
var ?subMenu: Void->ContextActions;
var ?selectionTick : Bool;
var ?keepOpen : Bool;
}

enum ContextMenuElement {
CM_Action(a:ContextAction);
CM_Title(str:LocaleString);
}

class ContextMenu extends ui.Modal {
public static var ALL : Array<ContextMenu> = [];
var jAttachTarget : js.jquery.JQuery; // could be empty
var elements : Array<ContextMenuElement> = [];

public function new(?m:Coords, ?jNear:js.jquery.JQuery, ?openEvent:js.jquery.Event, isSubMenu=false) {
super();
Expand Down Expand Up @@ -124,27 +117,19 @@ class ContextMenu extends ui.Modal {
}


function reAttach() {
jContent.empty();
var elems = elements.copy();
elements = [];
for(e in elems)
switch e {
case CM_Action(a): add(a);
case CM_Title(str): addTitle(str);
}
}


public function addTitle(str:LocaleString) {
elements.push( CM_Title(str) );
var jTitle = new J('<div class="title">$str</div>');
jTitle.appendTo(jContent);
applyAnchor();
}

function createButton(a:ContextAction) {

public function add(a:ContextAction) {
if( a.show!=null && !a.show() )
return new js.jquery.JQuery();

var jButton = new J('<button class="transparent"/>');
jButton.appendTo(jContent);

if( a.jHtmlImg!=null ) {
jButton.prepend(a.label);
Expand Down Expand Up @@ -173,46 +158,29 @@ class ContextMenu extends ui.Modal {
if( a.selectionTick!=null ) {
if( a.selectionTick ) {
jButton.addClass("selected");
jButton.append('<span class="icon selectionTick active"></span>');
jButton.prepend('<span class="icon selectionTick checkboxOn"></span>');
}
else
jButton.append('<span class="icon selectionTick inactive"></span>');
jButton.prepend('<span class="icon selectionTick checkboxOff"></span>');
}

// Button action
jButton.click( (_)->{
if( a.cb!=null )
a.cb();

if( a.subMenu==null ) {
if( a.keepOpen==true )
reAttach();
else
closeAll();
}

if( a.subMenu!=null ) {
if( a.subMenu==null )
closeAll();
else {
addClass("subMenuOpen");
var c = new ContextMenu(jButton, true);
c.onCloseCb = ()->removeClass("subMenuOpen");

for(subAction in a.subMenu())
c.add(subAction);
}
});

return jButton;
}

if( a.cb!=null )
a.cb();
});

public function add(a:ContextAction) {
if( a.show!=null && !a.show() )
return new js.jquery.JQuery();

elements.push( CM_Action(a) );

var jButton = createButton(a);
jButton.appendTo(jContent);
applyAnchor();
return jButton;
}
Expand Down
69 changes: 37 additions & 32 deletions src/electron.renderer/ui/modal/panel/EditAllAutoLayerRules.hx
Original file line number Diff line number Diff line change
Expand Up @@ -513,64 +513,68 @@ class EditAllAutoLayerRules extends ui.modal.Panel {
}


function createBiomePickerCtxActions(rg:AutoLayerRuleGroup) {
// Biome sub menu
var enumDef : data.def.EnumDef = null;
if( ld.biomeFieldUid!=null ) {
var fd = project.defs.getFieldDef(ld.biomeFieldUid);
if( fd!=null && fd.isEnum() && fd.getEnumDefinition().values.length>0 )
enumDef = fd.getEnumDefinition();
}

var subMenu : ui.modal.ContextMenu.ContextActions = [
{
function openBiomePicker(rg:AutoLayerRuleGroup) {
var enumDef = ld.getBiomeEnumDef();
var actions : ui.modal.ContextMenu.ContextActions = [];

// Error messages
if( enumDef==null )
actions.push({
label: L.untranslated("Missing biome enum"),
subText: L.untranslated("Click to select your level biome enum"),
cb: editor.executeAppCommand.bind(C_OpenLayerPanel),
show: ()->enumDef==null,
},
{
label: L.untranslated("Enum has no value"),
subText: L.untranslated("The selected biome Enum has no value."),
show: ()->enumDef!=null && enumDef.values.length==0,
});
else if( enumDef.values.length==0 )
actions.push({
label: L.untranslated("Enum "+enumDef.identifier+" has no value"),
enable: ()->false
},
];
});

// Biome enum values
if( enumDef!=null ) {
subMenu.push({
actions.push({
label: L.untranslated("Any biome"),
cb: ()->{
rg.requiredBiomeValues = [];
invalidateRuleGroup(rg);
editor.ge.emit( LayerRuleGroupChanged(rg) );
openBiomePicker(rg);
},
selectionTick: rg.requiredBiomeValues.length==0 ? true : null,
keepOpen: true,
selectionTick: rg.requiredBiomeValues.length==0 ? true : false,
});
for(ev in enumDef.values) {
subMenu.push({
actions.push({
label: L.untranslated(ev.id),
enable: ()->!rg.requiredBiomeValues.contains(ev.id),
cb: ()->{
rg.requiredBiomeValues.push(ev.id);
if( rg.requiredBiomeValues.contains(ev.id) )
rg.requiredBiomeValues.remove(ev.id);
else
rg.requiredBiomeValues.push(ev.id);
invalidateRuleGroup(rg);
editor.ge.emit( LayerRuleGroupChanged(rg) );
openBiomePicker(rg);
},
selectionTick: rg.requiredBiomeValues.contains(ev.id) ? true : null,
selectionTick: rg.requiredBiomeValues.contains(ev.id) ? true : false,
jHtmlImg: ev.tileRect!=null ? project.resolveTileRectAsHtmlImg(ev.tileRect) : null,
keepOpen: true,
});
}
}
return subMenu;

// Create menu
var jTarget = jContent.find("ul.ruleGroups").children('[groupUid=${rg.uid}]').find(".biome");
var ctx = new ContextMenu(jTarget);
for(a in actions)
ctx.add(a);
}



function createRuleGroupBlock(rg:AutoLayerRuleGroup, groupIdx:Int) {
var jGroup = jContent.find("xml#ruleGroup").clone().children().wrapAll('<li/>').parent();
jGroup.addClass(li.isRuleGroupEnabled(rg) ? "enabled" : "disabled");
jGroup.addClass(li.isRuleGroupAppliedHere(rg) ? "applied" : "notApplied");
jGroup.attr("groupUid", rg.uid);

if( rg.color!=null ) {
jGroup.find(".sortHandle, header").css("background-color", rg.color.toCssRgba(0.7));
Expand Down Expand Up @@ -652,9 +656,10 @@ class EditAllAutoLayerRules extends ui.modal.Panel {
jBiome.append('<span class="empty"/>');

jBiome.click( (ev)->{
var ctx = new ContextMenu(ev);
for(a in createBiomePickerCtxActions(rg))
ctx.add(a);
openBiomePicker(rg);
// var ctx = new ContextMenu(ev);
// for(a in createBiomePickerCtxActions(rg))
// ctx.add(a);
});
}

Expand Down Expand Up @@ -738,8 +743,8 @@ class EditAllAutoLayerRules extends ui.modal.Panel {

{
label: L.t._("Assign biome enum"),
cb: ()->{},
subMenu: ()->createBiomePickerCtxActions(rg),
cb: ()->openBiomePicker(rg),
// subMenu: ()->createBiomePickerCtxActions(rg),
},

{
Expand Down

0 comments on commit feaf0db

Please sign in to comment.