DayZ 1.24
Loading...
Searching...
No Matches
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")]
4class WorldsMenuClass
5{
6
7}
8
9WorldsMenuClass WorldsMenuSource;
10
11class 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 GetGame().RequestClose();
63 DbgUI.End();
64 }
65
66 void LoadWorlds()
67 {
68 string fileName;
69 FileAttr fileAttr;
70 FindFileHandle worlds = FindFile("worlds/*.ent", fileName, fileAttr, 0);
71
72 if (!worlds)
73 return;
74
75 InsertWorldToList(fileName);
76
77 while (FindNextFile(worlds, fileName, fileAttr))
78 InsertWorldToList(fileName);
79
80 CloseFindFile(worlds);
81
82 m_WorldsCount = m_DbgOptions.Count();
83 }
84
85 void InsertWorldToList(string fileName)
86 {
87 string path = String("worlds/" + fileName);
88 if (path != DEFAULT_WORLD)
89 m_DbgOptions.Insert(String(path));
90 }
91}
92
93#endif
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition DbgUI.c:60
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
proto native void SetFlags(ShapeFlags flags)
static proto void List(string label, out int selection, TStringArray elems)
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native bool Button(string txt, int minWidth=0)
static proto native void Text(string label)
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Definition EnScript.c:338
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition EnEntity.c:44
EntityFlags
Entity flags.
Definition EnEntity.c:114
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:851
proto native void CloseFindFile(FindFileHandle handle)
enum FindFileFlags FindFile(string pattern, out string fileName, out FileAttr fileAttributes, FindFileFlags flags)
proto bool FindNextFile(FindFileHandle handle, out string fileName, out FileAttr fileAttributes)
int[] FindFileHandle
Definition EnSystem.c:503
FileAttr
Definition EnSystem.c:506
proto native void SetCursorWidget(Widget cursor)