Код
-- File: UI_MAIN_MENU.SCRIPT
-- Description: Load Dialog for STALKER build stile
-- Created: 25.10.2011
-- Copyright: 2011 (c) alg0r1tm & Draummer
-- Addon: Build Menu mod
-- Author: alg0r1tm & Draummer
-- Version: 3.0 [Work in progress]
function main()
local dlg = ui_main_menu.main_menu()
level.start_stop_menu(dlg,true)
while true do
wait(3000)
end
end
class "main_menu" (CUIScriptWnd)
function main_menu:__init() super()
self:SetFont(GetFontMedium()) --set base font for dialog.
self:InitControls()
self:InitCallBacks()
end
function main_menu:__finalize()
end
function main_menu:InitControls()
self.indent = 18
self.button_indent = -1
self.screen = {x = 0, y = 0, width = 1024, height = 768}
-- rect of main window
self.main_rect = {x = 0, y = 0,
width = 1024,
height = 512}
self.main_rect.x = (self.screen.width - self.main_rect.width )/2
self.main_rect.y = (self.screen.height - self.main_rect.height)
-----------------------------------------------------------------
self.left_align_x = self.indent
self.right_align_x = self.main_rect.width - self.indent
self.top_align_y = self.indent
self.bottom_align_y = self.main_rect.height - self.indent
------------------------------------------------------------------
-- button template
self.btn_rect = {x = 657,
y = 92,
width = 256,
height = 33 }
self.tab_rect = {x = 657,
y = 124,
width = 256,
height = 33 }
-- Fonts
self.caption_font = GetFontLetterica25()
self.button_font = GetFontLetterica25()
local avi_rect = {x = 0, y = 0, width = 1024, height = 389}
-- profile button
local btn_prof_rect = {x = 640, y = 68, width = 200, height = 30}
-- INIT DATA >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< CODE
-- init self position and size
self:Init(self.screen.x,
self.screen.y,
self.screen.width,
self.screen.height)
-- AVI
self.avi = CUIStatic()
self.avi:SetAutoDelete(true)
self.avi:SetWindowName("avi")
self.avi:Init("ui\\ui_vid_back_02", avi_rect.x, avi_rect.y, avi_rect.width, avi_rect.height)
self.avi:SetStretchTexture(true)
self:AttachChild(self.avi)
-- BACKGROUND
self.background = CUIStatic()
self.background:SetAutoDelete(true)
self.background:SetWindowName("background")
self.background:Init("ui\\del_ui_static_mm_back_01",self.screen.x, self.screen.y, self.screen.width, self.screen.height)
self:AttachChild(self.background)
-- MAIN WINDOW
self.main_frame = CUIStatic()
self.main_frame:SetAutoDelete(true)
self.main_frame:SetWindowName("main_frame")
self.main_frame:Init("ui\\ui_static_main_menu", self.main_rect.x,
self.main_rect.y,
self.main_rect.width,
self.main_rect.height)
self:AttachChild(self.main_frame)
-- PROFILE --
local btn = CUI3tButton()
btn:SetAutoDelete(true)
btn:SetWindowName("btn_profile")
btn:SetFont(self.caption_font)
btn:SetTextAlign(CGameFont.alLeft)
btn:SetText("..::GAMEINATOR::.. addon")
btn:Init(btn_prof_rect.x, btn_prof_rect.y, btn_prof_rect.width, btn_prof_rect.height)
self.main_frame:AttachChild(btn)
self.main_tab = ui_main_main_tab.main_main_tab()
self.main_tab:InitControls(self.tab_rect.x, self.tab_rect.y, self)
self.main_tab:Show(true)
self.main_frame:AttachChild(self.main_tab)
self.new_tab = ui_main_new_tab.main_new_tab()
self.new_tab:InitControls(self.tab_rect.x, self.tab_rect.y, self)
self.main_frame:AttachChild(self.new_tab)
self.multi_tab = ui_main_multi_tab.main_multi_tab()
self.multi_tab:InitControls(self.tab_rect.x, self.tab_rect.y, self)
self.main_frame:AttachChild(self.multi_tab)
end
function main_menu:InitCallBacks()
-- new game
self:AddCallback("btn_new_game", ui_events.BUTTON_CLICKED, self.OnButton_new_game_clicked, self)
self:AddCallback("btn_novice", ui_events.BUTTON_CLICKED, self.OnButton_new_novice_game, self)
self:AddCallback("btn_stalker", ui_events.BUTTON_CLICKED, self.OnButton_new_stalker_game, self)
self:AddCallback("btn_veteran", ui_events.BUTTON_CLICKED, self.OnButton_new_veteran_game, self)
self:AddCallback("btn_master", ui_events.BUTTON_CLICKED, self.OnButton_new_master_game, self)
self:AddCallback("btn_spawn", ui_events.BUTTON_CLICKED, self.OnButton_load_spawn, self)
self:AddCallback("btn_new_back", ui_events.BUTTON_CLICKED, self.OnButton_back, self)
-- options
self:AddCallback("btn_options", ui_events.BUTTON_CLICKED, self.OnButton_options_clicked, self)
-- load
self:AddCallback("btn_load", ui_events.BUTTON_CLICKED, self.OnButton_load_clicked, self)
-- save
self:AddCallback("btn_save", ui_events.BUTTON_CLICKED, self.OnButton_save_clicked, self)
-- multiplayer
self:AddCallback("btn_findsrv", ui_events.BUTTON_CLICKED, self.OnButton_findsrv, self)
self:AddCallback("btn_createsrv", ui_events.BUTTON_CLICKED, self.OnButton_createsrv, self)
self:AddCallback("btn_multiplayer", ui_events.BUTTON_CLICKED, self.OnButton_multiplayer_clicked, self)
self:AddCallback("btn_multy_back", ui_events.BUTTON_CLICKED, self.OnButton_back, self)
-- credits
self:AddCallback("btn_credits", ui_events.BUTTON_CLICKED, self.OnButton_credits_clicked, self)
-- quit
self:AddCallback("btn_quit", ui_events.BUTTON_CLICKED, self.OnButton_quit_clicked, self)
self:AddCallback("btn_quit_to_mm", ui_events.BUTTON_CLICKED, self.OnButton_disconnect_clicked, self)
self:AddCallback("btn_ret", ui_events.BUTTON_CLICKED, self.OnButton_return_game, self)
self:AddCallback("btn_lastsave", ui_events.BUTTON_CLICKED, self.OnButton_last_save, self)
self:AddCallback("btn_credits", ui_events.BUTTON_CLICKED, self.OnButton_credits_clicked, self)
-- message box
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_OK_CLICKED, self.OnMsgOk, self)
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_CANCEL_CLICKED, self.OnMsgCancel, self)
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_YES_CLICKED, self.OnMsgYes, self)
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_NO_CLICKED, self.OnMsgNo, self)
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_QUIT_GAME_CLICKED,self.OnMessageQuitGame, self)
self:AddCallback("msg_box", ui_events.MESSAGE_BOX_QUIT_WIN_CLICKED, self.OnMessageQuitWin, self)
end
function main_menu:OnButton_new_game_clicked()
self:HideAllTabs()
self.new_tab:Show(true)
end
function main_menu:HideAllTabs()
self.main_tab:Show(false)
self.new_tab:Show(false)
self.multi_tab:Show(false)
end
function main_menu:OnButton_back()
self:HideAllTabs()
self.main_tab:Show(true)
end
function main_menu:OnMsgOk()
self.mbox_mode = 0
end
function main_menu:OnMsgCancel()
self.mbox_mode = 0
end
function main_menu:OnMsgYes()
if self.mbox_mode == 1 then
self:LoadLastSave()
end
self.mbox_mode = 0
end
function main_menu:OnMsgNo()
self.mbox_mode = 0
end
function main_menu:LoadLastSave()
local console = get_console()
console:execute ("main_menu off")
console:execute ("load_last_save")
end
function main_menu:OnButton_last_save()
if (alife() == nil) then
self:LoadLastSave ();
return
end
self.mbox_mode = 1
self.message_box:Init ("message_box_confirm_load_save")
self:GetHolder():start_stop_menu(self.message_box, true)
end
function main_menu:OnButton_credits_clicked()
-- local console = get_console()
-- console:execute("main_menu off")
game.start_tutorial("credits_seq")
end
function main_menu:OnButton_quit_clicked()
local console = get_console()
console:execute("quit")
end
function main_menu:OnButton_disconnect_clicked()
self.message_box:Init("message_box_quit_game")
if (level.game_id() ~= 1) then
self.message_box:SetText("ui_mm_disconnect_message") -- MultiPlayer
else
self.message_box:SetText("ui_mm_quit_game_message") -- SinglePlayer
end
self:GetHolder():start_stop_menu(self.message_box, true)
end
function main_menu:OnMessageQuitGame()
local console = get_console()
console:execute("disconnect")
end
function main_menu:OnMessageQuitWin()
local console = get_console()
console:execute("quit")
end
function main_menu:OnButton_return_game()
local console = get_console()
console:execute("main_menu off")
end
function main_menu:OnButton_new_novice_game()
local console = get_console()
console:execute("g_game_difficulty gd_novice")
self:StartGame()
end
function main_menu:OnButton_new_stalker_game()
local console = get_console()
console:execute("g_game_difficulty gd_stalker")
self:StartGame()
end
function main_menu:OnButton_new_veteran_game()
local console = get_console()
console:execute("g_game_difficulty gd_veteran")
self:StartGame()
end
function main_menu:OnButton_new_master_game()
local console = get_console()
console:execute("g_game_difficulty gd_master")
self:StartGame()
end
function main_menu:StartGame()
local console = get_console()
if (alife() ~= nil) then
console:execute ("disconnect")
end
console:execute("start server(all/single/alife/new) client(localhost)")
console:execute("main_menu off")
end
function main_menu:OnButton_load_spawn()
if self.spawn_dlg == nil then
self.spawn_dlg = ui_spawn_dialog.spawn_dialog()
self.spawn_dlg.owner = self
end
self:GetHolder():start_stop_menu(self.spawn_dlg, true)
self:GetHolder():start_stop_menu(self, true) --new
self:Show(false)
end
function main_menu:OnButton_save_clicked()
if self.save_dlg == nil then
self.save_dlg = ui_save_dialog.save_dialog()
self.save_dlg.owner = self
end
self:GetHolder():start_stop_menu(self.save_dlg, true)
self:GetHolder():start_stop_menu(self, true) --new
self:Show(false)
end
function main_menu:OnButton_options_clicked()
if self.opt_dlg == nil then
self.opt_dlg = ui_mm_opt_main.options_dialog()
self.opt_dlg.owner = self
end
self.opt_dlg:UpdateControls()
self:GetHolder():start_stop_menu(self.opt_dlg, true)
self:GetHolder():start_stop_menu(self, true) --new
self:Show(false)
end
function main_menu:OnButton_load_clicked()
if self.load_dlg ==nil then
self.load_dlg = ui_load_dialog.load_dialog()
self.load_dlg.owner = self
end
self:GetHolder():start_stop_menu(self.load_dlg, true)
self:GetHolder():start_stop_menu(self, true) --new
self:Show(false)
end
function main_menu:OnButton_multiplayer_clicked()
if self.mp_dlg ==nil then
self.mp_dlg = ui_mp_main.mp_main()
self.mp_dlg.owner = self
end
self.mp_dlg:UpdateControls()
self:GetHolder():start_stop_menu(self.mp_dlg, true)
self:GetHolder():start_stop_menu(self, true) --new
self:Show(false)
-- self.mp_dlg:OnBtn_Refresh()
local console = get_console()
console:execute ("check_for_updates 0")
self.mp_dlg:OnRadio_NetChanged()
end
function main_menu:Dispatch(cmd, param) --virtual function
if cmd == 2 then
self:OnButton_multiplayer_clicked()
end
return true
end
function main_menu:OnKeyboard(dik, keyboard_action) --virtual function
CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
local bind = dik_to_bind(dik)
local console = get_console()
if keyboard_action == ui_events.WINDOW_KEY_PRESSED then
if dik == DIK_keys.DIK_ESCAPE then
if level.present() and (db.actor ~= nil) and db.actor:alive() then
console:execute("main_menu off")
end
end
-- if dik == DIK_keys.DIK_S then
-- self:OnButton_load_spawn()
-- else
if dik == DIK_keys.DIK_Q then
self:OnMessageQuitWin()
end
end
return true
end