--[[ *** ESCAPE_DIALOG.SCRIPT *** function run_tutorial_pda(first_speaker, second_speaker) printf("!-!-!") first_speaker:stop_talk() second_speaker:stop_talk() local dlg = ui_repair_items.uiRepairDialog( first_speaker, (2/3) ) dlg.Open() wait( 10000 ) game.start_tutorial("part_1_pda") end ]]-- -- db.actor is the player character -- ui_repair_items.uiRepairDialog( repairer, cost_modifier ) class "uiRepairDialog" (CUIScriptWnd) function logf( fmt, ... ) log( string.format( fmt, ... ) ) end local color_valid = GetARGB( 255, 255, 255, 255 ) local color_invalid = GetARGB( 255, 255, 0, 0 ) -- find repairable items on someone function find_repairable_items( owner, repair_table ) logf( "find_repairable_items() called") -- the to-be-filled table of repairable items from owner local items_repairable = {} -- for find_repairable_items - what is iterated over each item function iterant_find_repairable_item( owner, item ) logf( "iterant_find_repairable_item() called") if repair_table.length == 0 then table.insert( items_repairable, item ) return end local item_section = item:section() local item_repairable = repair_table[item_section] if item_repairable ~= nil then local item_condition = item:condition() if item_repairable >= 0 then if item_condition < item_repairable then table.insert( items_repairable, item ) end elseif item_repairable == -1 then table.insert( items_repairable, item ) end end logf( "iterant_find_repairable_item() complete") end -- fill the items_repairable table owner:iterate_inventory( iterant_find_repairable_item, owner ) logf( "find_repairable_items() complete") return items_repairable end function calculate_cost_at_condition( cost, condition ) return math.ceil( cost - ( cost * condition ) ) end -- returns 2 values: condition repaired to, and cost of repairs function calculate_repairable( cost_modifier, condition_current, target_condition, budget ) logf( "calculate_repairable() called") -- check current condition against target condition if condition_current > target_condition then logf( "calculate_repairable() complete") return condition_current, 0 end -- calculate amount of repair needed local repair_needed = target_condition - condition_current -- calculate maximum repair cost for fractional cost local repair_max_cost = math.ceil( item:cost() * cost_modifier ) -- calculate amount repairable under budget local repair_budgeted = budget / repair_max_cost -- repair to target condition can be made under budget if repair_budgeted > repair_needed then logf( "calculate_repairable() complete") return repair_needed, math.ceil( repair_needed * repair_max_cost ) end -- repair can only be made to budget cap logf( "calculate_repairable() complete") return repair_budgeted, budget end function condition_as_color( condition ) logf( "condition_as_color() called") local n local r, g -- to scale down means n*v, the opposite, scale up, means (1-n)*v if condition >= 0.75 then -- lime (255, 0) -> green (128, 0) n = ( condition - 0.75 ) * 4 -- scale down green from full to half r, g = 0 , (( n)*128)+127 elseif condition >= 0.50 then -- green (128, 0) -> yellow (255, 255) n = ( condition - 0.50 ) * 4 -- scale up green from half to full, scale up red from none to full r, g = ((1-n)*255) , ((1-n)*128)+127 elseif condition >= 0.25 then -- yellow (255, 255) -> olive (128, 128) n = ( condition - 0.25 ) * 4 -- scale down green from full to half, scale down red from full to half r, g = (( n)*128)+127, (( n)*128)+127 else -- ( condition >= 0.00 ) then -- olive (128, 128) -> red (255, 0) n = condition * 4 -- scale down green from half to none, scale up red from half to full r, g = ((1-n)*128)+127, (( n)*128) end logf( "condition_as_color() complete") return GetARGB( 255, math.floor( r ), math.ceil( g ), 0 ); end function translate( string ) return game.translate_string( "ui_repair_items_" .. string ) end --[[ set of registered in game fonts: GetFontArialN21Russian() GetFontGraffiti32Russian() GetFontDI() GetFontHeaderRussian() GetFontGraffiti19Russian() GetFontLetterica25() GetFontMedium() GetFontLetterica16Russian() GetFontSmall() GetFontGraffiti22Russian() GetFontLetterica18Russian() GetFontBigDigit() GetFontHeaderEurope() GetFontGraffiti50Russian() --]] --[[ take control by name, dependent on type GetCheckButton(string) GetFrameLineWnd(string) GetPropertiesBox(string) GetListWnd(string) GetStatic(string) GetEditBox(string) GetTabControl(string) GetRadioGroup(string) GetDialogWnd(string) GetButton(string) GetMessageBox(string) GetProgressBar(string) GetRadioButton(string) GetFrameWindow(string) --]] function main( repairer, cost_modifier ) logf( "main() called") local dlg if repairer.repair_cost_modifier ~= nil and cost_modifier ~= nil then dlg = ui_repair_items.uiRepairDialog( repairer, repairer.repair_cost_modifier * cost_modifier ) elseif repairer.repair_cost_modifier ~= nil then dlg = ui_repair_items.uiRepairDialog( repairer, repairer.repair_cost_modifier ) elseif cost_modifier ~= nil then dlg = ui_repair_items.uiRepairDialog( repairer, cost_modifier ) else dlg = ui_repair_items.uiRepairDialog( repairer, (2/3) ) end dlg.Open() while dlg.IsOpen do wait( 1000 ) end logf( "main() complete") end function uiRepairDialog:__init( repairer, cost_modifier ) super() logf( "uiRepairDialog:__init() called") self.repairer = repairer self.cost_modifier = cost_modifier self.last_recalc_params = { nil, nil } self.valid_repair = false self.IsOpen = false -- set base font for dialog self:SetFont( GetFontMedium() ) self:InitControls() self:InitCallBacks() logf( "uiRepairDialog:__init() complete") end function uiRepairDialog:__finalize() logf( "uiRepairDialog:__finalize() called") self:Close() logf( "uiRepairDialog:__finalize() complete") end function uiRepairDialog:SetClGame( game_cl ) logf( "uiRepairDialog:SetClGame() called") self.m_game_cl = game_cl logf( "uiRepairDialog:SetClGame() complete") end function uiRepairDialog:InitControls() logf( "uiRepairDialog:InitControls() called") local money = db.actor:money() local dev = device() local screen_w, screen_h = dev.width, dev.height local size_w, size_h = screen_w-100, screen_h-100 local pos_x, pos_y = (screen_w/2) - (size_w/2), (screen_h/2) - (size_h/2) local margin_size = 10 local top_margin, left_margin = margin_size, margin_size local bottom_margin, right_margin = size_h-margin_size, size_w-margin_size -- init self position and size -- position & size: x (from left), y (from top), width, height self:Init( pos_x, pos_y, size_w, size_h ) ---------------------------------------------------------------- BACKGROUND local bkg_repair_wnd = CUIStatic() local bkg_repair_wnd_r = { --[[ [0] left ]] 0, --[[ [1] top ]] 0, --[[ [2] width ]] size_w, --[[ [3] height ]] size_h } bkg_repair_wnd:SetAutoDelete( true ) bkg_repair_wnd:SetWindowName( "bkg_repair_wnd" ) bkg_repair_wnd:Init( unpack( bkg_repair_wnd_r ) ) bkg_repair_wnd:SetColor( GetARGB( 255, 0, 0, 0 ) ) self:AttachChild( bkg_repair_wnd ) -- Start creating controls from bottom of window up up ------------------------------------------------------------- REPAIR BUTTON logf( "constructing btn_repair" ) local btn_repair = CUIButton() local btn_repair_r = { --[[ [0] left ]] left_margin, --[[ [1] top ]] bottom_margin-40, --[[ [2] width ]] 135, --[[ [3] height ]] 40 } btn_repair:SetAutoDelete( true ) btn_repair:SetWindowName( "btn_repair" ) btn_repair:Init( unpack( btn_repair_r ) ) btn_repair:SetText( translate( "btn_repair" ) ) btn_repair:SetTextAlign( CGameFont.alCenter ) btn_repair:SetTextY( -1 ) self:Register( btn_repair ) bkg_repair_wnd:AttachChild( btn_repair ) ------------------------------------------------------------- CANCEL BUTTON logf( "constructing btn_cancel" ) local btn_cancel = CUIButton() local btn_cancel_r = { --[[ [0] left ]] right_margin-btn_repair_r[2], --[[ [1] top ]] btn_repair_r[1], --[[ [2] width ]] btn_repair_r[2], --[[ [3] height ]] btn_repair_r[3] } btn_cancel:SetAutoDelete( true ) btn_cancel:SetWindowName( "btn_cancel" ) btn_cancel:Init( unpack( btn_cancel_r ) ) btn_cancel:SetText( translate( "btn_cancel" ) ) btn_cancel:SetTextAlign( CGameFont.alCenter ) btn_cancel:SetTextY( -1 ) self:Register( btn_cancel ) bkg_repair_wnd:AttachChild( btn_cancel ) ----------------------------------------------------------- TIME COST LABEL logf( "constructing lbl_repair_time" ) local lbl_repair_time = CUIStatic() local lbl_repair_time_r = { --[[ [0] left ]] left_margin, --[[ [1] top ]] btn_repair_r[1]-5, --[[ [2] width ]] size_w-(margin_size*2), --[[ [3] height ]] btn_repair_r[3] } lbl_repair_time:SetAutoDelete( true ) lbl_repair_time:SetWindowName( "lbl_repairable_items" ) lbl_repair_time:Init( unpack( lbl_repair_time_r ) ) lbl_repair_time:SetTextColor( GetARGB(255,0,0,0) ) lbl_repair_time:SetText( translate( "time_unknown" ) ) lbl_repair_time:SetTextAlign( CGameFont.alCenter ) lbl_repair_time:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_repair_time_take ) -------------------------------------------------- IMPROVED CONDITION LABEL logf( "constructing lbl_condition_result" ) local lbl_condition_result = CUIStatic() local lbl_condition_result_r = { --[[ [0] left ]] left_margin, --[[ [1] top ]] lbl_repair_time_r[1]-5, --[[ [2] width ]] 200, --[[ [3] height ]] btn_repair_r[3] } lbl_condition_result:SetAutoDelete( true ) lbl_condition_result:SetWindowName( "lbl_condition_result" ) lbl_condition_result:Init( unpack( lbl_condition_result_r ) ) lbl_condition_result:SetText( translate( "lbl_condition_result" ) ) lbl_condition_result:SetTextAlign( CGameFont.alRight ) lbl_condition_result:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_condition_result ) --------------------------------------------------- IMPROVE CONDITION VALUE logf( "constructing ebx_condition_result_v" ) local ebx_condition_result_v = CUIEditBox() local ebx_condition_result_v_r = { --[[ [0] left ]] lbl_condition_result_r[0]+lbl_condition_result_r[2]+5, --[[ [1] top ]] lbl_condition_result_r[1], --[[ [2] width ]] 40, --[[ [3] height ]] lbl_condition_result_r[3] } ebx_condition_result_v:SetAutoDelete( true ) ebx_condition_result_v:SetWindowName( "ebx_condition_result_v" ) ebx_condition_result_v:Init( unpack( ebx_condition_result_v_r ) ) ebx_condition_result_v:SetText("0") ebx_condition_result_v:SetNumbersOnly( true ); ebx_condition_result_v:SetTextAlignment( CGameFont.alRight ) ebx_condition_result_v:SetTextY( -1 ) ebx_condition_result_v:SetTextColor( GetARGB(255,255,0,0) ) bkg_repair_wnd:AttachChild( ebx_condition_result_v ) ------------------------------------- IMPROVED CONDITION LABEL PERCENT SIGN logf( "constructing lbl_condition_result_pct" ) local lbl_condition_result_pct = CUIStatic() local lbl_condition_result_pct_r = { --[[ [0] left ]] ebx_condition_result_v_r[0]+ebx_condition_result_v_r[2]+5, --[[ [1] top ]] ebx_condition_result_v_r[1], --[[ [2] width ]] 20, --[[ [3] height ]] ebx_condition_result_v_r[3] } lbl_condition_result_pct:SetAutoDelete( true ) lbl_condition_result_pct:SetWindowName( "lbl_condition_result_pct" ) lbl_condition_result_pct:Init( unpack( lbl_condition_result_pct_r ) ) lbl_condition_result_pct:SetText( translate( "pct" ) ) lbl_condition_result_pct:SetTextAlign( CGameFont.alLeft ) lbl_condition_result_pct:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_condition_result_pct ) --------------------------------------------------- IMPROVE CONDITION LABEL logf( "constructing lbl_condition_improve" ) local lbl_condition_improve = CUIStatic() local lbl_condition_improve_r = { --[[ [0] left ]] lbl_condition_result_r[0], --[[ [1] top ]] (lbl_condition_result_r[1]-lbl_condition_result_r[3])-5, --[[ [2] width ]] lbl_condition_result_r[2], --[[ [3] height ]] lbl_condition_result_r[3] } lbl_condition_improve:SetAutoDelete( true ) lbl_condition_improve:SetWindowName( "lbl_condition_improve" ) lbl_condition_improve:Init( unpack( lbl_condition_improve_r ) ) lbl_condition_improve:SetText( translate( "lbl_condition_improve" ) ) lbl_condition_improve:SetTextAlign( CGameFont.alRight ) lbl_condition_improve:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_condition_improve ) --------------------------------------------------- IMPROVE CONDITION VALUE logf( "constructing ebx_condition_improve_v" ) local ebx_condition_improve_v = CUIEditBox() local ebx_condition_improve_v_r = { --[[ [0] left ]] ebx_condition_result_v_r[0], --[[ [1] top ]] lbl_condition_improve_r[1], --[[ [2] width ]] ebx_condition_result_v_r[2], --[[ [3] height ]] ebx_condition_result_v_r[3] } ebx_condition_improve_v:SetAutoDelete( true ) ebx_condition_improve_v:SetWindowName( "ebx_condition_improve_v" ) ebx_condition_improve_v:Init( unpack( ebx_condition_improve_v_r ) ) ebx_condition_improve_v:SetText("0") ebx_condition_improve_v:SetNumbersOnly( true ); ebx_condition_improve_v:SetTextAlignment( CGameFont.alRight ) ebx_condition_improve_v:SetTextY( -1 ) ebx_condition_improve_v:SetTextColor( GetARGB(255,255,0,0) ) bkg_repair_wnd:AttachChild( ebx_condition_improve_v ) -------------------------------------- IMPROVE CONDITION LABEL PERCENT SIGN logf( "constructing lbl_condition_improve_pct" ) local lbl_condition_improve_pct = CUIStatic() local lbl_condition_improve_pct_r = { --[[ [0] left ]] lbl_condition_result_pct_r[0], --[[ [1] top ]] lbl_condition_improve_r[1], --[[ [2] width ]] lbl_condition_result_pct_r[2], --[[ [3] height ]] lbl_condition_result_pct_r[3] } lbl_condition_improve_pct:SetAutoDelete( true ) lbl_condition_improve_pct:SetWindowName( "lbl_condition_improve_pct" ) lbl_condition_improve_pct:Init( unpack( lbl_condition_improve_pct_r ) ) lbl_condition_improve_pct:SetText( translate( "pct" ) ) lbl_condition_improve_pct:SetTextAlign( CGameFont.alLeft ) lbl_condition_improve_pct:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_condition_improve_pct ) --------------------------------------------------- CURRENT CONDITION LABEL logf( "constructing lbl_condition_current" ) local lbl_condition_current = CUIStatic() local lbl_condition_current_r = { --[[ [0] left ]] lbl_condition_improve_r[0], --[[ [1] top ]] (lbl_condition_improve_r[1]-lbl_condition_improve_r[3])-5, --[[ [2] width ]] lbl_condition_improve_r[2], --[[ [3] height ]] lbl_condition_improve_r[3] } lbl_condition_current:SetAutoDelete( true ) lbl_condition_current:SetWindowName( "lbl_condition_current" ) lbl_condition_current:Init( unpack( lbl_condition_current_r ) ) lbl_condition_current:SetText( translate( "lbl_condition_current" ) ) lbl_condition_current:SetTextAlign( CGameFont.alRight ) lbl_condition_current:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_condition_current ) --------------------------------------------------- CURRENT CONDITION VALUE logf( "constructing ebx_condition_current_v" ) local ebx_condition_current_v = CUIEditBox() local ebx_condition_current_v_r = { --[[ [0] left ]] ebx_condition_improve_v_r[0], --[[ [1] top ]] lbl_condition_current_r[1], --[[ [2] width ]] ebx_condition_improve_v_r[2], --[[ [3] height ]] ebx_condition_improve_v_r[3] } ebx_condition_current_v:SetAutoDelete( true ) ebx_condition_current_v:SetWindowName( "ebx_condition_current_v" ) ebx_condition_current_v:Init( unpack( ebx_condition_current_v_r ) ) ebx_condition_current_v:SetText("0") ebx_condition_current_v:SetTextAlign( CGameFont.alRight ) ebx_condition_current_v:SetTextY( -1 ) ebx_condition_current_v:Enable(false) -- read only bkg_repair_wnd:AttachChild( ebx_condition_current_v ) -------------------------------------- CURRENT CONDITION LABEL PERCENT SIGN logf( "constructing lbl_condition_current_pct" ) local lbl_condition_current_pct = CUIStatic() local lbl_condition_current_pct_r = { --[[ [0] left ]] ebx_condition_improve_v_r[0], --[[ [1] top ]] lbl_condition_current_r[1], --[[ [2] width ]] ebx_condition_improve_v_r[2], --[[ [3] height ]] ebx_condition_improve_v_r[3] } lbl_condition_current_pct:SetAutoDelete( true ) lbl_condition_current_pct:SetWindowName( "lbl_condition_current_pct" ) lbl_condition_current_pct:Init( unpack( lbl_condition_current_pct ) ) lbl_condition_current_pct:SetText( translate( "pct" ) ) lbl_condition_current_pct:SetTextAlign( CGameFont.alLeft ) lbl_condition_current_pct:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_condition_current_pct ) -- right aligned, horizontally reversed control creation ---------------------------------------------------- MONEY REMAINING RUBLES logf( "constructing lbl_money_remaining_ru" ) local lbl_money_remaining_ru = CUIStatic() local lbl_money_remaining_ru_r = { --[[ [0] left ]] right_margin-30, --[[ [1] top ]] lbl_condition_result_r[1], --[[ [2] width ]] 30, --[[ [3] height ]] lbl_condition_result_r[3] } lbl_money_remaining_ru:SetAutoDelete( true ) lbl_money_remaining_ru:SetWindowName( "lbl_money_remaining_ru" ) lbl_money_remaining_ru:Init( unpack( lbl_money_remaining_ru_r ) ) lbl_money_remaining_ru:SetText( translate( "rubles" ) ) lbl_money_remaining_ru:SetTextAlign( CGameFont.alLeft ) lbl_money_remaining_ru:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_money_remaining_ru ) ----------------------------------------------------- MONEY REMAINING VALUE logf( "constructing ebx_money_remaining_v" ) local ebx_money_remaining_v = CUIEditBox() local ebx_money_remaining_v_r = { --[[ [0] left ]] lbl_money_remaining_ru_r[0]-lbl_money_remaining_ru_r[2]-5, --[[ [1] top ]] ebx_money_remaining_v_r[1], --[[ [2] width ]] 120, --[[ [3] height ]] ebx_money_remaining_v_r[3] } ebx_money_remaining_v:SetAutoDelete( true ) ebx_money_remaining_v:SetWindowName( "ebx_money_remaining_v" ) ebx_money_remaining_v:Init( unpack( ebx_money_remaining_v_r ) ) ebx_money_remaining_v:SetText( money ) ebx_money_remaining_v:SetNumbersOnly( true ); ebx_money_remaining_v:SetTextAlignment( CGameFont.alRight ) ebx_money_remaining_v:SetTextY( -1 ) ebx_money_remaining_v:SetTextColor( GetARGB(255,255,0,0) ) bkg_repair_wnd:AttachChild( ebx_money_remaining_v ) ----------------------------------------------------- MONEY REMAINING LABEL logf( "constructing lbl_money_remaining" ) local lbl_money_remaining = CUIStatic() local lbl_money_remaining_r = { --[[ [0] left ]] (ebx_money_remaining_v_r[0]-ebx_money_remaining_v_r[2])-5, --[[ [1] top ]] ebx_money_remaining_v_r[1], --[[ [2] width ]] 200, --[[ [3] height ]] ebx_money_remaining_v_r[3] } lbl_money_remaining:SetAutoDelete( true ) lbl_money_remaining:SetWindowName( "lbl_money_remaining" ) lbl_money_remaining:Init( unpack( lbl_money_remaining_r ) ) lbl_money_remaining:SetText( translate( "lbl_money_remaining" ) ) lbl_money_remaining:SetTextAlign( CGameFont.alRight ) lbl_money_remaining:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_money_remaining ) -------------------------------------------------------- SPEND MONEY RUBLES logf( "constructing lbl_money_spending_ru" ) local lbl_money_spending_ru = CUIStatic() local lbl_money_spending_ru_r = { --[[ [0] left ]] lbl_money_remaining_ru_r[0], --[[ [1] top ]] (lbl_money_remaining_ru_r[1]-lbl_money_remaining_ru_r[3])-5, --[[ [2] width ]] lbl_money_remaining_ru_r[2], --[[ [3] height ]] lbl_money_remaining_ru_r[3] } lbl_money_spending_ru:SetAutoDelete( true ) lbl_money_spending_ru:SetWindowName( "lbl_money_spending_ru" ) lbl_money_spending_ru:Init( unpack( lbl_money_remaining_r ) ) lbl_money_spending_ru:SetText( translate( "rubles" ) ) lbl_money_spending_ru:SetTextAlign( CGameFont.alLeft ) lbl_money_spending_ru:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_money_spending_ru ) --------------------------------------------------------- SPEND MONEY VALUE logf( "constructing ebx_money_spending_v" ) local ebx_money_spending_v = CUIEditBox() local ebx_money_spending_v_r = { --[[ [0] left ]] ebx_money_remaining_v_r[0], --[[ [1] top ]] lbl_money_spending_ru_r[1], --[[ [2] width ]] ebx_money_remaining_v_r[2], --[[ [3] height ]] ebx_money_remaining_v_r[3] } ebx_money_spending_v:SetAutoDelete( true ) ebx_money_spending_v:SetWindowName( "ebx_money_spending_v" ) ebx_money_spending_v:Init( unpack( ebx_money_spending_v_r ) ) ebx_money_spending_v:SetText( "0" ) ebx_money_spending_v:SetNumbersOnly( true ); ebx_money_spending_v:SetTextAlignment( CGameFont.alRight ) ebx_money_spending_v:SetTextY( -1 ) ebx_money_spending_v:SetTextColor( GetARGB(255,255,0,0) ) bkg_repair_wnd:AttachChild( ebx_money_spending_v ) --------------------------------------------------------- SPEND MONEY LABEL logf( "constructing lbl_money_spending" ) local lbl_money_spending = CUIStatic() local ebx_money_spending_v_r = { --[[ [0] left ]] lbl_money_remaining_r[0], --[[ [1] top ]] lbl_money_spending_ru_r[1], --[[ [2] width ]] lbl_money_remaining_r[2], --[[ [3] height ]] lbl_money_remaining_r[3] } lbl_money_spending:SetAutoDelete( true ) lbl_money_spending:SetWindowName( "lbl_money_spending" ) lbl_money_spending:Init( unpack( ebx_money_spending_v_r ) ) lbl_money_spending:SetText( translate( "lbl_money_spending" ) ) lbl_money_spending:SetTextAlign( CGameFont.alRight ) lbl_money_spending:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_money_spending ) ------------------------------------------------------ CURRENT MONEY RUBLES logf( "constructing lbl_money_current_ru" ) local lbl_money_current_ru = CUIStatic() local lbl_money_current_ru_r = { --[[ [0] left ]] lbl_money_remaining_ru_r[0], --[[ [1] top ]] (lbl_money_spending_ru_r[1]-lbl_money_spending_ru_r[3])-5, --[[ [2] width ]] lbl_money_remaining_ru_r[2], --[[ [3] height ]] lbl_money_remaining_ru_r[3] } lbl_money_current_ru:SetAutoDelete( true ) lbl_money_current_ru:SetWindowName( "lbl_money_current_ru" ) lbl_money_current_ru:Init( unpack( lbl_money_current_ru_r ) ) lbl_money_current_ru:SetText( translate( "rubles" ) ) lbl_money_current_ru:SetTextAlign( CGameFont.alLeft ) lbl_money_current_ru:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_money_current_ru ) ------------------------------------------------------- CURRENT MONEY VALUE logf( "constructing lbl_money_current_v" ) local lbl_money_current_v = CUIStatic() local lbl_money_current_v_r = { --[[ [0] left ]] ebx_money_remaining_v_r[0], --[[ [1] top ]] lbl_money_current_ru_r[1], --[[ [2] width ]] ebx_money_remaining_v_r[2], --[[ [3] height ]] ebx_money_remaining_v_r[3] } lbl_money_current_v:SetAutoDelete( true ) lbl_money_current_v:SetWindowName( "lbl_money_current_v" ) lbl_money_current_v:Init( unpack( lbl_money_current_v_r ) ) lbl_money_current_v:SetText( money ) lbl_money_current_v:SetTextAlign( CGameFont.alRight ) lbl_money_current_v:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_money_current_v ) ------------------------------------------------------- CURRENT MONEY LABEL logf( "constructing lbl_money_current" ) local lbl_money_current = CUIStatic() local lbl_money_current_r = { --[[ [0] left ]] lbl_money_remaining_r[0], --[[ [1] top ]] lbl_money_current_ru_r[1], --[[ [2] width ]] lbl_money_remaining_r[2], --[[ [3] height ]] lbl_money_remaining_r[3] } lbl_money_current:SetAutoDelete( true ) lbl_money_current:SetWindowName( "lbl_money_current" ) lbl_money_current:Init( unpack( lbl_money_current_r ) ) lbl_money_spending:SetText( translate( "lbl_money_current" ) ) lbl_money_current:SetTextAlign( CGameFont.alRight ) lbl_money_current:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_money_current ) -- Switch to creating controls from top down here ------------------------------------------------------ RUSH REPAIR CHECKBOX logf( "constructing chb_repair_rush" ) local chb_repair_rush = CUICheckButton() local chb_repair_rush_r = { --[[ [0] left ]] right_margin-btn_repair_r[2], --[[ [1] top ]] top_margin, --[[ [2] width ]] btn_repair_r[2], --[[ [3] height ]] btn_repair_r[3] } chb_repair_rush:SetAutoDelete( true ) chb_repair_rush:SetWindowName( "chb_repair_rush" ) chb_repair_rush:Init( unpack( chb_repair_rush_r ) ) chb_repair_rush:SetText( translate( "chb_repair_rush" ) ) chb_repair_rush:SetTextAlign( CGameFont.alCenter ) chb_repair_rush:SetTextY( -1 ) self:Register( chb_repair_rush ) bkg_repair_wnd:AttachChild( chb_repair_rush ) ----------------------------------------------- REPAIRABLE ITEMS LIST LABEL logf( "constructing lbl_repairable_items" ) local lbl_repairable_items = CUIStatic() local lbl_repairable_items_r = { --[[ [0] left ]] left_margin, --[[ [1] top ]] top_margin, --[[ [2] width ]] (size_w-(margin_size*2))/2, --[[ [3] height ]] btn_repair_r[3] } lbl_repairable_items:SetAutoDelete( true ) lbl_repairable_items:SetWindowName( "lbl_repairable_items" ) lbl_repairable_items:Init( unpack( lbl_repairable_items_r ) ) lbl_repairable_items:SetText( translate( "lbl_repairable_items" ) ) lbl_repairable_items:SetTextAlign( CGameFont.alCenter ) lbl_repairable_items:SetTextY( -1 ) bkg_repair_wnd:AttachChild( lbl_repairable_items ) ----------------------------------------------------- REPAIRABLE ITEMS LIST logf( "constructing lst_repairable_items" ) local lst_repairable_items = CUIListWnd() local lst_repairable_items_r = { --[[ [0] left ]] lbl_repairable_items_r[0], --[[ [1] top ]] lbl_repairable_items_r[1]+lbl_repairable_items_r[3]+5, --[[ [2] width ]] size_w-(margin_size*2), --[[ [3] height ]] size_h-(5+lbl_money_current_ru_r[3]) } lst_repairable_items:SetAutoDelete( true ) lst_repairable_items:SetWindowName( "lst_repairable_items" ) lst_repairable_items:SetItemHeight( 20 ) lst_repairable_items:Init( unpack( lst_repairable_items_r ) ) lst_repairable_items:EnableScrollBar( true ) lst_repairable_items:ShowSelectedItem( true ) self:Register( lst_repairable_items ) bkg_repair_wnd:AttachChild( lst_repairable_items ) self.items = find_repairable_items( db.actor ) local lsi_item, lsi_item_name, item, item_condition, item_condition_percent for item in self.items do item_condition = item:condition() item_condition_percent = math.floor(item_condition*100) lsi_item_name = "lsi_"..item:id().."_"..item_condition_percent -------------------------------------------- REPAIRABLE ITEMS LIST ITEM logf( "constructing " .. lsi_item_name ) lsi_item = CUIListItem() lsi_item:SetAutoDelete( true ) lsi_item:SetWindowName( lsi_item_name ) lsi_item:Init( 0, 0, lst_repairable_items_r[2], 20 ) lsi_item:SetText( item:name().." ("..item_condition_percent..translate( "pct" )..")" ) lsi_item:SetTextAlign( CGameFont.alCenter ) lsi_item:SetTextY( -1 ) lsi_item:SetTextColor( condition_as_color( item_condition ) ) lst_repairable_items:AddItem( lsi_item ) end logf( "uiRepairDialog:InitControls() complete" ) end function register_callbacks( element, event_action_pairs ) logf( "register_callbacks() called" ) for event, action in event_action_pairs do self:AddCallback( element, event, self, action ) end logf( "register_callbacks() complete" ) end function uiRepairDialog:InitCallBacks() logf( "uiRepairDialog:InitCallBacks() called" ) register_callbacks( "chb_repair_rush", { { ui_events.CHECK_BUTTON_SET, "on_chb_repair_rush_set" }, { ui_events.CHECK_BUTTON_RESET, "on_chb_repair_rush_reset" } } ) register_callbacks( "ebx_condition_improve_v", { { ui_events.EDIT_TEXT_CHANGED, "on_ebx_condition_improve_v_changed" }, { ui_events.EDIT_TEXT_COMMIT, "on_ebx_condition_improve_v_commit" } } ) register_callbacks( "ebx_condition_result_v", { { ui_events.EDIT_TEXT_CHANGED, "on_ebx_condition_result_v_changed" }, { ui_events.EDIT_TEXT_COMMIT, "on_ebx_condition_result_v_commit" } } ) register_callbacks( "ebx_money_spending_v", { { ui_events.EDIT_TEXT_CHANGED, "on_ebx_money_spending_v_changed" }, { ui_events.EDIT_TEXT_COMMIT, "on_ebx_money_spending_v_commit" } } ) register_callbacks( "ebx_money_remaining_v", { { ui_events.EDIT_TEXT_CHANGED, "on_ebx_money_remaining_v_changed" }, { ui_events.EDIT_TEXT_COMMIT, "on_ebx_money_remaining_v_commit" } } ) register_callbacks( "btn_repair", { { ui_events.BUTTON_CLICKED, "on_btn_repair_clicked" } } ) register_callbacks( "btn_cancel", { { ui_events.BUTTON_CLICKED, "on_btn_cancel_clicked" } } ) logf( "uiRepairDialog:InitCallBacks() complete" ) end function uiRepairDialog:Open() logf( "uiRepairDialog:Open() called") holder = self:GetHolder() self:Show( true ) self.Enabled( true ) if holder == nil then holder = level end if not self.isOpen then holder.start_stop_menu( self, true ) end self.IsOpen = true logf( "uiRepairDialog:Open() complete") end function uiRepairDialog:Close() logf( "uiRepairDialog:Close() called") holder = self:GetHolder() self:Show( false ) self.Enabled( false ) if holder == nil then holder = level end if self.isOpen then holder.start_stop_menu( self, true ) end self.IsOpen = false logf( "uiRepairDialog:Close() complete") end function uiRepairDialog:RecalcMoney( budget ) logf( "uiRepairDialog:RecalcMoney() called") uiRepairDialog:Recalc( 1, budget ) logf( "uiRepairDialog:RecalcMoney() complete") end function uiRepairDialog:RecalcCondition( condition_target ) logf( "uiRepairDialog:RecalcCondition() called") uiRepairDialog:Recalc( condition_target, nil ) logf( "uiRepairDialog:RecalcCondition() complete") end function uiRepairDialog:Recalc( condition_target, budget ) logf( "uiRepairDialog:Recalc() called") -- TODO: Factor in 'goodwill' towards db.actor local money = db.actor:money() if condition_target == nil or condition_target > 1 then condition_target = 1 end self.valid_repair = true if budget == nil then budget = money elseif budget > money then budget = money end self.last_recalc_params = { condition_target, budget } local lst_repairable_items = self:GetListWnd( "lst_repairable_items" ) local lst_repairable_items_index = list:GetSelectedItem() if lst_repairable_items_index == -1 then logf( "uiRepairDialog:Recalc() complete") return end local repairable_item = self.items[index] local chb_repair_rush = self:GetCheckButton( "chb_repair_rush" ) local ebx_condition_current_v = self:GetEditBox( "ebx_condition_current_v" ) local ebx_condition_improve_v = self:GetEditBox( "ebx_condition_improve_v" ) local ebx_condition_result_v = self:GetEditBox( "ebx_condition_result_v" ) local ebx_money_spending_v = self:GetEditBox( "ebx_money_spending_v" ) local ebx_money_remaining_v = self:GetEditBox( "ebx_money_remaining_v" ) if money <= 0 then self.valid_repair = false ebx_condition_current_v:SetTextColor( color_invalid ) end local rush_state = chb_repair_rush:GetCheck() local condition = repairable_item:condition() local condition_value = math.floor( condition * 10000 ) / 100 local condition_target_value local condition_amount, expense if condition > condition_target then condition_target = condition condition_target_value = condition_value condition_ammount = 0 expense = 0 self.valid_repair = false ebx_money_spending_v:SetTextColor( color_invalid ) ebx_condition_improve_v:SetTextColor( color_invalid ) else condition_target_value = math.floor( condition_target * 10000 ) / 100 condition_amount, expense = calculate_repairable( self.cost_modifier, condition_value, condition_target, budget ) ebx_money_spending_v:SetTextColor( color_valid ) ebx_condition_improve_v:SetTextColor( color_valid ) end local condition_amount_value = math.floor( condition_amount * 10000 ) / 100 ebx_condition_current_v:SetText( condition_value ) ebx_condition_result_v:SetText( condition_target_value ) ebx_condition_improve_v:SetText( condition_amount_value ) local balance = money - expense ebx_money_spending_v:SetText( expense ) ebx_money_remaining_v:SetText( balance ) if balance < 0 then self.valid_repair = false ebx_money_remaining_v:SetTextColor( color_invalid ) else ebx_money_remaining_v:SetTextColor( color_valid ) end ebx_condition_current_v:SetTextColor( condition_as_color( condition ) ) ebx_condition_result_v:SetTextColor( condition_as_color( condition_target ) ) logf( "uiRepairDialog:Recalc() complete") end function uiRepairDialog:on_btn_cancel_clicked() logf( "on_btn_cancel_clicked() called") self:Close() logf( "on_btn_cancel_clicked() complete") end function uiRepairDialog:on_chb_repair_rush_set() logf( "on_chb_repair_rush_set() called") self:Recalc( unpack( self.last_calc_value ) ) logf( "on_chb_repair_rush_set() complete") end function uiRepairDialog:on_chb_repair_rush_reset() logf( "on_chb_repair_rush_reset() called") self:Recalc( unpack( self.last_calc_value ) ) logf( "on_chb_repair_rush_reset() complete") end function uiRepairDialog:on_ebx_condition_improve_v_changed() logf( "on_ebx_condition_improve_v_changed() called") local ebx_condition_improve_v = self:GetEditBox( "ebx_condition_improve_v" ) self:RecalcCondition( tonumber( ebx_condition_improve_v:GetText() ) ) logf( "on_ebx_condition_improve_v_changed() complete") end function uiRepairDialog:on_ebx_condition_improve_v_commit() logf( "on_ebx_condition_improve_v_commit() called") local ebx_condition_improve_v = self:GetEditBox( "ebx_condition_improve_v" ) self:RecalcCondition( tonumber( ebx_condition_improve_v:GetText() ) ) logf( "on_ebx_condition_improve_v_commit() complete") end function uiRepairDialog:on_ebx_condition_result_v_changed() logf( "on_ebx_condition_result_v_changed() called") local ebx_condition_result_v = self:GetEditBox( "ebx_condition_result_v" ) self:RecalcCondition( tonumber( ebx_condition_result_v:GetText() ) ) logf( "on_ebx_condition_result_v_changed() complete") end function uiRepairDialog:on_ebx_ebx_condition_result_v_commit() logf( "on_ebx_ebx_condition_result_v_commit() called") local ebx_condition_result_v = self:GetEditBox( "ebx_condition_result_v" ) self:RecalcCondition( tonumber( ebx_condition_result_v:GetText() ) ) logf( "on_ebx_ebx_condition_result_v_commit() complete") end function uiRepairDialog:on_ebx_money_spending_v_changed() logf( "on_ebx_money_spending_v_commit() called") local ebx_money_spending_v = self:GetEditBox( "ebx_money_spending_v" ) self:RecalcMoney( tonumber( ebx_money_spending_v:GetText() ) ) logf( "on_ebx_money_spending_v_commit() complete") end function uiRepairDialog:on_ebx_money_spending_v_commit() logf( "on_ebx_money_spending_v_commit() called") local ebx_money_spending_v = self:GetEditBox( "ebx_money_spending_v" ) self:RecalcMoney( tonumber( ebx_money_spending_v:GetText() ) ) logf( "on_ebx_money_spending_v_commit() complete") end function uiRepairDialog:on_ebx_money_remaining_v_changed() logf( "on_ebx_money_remaining_v_changed() called") local ebx_money_remaining_v = self:GetEditBox( "ebx_money_remaining_v" ) self:RecalcMoney( tonumber( ebx_money_remaining_v:GetText() ) ) logf( "on_ebx_money_remaining_v_changed() complete") end function uiRepairDialog:on_ebx_money_remaining_v_commit() logf( "on_ebx_money_remaining_v_commit() called") local ebx_money_remaining_v = self:GetEditBox( "ebx_money_remaining_v" ) self:RecalcMoney( tonumber( ebx_money_remaining_v:GetText() ) ) logf( "on_ebx_money_remaining_v_commit() complete") end function uiRepairDialog:on_btn_repair_clicked() logf( "on_btn_repair_clicked() called") local lst_repairable_items = self:GetListWnd( "lst_repairable_items" ) local index = list:GetSelectedItem() if index == -1 then return end local item = self.items[index] local ebx_condition_result_v = self:GetEditBox( "ebx_condition_result_v" ) local ebx_money_spending_v = self:GetEditBox( "ebx_money_spending_v" ) -- db.actor:transfer_money( ebx_money_spending_v:GetText(), self.repairer ) -- TODO: Hide weapon in inaccessible virtual stash with repair and date info -- the player will be able to retrieve his weapon by asking the repairer -- even if the repairs aren't complete, and still get a partial repair -- maybe partial to full refunds depending on goodwill and time spent repairing? self:Close() logf( "on_btn_repair_clicked() complete") end -- virtual function (overloaded?) function uiRepairDialog:OnKeyboard( dik, keyboard_action ) CUIScriptWnd.OnKeyboard( self, dik, keyboard_action ) -- translate DirectInputKey to bound function (in user.ltx) local bind = dik_to_bind(dik) if keyboard_action == ui_events.WINDOW_KEY_PRESSED then logf("pressed dik=%d bind=%d", dik, bind ) elseif keyboard_action == ui_events.WINDOW_KEY_RELEASED then logf("released dik=%d bind=%d", dik, bind ) end if bind == key_bindings.kQUIT then self:Close() end return true -- catch all keys. end