Class: GamesAndRpgParadise::GUI::UniversalWidgets::SimpleGamebook

Inherits:
Base
  • Object
show all
Includes:
UniversalWidgets::BaseModule
Defined in:
lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb

Overview

GamesAndRpgParadise::GUI::UniversalWidgets::SimpleGamebook

Constant Summary collapse

TITLE =
#

TITLE

#
'Simple Gamebook'
WIDTH =
#

WIDTH

#
'85% or minimum 1820px'
HEIGHT =
#

HEIGHT

#
'80% or minimum 1480px'
LARGER_FONT =
#

LARGER_FONT

#
:hack_38
SLIGHTLY_SMALLER_FONT =
#

SLIGHTLY_SMALLER_FONT

#
:hack_33
USE_THIS_FONT =
#

USE_THIS_FONT

#
:hack_28
SMALLER_FONT =
#

SMALLER_FONT

#
:hack_25
HASH_DESIGNATED_KEY_COMBINATIONS =
#

HASH_DESIGNATED_KEY_COMBINATIONS

Add useful key-combinations to the following Hash.

#
{
  'alt+1':  'activate_this_tab(1)',
  'alt+2':  'activate_this_tab(2)',
  'alt+3':  'activate_this_tab(3)',
  'alt+4':  'activate_this_tab(4)',
  'alt+5':  'activate_this_tab(5)',
  'alt+6':  'activate_this_tab(6)',
  'alt+7':  'activate_this_tab(7)',
  'alt+8':  'activate_this_tab(8)',
  'alt+9':  'activate_this_tab(9)'
}

Constants included from Base::Extensions::Colours

Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS

Constants included from CommonExtensions

CommonExtensions::CONTROL_C_CODE, CommonExtensions::N

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base::Extensions::Colours

ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow

Methods included from Base::Extensions::CommandlineArguments

#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments

Methods included from CommonExtensions

#cat, #cd, #cliner, #copy_file, #delete, #dirname_but_retains_the_trailing_slash, #disable_colours, #ensure_that_the_log_directory_exists, #esystem, #get_user_input, #infer_the_namespace, #is_on_roebe?, #log_dir?, #mkdir, #mkdir_then_cd_into_it, #mv, #namespace?, #opne, #opnn, #project_base_directory?, #project_image_directory?, #project_yaml_directory?, #rds, #register_sigint, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ SimpleGamebook

#

initialize

#


84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 84

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  super(:vertical) if use_gtk3?
  determine_the_GUI_to_be_used(commandline_arguments) # This must come first, even before reset().
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  on_delete_event_quit_the_application
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

GamesAndRpgParadise::GUI::UniversalWidgets::SimpleGamebook[]

#


422
423
424
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 422

def self.[](i = ARGV)
  new(i)
end

.run(i = ARGV) ⇒ Object

#

GamesAndRpgParadise::GUI::Gtk::SimpleGamebook.run

#


306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 306

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = ::GamesAndRpgParadise::GUI::Gtk::SimpleGamebook.new(i)
  r = ::Gtk.run
  _.set_parent_widget(r) # Must come before we enable the key-combinations.
  r << _
  r.automatic_size_then_automatic_title
  r.enable_quick_exit
  r.set_background :white
  r.top_left_then_run
end

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


176
177
178
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 176

def border_size?
  2
end

#conceal_these_buttons(i = @array_buttons_on_the_bottom) ⇒ Object

#

conceal_these_buttons

#


253
254
255
256
257
258
259
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 253

def conceal_these_buttons(
    i = @array_buttons_on_the_bottom
  )
  if i
    i.each {|entry| entry.hide }
  end
end

#connect_the_skeletonObject

#

connect_the_skeleton (connect tag)

#


363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 363

def connect_the_skeleton
  abort_on_exception

  window = create_window_or_runner
  window.setLayout(FlowLayout.new) # or the next line
  # window.setLayout(GridBagLayout.new), and then GridLayout.new(5, 3) or something like this.

  outer_vbox = create_vbox # In jruby-swing this is Java::JavaxSwing::Box

  hbox1 = create_hbox
  text_to_use = text_font('Current subpage ', main_font?)
  text_to_use.padding(8)
  hbox1.add(text_to_use)
  hbox1.add(entry_current_subpage?)
  outer_vbox << hbox1

  hbox1 = create_hbox
  button_go_to_the_current_subpage = button('Go to the current subpage', self) {
    :go_to_the_current_subpage
  }
  button_go_to_the_current_subpage.use_this_font = main_font?
  hbox1.add(button_go_to_the_current_subpage)
  outer_vbox << hbox1

  hbox3 = create_hbox
  @textview1 = create_textview # For jruby-swing this is a JTextArea.
  @textview1.set_padding(5)
  @textview1.use_this_font = slightly_smaller_font?

  scrolled_window = scroll_pane(@textview1)
  scrolled_window.always_policy

  hbox3.add(scrolled_window)
  outer_vbox << hbox3
  do_load_the_current_subpage
  outer_vbox.show_all
  outer_vbox.add(return_the_button_box_on_bottom)
  properly_prepare_this_window(window,
    {
      widget:      outer_vbox,
      title:       title?,
      font:        font?,
      width:       width?,
      height:      height?,
      padding:     padding?,
      border_size: border_size?
    }
  )
  
  window.show_all
  window.top_left
  window.maximize
  do_all_startup_related_actions
  run_main
end

#create_the_button_box_on_bottomObject

#

create_the_button_box_on_bottom

#


330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 330

def create_the_button_box_on_bottom
  vbox = create_vbox
  10.times {|n_iteration|
    button = create_button
    @array_buttons_on_the_bottom << button
    button.use_this_font = slightly_smaller_font?
    unless n_iteration > 8
      button.keycombo(
        'Alt+'+(n_iteration+1).to_s
      )
    end
    vbox.add(button)
    # ===================================================================== #
    # Next let the button respond to on-clicked events:
    # ===================================================================== #
    button.on_clicked {
      text = button.text?
      text = remove_html(text)
      if text and text.include?(' ')
        target = text.split(' ').first
        do_jump_to_this_target(target)
        # And also change the subpage.
        set_subpage(target)
      end
    }
  }
  @button_box_on_bottom = vbox
  return @button_box_on_bottom
end

#create_the_entriesObject

#

create_the_entries (entries tag, entry tag)

#


189
190
191
192
193
194
195
196
197
198
199
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 189

def create_the_entries
  # ======================================================================= #
  # === @entry_current_subpage
  # ======================================================================= #
  @entry_current_subpage = create_entry
  @entry_current_subpage.set_text('1')
  @entry_current_subpage.use_this_font = main_font?
  @entry_current_subpage.preferred_width_height(220, 25)
  @entry_current_subpage.do_center
  @entry_current_subpage.on_mouse_click_select_everything
end

#create_the_skeletonObject

#

create_the_skeleton (create tag, skeleton tag)

#


271
272
273
274
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 271

def create_the_skeleton
  create_the_button_box_on_bottom
  create_the_entries
end

#current_subpage?Boolean

#

current_subpage?

#

Returns:

  • (Boolean)


204
205
206
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 204

def current_subpage?
  entry_current_subpage?.text?
end
#
#


183
184
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 183

def do_all_startup_related_actions
end

#entry_current_subpage?Boolean Also known as: entry1, entry1?, entry_current_subpage

#

entry_current_subpage?

#

Returns:

  • (Boolean)


279
280
281
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 279

def entry_current_subpage?
  @entry_current_subpage
end

#go_to_the_current_subpage(target_number = current_subpage? ) ⇒ Object Also known as: do_load_the_current_subpage, do_jump_to_this_target

#

go_to_the_current_subpage

#


218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 218

def go_to_the_current_subpage(
    target_number = current_subpage?
  )
  target_number = target_number.to_i # Must be an Integer always.
  pointer = @dataset_from_the_gamebook[target_number]
  if pointer
    content = pointer['content']
    @textview1.set_text(content.to_s.lstrip)
    # Handle the exits next:
    exits = pointer['exits']
    if exits and exits.is_a?(Hash)
      conceal_these_buttons(@array_buttons_on_the_bottom)
      index = 0
      exits.each_pair {|key, value|
        new_value = '<html><b>'+key.to_s+'</b> '+
                     value.to_s+
                     '</html>'
        this_button = @array_buttons_on_the_bottom[index]
        this_button.do_reveal
        # ================================================================= #
        # Next set the text of the button:
        # ================================================================= #
        this_button.set_text(
          new_value
        ) if new_value
        index += 1
      }
    end
  end
end

#handle_CSS_rulesObject

#

handle_CSS_rules (CSS tag)

#


124
125
126
127
128
129
130
131
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 124

def handle_CSS_rules
  use_gtk_paradise_project_css_file
  append_project_css_file
  more_CSS_then_apply_it '


'
end

#load_the_dataset_from_the_gamebookObject

#

load_the_dataset_from_the_gamebook

#


288
289
290
291
292
293
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 288

def load_the_dataset_from_the_gamebook
  # ======================================================================= #
  # === @dataset_from_the_gamebook
  # ======================================================================= #
  @dataset_from_the_gamebook = GamesAndRpgParadise.load_gamebook_dataset(@use_this_gamebook)
end

#main_font?Boolean

#

main_font?

#

Returns:

  • (Boolean)


136
137
138
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 136

def main_font?
  LARGER_FONT
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


169
170
171
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 169

def padding?
  0
end

#resetObject

#

reset (reset tag)

#


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 101

def reset
  super() if respond_to?(:super)
  reset_the_shared_module # This can come early.
  reset_the_base_module
  reset_the_internal_variables
  infer_the_namespace
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, namespace?]
  # ======================================================================= #
  # === Set the title, width, height and the font in use.
  # ======================================================================= #
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  if use_gtk3?
    handle_CSS_rules
  end
  infer_the_size_automatically
end

#reset_the_shared_moduleObject

#

reset_the_shared_module

This method can be used for ruby-gtk3 and ruby-libui, among other toolkits.

#


153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 153

def reset_the_shared_module
  # ======================================================================= #
  # === @use_this_gamebook
  #
  # Keep track of the proper gamebook next.
  # ======================================================================= #
  @use_this_gamebook = :lone_wolf_1
  # ======================================================================= #
  # === @array_buttons_on_the_bottom
  # ======================================================================= #
  @array_buttons_on_the_bottom = []
end

#return_the_button_box_on_bottomObject

#

return_the_button_box_on_bottom

#


323
324
325
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 323

def return_the_button_box_on_bottom
  @button_box_on_bottom
end

#runObject

#

run (run tag)

#


298
299
300
301
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 298

def run
  load_the_dataset_from_the_gamebook
  run_super
end

#set_subpage_value(i) ⇒ Object Also known as: set_subpage

#

set_subpage_value

#


211
212
213
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 211

def set_subpage_value(i)
  entry1?.set_text(i.to_s)
end

#slightly_smaller_font?Boolean

#

slightly_smaller_font?

#

Returns:

  • (Boolean)


264
265
266
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 264

def slightly_smaller_font?
  SLIGHTLY_SMALLER_FONT
end

#smaller_font?Boolean

#

smaller_font?

#

Returns:

  • (Boolean)


143
144
145
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/simple_gamebook/simple_gamebook.rb', line 143

def smaller_font?
  SMALLER_FONT
end