From b02666a0e139f8d6b11373573098170c42e5f697 Mon Sep 17 00:00:00 2001 From: nekotoro Date: Mon, 5 Jan 2026 14:09:38 +0100 Subject: [PATCH] first test with https://github.com/profelis/bindx2 --- project.xml | 1 + src/view/ConfirmationPanel.hx | 1 + src/view/RiderCardDrawer.hx | 54 +++++++++++++++++++---------------- src/vo/RiderVO.hx | 4 ++- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/project.xml b/project.xml index 19373eb..812ffb7 100644 --- a/project.xml +++ b/project.xml @@ -22,6 +22,7 @@ + diff --git a/src/view/ConfirmationPanel.hx b/src/view/ConfirmationPanel.hx index 0fc7ac3..90863d1 100644 --- a/src/view/ConfirmationPanel.hx +++ b/src/view/ConfirmationPanel.hx @@ -102,6 +102,7 @@ class ConfirmationPanel extends Panel { b2.setIconForState(ButtonState.DOWN, SVGIconFactory.makeIcon("vector/check_icon_black.svg", Constants.BUTTONS_ICON_SIZE, Constants.HERO_COLOR)); b2.addEventListener(TriggerEvent.TRIGGER, (e) -> { confirmFunction(); + PopUpManager.removePopUp(this); }); // footer diff --git a/src/view/RiderCardDrawer.hx b/src/view/RiderCardDrawer.hx index 031d827..64c0a24 100644 --- a/src/view/RiderCardDrawer.hx +++ b/src/view/RiderCardDrawer.hx @@ -1,5 +1,7 @@ package view; +import haxe.macro.Expr; +import bindx.Bind; import openfl.utils.Function; import feathers.core.PopUpManager; import components.VSpacer; @@ -65,7 +67,7 @@ class RiderCardDrawer extends Drawer { var mainVerticalLayout = new VerticalLayout(); mainVerticalLayout.paddingLeft = mainVerticalLayout.paddingRight = Constants.GLOBAL_PADDING; - //mainVerticalLayout.gap = Constants.GLOBAL_PADDING; + // mainVerticalLayout.gap = Constants.GLOBAL_PADDING; mainVerticalLayout.horizontalAlign = JUSTIFY; mainVerticalLayout.verticalAlign = TOP; mainScrollContainer.layout = mainVerticalLayout; @@ -86,7 +88,7 @@ class RiderCardDrawer extends Drawer { // profile picture ppal = new AssetLoader(); - ppal.addEventListener(Event.COMPLETE, onPPLoaded); + // ppal.addEventListener(Event.COMPLETE, (e:Event) -> cast(e.currentTarget, AssetLoader).validateNow()); mainScrollContainer.addChild(ppal); // ##### SPACER @@ -145,9 +147,10 @@ class RiderCardDrawer extends Drawer { removeOneCredit.addEventListener(TriggerEvent.TRIGGER, (e) -> { traceRed("removeOneCredit()"); // this function will be exectuted when the user will click on the ConfirmationPanel's "confirm" button - var f:Function = function () { + var f:Function = function() { trace("remove 1 credit to selected rider in model"); // TODO remove 1 credit to selected rider in model + model.selectedRider.credit--; } PopUpManager.addPopUp(new ConfirmationPanel(Strings.CP_S2, Strings.CP_S3, f), parent, true, true); }); @@ -155,7 +158,7 @@ class RiderCardDrawer extends Drawer { // ##### SPACER mainScrollContainer.addChild(new VSpacer(10)); - //mainScrollContainer.addChild(new VSpacer(2, Constants.MAIN_COLOR2, 1)); + // mainScrollContainer.addChild(new VSpacer(2, Constants.MAIN_COLOR2, 1)); drawer = mainScrollContainer; } @@ -165,13 +168,13 @@ class RiderCardDrawer extends Drawer { } public function populateAndShow() { - var rvo:RiderVO = model.selectedRider; + // var rvo:RiderVO = model.selectedRider; // profile picture - ppal.source = Constants.PROFIL_PICTURES_PATH_512 + rvo.uid + ".jpg"; + ppal.source = Constants.PROFIL_PICTURES_PATH_512 + model.selectedRider.uid + ".jpg"; // first name text input - firstNameLabel.text = rvo.firstName; + firstNameLabel.text = model.selectedRider.firstName; if (!firstNameLabel.hasEventListener(Event.CHANGE)) { firstNameLabel.addEventListener(Event.CHANGE, (e) -> { if (firstNameLabel.text != model.selectedRider.firstName) { @@ -181,7 +184,7 @@ class RiderCardDrawer extends Drawer { } // name text input - nameLabel.text = rvo.name; + nameLabel.text = model.selectedRider.name; if (!nameLabel.hasEventListener(Event.CHANGE)) { nameLabel.addEventListener(Event.CHANGE, (e) -> { if (nameLabel.text != model.selectedRider.name) { @@ -190,27 +193,28 @@ class RiderCardDrawer extends Drawer { }); } - // remaing credit text - creditLabel.text = Strings.RCD_S1 + Std.string(rvo.credit); + // remaining credit label & progress bar + updateCreditUIElments(null, model.selectedRider.credit); + Bind.bind(model.selectedRider.credit, updateCreditUIElments); - // remaining credit progress bar - if (rvo.credit <= Constants.CREDIT_ULTRA_LOW_LIMIT) { - creditProgressBar.variant = LPTCTheme.H_PROGRESS_BAR_VARIANT_ALARM; - } else if (rvo.credit <= Constants.CREDIT_LOW_LIMIT) { - creditProgressBar.variant = LPTCTheme.H_PROGRESS_BAR_VARIANT_ALERT; - } else if (rvo.credit <= Constants.CREDIT_AVERAGE_LIMIT) { - creditProgressBar.variant = LPTCTheme.H_PROGRESS_BAR_VARIANT_WARNING; - } else { - creditProgressBar.variant = LPTCTheme.H_PROGRESS_BAR_VARIANT_INFO; - } - creditProgressBar.value = rvo.credit; openDrawer(); } - private function onPPLoaded(e:Event):Void { - var rvo:RiderVO = model.selectedRider; - var al:AssetLoader = cast(e.currentTarget, AssetLoader); - al.validateNow(); + // update remaining credit label and progress bar + private function updateCreditUIElments(pFromValue:Dynamic, pToValue:Dynamic) { + + creditLabel.text = Strings.RCD_S1 + Std.string(pToValue); + + if (pToValue <= Constants.CREDIT_ULTRA_LOW_LIMIT) { + creditProgressBar.variant = LPTCTheme.H_PROGRESS_BAR_VARIANT_ALARM; + } else if (pToValue <= Constants.CREDIT_LOW_LIMIT) { + creditProgressBar.variant = LPTCTheme.H_PROGRESS_BAR_VARIANT_ALERT; + } else if (pToValue <= Constants.CREDIT_AVERAGE_LIMIT) { + creditProgressBar.variant = LPTCTheme.H_PROGRESS_BAR_VARIANT_WARNING; + } else { + creditProgressBar.variant = LPTCTheme.H_PROGRESS_BAR_VARIANT_INFO; + } + creditProgressBar.value = pToValue; } } diff --git a/src/vo/RiderVO.hx b/src/vo/RiderVO.hx index 164959b..f1b9e8e 100644 --- a/src/vo/RiderVO.hx +++ b/src/vo/RiderVO.hx @@ -1,6 +1,8 @@ package vo; +import bindx.IBindable; -class RiderVO { +@:bindable +class RiderVO implements IBindable { // constants for use with Reflect api when updating SelectedRider VO public static final ID:String = "id";