-- Внимание Увага Achtung Attenzione Attention 주의 慎重 Զգուշացեք Собери

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
-- Внимание! Увага! Achtung! Attenzione! Attention! 주의! 慎重! Զգուշացեք! Собери движок с правкой, ибо вылетит!
local UICursor = UI.GetCursor();
--
local mRadialItems = {
{
Name = 'btn_00',
angles = {0, 90}, -- 0 - 360
functor = function() news_manager.send_tip( db.actor, "Авотхуй! х1") end,
},
{
Name = 'btn_10',
angles = {90, 180}, -- 0 - 360
functor = function() news_manager.send_tip( db.actor, "Авотхуй! х2") end,
},
{
Name = 'btn_01',
angles = {180, 270}, -- 0 - 360
functor = function() news_manager.send_tip( db.actor, "Авотхуй! х3") end
}
};
local xmlName = 'ui_radial_wnd';
class 'UIRadialMenu' (CUIScriptWnd)
function UIRadialMenu:__init( HIDE_KEY) super()
self.HIDE_KEY = HIDE_KEY;
self.text = CUITextWnd();
self:AttachChild( self.text);
self.text:SetFont( GetFontDI())
self.text:SetWndPos( vector2():set(512,384))
local xml = CScriptXmlInit();
xml:ParseFile( xmlName);
for id, Item in pairs( mRadialItems) do
Item.st = xml:InitStatic( Item.Name, self);
Item.hl = xml:InitStatic( Item.Name .. ":highlight", Item.st);
Item.hl:Show( false);
end
end
local FREE_ZONE_RADIUS = 75; -- радиус "свободной зоны"
local MAX_CURSOR_DIST = 100; -- максималное расстояние курсора от центра экрана
local SCREEN_MID_X = 512;
local SCREEN_MID_Y = 384;
function UIRadialMenu:Update()
CUIScriptWnd.Update( self);
--UICursor:Hide();
local mousePosition = UICursor:GetPosition();
local dist = math.sqrt((mousePosition.x - SCREEN_MID_X)^2 + (mousePosition.y - SCREEN_MID_Y)^2);
local Angle = math.deg( math.atan2( mousePosition.x - SCREEN_MID_X, mousePosition.y - SCREEN_MID_Y)) + 180;
for id, Item in pairs( mRadialItems) do
if Item.angles[1] < Angle and Item.angles[2] > Angle then
if( dist > FREE_ZONE_RADIUS) then
Item.hl:Show( true);
Item.Active = true;
self.functor = Item.functor;
end
else
Item.hl:Show( false);
if Item.Active == true then
self.functor = nil;
end
end
end
if( dist > MAX_CURSOR_DIST) then
local _X = math.cos( math.rad(Angle + 90)) * (MAX_CURSOR_DIST - 2) + SCREEN_MID_X; -- +90
local _Y = math.sin( math.rad(Angle - 90)) * (MAX_CURSOR_DIST - 2) + SCREEN_MID_Y; -- -90
UICursor:SetPosition( vector2():set( _X, _Y));
end
end
function UIRadialMenu:OnKeyboard( dik, keyboard_action)
CUIScriptWnd.OnKeyboard( self, dik, keyboard_action)
if keyboard_action == ui_events.WINDOW_KEY_RELEASED then
if dik == self.HIDE_KEY then
self:HideDialog();
self.IsShowed = false;
if self.functor then
self.functor();
end
end
end
end
function showRadial()
if not mRadialMenu then
news_manager.send_tip( db.actor, "UIRadialMenu created");
mRadialMenu = UIRadialMenu( DIK_keys.DIK_TAB);
end
if mRadialMenu.IsShowed then
return nil;
end
news_manager.send_tip( db.actor, "UIRadialMenu showed");
mRadialMenu:ShowDialog( true);
mRadialMenu.IsShowed = true;
end