#!ruby # -*- mode: ruby; coding: utf-8 -*- # Last updated: <2018/02/27 02:46:04 +0900> # # FXRuby FileDialog sample require "fox16" include Fox class MyMainWindow < FXMainWindow def initialize(app, title = "Generate Tilemap collision data") # main is window class # mw = super(app, title, :width => 480, :height => 360) mw = super(app, title) # create layout # pack = FXPacker.new(mw, :opts => LAYOUT_FILL) pack = FXPacker.new(mw) @frms = [] tbls = [ { :label => "Source Tiled JSON", :type => 0, :len => 50 }, { :label => "Source PNG Image", :type => 0, :len => 50 }, { :label => "Collision layer name", :type => 1, :len => 20 }, { :label => "layer name (overwrite)", :type => 1, :len => 20 }, { :label => "Null code", :type => 1, :len => 5 }, { :label => "Output JSON", :type => 0, :len => 50 }, ] tbls.each_with_index do |dt, i| s = dt[:label] kind = dt[:type] l = dt[:len] # create frame frm = FXHorizontalFrame.new( pack, # :opts => LAYOUT_SIDE_LEFT|LAYOUT_SIDE_TOP|LAYOUT_FIX_WIDTH, #:padLeft=>0,:padRight=>0,:padTop=>0,:padBottom=>0, # :width=>300 ) # create label FXLabel.new(frm, s) # create textfield tf = FXTextField.new(frm, l) case kind when 0 # create button btn = FXButton.new(frm, "...") # set button event btn.connect(SEL_COMMAND) do |sender, sel, data| # show File dialog dialog = FXFileDialog.new(self, "Select file.") dialog.patternList = [ "All Files (*)", "JSON (*.json)", "PNG Image (*.png)", ] dialog.selectMode = SELECTFILE_ANY if dialog.execute != 0 tf.text = dialog.filename end end @frms.push( { :type => kind, :textfield => tf, :button => btn } ) when 1 @frms.push( {:type => kind, :textfield => tf } ) end end @frms[2][:textfield].text = "layer0" @frms[4][:textfield].text = "0" frm = FXHorizontalFrame.new( pack, :opts => LAYOUT_SIDE_RIGHT|LAYOUT_SIDE_TOP, :width => 300, ) sx, sy = 32, 8 btn = FXButton.new(frm, "Check", :padLeft => sx, :padRight => sx, :padTop => sy, :padBottom => sy) btn.connect(SEL_COMMAND) do |sender, sel, data| # dump input string jsonfile = @frms[0][:textfield].text pngfile = @frms[1][:textfield].text layername = @frms[2][:textfield].text layername_s = @frms[3][:textfield].text nullcode = @frms[4][:textfield].text.to_i outfile = @frms[5][:textfield] s = [ "json file : #{jsonfile}", "png file : #{pngfile}", "layer name : #{layername}", "layer name sub : #{layername_s}", "null code : #{nullcode}", "output file : #{outfile}", ].join("\n") msgBox = FXMessageBox.new(btn, "Result", s, :opts => MBOX_OK) msgBox.execute end end def create super show(PLACEMENT_SCREEN) end end if __FILE__ == $0 FXApp.new do |app| mw = MyMainWindow.new(app) app.create # mw.show(PLACEMENT_SCREEN) app.run end end