Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


CEListBox - MultiSelect items

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sat Mar 03, 2018 9:43 pm    Post subject: CEListBox - MultiSelect items Reply with quote

Refer to CE documentation :

Code:
createListBox(owner): Creates a ListBox class object which belongs to the given owner. Owner can be any object inherited from WinControl

properties
  MultiSelect: boolean - When set to true you can select multiple items
  Items: Strings - Strings derived object containings all the items in the list
  Selected[] - Returns true if the given line is selected. Use Items.Count-1 to find out the max index
  ItemIndex: integer - Get selected index. -1 is nothing selected
  Canvas: Canvas - The canvas object used to render on the object

methods
  clear()
  clearSelection() : Deselects all items in the list
  selectAll(): Selects all items in the list
  getItems(): Returns a strings object
  setItems(Strings): sets a strings object to the listbox
  getItemIndex()
  setItemIndex(integer)
  getCanvas()


Questions :
1. How to select multi items from CEListbox ? i.e : pick item1, item2 from 14 items. Or pick item1 and item5 from 14 items.
2. Can we highlighted selected items ?

Tried (not work) :
Code:
 list1 = UDF1.CEListBox1
  list2 = UDF1.CEListBox2

  list1.MultiSelect = true
  count = list1.Items.Count

  for i = 0,i<count-1, i+1 do
   if list1.items[i].Selected then
    x = list1.items[i]
    list2.items.Add(x)
   end
  end


should easy If I am us C# :

Code:
private void MoveListBoxItems(ListBox source, ListBox destination)
{       
    ListBox.SelectedObjectCollection sourceItems = source.SelectedItems;
    foreach (var item in sourceItems)
    {
        destination.Items.Add(item);
    }
    while (source.SelectedItems.Count > 0)
    {
        source.Items.Remove(source.SelectedItems[0]);
    }
}

//Use: On the click event of your move from 1 to 2 button:

MoveListBoxItems(listBox1, listBox2);

//To move them back:

MoveListBoxItems(listBox2, listBox1);


any solution ?. Thank you

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Mar 04, 2018 6:09 am    Post subject: This post has 1 review(s) Reply with quote

Code:
for i = 0,i<count-1, i+1 do
this is not how lua for loops work Smile
Code:
for i=0,list1.Count-1 -- or count-1 if stored, optionally with ",1" at the end to explicitly show that it's i=i+1


Second, Selected is an array of booleans on the listbox (and yeah, that's how Pascal/Lazarus TListBox works...), .Items[whatever] is just a string because Items gives you access to the underlying stringlist of items. So a working example:

Code:
if not UDF1 or false then
  UDF1 = createForm()

  list1 = createListBox(UDF1)
  list1.Items.setText("1\n2\n3\n4\n")
  list1.MultiSelect = true
  list2 = createListBox(UDF1)
  list2.Top = list1.Height
end

count = list1.Items.Count

for i = 0,count-1 do
 if list1.Selected[i] then
  list2.items.Add(list1.items[i])
 else
   --print(list1.Items[i],'not selected')
 end
end

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sun Mar 04, 2018 8:29 am    Post subject: Reply with quote

Quote:
for i = 0,i<count-1, i+1 do
this is not how lua for loops work Smile


This is stupid mis-typed by me, typically.... Shocked
it must be i = i + 1 to to refer i++ usually use on C++. Hhhhh.....

By the way, your example code is work properly. Thank you.
And for 2nd question, since I don't find any solution to highlighted selected items (by default
that already done by CE itself with show 'blue prompt' for each items selected),
then if want 'give a mark' to selected items :


Code:
count = list1.Items.Count

for i = 0,count-1 do
 if list1.Selected[i] then
  sltd_item = list1.items[i]..'  '..string.rep(string.char(17),2)
  list1.items[i] = sltd_item
  list2.items.Add(list1.items[i])
 else
   --print(list1.Items[i],'not selected')
 end
end


In case no visualization if selecting items not in order, i.e : select item 1, 2 and 7.
Of course that code above will put under a function.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Mar 04, 2018 8:54 am    Post subject: Reply with quote

Hm, I'm not quite sure what you mean, I get a blue highlight in windows 10


