Skip to content

Commit

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

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions app/assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8576,16 +8576,27 @@ body.sorting ul.collapsedSortTarget {
.biome {
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
min-width: 24px;

&:hover{
background-color: transparentize($color: white, $amount: 0.6);
}

img {
margin-left: -10px;
}
img:first-of-type {
margin-left: 0;
}
&:hover{
background-color: transparentize($color: white, $amount: 0.6);

.empty {
width: 8px;
height: 8px;
border-radius: 8px;
border: 1px solid black;
opacity: 0.4;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/electron.renderer/data/def/LayerDef.hx
Original file line number Diff line number Diff line change
Expand Up @@ -718,5 +718,12 @@ class LayerDef {
i++;
}
}

if( biomeFieldUid==null )
for(rg in autoRuleGroups)
if( rg.requiredBiomeValues.length>0 ) {
App.LOG.add("tidy", 'Removed biome value from group ${rg.name} in $this');
rg.requiredBiomeValues = [];
}
}
}
41 changes: 33 additions & 8 deletions src/electron.renderer/ui/modal/ContextMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ typedef ContextAction = {
var ?separatorAfter: Bool;
var ?subMenu: Void->ContextActions;
var ?selectionTick : Bool;
var ?closeAfter : 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 @@ -118,7 +124,20 @@ 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();
Expand Down Expand Up @@ -162,20 +181,24 @@ class ContextMenu extends ui.Modal {

// Button action
jButton.click( (_)->{
if( a.subMenu==null && a.closeAfter!=false )
closeAll();
if( a.cb!=null )
a.cb();

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

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

for(subAction in a.subMenu())
c.add(subAction);
}
if( a.cb!=null )
a.cb();
});

return jButton;
Expand All @@ -186,6 +209,8 @@ class ContextMenu extends ui.Modal {
if( a.show!=null && !a.show() )
return new js.jquery.JQuery();

elements.push( CM_Action(a) );

var jButton = createButton(a);
jButton.appendTo(jContent);
applyAnchor();
Expand Down
23 changes: 13 additions & 10 deletions src/electron.renderer/ui/modal/panel/EditAllAutoLayerRules.hx
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ class EditAllAutoLayerRules extends ui.modal.Panel {
invalidateRuleGroup(rg);
editor.ge.emit( LayerRuleGroupChanged(rg) );
},
closeAfter: false,
selectionTick: rg.requiredBiomeValues.length==0 ? true : null,
keepOpen: true,
});
for(ev in enumDef.values) {
subMenu.push({
Expand All @@ -559,7 +559,7 @@ class EditAllAutoLayerRules extends ui.modal.Panel {
},
selectionTick: rg.requiredBiomeValues.contains(ev.id) ? true : null,
jHtmlImg: ev.tileRect!=null ? project.resolveTileRectAsHtmlImg(ev.tileRect) : null,
closeAfter: false,
keepOpen: true,
});
}
}
Expand Down Expand Up @@ -639,21 +639,24 @@ class EditAllAutoLayerRules extends ui.modal.Panel {

// Biome
var jBiome = jGroupHeader.find(".biome");
if( rg.requiredBiomeValues.length>0 ) {
var biomeImgs = ld.getRuleGroupBiomeHtmlImgs(rg,22);
if( biomeImgs.length>0 ) {
for( jImg in biomeImgs )
jImg.appendTo(jBiome);
if( ld.biomeFieldUid==null )
jBiome.hide();
else {
if( rg.requiredBiomeValues.length>0 ) {
var biomeImgs = ld.getRuleGroupBiomeHtmlImgs(rg,22);
if( biomeImgs.length>0 )
for( jImg in biomeImgs )
jImg.appendTo(jBiome);
}
else
jBiome.append('<span class="empty"/>');

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

// Add rule
var jAdd = jGroupHeader.find(".addRule");
Expand Down
6 changes: 2 additions & 4 deletions src/electron.renderer/ui/modal/panel/EditLayerDefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class EditLayerDefs extends ui.modal.Panel {
}
);

// Biome enum select
// Biome field select
var enumFieldUids = project.defs.levelFields.filter( f->f.isEnum() ).map( f->f.uid );
JsTools.createValuesSelect(
jForm.find("[name=biomeField]"),
Expand All @@ -460,10 +460,8 @@ class EditLayerDefs extends ui.modal.Panel {
new LastChance(Lang.t._("Changed auto-layer biome enum"), project);

cur.biomeFieldUid = uid;

// TODO cleanup rules with invalid biome values

editor.ge.emit( LayerDefChanged(cur.uid) );
cur.tidy(project);
}
);
}
Expand Down

0 comments on commit 025e9e9

Please sign in to comment.