DayZ-CommunityFramework icon indicating copy to clipboard operation
DayZ-CommunityFramework copied to clipboard

Model View ViewModel (MVVM)

Open Jacob-Mango opened this issue 3 years ago • 2 comments

Jacob-Mango avatar Jun 16 '21 18:06 Jacob-Mango

Example of MVVM:

Script

class ExpansionPlayerListEntry : CF_Model
{
  int Color;
  string Name;
  string ID;

  void ExpansionPlayerListEntry(string name, string id, Widget parent = null)
  {
    CF.MVVM.Create(this, "DayZExpansion/PlayerList/GUI/layouts/expansion_player_list_entry.layout", parent);

    Name = name;
    ID = id;

    NotifyPropertyChanged("Name");
    NotifyPropertyChanged("ID");
  }

  void ~ExpansionPlayerListEntry()
  {
    CF.MVVM.Destroy(this);
  }

  void OnMouseEnter(CF_MouseEvent evt)
  {
    Color = ARGB(255, 1, 1, 1);

    NotifyPropertyChanged("IconColor");
  }

  void OnMouseLeave(CF_MouseEvent evt)
  {
    Color = ARGB(255, 220, 220, 220);

    NotifyPropertyChanged("IconColor");
  }
};

Layout

GridSpacerWidgetClass ExpansionPlayerListEntry {
 scriptclass "CF_GridSpacerWidget"
 {
  PanelWidgetClass player_entry {
   {
    ImageWidgetClass player_icon {
     scriptclass "CF_ImageWidget"
     {
      ScriptParamsClass {
       Color "Color"
      }
     }
    }
    TextWidgetClass player_name {
     scriptclass "CF_TextWidget"
     {
      ScriptParamsClass {
       Text "Name"
      }
     }
    }
   }
  }
 }
 {
  ScriptParamsClass {
   Event_MouseEnter "OnMouseEnter"
   Event_MouseLeave "OnMouseLeave"
  }
 }
}

Jacob-Mango avatar Jun 16 '21 19:06 Jacob-Mango

Will resolve #41

Arkensor avatar Jun 26 '21 11:06 Arkensor