As for the code, not sure what string.char(17) is meant to be but that's a non-printable character in ascii...I changed it to '*' in the image above. But changing it means you'd also have to deal with the mark being there whenever you go to use the values so if you didn't want to do that then you might instead add labels or or something next to the list box and update those based on what's selected (though if the list is long enough to need a scrollbar then that may not be possible since I don't see a way to find which is currently being displayed...).

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Mon Mar 05, 2018 4:04 pm    Post subject: Reply with quote

Can we expect an update?
For 4.1 Wink


http://forum.cheatengine.org/viewtopic.php?p=5736889#5736889

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Mon Mar 05, 2018 10:51 pm    Post subject: Reply with quote

Aylin wrote:
Can we expect an update?
For 4.1 Wink

http://forum.cheatengine.org/viewtopic.php?p=5736889#5736889


Yeah..something like this :



Capture.JPG
 Description:
 Filesize:  24.34 KB
 Viewed:  8137 Time(s)

Capture.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Tue Mar 06, 2018 4:30 am    Post subject: Reply with quote

Corroder wrote:
Yeah..something like this :


Thanks @Corroder

I hope we have a chance to add to the current Trainer. Smile

EDIT:
Seeing People are starting to be affected. Wink

http://forum.cheatengine.org/viewtopic.php?p=5736989#5736989

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Wed Mar 14, 2018 9:31 am    Post subject: Reply with quote

Quote:
I hope we have a chance to add to the current Trainer.

EDIT:
Seeing People are starting to be affected


Just goes to semi pro :

https://youtu.be/pwBsDrFQEic

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Wed Mar 14, 2018 10:00 am    Post subject: Reply with quote

I guess there is still no multiple selection and installation fixes?
or coding ideas may be incompatible?
The sliding menus are still beautiful.
You know how to have fun, @Corroder. Wink

https://www.youtube.com/watch?v=pwBsDrFQEic&feature=youtu.be

The old encoding meets the multiple list in its own folder.
Multiple selection in a separate folder may still require proper encoding.

Code:
--Corroder's code
function exploMP3()
load_dialog = createOpenDialog(self)
load_dialog.InitalDir = os.getenv('%USERPROFILE%')
load_dialog.execute()
file = load_dialog.FileName
if file then
  local path, name = file:match('(.*\\)(.*)%.mp3')
  if name then -- might not be mp3 since it was not forced in dialog
    UDF1.CEComboBox1.Items.add(name)
  end
end
end
------ FreeER Code:
UDF1.CEComboBox1.ItemIndex = -1
UDF1.CEComboBox1.OnChange = function(thecombobox)
  local name = thecombobox.Items[thecombobox.ItemIndex]
  local path = TrainerOrigin .. name .. '.mp3'
--  print(path)
  playMP3(path)
  volumeMP3(UDF1.CETrackBar1.Position*10)
end
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Wed Mar 14, 2018 7:16 pm    Post subject: Reply with quote

Quote:
I guess there is still no multiple selection and installation fixes?
or coding ideas may be incompatible?


I am not sure what you mean with 'multiple selection'.
is multiple selection to select songs to play or is multiple selection files when execute open dialog, so next selected files will add to your combobox.

Anyway, what ever....

Code:
--- make a form with default name = UDF1
--- add a combobox to UDF1 with default name
--- add a openDialog to UDF1 with default name
--- then try these code below

combobox = UDF1.CEComboBox1
load_dialog = UDF1.CEOpenDialog1

load_dialog.InitalDir = os.getenv('%USERPROFILE%')
load_dialog.Filter = 'MP3 files|*.mp3|*'
load_dialog.ofAllowMultiSelect = true
--load_dialog.ofNoLongNames = true
load_dialog.FilterIndex = 1
load_dialog.Execute()

od_files = load_dialog.Files
--cb_items = combobox_getItems(combobox)
--strings_add(cb_items, "Pick a song")
combobox.itemIndex = 0
for i=0,strings_getCount(od_files)-1 do
 file = od_files[i]
 local path, name = file:match('(.*\\)(.*)%.mp3')
 combobox.Items.Add(name..'.mp3')
-- print(od_files[i])
end

UDF1.show()


Try that codes above and next try to implementing to your codes.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL


Last edited by Corroder on Wed Mar 14, 2018 10:11 pm; edited 1 time in total
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Wed Mar 14, 2018 8:46 pm    Post subject: Reply with quote

Thanks @Corroder
This works fine.
I can create a list with multiple selections from the file I want.
Compared to many codes, the code you gave me is the result.
thanks again.


Code:
function CEButton1Click(sender)
combobox = UDF1.CEComboBox1
load_dialog = UDF1.CEOpenDialog1

load_dialog.InitalDir = os.getenv('%USERPROFILE%')
load_dialog.Filter = 'MP3 files|*.mp3|*'
load_dialog.FilterIndex = 1
load_dialog.Execute()

od_files = load_dialog.Files
combobox.itemIndex = 0
for i=0,strings_getCount(od_files)-1 do
 file = od_files[i]
 local path, name = file:match('(.*\\)(.*)%.mp3')
 combobox.Items.Add(name..'.mp3')
end
end
UDF1.show()

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites