Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
worldsmenu.c
Go to the documentation of this file.
1 #ifdef GAME_TEMPLATE
2 
3 [EditorAttribute("box", "GameLib/Scripted", "Worlds menu", "-0.25 -0.25 -0.25", "0.25 0.25 0.25", "255 0 0 255")]
4 class WorldsMenuClass
5 {
6 
7 }
8 
9 WorldsMenuClass WorldsMenuSource;
10 
11 class WorldsMenu: GenericEntity
12 {
13  int m_DbgListSelection = 0;
14  int m_WorldsCount = 0;
15  string DEFAULT_WORLD = "worlds/default.ent";
16  ref array<string> m_DbgOptions = {};
17  ref ImageWidget m_MouseWidget;
18 
19  void WorldsMenu(IEntitySource src, IEntity parent)
20  {
21  SetFlags(EntityFlags.ACTIVE, false);
22  SetEventMask(EntityEvent.POSTFRAME);
23 
24  Class.CastTo(m_MouseWidget, GetGame().GetWorkspace().CreateWidgets("gui/layouts/mouse.layout"));
25  m_MouseWidget.SetSort(1024);
26  SetCursorWidget(m_MouseWidget);
27 
28  LoadWorlds();
29  }
30 
31  void ~WorldsMenu()
32  {
33  delete m_MouseWidget;
34  }
35 
36  array<string> GetWorldList()
37  {
38  return m_DbgOptions;
39  }
40 
41  override void EOnPostFrame(IEntity other, int extra) //EntityEvent.POSTFRAME
42  {
43  InputManager im = GetGame().GetInputManager();
44  im.ActivateContext("MenuContext");
45  bool menuSelect = im.GetActionTriggered("MenuSelect");
46  bool menuBack = im.GetActionTriggered("MenuBack");
47 
48  DbgUI.Begin("Load world", 400, 100);
49 
50  DbgUI.Text("Select world to load from worlds directory");
51 
52  if (m_DbgOptions.Count() > 0)
53  {
54  DbgUI.List("Worlds", m_DbgListSelection, m_DbgOptions);
55  if (DbgUI.Button("Start") || menuSelect)
56  {
57  string worldToLoad = m_DbgOptions.Get(m_DbgListSelection);
58  GetGame().SetWorldFile(worldToLoad, true);
59  }
60  }
61  if (DbgUI.Button("Exit") || menuBack)
62  {
63  GetGame().RequestClose();
64  }
65  DbgUI.End();
66  }
67 
68  void LoadWorlds()
69  {
70  string fileName;
71  FileAttr fileAttr;
72  FindFileHandle worlds = FindFile("worlds/*.ent", fileName, fileAttr, 0);
73 
74  if (!worlds)
75  return;
76 
77  InsertWorldToList(fileName);
78 
79  while(FindNextFile(worlds, fileName, fileAttr))
80  {
81  InsertWorldToList(fileName);
82  }
83 
84  CloseFindFile(worlds);
85 
86  m_WorldsCount = m_DbgOptions.Count();
87  }
88 
89  void InsertWorldToList(string fileName)
90  {
91  string path = String("worlds/" + fileName);
92  if (path != DEFAULT_WORLD)
93  m_DbgOptions.Insert(String(path));
94  }
95 }
96 
97 #endif
GetGame
proto native CGame GetGame()
IEntitySource
Definition: enentity.c:15
EntityFlags
EntityFlags
Entity flags.
Definition: enentity.c:114
DbgUI
Definition: dbgui.c:59
String
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition: enscript.c:339
FindNextFile
proto bool FindNextFile(FindFileHandle handle, out string fileName, out FileAttr fileAttributes)
FindFileHandle
int[] FindFileHandle
Definition: ensystem.c:503
SetCursorWidget
proto native void SetCursorWidget(Widget cursor)
IEntity
Definition: enentity.c:164
EditorAttribute
void EditorAttribute(string style, string category, string description, vector sizeMin, vector sizeMax, string color, string color2="0 0 0 0", bool visible=true, bool insertable=true, bool dynamicBox=false)
Definition: enentity.c:854
FindFile
enum FindFileFlags FindFile(string pattern, out string fileName, out FileAttr fileAttributes, FindFileFlags flags)
CloseFindFile
proto native void CloseFindFile(FindFileHandle handle)
SetFlags
proto native void SetFlags(ShapeFlags flags)
FileAttr
FileAttr
Definition: ensystem.c:505
array< string >
EntityEvent
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition: enentity.c:44
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
path
string path
Definition: optionselectormultistate.c:135